Remove specific file from cmake build

后端 未结 1 518
刺人心
刺人心 2020-12-24 06:15

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

相关标签:
1条回答
  • 2020-12-24 06:46

    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})
    
    0 讨论(0)
提交回复
热议问题