我正在cmake中迁移make build系统,因此我需要使用不同的2标志编译源文件,然后创建静态库。例如,我有
$(OBJSGEN):$(OBJDIR1)/%。o:$(SRCDIR)/%。cpp
$(CC)$(FLAGS)$(CFLAGS)$(DFLAGS)$(EFLAGS1)$(INCLUDES)-c $< -o $ @
任何人都可以帮帮我吗?
提前致谢
答案 0 :(得分:2)
您可以使用CMake object libraries执行此操作:
# compiles source.cpp with -DSOME_DEF=1
add_library(obj1 OBJECT source.cpp)
# This is the "modern" syntax for setting preprocessor definitions:
target_compile_definitions(obj1 PRIVATE SOME_DEF=1)
# compiles source.cpp with -DSOME_DEF=2
add_library(obj2 OBJECT source.cpp)
# This is the "old" way of setting preprocessor definitions:
set_target_properties(obj2 PROPERTIES
COMPILE_DEFINITIONS SOME_DEF=2)
# creates a static library with both objects
add_library(lib STATIC
$<TARGET_OBJECTS:obj1>
$<TARGET_OBJECTS:obj2>)
编辑:我使用set_target_properties
包含了与每个目标设置预处理器定义的CMake 2.8兼容方式。