CMake: Managing a list of source files
cmake
Solution
You can do that by using the list command with the REMOVE_ITEM option:
list(REMOVE_ITEM <list> <value> [<value> ...])
Have a look:
file(GLOB FOO *)
set (ITEMS_TO_REMOVE "item;item2;item3")
message(STATUS "FOO is ${FOO}")
list(REMOVE_ITEM FOO ${ITEMS_TO_REMOVE})
message(STATUS "FOO is now ${FOO}")
Keep in mind that the paths returned by `file(GLOB)` are absolute, you might want to build your list of items to remove by prepending `${CMAKE_CURRENT_LIST_DIR}` to each one of them:
set (ITEMS_TO_REMOVE "${CMAKE_CURRENT_LIST_DIR}/item;
${CMAKE_CURRENT_LIST_DIR}/item2;
${CMAKE_CURRENT_LIST_DIR}/item3")
Problem
The problem I'm having at the moment is that I simply wish to manage my list of source files by grabbing everything and removing the few odds and ends that I do not need. I was hoping that Cmake provided nice built-in tools for this. So I might start with: ``` file(GLOB A "Application/*.cpp") ``` I feel like I want to create another list of files to be removed and I want to tell CMake: Remove from list A items that are in list B. If this were Python I might do something like: ``` C = [f for f in A if f not in B] ``` I may have screwed that syntax up but I'm wondering if there is built-in support for managing these lists of files in a more elegant way? Even if I could do something like my Python example, A is list of absolute paths so constructing B is clunky. And why absolute paths anyway? It seems like this will break your build as soon as you relocate the source.