Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove specific file from cmake build

Tags:

cmake

I have a project in which i have essentially two main methods. One for testing and one for, well, running the code. Normally you would create submodules, but this is not an option.

file(GLOB sources "*.cpp") file(GLOB headers "*.h") add_executable(testing ${sources} ${headers})    add_executable(main ${sources} ${headers})    

So testing should compile all sources except for main.cpp. Main should compile everything but testing.cpp.

like image 766
CodeTower Avatar asked May 08 '13 20:05

CodeTower


People also ask

Can I delete CMakeCache txt?

Deleting CMakeCache. txt should not affect any binaries, a full rebuild is not triggered. Otherwise you might have a local variable passed on before being cached which then leads to inconsistent runs. The regeneration of the project can trigger rebuilds if the configuration is different to the previous one.

How do I delete a folder in CMake?

But if instead cmake -E remove_directory you would use rmdir /Q /S command the links are not followed and the directories are unlinked in both cases.

What does CMake -- Build do?

CMake can generate a native build environment that will compile source code, create libraries, generate wrappers and build executables in arbitrary combinations. CMake supports in-place and out-of-place builds, and can therefore support multiple builds from a single source tree.


1 Answers

The normal way would probably be to create a library from all the sources except main.cpp and testing.cpp, then link this to each executable. However, I guess you mean you can't do that when you say you can't create submodules.

Instead, you can use the list(REMOVE_ITEM ...) command:

file(GLOB sources "*.cpp") file(GLOB headers "*.h") set(testing_sources ${sources}) list(REMOVE_ITEM testing_sources ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) list(REMOVE_ITEM sources ${CMAKE_CURRENT_SOURCE_DIR}/testing.cpp) add_executable(main ${sources} ${headers}) add_executable(testing ${testing_sources} ${headers}) 
like image 66
Fraser Avatar answered Sep 20 '22 17:09

Fraser