我有多个项目,它们各自的CMakeLists.txt中具有相同/重复的代码。至少我需要一个位置来存储可以放入CMakeLists.txt文件的字符串定义。最好的方法是什么?我的目录结构
common_defs/
src_files
hdr_files
CMakeLists.Txt - file that has common defs
independent_dir1/
src_files
hdr_files
CMakeLists.Txt --> Imports/Includes from ../common_defs/CMakeLists.txt
independent_dir2/
src_files
hdr_files
CMakeLists.Txt --> Imports/Includes from ../common_defs/CMakeLists.txt
independent_dir1和Independent_dir2将彼此独立地构建。在common_defs中构建不应触发在Independent_dirs中构建
答案 0 :(得分:1)
在common_defs/common_defs.cmake
中使用通用字符串和定义创建文件,然后将其添加到CMakeLists.txt:
// add path common_defs to include search path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../common_defs")
// include module from file common.cmake searched in search path
include(common_defs)