Question

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

I have written a CTest script that runs continuous tests on my project and submit to a dashboard. I would like to use the suppression file during the memory-checking stage. 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?

Was it helpful?

Solution

You can't directly access CMake cache variables from the ctest -S script.

However, you could possibly:

  1. include the third party CMake script in the ctest -S script with "include" (after the update step, so the source tree is up to date)
  2. read the CMakeCache.txt file after the configure step to pull out the cache variable of interest
  3. add code to your CMakeLists.txt file to write out a mini-script that contains just the information you're looking for

For (1), the code would be something like:

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

This would only be realistically possible if the script does only simple things like set variable values that you can then reference. If it does any CMake-configure-time things like find_library or add_executable, then you shouldn't 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 your ctest -S script, after the ctest_configure call:

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top