[CMake] How to append a string on list inside a function
Romain LEGUAY
romain.leguay at gmail.com
Thu Sep 27 06:43:24 EDT 2018
Hello everyone,
I try to append a string (target name) on a list inside a function called in other CMakeLists.
I have the following project’s tree:
├── CMakeLists.txt
├── test
├── CMakeLists.txt
└── app
├── CMakeLists.txt
├── appA
│ ├── CMakeLists.txt
│ └── main.cpp
└── appB
├── CMakeLists.txt
└── main.cpp
Inside the test/CMakeLists.txt, I defined an internal variable like this:
set(allTestsList "" CACHE INTERNAL "All executable tests.'')
And my function:
function(addTest targetName)
# create the executable with all the souces
add_executable(${targetName} ${ARGN})
list(APPEND allTestsList ${targetName})
message("inside addTestFunction. allTestsList: " ${allTestsList})
endfunction()
I call this function inside the test/app/appA and test/app/appB CMakeLists.txt like this:
addTest(appA main.cpp)
addTest(appB main.cpp)
I expected to have as final result:
inside addTestFunction. allTestsList: appA;appB
But I only have:
inside addTestFunction. allTestsList: appB
I suspect that a new variable is created at each call of the function.
Is it possible to use a global variable? (I tried to use PARENT_SCOPE with no success).
Thank you,
Romain
More information about the CMake
mailing list