C++ 如何为CMake中的文件组设置编译器标志?
在我的CMake项目中,我设置了如下编译器标志:C++ 如何为CMake中的文件组设置编译器标志?,c++,cmake,C++,Cmake,在我的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\"") ad
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
如何设置这些标志,使其仅应用于源代码的某些子集
例如
您可能需要参考。您应该能够传递要更改其编译器标志的文件列表。可能重复的文件
# 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})