Skip to content

Commit c0634f4

Browse files
committed
feat: Add CONAN_V2 detecting mechanism
1 parent 45301e3 commit c0634f4

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

conan.cmake

+16-4
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,7 @@ macro(_conan_detect_compiler)
343343
AND "${CMAKE_${LANGUAGE}_SIMULATE_ID}" STREQUAL "MSVC"))
344344
# Using MSVC compilers.
345345

346-
conan_version(CONAN_VERSION)
347-
if (${CONAN_VERSION} VERSION_LESS "2.0.0")
348-
# Conan 1.0
346+
if (NOT MODE_CONAN_V2)
349347
# Detect 'Visual Studio' compiler settings.
350348

351349
# Detect 'compiler' and 'compiler.version' settings.
@@ -384,7 +382,6 @@ macro(_conan_detect_compiler)
384382
set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET})
385383
endif()
386384
else ()
387-
# Conan 2.0
388385
# Detect 'msvc' compiler settings.
389386

390387
# Detect 'compiler' and 'compiler.version' settings.
@@ -625,6 +622,21 @@ function(_collect_settings result)
625622
endfunction()
626623

627624
function(conan_cmake_autodetect detected_settings)
625+
# Detect whether CONAN_V2 is specified with ON:
626+
# - If CONAN_V2 is specified with ON, then MODE_CONAN_V2 will be ON.
627+
# - Otherwise:
628+
# - If current Conan version is 1.0, then set MODE_CONAN_V2 to OFF.
629+
# - If current Conan version is 2.0, then set MODE_CONAN_V2 TO ON.
630+
set(autodetectOneValueArgs CONAN_V2)
631+
cmake_parse_arguments(MODE "" "${autodetectOneValueArgs}" "" ${ARGV})
632+
if (NOT MODE_CONAN_V2)
633+
conan_version(CONAN_VERSION)
634+
if (CONAN_VERSION VERSION_LESS "2.0.0")
635+
set(MODE_CONAN_V2 OFF)
636+
else ()
637+
set(MODE_CONAN_V2 ON)
638+
endif ()
639+
endif ()
628640
_conan_detect_build_type(${ARGV})
629641
_conan_check_system_name()
630642
_conan_check_language()

0 commit comments

Comments
 (0)