Skip to content

Commit 3c991f5

Browse files
committed
add new conan_provider
1 parent 3c5806f commit 3c991f5

1 file changed

Lines changed: 56 additions & 22 deletions

File tree

cmake/conan_provider.cmake

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,14 @@ function(detect_arch arch)
135135
endfunction()
136136

137137

138-
function(detect_cxx_standard cxx_standard)
138+
function(detect_cxx_standard compiler cxx_standard)
139139
set(${cxx_standard} ${CMAKE_CXX_STANDARD} PARENT_SCOPE)
140140
if(CMAKE_CXX_EXTENSIONS)
141-
set(${cxx_standard} "gnu${CMAKE_CXX_STANDARD}" PARENT_SCOPE)
141+
if(compiler STREQUAL "msvc")
142+
set(${cxx_standard} "${CMAKE_CXX_STANDARD}" PARENT_SCOPE)
143+
else()
144+
set(${cxx_standard} "gnu${CMAKE_CXX_STANDARD}" PARENT_SCOPE)
145+
endif()
142146
endif()
143147
endfunction()
144148

@@ -356,8 +360,10 @@ macro(append_compiler_executables_configuration)
356360
# Not necessary to warn if RC not defined
357361
endif()
358362
if(NOT "x${_conan_compilers_list}" STREQUAL "x")
359-
string(REPLACE ";" "," _conan_compilers_list "${_conan_compilers_list}")
360-
string(APPEND profile "tools.build:compiler_executables={${_conan_compilers_list}}\n")
363+
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
364+
string(REPLACE ";" "," _conan_compilers_list "${_conan_compilers_list}")
365+
string(APPEND profile "tools.build:compiler_executables={${_conan_compilers_list}}\n")
366+
endif()
361367
endif()
362368
unset(_conan_c_compiler)
363369
unset(_conan_cpp_compiler)
@@ -370,7 +376,7 @@ function(detect_host_profile output_file)
370376
detect_os(os os_api_level os_sdk os_subsystem os_version)
371377
detect_arch(arch)
372378
detect_compiler(compiler compiler_version compiler_runtime compiler_runtime_type)
373-
detect_cxx_standard(compiler_cppstd)
379+
detect_cxx_standard(${compiler} compiler_cppstd)
374380
detect_lib_cxx(compiler_libcxx)
375381
detect_build_type(build_type)
376382

@@ -461,10 +467,9 @@ endfunction()
461467

462468

463469
function(conan_install)
464-
cmake_parse_arguments(ARGS conan_args ${ARGN})
465470
set(conan_output_folder ${CMAKE_BINARY_DIR}/conan)
466471
# Invoke "conan install" with the provided arguments
467-
set(conan_args ${conan_args} -of=${conan_output_folder})
472+
set(conan_args -of=${conan_output_folder})
468473
message(STATUS "CMake-Conan: conan install ${CMAKE_SOURCE_DIR} ${conan_args} ${ARGN}")
469474

470475

