diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f496471..af146aab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ option(BUILD_SHARED_LIBS "Build shared libraries" OFF) option(OATPP_INSTALL "Create installation target for oat++" ON) option(OATPP_BUILD_TESTS "Create test target for oat++" ON) option(OATPP_LINK_ATOMIC "Link atomic library for other platform than MSVC|MINGW|APPLE|FreeBSD" ON) +option(OATPP_MSVC_LINK_STATIC_RUNTIME "MSVC: Link with static runtime (/MT and /MTd)." OFF) ################################################################################################### ## COMPILATION CONFIG ############################################################################# @@ -113,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) diff --git a/cmake/msvc-runtime.cmake b/cmake/msvc-runtime.cmake new file mode 100644 index 00000000..42338978 --- /dev/null +++ b/cmake/msvc-runtime.cmake @@ -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) \ No newline at end of file