Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a list of files matching a pattern in CMake?

Tags:

cmake

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.

like image 558
becko Avatar asked Jul 31 '15 21:07

becko


People also ask

What is ${} in CMake?

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.

What is a .CMake file?

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.


1 Answers

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

like image 183
Anoop Avatar answered Nov 15 '22 07:11

Anoop