[CMake] Accessing cache variable from CTest script

David Cole david.cole at kitware.com
Fri Aug 24 10:53:32 EDT 2012


On Fri, Aug 24, 2012 at 10:42 AM, David Cole <david.cole at kitware.com> wrote:
> On Fri, Aug 24, 2012 at 9:46 AM, Davide Mancusi <arekfu at gmail.com> wrote:
>>
>> Hello everyone,
>>
>> I have tried asking this question on stackoverflow [1] without much
>> luck, so here we go:
>>
>> 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 to build and test my project and 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?
>>
>> Thanks in advance for the help.
>> Davide
>>
>> [1] http://stackoverflow.com/questions/12108741/access-cmake-cache-variable-from-ctest-script
>> --
>>
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>
>
>
> I've answered on stackoverflow directly.
>
> For the mailing list record, here's the initial answer I gave there:
>
>
> 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
>
> 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}'")


Solution (3) also may be a possibility that some would prefer over the
first two suggested:

  http://stackoverflow.com/a/12111587/236192


Cheers,
David


More information about the CMake mailing list