Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>OK - This answer feels a bit fragile since it's making use of undocumented CMake behaviour. However, it does seem to work.</p> <p>Towards the end of the configuring process, after all commands in the CMakeLists.txt file have been processed, CMake checks the value of <a href="http://www.cmake.org/cmake/help/v2.8.10/cmake.html#variable%3aCMAKE_BACKWARDS_COMPATIBILITY" rel="nofollow" title="CMake v2.8.10 documentation for &quot;CMAKE_BACKWARDS_COMPATIBILITY&quot; variable"><code>CMAKE_BACKWARDS_COMPATIBILITY</code></a>. If this variable is being watched via the <a href="http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command%3avariable_watch" rel="nofollow" title="CMake v2.8.10 documentation for &quot;variable_watch&quot; command"><code>variable_watch</code></a> command, then it will be triggered here.</p> <p>So you can wrap this functionality into a couple of functions:</p> <pre><code>function(EOFHook Variable Access) if(${Variable} STREQUAL CMAKE_BACKWARDS_COMPATIBILITY AND (${Access} STREQUAL UNKNOWN_READ_ACCESS OR ${Access} STREQUAL READ_ACCESS)) execute_process(COMMAND ${CMAKE_COMMAND} -E echo "In EOF hook command") ... do whatever else is required ... endif() endfunction() function(SetupEOFHook) variable_watch(CMAKE_BACKWARDS_COMPATIBILITY EOFHook) endfunction() </code></pre> <p>To use this in any CMakeLists file, simply call <code>SetupEOFHook()</code> anywhere in the file.</p> <p>It's a bit risky; if the variable is also read elsewhere in the CMakeLists.txt e.g. via</p> <pre><code>message(${CMAKE_BACKWARDS_COMPATIBILITY}) </code></pre> <p>then it would trigger the <code>EOFHook</code> function here <em>and</em> at the end. You could add more complexity to the function by adding a counter and checking that it's only called once or else issue a <code>message(FATAL_ERROR ...)</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload