【发布时间】:2015-03-16 07:12:39
【问题描述】:
在我的 CMake 项目中,我设置了如下编译器标志:
if (MSVC)
# Build cpp files on all cores
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /W4")
# can't use the "secure" versions as they're Windows specific
add_definitions("/D\"_CRT_SECURE_NO_WARNINGS\"")
add_definitions("/D\"_SCL_SECURE_NO_WARNINGS\"")
add_definitions("/wd4290")
else()
# Enable C++11, you may need to use -std=c++0x if using an older gcc compiler
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-unused-parameter -fPIC -Wall -Weffc++ -pedantic")
endif()
endif()
为 MSVC、Clang 和 GCC 设置标志。但是,在我的源文件 var 中,我有我的源代码和 gtest 和 gmock 等第 3 方的东西。
如何设置这些标志,使其仅适用于我的源代码的某些子集?
例如
# This should use the flags set above
SET(source
mycode/mysrc.cpp)
# This should not use the flags from above
SET(not_my_source
3rdparty/3rdparty.cpp)
# But both end up being part of the same executable
add_executable(Test ${source} ${not_my_source})
【问题讨论】: