如何使用 cmd 行参数不编译 CMakeList 的部分.txt
How to not compile parts of CMakeLists.txt using cmd line parameters?
我正在使用CMake 3.10.2,并将其放在我的目标CMakeLists.txt文件之一中。
target_compile_definitions(mytarget PUBLIC USE_MY=${USE_MY})
然后,我可以在命令行上使用参数,例如 -DUSE_MY=0,以便我可以将这样的东西放在我的 c++ 文件中:
#ifdef USE_MY
// code left out
#endif
但是,我也希望能够省略 CMakeList 中的文件.txt从编译中。
set(my_sources
filea.cpp
fileb.cpp
filec.cpp (how would I leave out filec.cpp?)
)
在我的顶级CMakeLists.txt中,省略了整个库。
add_subdirectory(my_stuff/liba)
add_subdirectory(my_stuff/libb) (how to leave out this lib?)
add_subdirectory(my_stuff/libc
因此,我也想省略某些文件和目标的编译。感谢您对此的任何帮助。
正如@drescherjm所建议的,这样的东西可能对你有用:
set(my_sources
filea.cpp
fileb.cpp
)
if(USE_MY)
# Append filec if USE_MY is defined.
set(my_sources ${my_sources} filec.cpp)
endif()
同样地
add_subdirectory(my_stuff/liba)
if(USE_MY)
add_subdirectory(my_stuff/libb)
endif()
add_subdirectory(my_stuff/libc
# ... other code here ...
# Link the libraries.
target_link_libraries(targetA ${my_liba} ${my_libc})
if(USE_MY)
target_link_libraries(targetA ${my_libb})
endif()
在现代CMake中,你会做这样的事情:
add_subdirectory(my_stuff/liba)
if (USE_MY)
add_subdirectory(my_stuff/libb)
endif()
add_subdirectory(my_stuff/libc
然后对于来源:
add_library(libB source1.cpp source2.cpp source3.cpp)
if (USE_MY)
target_sources(libB source4.cpp source5.cpp)
endif()
相关文章:
- 更正 CMakeList.txt 用于谷歌测试的文件?
- 在Cmake构建CmakeList.txt中读取/解析XML文件
- 如果我想链接静态库并删除未使用的符号.txt我应该如何处理 Cmakelist
- CMakeList 中应包含哪些模块.txt以进行近似最近邻搜索?
- 如何在不同的CMakeList.txt之间共享变量?
- 如何使用cmake从主要的CMakeList.txt复制目标文件?
- 将 OpenSSL 包含在 CMakeList.txt 文件中
- C++带有 CMakeList 的地址清理器.txt会导致 asan 错误
- 如何在 CMakeList 中包含 h/hpp 头文件.txt而不是 cpp 或其他 hpp 文件
- 适应cmakelist.txt与cuda一起运行
- 用cmakelist.txt在clion上以一种不错的便携式方式配置sdl2
- 如何使用 cmd 行参数不编译 CMakeList 的部分.txt
- 我想使用 CMakeList 将 ODBC 集成到我的 Linux 和 Windows 代码中.txt但它只能在 Win
- 为什么 CMake 没有链接这个 CMakeList 中的 pthread.txt
- 使用动态库 qpOASES 和 CMakeList.txt 时对 qpOASES 错误的未定义引用
- C++ 如何使用CMakeList.txt链接mongoc和mongocxx静态库
- 我的CMakeList.txt出了什么问题?
- 我如何使用find_package在CMakeList.txt中链接Boost(不在usr/include中)
- 将"CmakeList.txt"移动到 Clion 中的另一个文件夹
- 我应该从源文件夹分离CMakeList.txt