<div dir="ltr">Is there a way to have CMake script delete a cache variable?&nbsp; I do realize CMake allows me to do this:<br><br>1. hide it away as an internal cache variable<br>2. mark it as advanced and bury it<br>3. set it to FOO-NOTFOUND prior to calling FIND_LIBRARY()<br>
<br>None of these will work for my use case.&nbsp; Option 3 makes it impossible for the user to set the cache variable manually, option 1 makes it impossible to bring it back from an internal state without using force (which is not acceptable), option 2 hides the problem but doesn&#39;t solve it.<br>
<br>The use case is:<br><br>1. On MSVC or when a particular CMake variable is set (let&#39;s call it FOO_HUNT_FOR_DEBUG), hunt for and expose FOO_LIBRARY_DEBUG, BAR_LIBRARY_DEBUG, etc. using find_library()<br>2. Otherwise set FOO_LIBRARY_DEBUG to FOO_LIBRARY, BAR_LIBRARY to BAR_LIBRARY_DEBUG, etc. but don&#39;t expose these via the cache since they will not be editable and exposing them will at best clutter up the cache, at worst confuse people when they try to set them, to no avail.<br>
3. The user should be able to toggle FOO_HUNT_FOR_DEBUG between true/false on non-MSVC platforms and have the DEBUG cache variables go away when set to false<br><br>Relevant code snippit:<br><br>&nbsp;&nbsp; if(MSVC OR OSG_FIND_LIBRARY_SEARCH_DEBUG)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set(${module_uc}_LIBRARY_DEBUG &quot;${module_uc}_LIBRARY_DEBUG-NOTFOUND&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # When compiling with VS, search for debug libraries since they are<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # nearly always needed at runtime.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; find_library(${module_uc}_LIBRARY_DEBUG<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NAMES ${library}d<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HINTS<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ENV{${module_uc}_DIR}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ENV{OSG_DIR}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ENV{OSGDIR}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PATH_SUFFIXES lib64 lib<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PATHS<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;snip&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br>&nbsp;&nbsp; else(MSVC OR OSG_FIND_LIBRARY_SEARCH_DEBUG)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # On all other platforms there is no requirement to link<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # debug targets against debug libraries and release targets<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # against release libraries so just set the FOO_LIBRARY_DEBUG<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # for the users&#39; convenience in calling target_link_libraries()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # once.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set(${module_uc}_LIBRARY_DEBUG ${${module_uc}_LIBRARY})<br>&nbsp;&nbsp;&nbsp; endif(MSVC OR OSG_FIND_LIBRARY_SEARCH_DEBUG)<br>
<br>endfunction(_OSG_FIND_LIBRARY module library)<br><br><br>-- <br>Philip Lowman<br>
</div>