How can I define a variable in CMake containing a list of files that match a pattern? For instance, test_*.cpp
?
And how can I define a variable containing a list of files that DON'T match a pattern? For instance, test_*.cpp
should match all files EXCEPT those matched above.
Local Variables You access a variable by using ${} , such as ${MY_VARIABLE} . 1. CMake has the concept of scope; you can access the value of the variable after you set it as long as you are in the same scope. If you leave a function or a file in a sub directory, the variable will no longer be defined.
A CMAKE file is a project file created by the open-source, cross-platform tool CMake. It contains source script in the CMake language for the entire program. CMake tool uses programming scripts, known as CMakeLists, to generate build files for a specific environment such as makefiles Unix machine.
For matching the source files of a particular pattern , you can use globbing pattern.
file(GLOB_RECURSE TEST_FILES
"${PROJECT_SOURCE_DIR}/src/test_*.cpp"
)
I'm not sure of how to exclude those specific files, maybe excluding them from the list of all the files work , like this
file(GLOB_RECURSE SRC_FILES
"${PROJECT_SOURCE_DIR}/src/*.cpp"
)
list(REMOVE_ITEM ${SRC_FILES} ${TEST_FILES})
I was referring to list REMOVE_ITEM
from this source http://www.cmake.org/cmake/help/v3.0/command/list.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With