@@ -567,7 +572,7 @@ macro(conan_provide_dependency method package_name)
567572
get_property(_conan_install_success GLOBAL PROPERTY CONAN_INSTALL_SUCCESS)
568573
if(NOT _conan_install_success)
569574
find_program(CONAN_COMMAND "conan" REQUIRED)
570-
conan_get_version(${CONAN_COMMAND} CONAN_CURRENT_VERSION)
575+
conan_get_version("${CONAN_COMMAND}" CONAN_CURRENT_VERSION)
571576
conan_version_check(MINIMUM ${CONAN_MINIMUM_VERSION} CURRENT ${CONAN_CURRENT_VERSION})
572577
message(STATUS "CMake-Conan: first find_package() found. Installing dependencies with Conan")
573578
if("default" IN_LIST CONAN_HOST_PROFILE OR "default" IN_LIST CONAN_BUILD_PROFILE)
@@ -580,30 +585,59 @@ macro(conan_provide_dependency method package_name)
580585
construct_profile_argument(_build_profile_flags CONAN_BUILD_PROFILE)
581586
if(EXISTS "${CMAKE_SOURCE_DIR}/conanfile.py")
582587
file(READ "${CMAKE_SOURCE_DIR}/conanfile.py" outfile)
583-
if(NOT "${outfile}" MATCHES ".*CMakeDeps.*")
584-
message(WARNING "Cmake-conan: CMakeDeps generator was not defined in the conanfile")
588+
if(NOT "${outfile}" MATCHES ".*CMakeConfigDeps.*")
589+
message(WARNING "Cmake-conan: CMakeConfigDeps generator was not defined in the conanfile")
585590
endif()
586-
set(generator "")
587591
elseif (EXISTS "${CMAKE_SOURCE_DIR}/conanfile.txt")
588592
file(READ "${CMAKE_SOURCE_DIR}/conanfile.txt" outfile)
589-
if(NOT "${outfile}" MATCHES ".*CMakeDeps.*")
590-
message(WARNING "Cmake-conan: CMakeDeps generator was not defined in the conanfile. "
591-
"Please define the generator as it will be mandatory in the future")
593+
if(NOT "${outfile}" MATCHES ".*CMakeConfigDeps.*")
594+
message(WARNING "Cmake-conan: CMakeConfigDeps generator was not defined in the conanfile")
592595
endif()
593-
set(generator "-g;CMakeDeps")
594596
endif()
597+
595598
get_property(_multiconfig_generator GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
596-
if(NOT _multiconfig_generator)
597-
message(STATUS "CMake-Conan: Installing single configuration ${CMAKE_BUILD_TYPE}")
598-
conan_install(${_host_profile_flags} ${_build_profile_flags} ${CONAN_INSTALL_ARGS} ${generator})
599+
600+
if(DEFINED CONAN_INSTALL_BUILD_CONFIGURATIONS)
601+
# Configurations are specified by the project or user
602+
set(_build_configs "${CONAN_INSTALL_BUILD_CONFIGURATIONS}")
603+
list(LENGTH _build_configs _build_configs_length)
604+
if(NOT _multiconfig_generator AND _build_configs_length GREATER 1)
605+
message(FATAL_ERROR "cmake-conan: when using a single-config CMake generator, "
606+
"please only specify a single configuration in CONAN_INSTALL_BUILD_CONFIGURATIONS")
607+
endif()
608+
unset(_build_configs_length)
599609
else()
600-
message(STATUS "CMake-Conan: Installing both Debug and Release")
601-
conan_install(${_host_profile_flags} ${_build_profile_flags} -s build_type=Release ${CONAN_INSTALL_ARGS} ${generator})
602-
conan_install(${_host_profile_flags} ${_build_profile_flags} -s build_type=Debug ${CONAN_INSTALL_ARGS} ${generator})
610+
# No configuration overrides, provide sensible defaults
611+
if(_multiconfig_generator)
612+
set(_build_configs Release Debug)
613+
else()
614+
set(_build_configs ${CMAKE_BUILD_TYPE})
615+
endif()
616+
603617
endif()
618+
619+
list(JOIN _build_configs ", " _build_configs_msg)
620+
message(STATUS "CMake-Conan: Installing configuration(s): ${_build_configs_msg}")
621+
foreach(_build_config IN LISTS _build_configs)
622+
set(_self_build_config "")
623+
if(NOT _multiconfig_generator AND NOT _build_config STREQUAL "${CMAKE_BUILD_TYPE}")
624+
set(_self_build_config -s &:build_type=${CMAKE_BUILD_TYPE})
625+
endif()
626+
conan_install(${_host_profile_flags} ${_build_profile_flags} -s build_type=${_build_config} ${_self_build_config} ${CONAN_INSTALL_ARGS})
627+
endforeach()
628+
629+
get_property(_conan_generators_folder GLOBAL PROPERTY CONAN_GENERATORS_FOLDER)
630+
if(EXISTS "${_conan_generators_folder}/conan_cmakedeps_paths.cmake")
631+
message(STATUS "CMake-Conan: Loading conan_cmakedeps_paths.cmake file")
632+
include(${_conan_generators_folder}/conan_cmakedeps_paths.cmake)
633+
endif()
634+
635+
unset(_self_build_config)
636+
unset(_multiconfig_generator)
637+
unset(_build_configs)
638+
unset(_build_configs_msg)
604639
unset(_host_profile_flags)
605640
unset(_build_profile_flags)
606-
unset(_multiconfig_generator)
607641
unset(_conan_install_success)
608642
else()
609643
message(STATUS "CMake-Conan: find_package(${ARGV1}) found, 'conan install' already ran")

0 commit comments

Comments
 (0)