Make MSVC runtime setting available for all projects

This commit is contained in:
Sébastien Gallou 2021-06-11 09:55:01 +02:00
parent 6940d26f2e
commit 47b34ef74c
4 changed files with 39 additions and 32 deletions

View File

@ -114,6 +114,9 @@ message("oatpp version: '${OATPP_THIS_MODULE_VERSION}'")
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
include(cmake/msvc-runtime.cmake)
configure_msvc_runtime()
add_subdirectory(src)
if(OATPP_BUILD_TESTS)

36
cmake/msvc-runtime.cmake Normal file
View File

@ -0,0 +1,36 @@
macro(configure_msvc_runtime)
if(MSVC)
# Set compiler options.
set(variables
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(OATPP_MSVC_LINK_STATIC_RUNTIME)
message(STATUS "MSVC: using statically-linked runtime (/MT and /MTd).")
foreach(variable ${variables})
if(${variable} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
endif()
endforeach()
else()
message(STATUS "MSVC: using dynamically-linked runtime (/MD and /MDd).")
foreach(variable ${variables})
if(${variable} MATCHES "/MT")
string(REGEX REPLACE "/MT" "/MD" ${variable} "${${variable}}")
endif()
endforeach()
endif()
foreach(variable ${variables})
set(${variable} "${${variable}}" CACHE STRING "MSVC_${variable}" FORCE)
endforeach()
endif()
endmacro(configure_msvc_runtime)

View File

@ -278,11 +278,6 @@ set_target_properties(oatpp PROPERTIES
CXX_STANDARD_REQUIRED ON
)
if(OATPP_MSVC_LINK_STATIC_RUNTIME)
include(MSVCStaticRuntime.cmake)
configure_msvc_static_runtime()
endif()
set(CMAKE_THREAD_PREFER_PTHREAD ON)
find_package(Threads REQUIRED)

View File

@ -1,27 +0,0 @@
macro(configure_msvc_static_runtime)
if(MSVC)
# Set compiler options.
set(variables
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO)
message(STATUS "MSVC: using statically-linked runtime (/MT and /MTd).")
foreach(variable ${variables})
if(${variable} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
endif()
endforeach()
foreach(variable ${variables})
set(${variable} "${${variable}}" CACHE STRING "MSVC_${variable}" FORCE)
endforeach()
endif()
endmacro(configure_msvc_static_runtime)