[CMake] How to exclude some files from building?
kipade
kipade at 163.com
Fri Mar 31 04:00:48 EDT 2017
Oh, I got it. I think the first method was so cool.
Thank you very much.
At 2017-03-31 14:10:12, "Domen Vrankar" <domen.vrankar at gmail.com> wrote:
2017-03-31 4:41 GMT+02:00 kipade <kipade at 163.com>:
There are some files I do not want to build if the specified condition was ture.
For example, for testing, I want build a new file witch include a main entry just
for testing; if not, a new file would be compile for normal task.
I do not want to write two main entries in the same file just using macros to
control compiling. I want to use different clean and simple files.
So, how to do it?
You can either use generator expressions:
-------------------------
cmake_minimum_required(VERSION 3.5)
project(dependent CXX)
set(MY_DEPEND "ON" CACHE BOOL "toggle feature")
add_executable(
${PROJECT_NAME}
main.cpp
$<$<BOOL:${MY_DEPEND}>:first/a.cpp>
$<$<NOT:$<BOOL:${MY_DEPEND}>>:second/a.cpp>
)
target_include_directories(
${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}"
)
-------------------------
Or add files to a variable:
-------------------------
cmake_minimum_required(VERSION 3.5)
project(dependent CXX)
set(MY_DEPEND "ON" CACHE BOOL "toggle feature")
if(MY_DEPEND)
set(extra_src_ "first/a.cpp")
else()
set(extra_src_ "second/a.cpp")
endif()
add_executable(
${PROJECT_NAME}
main.cpp
${extra_src_}
)
target_include_directories(
${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}"
)
-------------------------
Regards,
Domen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170331/0831f36e/attachment-0001.html>
More information about the CMake
mailing list