Access CMake cache variable from CTest script

My project references a third-party library that comes with the valgrind suppression file, as well as a CMake script. The script stores the location of the suppression file in the CMake cache variable.

I wrote a CTest script that runs continuous tests in my project and is sent to the toolbar. I would like to use the suppression file in the memory check phase. Unfortunately, the CTest script does not seem to know anything about the CMake cache. How can I access the CMake cache variable from my CTest script?

+4
source share
2 answers

You cannot directly access CMake cache variables from ctest -S script.

However, you could:

  • enable third-party CMake script in ctest -S script with "enable" (after the update step, so the source tree is updated)
  • read the CMakeCache.txt file after the configuration step to pull out the cache of interest
  • add code to your CMakeLists.txt file to write a mini-script that contains only the information you are looking for.

For (1), the code will look something like this:

include(${CTEST_SOURCE_DIRECTORY}/path/to/3rdParty/script.cmake) 

It would be real if the script does only simple things, such as given values โ€‹โ€‹of variables, which you can then reference. If it performs any CMake-configure-time actions, such as find_library or add_executable, then you should not do this.

For (2):

 file(STRINGS ${CTEST_BINARY_DIRECTORY}/CMakeCache.txt result REGEX "^CURSES_LIBRARY:FILEPATH=(.*)$") message("result='${result}'") string(REGEX REPLACE "^CURSES_LIBRARY:FILEPATH=(.*)$" "\\1" filename "${result}") message("filename='${filename}'") 

For (3):

In the CMakeLists.txt file:

 file(WRITE "${CMAKE_BINARY_DIR}/mini-script.cmake" " set(supp_file \"${supp_file_location}\") ") 

In ctest -S script after calling ctest_configure:

 include("${CTEST_BINARY_DIRECTORY}/mini-script.cmake") message("supp_file='${supp_file}'") # use supp_file as needed in the rest of your script 
+3
source

Tests should be configured in your CMakeLists.txt file using the ADD_TEST() command. The CTest script then simply calls ctest_test() to run all configured tests. By doing this this way, you gain access to cache variables, plus you can just run make test at any time to run the tests. Save the CTest script for nightly testing and / or sending Dashboard.

0
source

All Articles