Skip to content

Commit

Permalink
defaulting compiler.runtime for msvc (#609)
Browse files Browse the repository at this point in the history
* defaulting compiler.runtime for msvc

* review
  • Loading branch information
memsharded authored Jan 10, 2024
1 parent c53fbf5 commit b27d3ee
Showing 1 changed file with 31 additions and 26 deletions.
57 changes: 31 additions & 26 deletions conan_provider.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -195,37 +195,42 @@ function(detect_compiler COMPILER COMPILER_VERSION COMPILER_RUNTIME COMPILER_RUN
string(SUBSTRING ${MSVC_VERSION} 0 3 _COMPILER_VERSION)
# Configure compiler.runtime and compiler.runtime_type settings for MSVC
if(CMAKE_MSVC_RUNTIME_LIBRARY)
set(_KNOWN_MSVC_RUNTIME_VALUES "")
list(APPEND _KNOWN_MSVC_RUNTIME_VALUES MultiThreaded MultiThreadedDLL)
list(APPEND _KNOWN_MSVC_RUNTIME_VALUES MultiThreadedDebug MultiThreadedDebugDLL)
list(APPEND _KNOWN_MSVC_RUNTIME_VALUES MultiThreaded$<$<CONFIG:Debug>:Debug> MultiThreaded$<$<CONFIG:Debug>:Debug>DLL)

# only accept the 6 possible values, otherwise we don't don't know to map this
if(NOT CMAKE_MSVC_RUNTIME_LIBRARY IN_LIST _KNOWN_MSVC_RUNTIME_VALUES)
message(FATAL_ERROR "CMake-Conan: unable to map MSVC runtime: ${CMAKE_MSVC_RUNTIME_LIBRARY} to Conan settings")
endif()
set(_msvc_runtime_library ${CMAKE_MSVC_RUNTIME_LIBRARY})
else()
set(_msvc_runtime_library MultiThreaded$<$<CONFIG:Debug>:Debug>DLL) # default value documented by CMake
endif()

set(_KNOWN_MSVC_RUNTIME_VALUES "")
list(APPEND _KNOWN_MSVC_RUNTIME_VALUES MultiThreaded MultiThreadedDLL)
list(APPEND _KNOWN_MSVC_RUNTIME_VALUES MultiThreadedDebug MultiThreadedDebugDLL)
list(APPEND _KNOWN_MSVC_RUNTIME_VALUES MultiThreaded$<$<CONFIG:Debug>:Debug> MultiThreaded$<$<CONFIG:Debug>:Debug>DLL)

# only accept the 6 possible values, otherwise we don't don't know to map this
if(NOT _msvc_runtime_library IN_LIST _KNOWN_MSVC_RUNTIME_VALUES)
message(FATAL_ERROR "CMake-Conan: unable to map MSVC runtime: ${_msvc_runtime_library} to Conan settings")
endif()

# Runtime is "dynamic" in all cases if it ends in DLL
if(_msvc_runtime_library MATCHES ".*DLL$")
set(_COMPILER_RUNTIME "dynamic")
else()
set(_COMPILER_RUNTIME "static")
endif()
message(STATUS "CMake-Conan: CMake compiler.runtime=${_COMPILER_RUNTIME}")

# Runtime is "dynamic" in all cases if it ends in DLL
if(CMAKE_MSVC_RUNTIME_LIBRARY MATCHES ".*DLL$")
set(_COMPILER_RUNTIME "dynamic")
# Only define compiler.runtime_type when explicitly requested
# If a generator expression is used, let Conan handle it conditional on build_type
if(NOT _msvc_runtime_library MATCHES "<CONFIG:Debug>:Debug>")
if(_msvc_runtime_library MATCHES "Debug")
set(_COMPILER_RUNTIME_TYPE "Debug")
else()
set(_COMPILER_RUNTIME "static")
set(_COMPILER_RUNTIME_TYPE "Release")
endif()
message(STATUS "CMake-Conan: CMake compiler.runtime_type=${_COMPILER_RUNTIME_TYPE}")
endif()

# Only define compiler.runtime_type when explicitly requested
# If a generator expression is used, let Conan handle it conditional on build_type
get_property(_IS_MULTI_CONFIG_GENERATOR GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(NOT CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "<CONFIG:Debug>:Debug>")
if(CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "Debug")
set(_COMPILER_RUNTIME_TYPE "Debug")
else()
set(_COMPILER_RUNTIME_TYPE "Release")
endif()
endif()
unset(_KNOWN_MSVC_RUNTIME_VALUES)

unset(_KNOWN_MSVC_RUNTIME_VALUES)
unset(_IS_MULTI_CONFIG_GENERATOR)
endif()
elseif(_COMPILER MATCHES AppleClang)
set(_COMPILER "apple-clang")
string(REPLACE "." ";" VERSION_LIST ${CMAKE_CXX_COMPILER_VERSION})
Expand Down

0 comments on commit b27d3ee

Please sign in to comment.