CMake+VisualStudio联合编译选项
if(MSVC)
#add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/source-charset:utf-8>")
#add_compile_options("$<$<C_COMPILER_ID:MSVC>:/source-charset:utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
endif()
if(MSVC)
MESSAGE(STATUS "CMAKE_BUILD_TYPE=" ${CMAKE_BUILD_TYPE})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -bigobj")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -bigobj")
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELWITHDEBINFO
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
set(${CompilerFlag} "${${CompilerFlag}}" CACHE STRING "msvc compiler flags" FORCE)
message("MSVC flags: ${CompilerFlag}:${${CompilerFlag}}")
endforeach()
add_compile_options("/source-charset:utf-8" "/W4" "/bigobj" "/std:c++latest" "/IGNORE:4200"
"$<$<CONFIG:>:/MT>"
"$<$<CONFIG:Debug>:/MTd>"
"$<$<CONFIG:Release>:/MT>"
"$<$<CONFIG:Profile>:/MT>"
"$<$<CONFIG:MinSizeRel>:/MT>"
"$<$<CONFIG:RelWithDebInfo>:/MT>")
endif(MSVC)
或
target_compile_options(
${Project_Name} PUBLIC
$<$<CONFIG:>:/MT> #---------|
$<$<CONFIG:Debug>:/MTd> #---|-- Statically link the runtime libraries
$<$<CONFIG:Release>:/MT> #--|
$<$<CONFIG:Profile>:/MT> #--|
$<$<CONFIG:MinSizeRel>:/MT> #--|
$<$<CONFIG:RelWithDebInfo>:/MT> #--|
)