From a39ab8e4ac5be607106e31f8b419ac029d3a89c0 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Mon, 24 Oct 2022 22:04:24 +0800 Subject: [PATCH 01/31] feat: Modify '_get_msvc_ide_version' --- conan.cmake | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/conan.cmake b/conan.cmake index 66b381db..551cb7a4 100644 --- a/conan.cmake +++ b/conan.cmake @@ -40,23 +40,32 @@ include(CMakeParseArguments) function(_get_msvc_ide_version result) set(${result} "" PARENT_SCOPE) if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500) - set(${result} 8 PARENT_SCOPE) + # VS2005 + set(${result} 140 PARENT_SCOPE) elseif(NOT MSVC_VERSION VERSION_LESS 1500 AND MSVC_VERSION VERSION_LESS 1600) - set(${result} 9 PARENT_SCOPE) + # VS2008 + set(${result} 150 PARENT_SCOPE) elseif(NOT MSVC_VERSION VERSION_LESS 1600 AND MSVC_VERSION VERSION_LESS 1700) - set(${result} 10 PARENT_SCOPE) + # VS2010 + set(${result} 160 PARENT_SCOPE) elseif(NOT MSVC_VERSION VERSION_LESS 1700 AND MSVC_VERSION VERSION_LESS 1800) - set(${result} 11 PARENT_SCOPE) + # VS2012 + set(${result} 170 PARENT_SCOPE) elseif(NOT MSVC_VERSION VERSION_LESS 1800 AND MSVC_VERSION VERSION_LESS 1900) - set(${result} 12 PARENT_SCOPE) + # VS2013 + set(${result} 180 PARENT_SCOPE) elseif(NOT MSVC_VERSION VERSION_LESS 1900 AND MSVC_VERSION VERSION_LESS 1910) - set(${result} 14 PARENT_SCOPE) + # VS2015 + set(${result} 190 PARENT_SCOPE) elseif(NOT MSVC_VERSION VERSION_LESS 1910 AND MSVC_VERSION VERSION_LESS 1920) - set(${result} 15 PARENT_SCOPE) + # VS2017 + set(${result} 191 PARENT_SCOPE) elseif(NOT MSVC_VERSION VERSION_LESS 1920 AND MSVC_VERSION VERSION_LESS 1930) - set(${result} 16 PARENT_SCOPE) + # VS2019 + set(${result} 192 PARENT_SCOPE) elseif(NOT MSVC_VERSION VERSION_LESS 1930 AND MSVC_VERSION VERSION_LESS 1940) - set(${result} 17 PARENT_SCOPE) + # VS2022 + set(${result} 193 PARENT_SCOPE) else() message(FATAL_ERROR "Conan: Unknown MSVC compiler version [${MSVC_VERSION}]") endif() From b6e6cc564b8185aef6fbda2ec01aeac29dee745c Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Mon, 24 Oct 2022 22:14:22 +0800 Subject: [PATCH 02/31] feat: Modify '_collect_settings' --- conan.cmake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/conan.cmake b/conan.cmake index 551cb7a4..e30ea060 100644 --- a/conan.cmake +++ b/conan.cmake @@ -461,9 +461,10 @@ function(conan_cmake_detect_vs_runtime result) endfunction() function(_collect_settings result) - set(ARGUMENTS_PROFILE_AUTO arch build_type compiler compiler.version - compiler.runtime compiler.libcxx compiler.toolset - compiler.cppstd) + set(ARGUMENTS_PROFILE_AUTO arch build_type compiler compiler.version + compiler.runtime compiler.runtime_type + compiler.libcxx compiler.toolset + compiler.cppstd compiler.update) foreach(ARG ${ARGUMENTS_PROFILE_AUTO}) string(TOUPPER ${ARG} _arg_name) string(REPLACE "." "_" _arg_name ${_arg_name}) From 9350b9436993b3cfe55cdef625aebf019a33f862 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Mon, 24 Oct 2022 22:27:54 +0800 Subject: [PATCH 03/31] feat: Modify 'conan_cmake_detect_vs_runtime' --- conan.cmake | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/conan.cmake b/conan.cmake index e30ea060..c471f5f6 100644 --- a/conan.cmake +++ b/conan.cmake @@ -426,7 +426,7 @@ function(conan_cmake_detect_unix_libcxx result) endif() endfunction() -function(conan_cmake_detect_vs_runtime result) +function(conan_cmake_detect_vs_runtime result1 result2) conan_parse_arguments(${ARGV}) if(ARGUMENTS_BUILD_TYPE) @@ -445,18 +445,34 @@ function(conan_cmake_detect_vs_runtime result) if(NOT "${${variable}}" STREQUAL "") string(REPLACE " " ";" flags "${${variable}}") foreach (flag ${flags}) - if("${flag}" STREQUAL "/MD" OR "${flag}" STREQUAL "/MDd" OR "${flag}" STREQUAL "/MT" OR "${flag}" STREQUAL "/MTd") - string(SUBSTRING "${flag}" 1 -1 runtime) - set(${result} "${runtime}" PARENT_SCOPE) + if("${flag}" STREQUAL "/MD") + set(${result1} "dynamic" PARENT_SCOPE) + set(${result2} "release" PARENT_SCOPE) + return() + elseif("${flag}" STREQUAL "/MDd") + set(${result1} "dynamic" PARENT_SCOPE) + set(${result2} "debug" PARENT_SCOPE) + return() + elseif("${flag}" STREQUAL "/MT") + set(${result1} "static" PARENT_SCOPE) + set(${result2} "release" PARENT_SCOPE) + return() + elseif("${flag}" STREQUAL "/MTd") + set(${result1} "static" PARENT_SCOPE) + set(${result2} "debug" PARENT_SCOPE) return() endif() endforeach() endif() endforeach() if("${build_type}" STREQUAL "DEBUG") - set(${result} "MDd" PARENT_SCOPE) + # /MDd + set(${result1} "dynamic" PARENT_SCOPE) + set(${result2} "debug" PARENT_SCOPE) else() - set(${result} "MD" PARENT_SCOPE) + # /MD + set(${result1} "dynamic" PARENT_SCOPE) + set(${result2} "release" PARENT_SCOPE) endif() endfunction() From c536eccbac3dd8b24ac4dc274d2c40257479229f Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Mon, 24 Oct 2022 23:27:56 +0800 Subject: [PATCH 04/31] fix: Capitalize the first letter of runtime_type --- conan.cmake | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/conan.cmake b/conan.cmake index c471f5f6..b6a4ed8c 100644 --- a/conan.cmake +++ b/conan.cmake @@ -447,19 +447,19 @@ function(conan_cmake_detect_vs_runtime result1 result2) foreach (flag ${flags}) if("${flag}" STREQUAL "/MD") set(${result1} "dynamic" PARENT_SCOPE) - set(${result2} "release" PARENT_SCOPE) + set(${result2} "Release" PARENT_SCOPE) return() elseif("${flag}" STREQUAL "/MDd") set(${result1} "dynamic" PARENT_SCOPE) - set(${result2} "debug" PARENT_SCOPE) + set(${result2} "Debug" PARENT_SCOPE) return() elseif("${flag}" STREQUAL "/MT") set(${result1} "static" PARENT_SCOPE) - set(${result2} "release" PARENT_SCOPE) + set(${result2} "Release" PARENT_SCOPE) return() elseif("${flag}" STREQUAL "/MTd") set(${result1} "static" PARENT_SCOPE) - set(${result2} "debug" PARENT_SCOPE) + set(${result2} "Debug" PARENT_SCOPE) return() endif() endforeach() @@ -468,11 +468,11 @@ function(conan_cmake_detect_vs_runtime result1 result2) if("${build_type}" STREQUAL "DEBUG") # /MDd set(${result1} "dynamic" PARENT_SCOPE) - set(${result2} "debug" PARENT_SCOPE) + set(${result2} "Debug" PARENT_SCOPE) else() # /MD set(${result1} "dynamic" PARENT_SCOPE) - set(${result2} "release" PARENT_SCOPE) + set(${result2} "Release" PARENT_SCOPE) endif() endfunction() From ed7b3725b51beb19df6ff06922f11103902ff7d2 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Tue, 25 Oct 2022 02:56:06 +0800 Subject: [PATCH 05/31] refactor: Add comments and messages for detection --- conan.cmake | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/conan.cmake b/conan.cmake index b6a4ed8c..19c31452 100644 --- a/conan.cmake +++ b/conan.cmake @@ -231,16 +231,19 @@ macro(_conan_detect_compiler) OR (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Clang AND "${CMAKE_${LANGUAGE}_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC" AND "${CMAKE_${LANGUAGE}_SIMULATE_ID}" STREQUAL "MSVC")) + # using MSVC - set(_VISUAL "Visual Studio") - _get_msvc_ide_version(_VISUAL_VERSION) - if("${_VISUAL_VERSION}" STREQUAL "") - message(FATAL_ERROR "Conan: Visual Studio not recognized") + # Detect 'compiler' and 'compiler.version' + set(_MSVC "msvc") + _get_msvc_ide_version(_MSVC_VERSION) + if("${_MSVC_VERSION}" STREQUAL "") + message(FATAL_ERROR "Conan: MSVC not recognized") else() - set(_CONAN_SETTING_COMPILER ${_VISUAL}) - set(_CONAN_SETTING_COMPILER_VERSION ${_VISUAL_VERSION}) + set(_CONAN_SETTING_COMPILER ${_MSVC}) + set(_CONAN_SETTING_COMPILER_VERSION ${_MSVC_VERSION}) endif() + # Detect 'arch' if(NOT _CONAN_SETTING_ARCH) if (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "64") set(_CONAN_SETTING_ARCH x86_64) @@ -254,16 +257,25 @@ macro(_conan_detect_compiler) endif() endif() - conan_cmake_detect_vs_runtime(_vs_runtime ${ARGV}) - message(STATUS "Conan: Detected VS runtime: ${_vs_runtime}") + # Detect 'compiler.runtime' and 'compiler.runtime_type' + conan_cmake_detect_vs_runtime(_vs_runtime _vs_runtime_type ${ARGV}) + message(STATUS "Conan: Detected MSVC runtime: ${_vs_runtime}") set(_CONAN_SETTING_COMPILER_RUNTIME ${_vs_runtime}) - - if (CMAKE_GENERATOR_TOOLSET) - set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) - elseif(CMAKE_VS_PLATFORM_TOOLSET AND (CMAKE_GENERATOR STREQUAL "Ninja")) - set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) - endif() - else() + message(STATUS "Conan: Detected MSVC runtime_type: ${_vs_runtime_type}") + set(_CONAN_SETTING_COMPILER_RUNTIME_TYPE ${_vs_runtime_type}) + + # Detect 'compiler.toolset' + set(_XP_TOOLSETS v110_xp v120_xp v140_xp v141_xp) + foreach(_XP_TOOLSET ${_XP_TOOLSETS}) + if (CMAKE_GENERATOR_TOOLSET MATCHES ${_XP_TOOLSET}) + if (CMAKE_GENERATOR_TOOLSET) + set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) + elseif(CMAKE_VS_PLATFORM_TOOLSET AND (CMAKE_GENERATOR STREQUAL "Ninja")) + set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) + endif() + endif() + endforeach() + else() message(FATAL_ERROR "Conan: compiler setup not recognized") endif() From 466ef09fcfa23776fb052112bbb5654a12f445f4 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Tue, 25 Oct 2022 02:56:59 +0800 Subject: [PATCH 06/31] feat: Detect 'compiler.cppstd' --- conan.cmake | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/conan.cmake b/conan.cmake index 19c31452..ce3a1477 100644 --- a/conan.cmake +++ b/conan.cmake @@ -275,6 +275,20 @@ macro(_conan_detect_compiler) endif() endif() endforeach() + + # Detect 'compiler.cppstd' + if(CMAKE_CXX_STANDARD) + set(_CONAN_SETTING_COMPILER_CPPSTD ${CMAKE_CXX_STANDARD}) + else() + if(MSVC_VERSION VERSION_LESS 1900) + # VS < 2015, specify C++98 standard by default. + set(_CONAN_SETTING_COMPILER_CPPSTD 98) + else() + # VS >= 2015, specify C++14 standard by default. + set(_CONAN_SETTING_COMPILER_CPPSTD 14) + endif() + endif() + else() message(FATAL_ERROR "Conan: compiler setup not recognized") endif() From 0dd84c91a8ede978751aa563fbffa54f8e4e8501 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Tue, 25 Oct 2022 03:13:57 +0800 Subject: [PATCH 07/31] feat: Modify PROFILE_AUTO of 'conan_cmake_run' --- conan.cmake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/conan.cmake b/conan.cmake index ce3a1477..782f2639 100644 --- a/conan.cmake +++ b/conan.cmake @@ -339,8 +339,10 @@ function(conan_cmake_settings result) endforeach() if(NOT _SETTINGS OR ARGUMENTS_PROFILE_AUTO STREQUAL "ALL") - set(ARGUMENTS_PROFILE_AUTO arch build_type compiler compiler.version - compiler.runtime compiler.libcxx compiler.toolset) + set(ARGUMENTS_PROFILE_AUTO arch build_type compiler compiler.version + compiler.runtime compiler.runtime_type + compiler.libcxx compiler.toolset + compiler.cppstd compiler.update) endif() # remove any manually specified settings from the autodetected settings From 304299637258a32afefacadfdbec13745bc8dbc3 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Tue, 25 Oct 2022 03:43:45 +0800 Subject: [PATCH 08/31] test: Fix 'test_settings_removed_from_autodetect' --- tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.py b/tests.py index 83dc1e92..c9bf448a 100644 --- a/tests.py +++ b/tests.py @@ -667,7 +667,7 @@ def test_settings(self): def test_settings_removed_from_autodetect(self): if platform.system() == "Windows": settings_check = "compiler.runtime" - custom_setting = "{}=MTd".format(settings_check) + custom_setting = "{}=static".format(settings_check) else: settings_check = "compiler.libcxx" custom_setting = "{}=libstdc++".format(settings_check) From 9b8ea240d2e4a23efcfd6146c1a2b3ce21e38386 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Tue, 25 Oct 2022 04:00:37 +0800 Subject: [PATCH 09/31] test: Fix 'test_settings' --- tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.py b/tests.py index c9bf448a..a0114afd 100644 --- a/tests.py +++ b/tests.py @@ -645,7 +645,7 @@ def test_settings(self): include(conan.cmake) conan_cmake_run(BASIC_SETUP SETTINGS arch=armv6 - SETTINGS cppstd=14) + SETTINGS compiler.cppstd=14) if(NOT ${CONAN_SETTINGS_ARCH} STREQUAL "armv6") message(FATAL_ERROR "CONAN_SETTINGS_ARCH INCORRECT!") From fdc063337ae1f6a94fb11e5e4a4320c9aee46305 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Tue, 25 Oct 2022 16:17:54 +0800 Subject: [PATCH 10/31] test: Fix 'test_settings_removed_from_autodetect' --- tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.py b/tests.py index a0114afd..8a6c44d7 100644 --- a/tests.py +++ b/tests.py @@ -678,7 +678,7 @@ def test_settings_removed_from_autodetect(self): include(conan.cmake) conan_cmake_run(BASIC_SETUP SETTINGS {}) - STRING(REGEX MATCHALL "{}" matches "${{settings}}") + STRING(REGEX MATCHALL "{}=" matches "${{settings}}") list(LENGTH matches n_matches) if(NOT n_matches EQUAL 1) message(FATAL_ERROR "CONAN_SETTINGS DUPLICATED!") From 87b727ece7af61778c6b3962a10752cce9191d33 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Tue, 25 Oct 2022 16:40:27 +0800 Subject: [PATCH 11/31] test: Fix 'test_profile_auto' --- tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests.py b/tests.py index 8a6c44d7..0b4fa9be 100644 --- a/tests.py +++ b/tests.py @@ -702,6 +702,7 @@ def test_profile_auto(self): PROFILE myprofile PROFILE_AUTO build_type PROFILE_AUTO compiler + PROFILE_AUTO compiler.version ) if(NOT "${CONAN_SETTINGS_BUILD_TYPE}" STREQUAL "${CMAKE_BUILD_TYPE}") From f845739fc024847a70f1fc881b564de08fb4aa16 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Wed, 26 Oct 2022 18:22:48 +0800 Subject: [PATCH 12/31] refactor: Rename 'vs_runtime' to 'msvc_runtime' --- conan.cmake | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/conan.cmake b/conan.cmake index 782f2639..3ed3c1e8 100644 --- a/conan.cmake +++ b/conan.cmake @@ -258,11 +258,11 @@ macro(_conan_detect_compiler) endif() # Detect 'compiler.runtime' and 'compiler.runtime_type' - conan_cmake_detect_vs_runtime(_vs_runtime _vs_runtime_type ${ARGV}) - message(STATUS "Conan: Detected MSVC runtime: ${_vs_runtime}") - set(_CONAN_SETTING_COMPILER_RUNTIME ${_vs_runtime}) - message(STATUS "Conan: Detected MSVC runtime_type: ${_vs_runtime_type}") - set(_CONAN_SETTING_COMPILER_RUNTIME_TYPE ${_vs_runtime_type}) + conan_cmake_detect_msvc_runtime(_msvc_runtime _msvc_runtime_type ${ARGV}) + message(STATUS "Conan: Detected MSVC runtime: ${_msvc_runtime}") + set(_CONAN_SETTING_COMPILER_RUNTIME ${_msvc_runtime}) + message(STATUS "Conan: Detected MSVC runtime_type: ${_msvc_runtime_type}") + set(_CONAN_SETTING_COMPILER_RUNTIME_TYPE ${_msvc_runtime_type}) # Detect 'compiler.toolset' set(_XP_TOOLSETS v110_xp v120_xp v140_xp v141_xp) @@ -454,7 +454,7 @@ function(conan_cmake_detect_unix_libcxx result) endif() endfunction() -function(conan_cmake_detect_vs_runtime result1 result2) +function(conan_cmake_detect_msvc_runtime result1 result2) conan_parse_arguments(${ARGV}) if(ARGUMENTS_BUILD_TYPE) From deb24b85159d609107acce165ac7b4da44fae1da Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Sat, 29 Oct 2022 14:07:21 +0800 Subject: [PATCH 13/31] refactor: Rename to '_get_msvc_version' --- conan.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conan.cmake b/conan.cmake index 3ed3c1e8..41d6af30 100644 --- a/conan.cmake +++ b/conan.cmake @@ -37,7 +37,7 @@ include(CMakeParseArguments) -function(_get_msvc_ide_version result) +function(_get_msvc_version result) set(${result} "" PARENT_SCOPE) if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500) # VS2005 @@ -235,7 +235,7 @@ macro(_conan_detect_compiler) # Detect 'compiler' and 'compiler.version' set(_MSVC "msvc") - _get_msvc_ide_version(_MSVC_VERSION) + _get_msvc_version(_MSVC_VERSION) if("${_MSVC_VERSION}" STREQUAL "") message(FATAL_ERROR "Conan: MSVC not recognized") else() From 3c0431c89fbe8f16c0b39a66b0fadc0fbe126393 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Sat, 29 Oct 2022 14:25:23 +0800 Subject: [PATCH 14/31] refactor: Use CMAKE_LANG_COMPILER_ARCHITECTURE_ID --- conan.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/conan.cmake b/conan.cmake index 41d6af30..f2fbaa3f 100644 --- a/conan.cmake +++ b/conan.cmake @@ -245,15 +245,15 @@ macro(_conan_detect_compiler) # Detect 'arch' if(NOT _CONAN_SETTING_ARCH) - if (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "64") + if (CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID MATCHES "64") set(_CONAN_SETTING_ARCH x86_64) - elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "^ARM") + elseif (CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID MATCHES "^ARM") message(STATUS "Conan: Using default ARM architecture from MSVC") set(_CONAN_SETTING_ARCH armv6) - elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "86") + elseif (CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID MATCHES "86") set(_CONAN_SETTING_ARCH x86) else () - message(FATAL_ERROR "Conan: Unknown MSVC architecture [${MSVC_${LANGUAGE}_ARCHITECTURE_ID}]") + message(FATAL_ERROR "Conan: Unknown MSVC architecture [${CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID}]") endif() endif() From bd947957ee8db8eca2adc997cded28a74a046fe9 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Tue, 1 Nov 2022 20:01:22 +0800 Subject: [PATCH 15/31] refactor: Rename 'conan_cmake_detect_msvc_version' --- conan.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conan.cmake b/conan.cmake index f2fbaa3f..5a72900e 100644 --- a/conan.cmake +++ b/conan.cmake @@ -37,7 +37,7 @@ include(CMakeParseArguments) -function(_get_msvc_version result) +function(conan_cmake_detect_msvc_version result) set(${result} "" PARENT_SCOPE) if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500) # VS2005 @@ -235,7 +235,7 @@ macro(_conan_detect_compiler) # Detect 'compiler' and 'compiler.version' set(_MSVC "msvc") - _get_msvc_version(_MSVC_VERSION) + conan_cmake_detect_msvc_version(_MSVC_VERSION) if("${_MSVC_VERSION}" STREQUAL "") message(FATAL_ERROR "Conan: MSVC not recognized") else() From 4ed83a46870e7834818a96ddd74a78657250edde Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Wed, 16 Nov 2022 11:38:23 +0800 Subject: [PATCH 16/31] chore: Modify comments for MSVC detection --- conan.cmake | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/conan.cmake b/conan.cmake index 5a72900e..a19dd519 100644 --- a/conan.cmake +++ b/conan.cmake @@ -231,9 +231,9 @@ macro(_conan_detect_compiler) OR (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Clang AND "${CMAKE_${LANGUAGE}_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC" AND "${CMAKE_${LANGUAGE}_SIMULATE_ID}" STREQUAL "MSVC")) - # using MSVC + # Using MSVC compilers. - # Detect 'compiler' and 'compiler.version' + # Detect 'compiler' and 'compiler.version' settings. set(_MSVC "msvc") conan_cmake_detect_msvc_version(_MSVC_VERSION) if("${_MSVC_VERSION}" STREQUAL "") @@ -243,7 +243,7 @@ macro(_conan_detect_compiler) set(_CONAN_SETTING_COMPILER_VERSION ${_MSVC_VERSION}) endif() - # Detect 'arch' + # Detect 'arch' setting. if(NOT _CONAN_SETTING_ARCH) if (CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID MATCHES "64") set(_CONAN_SETTING_ARCH x86_64) @@ -257,14 +257,14 @@ macro(_conan_detect_compiler) endif() endif() - # Detect 'compiler.runtime' and 'compiler.runtime_type' + # Detect 'compiler.runtime' and 'compiler.runtime_type' settings. conan_cmake_detect_msvc_runtime(_msvc_runtime _msvc_runtime_type ${ARGV}) message(STATUS "Conan: Detected MSVC runtime: ${_msvc_runtime}") set(_CONAN_SETTING_COMPILER_RUNTIME ${_msvc_runtime}) message(STATUS "Conan: Detected MSVC runtime_type: ${_msvc_runtime_type}") set(_CONAN_SETTING_COMPILER_RUNTIME_TYPE ${_msvc_runtime_type}) - # Detect 'compiler.toolset' + # Detect 'compiler.toolset' setting. set(_XP_TOOLSETS v110_xp v120_xp v140_xp v141_xp) foreach(_XP_TOOLSET ${_XP_TOOLSETS}) if (CMAKE_GENERATOR_TOOLSET MATCHES ${_XP_TOOLSET}) @@ -276,7 +276,7 @@ macro(_conan_detect_compiler) endif() endforeach() - # Detect 'compiler.cppstd' + # Detect 'compiler.cppstd' setting. if(CMAKE_CXX_STANDARD) set(_CONAN_SETTING_COMPILER_CPPSTD ${CMAKE_CXX_STANDARD}) else() From 2d9fb66284157219431097c122928de6af9a5a0c Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Wed, 16 Nov 2022 12:04:04 +0800 Subject: [PATCH 17/31] feat: Add back conan_cmake_detect_vs_version --- conan.cmake | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/conan.cmake b/conan.cmake index a19dd519..7074dc1c 100644 --- a/conan.cmake +++ b/conan.cmake @@ -37,6 +37,44 @@ include(CMakeParseArguments) + +# Detecting 'compiler.version' setting for 'Visual Studio', +# which will be deprecated in Conan 2.0. +function(conan_cmake_detect_vs_version result) + set(${result} "" PARENT_SCOPE) + if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500) + # VS2005, VC 8.0 + set(${result} 8 PARENT_SCOPE) + elseif(NOT MSVC_VERSION VERSION_LESS 1500 AND MSVC_VERSION VERSION_LESS 1600) + # VS2008, VC 9.0 + set(${result} 9 PARENT_SCOPE) + elseif(NOT MSVC_VERSION VERSION_LESS 1600 AND MSVC_VERSION VERSION_LESS 1700) + # VS2010, VC 10.0 + set(${result} 10 PARENT_SCOPE) + elseif(NOT MSVC_VERSION VERSION_LESS 1700 AND MSVC_VERSION VERSION_LESS 1800) + # VS2012, VC 11.0 + set(${result} 11 PARENT_SCOPE) + elseif(NOT MSVC_VERSION VERSION_LESS 1800 AND MSVC_VERSION VERSION_LESS 1900) + # VS2013, VC 12.0 + set(${result} 12 PARENT_SCOPE) + elseif(NOT MSVC_VERSION VERSION_LESS 1900 AND MSVC_VERSION VERSION_LESS 1910) + # VS2015, VC 14.0 + set(${result} 14 PARENT_SCOPE) + elseif(NOT MSVC_VERSION VERSION_LESS 1910 AND MSVC_VERSION VERSION_LESS 1920) + # VS2017, VC 15.0 + set(${result} 15 PARENT_SCOPE) + elseif(NOT MSVC_VERSION VERSION_LESS 1920 AND MSVC_VERSION VERSION_LESS 1930) + # VS2019, VC 16.0 + set(${result} 16 PARENT_SCOPE) + elseif(NOT MSVC_VERSION VERSION_LESS 1930 AND MSVC_VERSION VERSION_LESS 1940) + # VS2022, VC 17.0 + set(${result} 17 PARENT_SCOPE) + else() + message(FATAL_ERROR "Conan: Unknown MSVC compiler version [${MSVC_VERSION}]") + endif() +endfunction() + + function(conan_cmake_detect_msvc_version result) set(${result} "" PARENT_SCOPE) if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500) From 0218e2f74cc79072c0a8c7d064dc0a7100e9d0f3 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Wed, 16 Nov 2022 12:08:43 +0800 Subject: [PATCH 18/31] feat: Add back conan_cmake_detect_vs_runtime --- conan.cmake | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/conan.cmake b/conan.cmake index 7074dc1c..981b7add 100644 --- a/conan.cmake +++ b/conan.cmake @@ -75,6 +75,42 @@ function(conan_cmake_detect_vs_version result) endfunction() +# Detect 'compiler.runtime' setting for 'Visual Studio', +# which will be deprecated in Conan 2.0. +function(conan_cmake_detect_vs_runtime result) + conan_parse_arguments(${ARGV}) + if(ARGUMENTS_BUILD_TYPE) + set(build_type "${ARGUMENTS_BUILD_TYPE}") + elseif(CMAKE_BUILD_TYPE) + set(build_type "${CMAKE_BUILD_TYPE}") + else() + message(FATAL_ERROR "Please specify in command line CMAKE_BUILD_TYPE (-DCMAKE_BUILD_TYPE=Release)") + endif() + + if(build_type) + string(TOUPPER "${build_type}" build_type) + endif() + set(variables CMAKE_CXX_FLAGS_${build_type} CMAKE_C_FLAGS_${build_type} CMAKE_CXX_FLAGS CMAKE_C_FLAGS) + foreach(variable ${variables}) + if(NOT "${${variable}}" STREQUAL "") + string(REPLACE " " ";" flags "${${variable}}") + foreach (flag ${flags}) + if("${flag}" STREQUAL "/MD" OR "${flag}" STREQUAL "/MDd" OR "${flag}" STREQUAL "/MT" OR "${flag}" STREQUAL "/MTd") + string(SUBSTRING "${flag}" 1 -1 runtime) + set(${result} "${runtime}" PARENT_SCOPE) + return() + endif() + endforeach() + endif() + endforeach() + if("${build_type}" STREQUAL "DEBUG") + set(${result} "MDd" PARENT_SCOPE) + else() + set(${result} "MD" PARENT_SCOPE) + endif() +endfunction() + + function(conan_cmake_detect_msvc_version result) set(${result} "" PARENT_SCOPE) if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500) From dde1edae00e8756a5702c47b873449324b77bb1b Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Wed, 16 Nov 2022 12:11:05 +0800 Subject: [PATCH 19/31] chore: Add comments for 'msvc' compiler.version --- conan.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/conan.cmake b/conan.cmake index 981b7add..afe793fd 100644 --- a/conan.cmake +++ b/conan.cmake @@ -111,6 +111,7 @@ function(conan_cmake_detect_vs_runtime result) endfunction() +# Detect 'compiler.version' setting for 'msvc' function(conan_cmake_detect_msvc_version result) set(${result} "" PARENT_SCOPE) if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500) From 341e8f4393e3ccce3b66f117a449b077a6ab2d85 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Wed, 16 Nov 2022 12:13:53 +0800 Subject: [PATCH 20/31] chore: Move up conan_cmake_detect_msvc_runtime --- conan.cmake | 102 +++++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 49 deletions(-) diff --git a/conan.cmake b/conan.cmake index afe793fd..b5cd36ef 100644 --- a/conan.cmake +++ b/conan.cmake @@ -146,6 +146,59 @@ function(conan_cmake_detect_msvc_version result) endif() endfunction() + +# Detect 'compiler.runtime' and 'compiler.runtime_type' settings for 'msvc' +function(conan_cmake_detect_msvc_runtime result1 result2) + + conan_parse_arguments(${ARGV}) + if(ARGUMENTS_BUILD_TYPE) + set(build_type "${ARGUMENTS_BUILD_TYPE}") + elseif(CMAKE_BUILD_TYPE) + set(build_type "${CMAKE_BUILD_TYPE}") + else() + message(FATAL_ERROR "Please specify in command line CMAKE_BUILD_TYPE (-DCMAKE_BUILD_TYPE=Release)") + endif() + + if(build_type) + string(TOUPPER "${build_type}" build_type) + endif() + set(variables CMAKE_CXX_FLAGS_${build_type} CMAKE_C_FLAGS_${build_type} CMAKE_CXX_FLAGS CMAKE_C_FLAGS) + foreach(variable ${variables}) + if(NOT "${${variable}}" STREQUAL "") + string(REPLACE " " ";" flags "${${variable}}") + foreach (flag ${flags}) + if("${flag}" STREQUAL "/MD") + set(${result1} "dynamic" PARENT_SCOPE) + set(${result2} "Release" PARENT_SCOPE) + return() + elseif("${flag}" STREQUAL "/MDd") + set(${result1} "dynamic" PARENT_SCOPE) + set(${result2} "Debug" PARENT_SCOPE) + return() + elseif("${flag}" STREQUAL "/MT") + set(${result1} "static" PARENT_SCOPE) + set(${result2} "Release" PARENT_SCOPE) + return() + elseif("${flag}" STREQUAL "/MTd") + set(${result1} "static" PARENT_SCOPE) + set(${result2} "Debug" PARENT_SCOPE) + return() + endif() + endforeach() + endif() + endforeach() + if("${build_type}" STREQUAL "DEBUG") + # /MDd + set(${result1} "dynamic" PARENT_SCOPE) + set(${result2} "Debug" PARENT_SCOPE) + else() + # /MD + set(${result1} "dynamic" PARENT_SCOPE) + set(${result2} "Release" PARENT_SCOPE) + endif() +endfunction() + + macro(_conan_detect_build_type) conan_parse_arguments(${ARGV}) @@ -529,55 +582,6 @@ function(conan_cmake_detect_unix_libcxx result) endif() endfunction() -function(conan_cmake_detect_msvc_runtime result1 result2) - - conan_parse_arguments(${ARGV}) - if(ARGUMENTS_BUILD_TYPE) - set(build_type "${ARGUMENTS_BUILD_TYPE}") - elseif(CMAKE_BUILD_TYPE) - set(build_type "${CMAKE_BUILD_TYPE}") - else() - message(FATAL_ERROR "Please specify in command line CMAKE_BUILD_TYPE (-DCMAKE_BUILD_TYPE=Release)") - endif() - - if(build_type) - string(TOUPPER "${build_type}" build_type) - endif() - set(variables CMAKE_CXX_FLAGS_${build_type} CMAKE_C_FLAGS_${build_type} CMAKE_CXX_FLAGS CMAKE_C_FLAGS) - foreach(variable ${variables}) - if(NOT "${${variable}}" STREQUAL "") - string(REPLACE " " ";" flags "${${variable}}") - foreach (flag ${flags}) - if("${flag}" STREQUAL "/MD") - set(${result1} "dynamic" PARENT_SCOPE) - set(${result2} "Release" PARENT_SCOPE) - return() - elseif("${flag}" STREQUAL "/MDd") - set(${result1} "dynamic" PARENT_SCOPE) - set(${result2} "Debug" PARENT_SCOPE) - return() - elseif("${flag}" STREQUAL "/MT") - set(${result1} "static" PARENT_SCOPE) - set(${result2} "Release" PARENT_SCOPE) - return() - elseif("${flag}" STREQUAL "/MTd") - set(${result1} "static" PARENT_SCOPE) - set(${result2} "Debug" PARENT_SCOPE) - return() - endif() - endforeach() - endif() - endforeach() - if("${build_type}" STREQUAL "DEBUG") - # /MDd - set(${result1} "dynamic" PARENT_SCOPE) - set(${result2} "Debug" PARENT_SCOPE) - else() - # /MD - set(${result1} "dynamic" PARENT_SCOPE) - set(${result2} "Release" PARENT_SCOPE) - endif() -endfunction() function(_collect_settings result) set(ARGUMENTS_PROFILE_AUTO arch build_type compiler compiler.version From 2f53c9fbf963f341ec096726e6c4811f94d8d26c Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Wed, 16 Nov 2022 12:20:18 +0800 Subject: [PATCH 21/31] chore: Modify some comments --- conan.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/conan.cmake b/conan.cmake index b5cd36ef..89f7a64e 100644 --- a/conan.cmake +++ b/conan.cmake @@ -38,7 +38,7 @@ include(CMakeParseArguments) -# Detecting 'compiler.version' setting for 'Visual Studio', +# Detect 'compiler.version' setting for 'Visual Studio', # which will be deprecated in Conan 2.0. function(conan_cmake_detect_vs_version result) set(${result} "" PARENT_SCOPE) @@ -111,7 +111,7 @@ function(conan_cmake_detect_vs_runtime result) endfunction() -# Detect 'compiler.version' setting for 'msvc' +# Detect 'compiler.version' setting for 'msvc'. function(conan_cmake_detect_msvc_version result) set(${result} "" PARENT_SCOPE) if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500) @@ -147,7 +147,7 @@ function(conan_cmake_detect_msvc_version result) endfunction() -# Detect 'compiler.runtime' and 'compiler.runtime_type' settings for 'msvc' +# Detect 'compiler.runtime' and 'compiler.runtime_type' settings for 'msvc'. function(conan_cmake_detect_msvc_runtime result1 result2) conan_parse_arguments(${ARGV}) From 7f7d4fb48337d250cd02bb33d5bdb95accbf94e3 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Wed, 16 Nov 2022 12:32:03 +0800 Subject: [PATCH 22/31] chore: Add comment for _conan_detect_build_type --- conan.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/conan.cmake b/conan.cmake index 89f7a64e..432947e8 100644 --- a/conan.cmake +++ b/conan.cmake @@ -199,6 +199,7 @@ function(conan_cmake_detect_msvc_runtime result1 result2) endfunction() +# Detect 'build_type' setting. macro(_conan_detect_build_type) conan_parse_arguments(${ARGV}) From 596265a62292a102612591151f988e04b496f1c3 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Wed, 16 Nov 2022 12:32:52 +0800 Subject: [PATCH 23/31] chore: Add comment for _conan_check_system_name --- conan.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/conan.cmake b/conan.cmake index 432947e8..7fa0de6d 100644 --- a/conan.cmake +++ b/conan.cmake @@ -223,6 +223,8 @@ macro(_conan_detect_build_type) endif() endmacro() + +# Detect 'os' setting. macro(_conan_check_system_name) #handle -s os setting if(CMAKE_SYSTEM_NAME AND NOT CMAKE_SYSTEM_NAME STREQUAL "Generic") From db8f8ae4deea5bc3a9b0a1c3e8087a1af749a572 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Wed, 16 Nov 2022 16:34:42 +0800 Subject: [PATCH 24/31] chore: Adjust condition statement indents of MSVC --- conan.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/conan.cmake b/conan.cmake index 7fa0de6d..bc4b2ba7 100644 --- a/conan.cmake +++ b/conan.cmake @@ -358,10 +358,10 @@ macro(_conan_detect_compiler) conan_cmake_detect_unix_libcxx(_LIBCXX) set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) endif () - elseif(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL MSVC - OR (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Clang - AND "${CMAKE_${LANGUAGE}_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC" - AND "${CMAKE_${LANGUAGE}_SIMULATE_ID}" STREQUAL "MSVC")) + elseif ("${CMAKE_${LANGUAGE}_COMPILER_ID}" STREQUAL "MSVC" + OR ("${CMAKE_${LANGUAGE}_COMPILER_ID}" STREQUAL "Clang" + AND "${CMAKE_${LANGUAGE}_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC" + AND "${CMAKE_${LANGUAGE}_SIMULATE_ID}" STREQUAL "MSVC")) # Using MSVC compilers. # Detect 'compiler' and 'compiler.version' settings. From 9f7446f4ca5db1c1df178399ad09000b936fc5f0 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Wed, 16 Nov 2022 17:01:09 +0800 Subject: [PATCH 25/31] feat: Add back old VS compiler detection --- conan.cmake | 138 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 91 insertions(+), 47 deletions(-) diff --git a/conan.cmake b/conan.cmake index bc4b2ba7..6353d9f4 100644 --- a/conan.cmake +++ b/conan.cmake @@ -364,62 +364,106 @@ macro(_conan_detect_compiler) AND "${CMAKE_${LANGUAGE}_SIMULATE_ID}" STREQUAL "MSVC")) # Using MSVC compilers. - # Detect 'compiler' and 'compiler.version' settings. - set(_MSVC "msvc") - conan_cmake_detect_msvc_version(_MSVC_VERSION) - if("${_MSVC_VERSION}" STREQUAL "") - message(FATAL_ERROR "Conan: MSVC not recognized") - else() - set(_CONAN_SETTING_COMPILER ${_MSVC}) - set(_CONAN_SETTING_COMPILER_VERSION ${_MSVC_VERSION}) - endif() + conan_version(CONAN_VERSION) + if (${CONAN_VERSION} VERSION_LESS "2.0.0") + # Conan 1.0 + # Detect 'Visual Studio' compiler settings. + + # Detect 'compiler' and 'compiler.version' settings. + set(_VISUAL "Visual Studio") + conan_cmake_detect_vs_version(_VISUAL_VERSION) + if("${_VISUAL_VERSION}" STREQUAL "") + message(FATAL_ERROR "Conan: Visual Studio not recognized") + else() + set(_CONAN_SETTING_COMPILER ${_VISUAL}) + set(_CONAN_SETTING_COMPILER_VERSION ${_VISUAL_VERSION}) + endif() - # Detect 'arch' setting. - if(NOT _CONAN_SETTING_ARCH) - if (CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID MATCHES "64") - set(_CONAN_SETTING_ARCH x86_64) - elseif (CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID MATCHES "^ARM") - message(STATUS "Conan: Using default ARM architecture from MSVC") - set(_CONAN_SETTING_ARCH armv6) - elseif (CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID MATCHES "86") - set(_CONAN_SETTING_ARCH x86) - else () - message(FATAL_ERROR "Conan: Unknown MSVC architecture [${CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID}]") + # Detect 'arch' setting. + if(NOT _CONAN_SETTING_ARCH) + if (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "64") + set(_CONAN_SETTING_ARCH x86_64) + elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "^ARM") + message(STATUS "Conan: Using default ARM architecture from VS") + set(_CONAN_SETTING_ARCH armv6) + elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "86") + set(_CONAN_SETTING_ARCH x86) + else () + message(FATAL_ERROR "Conan: Unknown VS architecture [${MSVC_${LANGUAGE}_ARCHITECTURE_ID}]") + endif() endif() - endif() - # Detect 'compiler.runtime' and 'compiler.runtime_type' settings. - conan_cmake_detect_msvc_runtime(_msvc_runtime _msvc_runtime_type ${ARGV}) - message(STATUS "Conan: Detected MSVC runtime: ${_msvc_runtime}") - set(_CONAN_SETTING_COMPILER_RUNTIME ${_msvc_runtime}) - message(STATUS "Conan: Detected MSVC runtime_type: ${_msvc_runtime_type}") - set(_CONAN_SETTING_COMPILER_RUNTIME_TYPE ${_msvc_runtime_type}) - - # Detect 'compiler.toolset' setting. - set(_XP_TOOLSETS v110_xp v120_xp v140_xp v141_xp) - foreach(_XP_TOOLSET ${_XP_TOOLSETS}) - if (CMAKE_GENERATOR_TOOLSET MATCHES ${_XP_TOOLSET}) - if (CMAKE_GENERATOR_TOOLSET) - set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) - elseif(CMAKE_VS_PLATFORM_TOOLSET AND (CMAKE_GENERATOR STREQUAL "Ninja")) - set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) + # Detect 'compiler.runtime' setting. + conan_cmake_detect_vs_runtime(VS_RUNTIME ${ARGV}) + message(STATUS "Conan: Detected VS runtime: ${VS_RUNTIME}") + set(_CONAN_SETTING_COMPILER_RUNTIME ${VS_RUNTIME}) + + # Detect 'compiler.toolset' setting. + if (CMAKE_GENERATOR_TOOLSET) + set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) + elseif(CMAKE_VS_PLATFORM_TOOLSET AND (CMAKE_GENERATOR STREQUAL "Ninja")) + set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) + endif() + else () + # Conan 2.0 + # Detect 'msvc' compiler settings. + + # Detect 'compiler' and 'compiler.version' settings. + set(_MSVC "msvc") + conan_cmake_detect_msvc_version(_MSVC_VERSION) + if("${_MSVC_VERSION}" STREQUAL "") + message(FATAL_ERROR "Conan: MSVC not recognized") + else() + set(_CONAN_SETTING_COMPILER ${_MSVC}) + set(_CONAN_SETTING_COMPILER_VERSION ${_MSVC_VERSION}) + endif() + + # Detect 'arch' setting. + if(NOT _CONAN_SETTING_ARCH) + if (CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID MATCHES "64") + set(_CONAN_SETTING_ARCH x86_64) + elseif (CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID MATCHES "^ARM") + message(STATUS "Conan: Using default ARM architecture from MSVC") + set(_CONAN_SETTING_ARCH armv6) + elseif (CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID MATCHES "86") + set(_CONAN_SETTING_ARCH x86) + else () + message(FATAL_ERROR "Conan: Unknown MSVC architecture [${CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID}]") endif() endif() - endforeach() - # Detect 'compiler.cppstd' setting. - if(CMAKE_CXX_STANDARD) - set(_CONAN_SETTING_COMPILER_CPPSTD ${CMAKE_CXX_STANDARD}) - else() - if(MSVC_VERSION VERSION_LESS 1900) - # VS < 2015, specify C++98 standard by default. - set(_CONAN_SETTING_COMPILER_CPPSTD 98) + # Detect 'compiler.runtime' and 'compiler.runtime_type' settings. + conan_cmake_detect_msvc_runtime(_MSVC_RUNTIME _MSVC_RUNTIME_TYPE ${ARGV}) + message(STATUS "Conan: Detected MSVC runtime: ${_MSVC_RUNTIME}") + set(_CONAN_SETTING_COMPILER_RUNTIME ${_MSVC_RUNTIME}) + message(STATUS "Conan: Detected MSVC runtime_type: ${_MSVC_RUNTIME_TYPE}") + set(_CONAN_SETTING_COMPILER_RUNTIME_TYPE ${_MSVC_RUNTIME_TYPE}) + + # Detect 'compiler.toolset' setting. + set(_XP_TOOLSETS v110_xp v120_xp v140_xp v141_xp) + foreach(_XP_TOOLSET ${_XP_TOOLSETS}) + if (CMAKE_GENERATOR_TOOLSET MATCHES ${_XP_TOOLSET}) + if (CMAKE_GENERATOR_TOOLSET) + set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) + elseif(CMAKE_VS_PLATFORM_TOOLSET AND (CMAKE_GENERATOR STREQUAL "Ninja")) + set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) + endif() + endif() + endforeach() + + # Detect 'compiler.cppstd' setting. + if(CMAKE_CXX_STANDARD) + set(_CONAN_SETTING_COMPILER_CPPSTD ${CMAKE_CXX_STANDARD}) else() - # VS >= 2015, specify C++14 standard by default. - set(_CONAN_SETTING_COMPILER_CPPSTD 14) + if(MSVC_VERSION VERSION_LESS 1900) + # VS < 2015, specify C++98 standard by default. + set(_CONAN_SETTING_COMPILER_CPPSTD 98) + else() + # VS >= 2015, specify C++14 standard by default. + set(_CONAN_SETTING_COMPILER_CPPSTD 14) + endif() endif() endif() - else() message(FATAL_ERROR "Conan: compiler setup not recognized") endif() From 32321d9c810d4120edc9196bc35785d796250e9f Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Wed, 16 Nov 2022 17:09:10 +0800 Subject: [PATCH 26/31] test: Fix test_settings_removed_from_autodetect --- tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.py b/tests.py index 0b4fa9be..6b3ca028 100644 --- a/tests.py +++ b/tests.py @@ -667,7 +667,7 @@ def test_settings(self): def test_settings_removed_from_autodetect(self): if platform.system() == "Windows": settings_check = "compiler.runtime" - custom_setting = "{}=static".format(settings_check) + custom_setting = "{}=MTd".format(settings_check) else: settings_check = "compiler.libcxx" custom_setting = "{}=libstdc++".format(settings_check) From 31154673f5b351b7e5602ac6ce268fee574b99f0 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Wed, 16 Nov 2022 20:38:51 +0800 Subject: [PATCH 27/31] feat: Add CONAN_V2 detecting mechanism --- conan.cmake | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/conan.cmake b/conan.cmake index 6353d9f4..b573b701 100644 --- a/conan.cmake +++ b/conan.cmake @@ -364,9 +364,7 @@ macro(_conan_detect_compiler) AND "${CMAKE_${LANGUAGE}_SIMULATE_ID}" STREQUAL "MSVC")) # Using MSVC compilers. - conan_version(CONAN_VERSION) - if (${CONAN_VERSION} VERSION_LESS "2.0.0") - # Conan 1.0 + if (NOT MODE_CONAN_V2) # Detect 'Visual Studio' compiler settings. # Detect 'compiler' and 'compiler.version' settings. @@ -405,7 +403,6 @@ macro(_conan_detect_compiler) set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) endif() else () - # Conan 2.0 # Detect 'msvc' compiler settings. # Detect 'compiler' and 'compiler.version' settings. @@ -646,6 +643,21 @@ function(_collect_settings result) endfunction() function(conan_cmake_autodetect detected_settings) + # Detect whether CONAN_V2 is specified with ON: + # - If CONAN_V2 is specified with ON, then MODE_CONAN_V2 will be ON. + # - Otherwise: + # - If current Conan version is 1.0, then set MODE_CONAN_V2 to OFF. + # - If current Conan version is 2.0, then set MODE_CONAN_V2 TO ON. + set(autodetectOneValueArgs CONAN_V2) + cmake_parse_arguments(MODE "" "${autodetectOneValueArgs}" "" ${ARGV}) + if (NOT MODE_CONAN_V2) + conan_version(CONAN_VERSION) + if (CONAN_VERSION VERSION_LESS "2.0.0") + set(MODE_CONAN_V2 OFF) + else () + set(MODE_CONAN_V2 ON) + endif () + endif () _conan_detect_build_type(${ARGV}) _conan_check_system_name() _conan_check_language() From 8e7ec0a1e591df93c0b5cabcb079d800f5651afd Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Thu, 17 Nov 2022 23:45:10 +0800 Subject: [PATCH 28/31] chore: Move up conan_cmake_detect_unix_libcxx --- conan.cmake | 168 ++++++++++++++++++++++++++-------------------------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/conan.cmake b/conan.cmake index b573b701..29f6dd4a 100644 --- a/conan.cmake +++ b/conan.cmake @@ -199,6 +199,90 @@ function(conan_cmake_detect_msvc_runtime result1 result2) endfunction() +function(conan_cmake_detect_unix_libcxx result) + # Take into account any -stdlib in compile options + get_directory_property(compile_options DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_OPTIONS) + string(GENEX_STRIP "${compile_options}" compile_options) + + # Take into account any _GLIBCXX_USE_CXX11_ABI in compile definitions + get_directory_property(defines DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_DEFINITIONS) + string(GENEX_STRIP "${defines}" defines) + + foreach(define ${defines}) + if(define MATCHES "_GLIBCXX_USE_CXX11_ABI") + if(define MATCHES "^-D") + set(compile_options ${compile_options} "${define}") + else() + set(compile_options ${compile_options} "-D${define}") + endif() + endif() + endforeach() + + # add additional compiler options ala cmRulePlaceholderExpander::ExpandRuleVariable + set(EXPAND_CXX_COMPILER ${CMAKE_CXX_COMPILER}) + if(CMAKE_CXX_COMPILER_ARG1) + # CMake splits CXX="foo bar baz" into CMAKE_CXX_COMPILER="foo", CMAKE_CXX_COMPILER_ARG1="bar baz" + # without this, ccache, winegcc, or other wrappers might lose all their arguments + separate_arguments(SPLIT_CXX_COMPILER_ARG1 NATIVE_COMMAND ${CMAKE_CXX_COMPILER_ARG1}) + list(APPEND EXPAND_CXX_COMPILER ${SPLIT_CXX_COMPILER_ARG1}) + endif() + + if(CMAKE_CXX_COMPILE_OPTIONS_TARGET AND CMAKE_CXX_COMPILER_TARGET) + # without --target= we may be calling the wrong underlying GCC + list(APPEND EXPAND_CXX_COMPILER "${CMAKE_CXX_COMPILE_OPTIONS_TARGET}${CMAKE_CXX_COMPILER_TARGET}") + endif() + + if(CMAKE_CXX_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN AND CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN) + list(APPEND EXPAND_CXX_COMPILER "${CMAKE_CXX_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN}${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}") + endif() + + if(CMAKE_CXX_COMPILE_OPTIONS_SYSROOT) + # without --sysroot= we may find the wrong #include + if(CMAKE_SYSROOT_COMPILE) + list(APPEND EXPAND_CXX_COMPILER "${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT_COMPILE}") + elseif(CMAKE_SYSROOT) + list(APPEND EXPAND_CXX_COMPILER "${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT}") + endif() + endif() + + separate_arguments(SPLIT_CXX_FLAGS NATIVE_COMMAND ${CMAKE_CXX_FLAGS}) + + if(CMAKE_OSX_SYSROOT) + set(xcode_sysroot_option "--sysroot=${CMAKE_OSX_SYSROOT}") + endif() + + execute_process( + COMMAND ${CMAKE_COMMAND} -E echo "#include " + COMMAND ${EXPAND_CXX_COMPILER} ${SPLIT_CXX_FLAGS} -x c++ ${xcode_sysroot_option} ${compile_options} -E -dM - + OUTPUT_VARIABLE string_defines + ) + + if(string_defines MATCHES "#define __GLIBCXX__") + # Allow -D_GLIBCXX_USE_CXX11_ABI=ON/OFF as argument to cmake + if(DEFINED _GLIBCXX_USE_CXX11_ABI) + if(_GLIBCXX_USE_CXX11_ABI) + set(${result} libstdc++11 PARENT_SCOPE) + return() + else() + set(${result} libstdc++ PARENT_SCOPE) + return() + endif() + endif() + + if(string_defines MATCHES "#define _GLIBCXX_USE_CXX11_ABI 1\n") + set(${result} libstdc++11 PARENT_SCOPE) + else() + # Either the compiler is missing the define because it is old, and so + # it can't use the new abi, or the compiler was configured to use the + # old abi by the user or distro (e.g. devtoolset on RHEL/CentOS) + set(${result} libstdc++ PARENT_SCOPE) + endif() + else() + set(${result} libc++ PARENT_SCOPE) + endif() +endfunction() + + # Detect 'build_type' setting. macro(_conan_detect_build_type) conan_parse_arguments(${ARGV}) @@ -543,90 +627,6 @@ function(conan_cmake_settings result) endfunction() -function(conan_cmake_detect_unix_libcxx result) - # Take into account any -stdlib in compile options - get_directory_property(compile_options DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_OPTIONS) - string(GENEX_STRIP "${compile_options}" compile_options) - - # Take into account any _GLIBCXX_USE_CXX11_ABI in compile definitions - get_directory_property(defines DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_DEFINITIONS) - string(GENEX_STRIP "${defines}" defines) - - foreach(define ${defines}) - if(define MATCHES "_GLIBCXX_USE_CXX11_ABI") - if(define MATCHES "^-D") - set(compile_options ${compile_options} "${define}") - else() - set(compile_options ${compile_options} "-D${define}") - endif() - endif() - endforeach() - - # add additional compiler options ala cmRulePlaceholderExpander::ExpandRuleVariable - set(EXPAND_CXX_COMPILER ${CMAKE_CXX_COMPILER}) - if(CMAKE_CXX_COMPILER_ARG1) - # CMake splits CXX="foo bar baz" into CMAKE_CXX_COMPILER="foo", CMAKE_CXX_COMPILER_ARG1="bar baz" - # without this, ccache, winegcc, or other wrappers might lose all their arguments - separate_arguments(SPLIT_CXX_COMPILER_ARG1 NATIVE_COMMAND ${CMAKE_CXX_COMPILER_ARG1}) - list(APPEND EXPAND_CXX_COMPILER ${SPLIT_CXX_COMPILER_ARG1}) - endif() - - if(CMAKE_CXX_COMPILE_OPTIONS_TARGET AND CMAKE_CXX_COMPILER_TARGET) - # without --target= we may be calling the wrong underlying GCC - list(APPEND EXPAND_CXX_COMPILER "${CMAKE_CXX_COMPILE_OPTIONS_TARGET}${CMAKE_CXX_COMPILER_TARGET}") - endif() - - if(CMAKE_CXX_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN AND CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN) - list(APPEND EXPAND_CXX_COMPILER "${CMAKE_CXX_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN}${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}") - endif() - - if(CMAKE_CXX_COMPILE_OPTIONS_SYSROOT) - # without --sysroot= we may find the wrong #include - if(CMAKE_SYSROOT_COMPILE) - list(APPEND EXPAND_CXX_COMPILER "${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT_COMPILE}") - elseif(CMAKE_SYSROOT) - list(APPEND EXPAND_CXX_COMPILER "${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT}") - endif() - endif() - - separate_arguments(SPLIT_CXX_FLAGS NATIVE_COMMAND ${CMAKE_CXX_FLAGS}) - - if(CMAKE_OSX_SYSROOT) - set(xcode_sysroot_option "--sysroot=${CMAKE_OSX_SYSROOT}") - endif() - - execute_process( - COMMAND ${CMAKE_COMMAND} -E echo "#include " - COMMAND ${EXPAND_CXX_COMPILER} ${SPLIT_CXX_FLAGS} -x c++ ${xcode_sysroot_option} ${compile_options} -E -dM - - OUTPUT_VARIABLE string_defines - ) - - if(string_defines MATCHES "#define __GLIBCXX__") - # Allow -D_GLIBCXX_USE_CXX11_ABI=ON/OFF as argument to cmake - if(DEFINED _GLIBCXX_USE_CXX11_ABI) - if(_GLIBCXX_USE_CXX11_ABI) - set(${result} libstdc++11 PARENT_SCOPE) - return() - else() - set(${result} libstdc++ PARENT_SCOPE) - return() - endif() - endif() - - if(string_defines MATCHES "#define _GLIBCXX_USE_CXX11_ABI 1\n") - set(${result} libstdc++11 PARENT_SCOPE) - else() - # Either the compiler is missing the define because it is old, and so - # it can't use the new abi, or the compiler was configured to use the - # old abi by the user or distro (e.g. devtoolset on RHEL/CentOS) - set(${result} libstdc++ PARENT_SCOPE) - endif() - else() - set(${result} libc++ PARENT_SCOPE) - endif() -endfunction() - - function(_collect_settings result) set(ARGUMENTS_PROFILE_AUTO arch build_type compiler compiler.version compiler.runtime compiler.runtime_type From 47189447beadb35eb415019cc7050f081c194a48 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Thu, 17 Nov 2022 23:50:39 +0800 Subject: [PATCH 29/31] chore: Add comments for detecting compiler.libcxx --- conan.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/conan.cmake b/conan.cmake index 29f6dd4a..34198e10 100644 --- a/conan.cmake +++ b/conan.cmake @@ -199,6 +199,7 @@ function(conan_cmake_detect_msvc_runtime result1 result2) endfunction() +# Detect 'compiler.libcxx' setting for 'gcc', 'clang'...etc. function(conan_cmake_detect_unix_libcxx result) # Take into account any -stdlib in compile options get_directory_property(compile_options DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_OPTIONS) From c144477ceff65cb4e502099083f666bdbca52467 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Sun, 27 Nov 2022 00:34:27 +0800 Subject: [PATCH 30/31] chore: Rename to _conan_detect_xxx --- conan.cmake | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/conan.cmake b/conan.cmake index 34198e10..548604e5 100644 --- a/conan.cmake +++ b/conan.cmake @@ -40,7 +40,7 @@ include(CMakeParseArguments) # Detect 'compiler.version' setting for 'Visual Studio', # which will be deprecated in Conan 2.0. -function(conan_cmake_detect_vs_version result) +function(_conan_detect_vs_version result) set(${result} "" PARENT_SCOPE) if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500) # VS2005, VC 8.0 @@ -77,7 +77,7 @@ endfunction() # Detect 'compiler.runtime' setting for 'Visual Studio', # which will be deprecated in Conan 2.0. -function(conan_cmake_detect_vs_runtime result) +function(_conan_detect_vs_runtime result) conan_parse_arguments(${ARGV}) if(ARGUMENTS_BUILD_TYPE) set(build_type "${ARGUMENTS_BUILD_TYPE}") @@ -112,7 +112,7 @@ endfunction() # Detect 'compiler.version' setting for 'msvc'. -function(conan_cmake_detect_msvc_version result) +function(_conan_detect_msvc_version result) set(${result} "" PARENT_SCOPE) if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500) # VS2005 @@ -148,7 +148,7 @@ endfunction() # Detect 'compiler.runtime' and 'compiler.runtime_type' settings for 'msvc'. -function(conan_cmake_detect_msvc_runtime result1 result2) +function(_conan_detect_msvc_runtime result1 result2) conan_parse_arguments(${ARGV}) if(ARGUMENTS_BUILD_TYPE) @@ -200,7 +200,7 @@ endfunction() # Detect 'compiler.libcxx' setting for 'gcc', 'clang'...etc. -function(conan_cmake_detect_unix_libcxx result) +function(_conan_detect_unix_libcxx result) # Take into account any -stdlib in compile options get_directory_property(compile_options DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_OPTIONS) string(GENEX_STRIP "${compile_options}" compile_options) @@ -380,7 +380,7 @@ macro(_conan_detect_compiler) set(_CONAN_SETTING_COMPILER_VERSION ${COMPILER_VERSION}) if (USING_CXX) - conan_cmake_detect_unix_libcxx(_LIBCXX) + _conan_detect_unix_libcxx(_LIBCXX) set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) endif () elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Intel) @@ -391,7 +391,7 @@ macro(_conan_detect_compiler) set(_CONAN_SETTING_COMPILER intel) set(_CONAN_SETTING_COMPILER_VERSION ${COMPILER_VERSION}) if (USING_CXX) - conan_cmake_detect_unix_libcxx(_LIBCXX) + _conan_detect_unix_libcxx(_LIBCXX) set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) endif () elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL AppleClang) @@ -411,7 +411,7 @@ macro(_conan_detect_compiler) set(_CONAN_SETTING_COMPILER apple-clang) if (USING_CXX) - conan_cmake_detect_unix_libcxx(_LIBCXX) + _conan_detect_unix_libcxx(_LIBCXX) set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) endif () elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Clang @@ -440,7 +440,7 @@ macro(_conan_detect_compiler) endif() endif() if (USING_CXX) - conan_cmake_detect_unix_libcxx(_LIBCXX) + _conan_detect_unix_libcxx(_LIBCXX) set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) endif () elseif ("${CMAKE_${LANGUAGE}_COMPILER_ID}" STREQUAL "MSVC" @@ -454,7 +454,7 @@ macro(_conan_detect_compiler) # Detect 'compiler' and 'compiler.version' settings. set(_VISUAL "Visual Studio") - conan_cmake_detect_vs_version(_VISUAL_VERSION) + _conan_detect_vs_version(_VISUAL_VERSION) if("${_VISUAL_VERSION}" STREQUAL "") message(FATAL_ERROR "Conan: Visual Studio not recognized") else() @@ -477,7 +477,7 @@ macro(_conan_detect_compiler) endif() # Detect 'compiler.runtime' setting. - conan_cmake_detect_vs_runtime(VS_RUNTIME ${ARGV}) + _conan_detect_vs_runtime(VS_RUNTIME ${ARGV}) message(STATUS "Conan: Detected VS runtime: ${VS_RUNTIME}") set(_CONAN_SETTING_COMPILER_RUNTIME ${VS_RUNTIME}) @@ -492,7 +492,7 @@ macro(_conan_detect_compiler) # Detect 'compiler' and 'compiler.version' settings. set(_MSVC "msvc") - conan_cmake_detect_msvc_version(_MSVC_VERSION) + _conan_detect_msvc_version(_MSVC_VERSION) if("${_MSVC_VERSION}" STREQUAL "") message(FATAL_ERROR "Conan: MSVC not recognized") else() @@ -515,7 +515,7 @@ macro(_conan_detect_compiler) endif() # Detect 'compiler.runtime' and 'compiler.runtime_type' settings. - conan_cmake_detect_msvc_runtime(_MSVC_RUNTIME _MSVC_RUNTIME_TYPE ${ARGV}) + _conan_detect_msvc_runtime(_MSVC_RUNTIME _MSVC_RUNTIME_TYPE ${ARGV}) message(STATUS "Conan: Detected MSVC runtime: ${_MSVC_RUNTIME}") set(_CONAN_SETTING_COMPILER_RUNTIME ${_MSVC_RUNTIME}) message(STATUS "Conan: Detected MSVC runtime_type: ${_MSVC_RUNTIME_TYPE}") From b6b59c619aa29fcaa7c10d923a36098cb7d6d648 Mon Sep 17 00:00:00 2001 From: hwhsu1231 Date: Mon, 19 Dec 2022 13:00:33 +0800 Subject: [PATCH 31/31] feat: Add _conan_detect_arch macro * Add '_conan_detect_arch' macro. * Apply '_conan_detect_arch' in 'conan_cmake_settings'. * Apply '_conan_detect_arch' in 'conan_cmake_autodetect'. * Remove detecting 'arch' mechanism in detecting MSVC compiler. --- conan.cmake | 61 ++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/conan.cmake b/conan.cmake index 548604e5..c57a2d2f 100644 --- a/conan.cmake +++ b/conan.cmake @@ -309,6 +309,34 @@ macro(_conan_detect_build_type) endmacro() +# Detect 'arch' setting. +macro(_conan_detect_arch) + conan_parse_arguments(${ARGV}) + if (ARGUMENTS_ARCH) + set(_CONAN_SETTING_ARCH ${ARGUMENTS_ARCH}) + else () + if ("${CMAKE_${LANGUAGE}_COMPILER_ID}" STREQUAL "MSVC" + OR ("${CMAKE_${LANGUAGE}_COMPILER_ID}" STREQUAL "Clang" + AND "${CMAKE_${LANGUAGE}_SIMULATE_ID}" STREQUAL "MSVC")) + # Available for MSVC + # Available for MSVC-based Clang + if (CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID MATCHES "64") + set(_CONAN_SETTING_ARCH x86_64) + elseif (CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID MATCHES "^ARM") + set(_CONAN_SETTING_ARCH armv6) + elseif (CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID MATCHES "86") + set(_CONAN_SETTING_ARCH x86) + else () + # Other architectures... + endif() + else () + # Other C/C++ compilers... + # Use other mechanism to detect its architecture + endif () + endif () +endmacro () + + # Detect 'os' setting. macro(_conan_check_system_name) #handle -s os setting @@ -462,20 +490,6 @@ macro(_conan_detect_compiler) set(_CONAN_SETTING_COMPILER_VERSION ${_VISUAL_VERSION}) endif() - # Detect 'arch' setting. - if(NOT _CONAN_SETTING_ARCH) - if (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "64") - set(_CONAN_SETTING_ARCH x86_64) - elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "^ARM") - message(STATUS "Conan: Using default ARM architecture from VS") - set(_CONAN_SETTING_ARCH armv6) - elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "86") - set(_CONAN_SETTING_ARCH x86) - else () - message(FATAL_ERROR "Conan: Unknown VS architecture [${MSVC_${LANGUAGE}_ARCHITECTURE_ID}]") - endif() - endif() - # Detect 'compiler.runtime' setting. _conan_detect_vs_runtime(VS_RUNTIME ${ARGV}) message(STATUS "Conan: Detected VS runtime: ${VS_RUNTIME}") @@ -500,20 +514,6 @@ macro(_conan_detect_compiler) set(_CONAN_SETTING_COMPILER_VERSION ${_MSVC_VERSION}) endif() - # Detect 'arch' setting. - if(NOT _CONAN_SETTING_ARCH) - if (CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID MATCHES "64") - set(_CONAN_SETTING_ARCH x86_64) - elseif (CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID MATCHES "^ARM") - message(STATUS "Conan: Using default ARM architecture from MSVC") - set(_CONAN_SETTING_ARCH armv6) - elseif (CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID MATCHES "86") - set(_CONAN_SETTING_ARCH x86) - else () - message(FATAL_ERROR "Conan: Unknown MSVC architecture [${CMAKE_${LANGUAGE}_COMPILER_ARCHITECTURE_ID}]") - endif() - endif() - # Detect 'compiler.runtime' and 'compiler.runtime_type' settings. _conan_detect_msvc_runtime(_MSVC_RUNTIME _MSVC_RUNTIME_TYPE ${ARGV}) message(STATUS "Conan: Detected MSVC runtime: ${_MSVC_RUNTIME}") @@ -567,11 +567,9 @@ function(conan_cmake_settings result) conan_parse_arguments(${ARGV}) _conan_detect_build_type(${ARGV}) - + _conan_detect_arch(${ARGV}) _conan_check_system_name() - _conan_check_language() - _conan_detect_compiler(${ARGV}) # If profile is defined it is used @@ -660,6 +658,7 @@ function(conan_cmake_autodetect detected_settings) endif () endif () _conan_detect_build_type(${ARGV}) + _conan_detect_arch(${ARGV}) _conan_check_system_name() _conan_check_language() _conan_detect_compiler(${ARGV})