Skip to content

Commit

Permalink
ci: detect compiler runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
dvirtz committed Sep 8, 2023
1 parent 005126b commit ce0fdfa
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions packages/parquet-reader/cmake/conan_provider.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function(detect_lib_cxx OS LIB_CXX)
endfunction()


function(detect_compiler COMPILER COMPILER_VERSION)
function(detect_compiler COMPILER COMPILER_VERSION COMPILER_RUNTIME COMPILER_RUNTIME_TYPE)
if(DEFINED CMAKE_CXX_COMPILER_ID)
set(_COMPILER ${CMAKE_CXX_COMPILER_ID})
set(_COMPILER_VERSION ${CMAKE_CXX_COMPILER_VERSION})
Expand All @@ -116,6 +116,39 @@ function(detect_compiler COMPILER COMPILER_VERSION)
if(_COMPILER MATCHES MSVC)
set(_COMPILER "msvc")
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()

# Runtime is "dynamic" in all cases if it ends in DLL
if(CMAKE_MSVC_RUNTIME_LIBRARY MATCHES ".*DLL$")
set(_COMPILER_RUNTIME "dynamic")
else()
set(_COMPILER_RUNTIME "static")
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(_IS_MULTI_CONFIG_GENERATOR)
endif()
elseif(_COMPILER MATCHES AppleClang)
set(_COMPILER "apple-clang")
string(REPLACE "." ";" VERSION_LIST ${CMAKE_CXX_COMPILER_VERSION})
Expand All @@ -132,9 +165,17 @@ function(detect_compiler COMPILER COMPILER_VERSION)

message(STATUS "CMake-Conan: [settings] compiler=${_COMPILER}")
message(STATUS "CMake-Conan: [settings] compiler.version=${_COMPILER_VERSION}")
if (_COMPILER_RUNTIME)
message(STATUS "CMake-Conan: [settings] compiler.runtime=${_COMPILER_RUNTIME}")
endif()
if (_COMPILER_RUNTIME_TYPE)
message(STATUS "CMake-Conan: [settings] compiler.runtime_type=${_COMPILER_RUNTIME_TYPE}")
endif()

set(${COMPILER} ${_COMPILER} PARENT_SCOPE)
set(${COMPILER_VERSION} ${_COMPILER_VERSION} PARENT_SCOPE)
set(${COMPILER_RUNTIME} ${_COMPILER_RUNTIME} PARENT_SCOPE)
set(${COMPILER_RUNTIME_TYPE} ${_COMPILER_RUNTIME_TYPE} PARENT_SCOPE)
endfunction()

function(detect_build_type BUILD_TYPE)
Expand All @@ -149,7 +190,7 @@ endfunction()
function(detect_host_profile output_file)
detect_os(MYOS MYOS_API_LEVEL MYOS_SDK MYOS_SUBSYSTEM MYOS_VERSION)
detect_arch(MYARCH)
detect_compiler(MYCOMPILER MYCOMPILER_VERSION)
detect_compiler(MYCOMPILER MYCOMPILER_VERSION MYCOMPILER_RUNTIME MYCOMPILER_RUNTIME_TYPE)
detect_cxx_standard(MYCXX_STANDARD)
detect_lib_cxx(MYOS MYLIB_CXX)
detect_build_type(MYBUILD_TYPE)
Expand Down Expand Up @@ -181,6 +222,12 @@ function(detect_host_profile output_file)
if(MYCOMPILER_VERSION)
string(APPEND PROFILE compiler.version=${MYCOMPILER_VERSION} "\n")
endif()
if(MYCOMPILER_RUNTIME)
string(APPEND PROFILE compiler.runtime=${MYCOMPILER_RUNTIME} "\n")
endif()
if(MYCOMPILER_RUNTIME_TYPE)
string(APPEND PROFILE compiler.runtime_type=${MYCOMPILER_RUNTIME_TYPE} "\n")
endif()
if(MYCXX_STANDARD)
string(APPEND PROFILE compiler.cppstd=${MYCXX_STANDARD} "\n")
endif()
Expand Down

0 comments on commit ce0fdfa

Please sign in to comment.