diff --git a/conan_provider.cmake b/conan_provider.cmake index 9931247c..0d2be004 100644 --- a/conan_provider.cmake +++ b/conan_provider.cmake @@ -35,37 +35,38 @@ set(CONAN_MINIMUM_VERSION 2.0.5) cmake_policy(PUSH) cmake_minimum_required(VERSION 3.24) -function(detect_os OS OS_API_LEVEL OS_SDK OS_SUBSYSTEM OS_VERSION) + +function(detect_os os os_api_level os_sdk os_subsystem os_version) # it could be cross compilation message(STATUS "CMake-Conan: cmake_system_name=${CMAKE_SYSTEM_NAME}") if(CMAKE_SYSTEM_NAME AND NOT CMAKE_SYSTEM_NAME STREQUAL "Generic") if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") - set(${OS} Macos PARENT_SCOPE) + set(${os} Macos PARENT_SCOPE) elseif(CMAKE_SYSTEM_NAME STREQUAL "QNX") - set(${OS} Neutrino PARENT_SCOPE) + set(${os} Neutrino PARENT_SCOPE) elseif(CMAKE_SYSTEM_NAME STREQUAL "CYGWIN") - set(${OS} Windows PARENT_SCOPE) - set(${OS_SUBSYSTEM} cygwin PARENT_SCOPE) + set(${os} Windows PARENT_SCOPE) + set(${os_subsystem} cygwin PARENT_SCOPE) elseif(CMAKE_SYSTEM_NAME MATCHES "^MSYS") - set(${OS} Windows PARENT_SCOPE) - set(${OS_SUBSYSTEM} msys2 PARENT_SCOPE) + set(${os} Windows PARENT_SCOPE) + set(${os_subsystem} msys2 PARENT_SCOPE) else() - set(${OS} ${CMAKE_SYSTEM_NAME} PARENT_SCOPE) + set(${os} ${CMAKE_SYSTEM_NAME} PARENT_SCOPE) endif() if(CMAKE_SYSTEM_NAME STREQUAL "Android") if(DEFINED ANDROID_PLATFORM) - string(REGEX MATCH "[0-9]+" _OS_API_LEVEL ${ANDROID_PLATFORM}) + string(REGEX MATCH "[0-9]+" _os_api_level ${ANDROID_PLATFORM}) elseif(DEFINED CMAKE_SYSTEM_VERSION) - set(_OS_API_LEVEL ${CMAKE_SYSTEM_VERSION}) + set(_os_api_level ${CMAKE_SYSTEM_VERSION}) endif() - message(STATUS "CMake-Conan: android api level=${_OS_API_LEVEL}") - set(${OS_API_LEVEL} ${_OS_API_LEVEL} PARENT_SCOPE) + message(STATUS "CMake-Conan: android api level=${_os_api_level}") + set(${os_api_level} ${_os_api_level} PARENT_SCOPE) endif() if(CMAKE_SYSTEM_NAME MATCHES "Darwin|iOS|tvOS|watchOS") # CMAKE_OSX_SYSROOT contains the full path to the SDK for MakeFile/Ninja # generators, but just has the original input string for Xcode. if(NOT IS_DIRECTORY ${CMAKE_OSX_SYSROOT}) - set(_OS_SDK ${CMAKE_OSX_SYSROOT}) + set(_os_sdk ${CMAKE_OSX_SYSROOT}) else() if(CMAKE_OSX_SYSROOT MATCHES Simulator) set(apple_platform_suffix simulator) @@ -73,27 +74,27 @@ function(detect_os OS OS_API_LEVEL OS_SDK OS_SUBSYSTEM OS_VERSION) set(apple_platform_suffix os) endif() if(CMAKE_OSX_SYSROOT MATCHES AppleTV) - set(_OS_SDK "appletv${apple_platform_suffix}") + set(_os_sdk "appletv${apple_platform_suffix}") elseif(CMAKE_OSX_SYSROOT MATCHES iPhone) - set(_OS_SDK "iphone${apple_platform_suffix}") + set(_os_sdk "iphone${apple_platform_suffix}") elseif(CMAKE_OSX_SYSROOT MATCHES Watch) - set(_OS_SDK "watch${apple_platform_suffix}") + set(_os_sdk "watch${apple_platform_suffix}") endif() endif() - if(DEFINED _OS_SDK) + if(DEFINED os_sdk) message(STATUS "CMake-Conan: cmake_osx_sysroot=${CMAKE_OSX_SYSROOT}") - set(${OS_SDK} ${_OS_SDK} PARENT_SCOPE) + set(${os_sdk} ${_os_sdk} PARENT_SCOPE) endif() if(DEFINED CMAKE_OSX_DEPLOYMENT_TARGET) message(STATUS "CMake-Conan: cmake_osx_deployment_target=${CMAKE_OSX_DEPLOYMENT_TARGET}") - set(${OS_VERSION} ${CMAKE_OSX_DEPLOYMENT_TARGET} PARENT_SCOPE) + set(${os_version} ${CMAKE_OSX_DEPLOYMENT_TARGET} PARENT_SCOPE) endif() endif() endif() endfunction() -function(detect_arch ARCH) +function(detect_arch arch) # CMAKE_OSX_ARCHITECTURES can contain multiple architectures, but Conan only supports one. # Therefore this code only finds one. If the recipes support multiple architectures, the # build will work. Otherwise, there will be a linker error for the missing architecture(s). @@ -112,67 +113,67 @@ function(detect_arch ARCH) set(host_arch ${CMAKE_SYSTEM_PROCESSOR}) endif() if(host_arch MATCHES "aarch64|arm64|ARM64") - set(_ARCH armv8) + set(_arch armv8) elseif(host_arch MATCHES "armv7|armv7-a|armv7l|ARMV7") - set(_ARCH armv7) + set(_arch armv7) elseif(host_arch MATCHES armv7s) - set(_ARCH armv7s) + set(_arch armv7s) elseif(host_arch MATCHES "i686|i386|X86") - set(_ARCH x86) + set(_arch x86) elseif(host_arch MATCHES "AMD64|amd64|x86_64|x64") - set(_ARCH x86_64) + set(_arch x86_64) endif() - message(STATUS "CMake-Conan: cmake_system_processor=${_ARCH}") - set(${ARCH} ${_ARCH} PARENT_SCOPE) + message(STATUS "CMake-Conan: cmake_system_processor=${_arch}") + set(${arch} ${_arch} PARENT_SCOPE) endfunction() -function(detect_cxx_standard CXX_STANDARD) - set(${CXX_STANDARD} ${CMAKE_CXX_STANDARD} PARENT_SCOPE) +function(detect_cxx_standard cxx_standard) + set(${cxx_standard} ${CMAKE_CXX_STANDARD} PARENT_SCOPE) if(CMAKE_CXX_EXTENSIONS) - set(${CXX_STANDARD} "gnu${CMAKE_CXX_STANDARD}" PARENT_SCOPE) + set(${cxx_standard} "gnu${CMAKE_CXX_STANDARD}" PARENT_SCOPE) endif() endfunction() macro(detect_gnu_libstdcxx) - # _CONAN_IS_GNU_LIBSTDCXX true if GNU libstdc++ + # _conan_is_gnu_libstdcxx true if GNU libstdc++ check_cxx_source_compiles(" #include #if !defined(__GLIBCXX__) && !defined(__GLIBCPP__) static_assert(false); #endif - int main(){}" _CONAN_IS_GNU_LIBSTDCXX) + int main(){}" _conan_is_gnu_libstdcxx) - # _CONAN_GNU_LIBSTDCXX_IS_CXX11_ABI true if C++11 ABI + # _conan_gnu_libstdcxx_is_cxx11_abi true if C++11 ABI check_cxx_source_compiles(" #include static_assert(sizeof(std::string) != sizeof(void*), \"using libstdc++\"); - int main () {}" _CONAN_GNU_LIBSTDCXX_IS_CXX11_ABI) + int main () {}" _conan_gnu_libstdcxx_is_cxx11_abi) - set(_CONAN_GNU_LIBSTDCXX_SUFFIX "") - if(_CONAN_GNU_LIBSTDCXX_IS_CXX11_ABI) - set(_CONAN_GNU_LIBSTDCXX_SUFFIX "11") + set(_conan_gnu_libstdcxx_suffix "") + if(_conan_gnu_libstdcxx_is_cxx11_abi) + set(_conan_gnu_libstdcxx_suffix "11") endif() - unset (_CONAN_GNU_LIBSTDCXX_IS_CXX11_ABI) + unset (_conan_gnu_libstdcxx_is_cxx11_abi) endmacro() macro(detect_libcxx) - # _CONAN_IS_LIBCXX true if LLVM libc++ + # _conan_is_libcxx true if LLVM libc++ check_cxx_source_compiles(" #include #if !defined(_LIBCPP_VERSION) static_assert(false); #endif - int main(){}" _CONAN_IS_LIBCXX) + int main(){}" _conan_is_libcxx) endmacro() -function(detect_lib_cxx LIB_CXX) +function(detect_lib_cxx lib_cxx) if(CMAKE_SYSTEM_NAME STREQUAL "Android") message(STATUS "CMake-Conan: android_stl=${CMAKE_ANDROID_STL_TYPE}") - set(${LIB_CXX} ${CMAKE_ANDROID_STL_TYPE} PARENT_SCOPE) + set(${lib_cxx} ${CMAKE_ANDROID_STL_TYPE} PARENT_SCOPE) return() endif() @@ -180,21 +181,21 @@ function(detect_lib_cxx LIB_CXX) if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") detect_gnu_libstdcxx() - set(${LIB_CXX} "libstdc++${_CONAN_GNU_LIBSTDCXX_SUFFIX}" PARENT_SCOPE) + set(${lib_cxx} "libstdc++${_conan_gnu_libstdcxx_suffix}" PARENT_SCOPE) elseif(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang") - set(${LIB_CXX} "libc++" PARENT_SCOPE) + set(${lib_cxx} "libc++" PARENT_SCOPE) elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_SYSTEM_NAME MATCHES "Windows") # Check for libc++ detect_libcxx() - if(_CONAN_IS_LIBCXX) - set(${LIB_CXX} "libc++" PARENT_SCOPE) + if(_conan_is_libcxx) + set(${lib_cxx} "libc++" PARENT_SCOPE) return() endif() # Check for libstdc++ detect_gnu_libstdcxx() - if(_CONAN_IS_GNU_LIBSTDCXX) - set(${LIB_CXX} "libstdc++${_CONAN_GNU_LIBSTDCXX_SUFFIX}" PARENT_SCOPE) + if(_conan_is_gnu_libstdcxx) + set(${lib_cxx} "libstdc++${_conan_gnu_libstdcxx_suffix}" PARENT_SCOPE) return() endif() @@ -209,24 +210,24 @@ function(detect_lib_cxx LIB_CXX) endfunction() -function(detect_compiler COMPILER COMPILER_VERSION COMPILER_RUNTIME COMPILER_RUNTIME_TYPE) +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}) + set(_compiler ${CMAKE_CXX_COMPILER_ID}) + set(_compiler_version ${CMAKE_CXX_COMPILER_VERSION}) else() if(NOT DEFINED CMAKE_C_COMPILER_ID) message(FATAL_ERROR "C or C++ compiler not defined") endif() - set(_COMPILER ${CMAKE_C_COMPILER_ID}) - set(_COMPILER_VERSION ${CMAKE_C_COMPILER_VERSION}) + set(_compiler ${CMAKE_C_COMPILER_ID}) + set(_compiler_version ${CMAKE_C_COMPILER_VERSION}) endif() - message(STATUS "CMake-Conan: CMake compiler=${_COMPILER}") - message(STATUS "CMake-Conan: CMake compiler version=${_COMPILER_VERSION}") + message(STATUS "CMake-Conan: CMake compiler=${_compiler}") + message(STATUS "CMake-Conan: CMake compiler version=${_compiler_version}") - if(_COMPILER MATCHES MSVC) - set(_COMPILER "msvc") - string(SUBSTRING ${MSVC_VERSION} 0 3 _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(_msvc_runtime_library ${CMAKE_MSVC_RUNTIME_LIBRARY}) @@ -246,64 +247,65 @@ function(detect_compiler COMPILER COMPILER_VERSION COMPILER_RUNTIME COMPILER_RUN # Runtime is "dynamic" in all cases if it ends in DLL if(_msvc_runtime_library MATCHES ".*DLL$") - set(_COMPILER_RUNTIME "dynamic") + set(_compiler_runtime "dynamic") else() - set(_COMPILER_RUNTIME "static") + set(_compiler_runtime "static") endif() - message(STATUS "CMake-Conan: CMake compiler.runtime=${_COMPILER_RUNTIME}") + message(STATUS "CMake-Conan: CMake compiler.runtime=${_compiler_runtime}") # 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 ":Debug>") if(_msvc_runtime_library MATCHES "Debug") - set(_COMPILER_RUNTIME_TYPE "Debug") + set(_compiler_runtime_type "Debug") else() - set(_COMPILER_RUNTIME_TYPE "Release") + set(_compiler_runtime_type "Release") endif() - message(STATUS "CMake-Conan: CMake compiler.runtime_type=${_COMPILER_RUNTIME_TYPE}") + message(STATUS "CMake-Conan: CMake compiler.runtime_type=${_compiler_runtime_type}") endif() unset(_KNOWN_MSVC_RUNTIME_VALUES) - elseif(_COMPILER MATCHES AppleClang) - set(_COMPILER "apple-clang") + elseif(_compiler MATCHES AppleClang) + set(_compiler "apple-clang") string(REPLACE "." ";" VERSION_LIST ${CMAKE_CXX_COMPILER_VERSION}) - list(GET VERSION_LIST 0 _COMPILER_VERSION) - elseif(_COMPILER MATCHES Clang) - set(_COMPILER "clang") + list(GET VERSION_LIST 0 _compiler_version) + elseif(_compiler MATCHES Clang) + set(_compiler "clang") string(REPLACE "." ";" VERSION_LIST ${CMAKE_CXX_COMPILER_VERSION}) - list(GET VERSION_LIST 0 _COMPILER_VERSION) - elseif(_COMPILER MATCHES GNU) - set(_COMPILER "gcc") + list(GET VERSION_LIST 0 _compiler_version) + elseif(_compiler MATCHES GNU) + set(_compiler "gcc") string(REPLACE "." ";" VERSION_LIST ${CMAKE_CXX_COMPILER_VERSION}) - list(GET VERSION_LIST 0 _COMPILER_VERSION) + list(GET VERSION_LIST 0 _compiler_version) endif() - 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}") + 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}") + 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) + 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) - get_property(_MULTICONFIG_GENERATOR GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) - if(NOT _MULTICONFIG_GENERATOR) +function(detect_build_type build_type) + get_property(multiconfig_generator GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(NOT multiconfig_generator) # Only set when we know we are in a single-configuration generator # Note: we may want to fail early if `CMAKE_BUILD_TYPE` is not defined - set(${BUILD_TYPE} ${CMAKE_BUILD_TYPE} PARENT_SCOPE) + set(${build_type} ${CMAKE_BUILD_TYPE} PARENT_SCOPE) endif() endfunction() + macro(set_conan_compiler_if_appleclang lang command output_variable) if(CMAKE_${lang}_COMPILER_ID STREQUAL "AppleClang") execute_process(COMMAND xcrun --find ${command} @@ -348,7 +350,7 @@ macro(append_compiler_executables_configuration) endif() if(NOT "x${_conan_compilers_list}" STREQUAL "x") string(REPLACE ";" "," _conan_compilers_list "${_conan_compilers_list}") - string(APPEND PROFILE "tools.build:compiler_executables={${_conan_compilers_list}}\n") + string(APPEND profile "tools.build:compiler_executables={${_conan_compilers_list}}\n") endif() unset(_conan_c_compiler) unset(_conan_cpp_compiler) @@ -358,74 +360,74 @@ endmacro() 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 MYCOMPILER_RUNTIME MYCOMPILER_RUNTIME_TYPE) - detect_cxx_standard(MYCXX_STANDARD) - detect_lib_cxx(MYLIB_CXX) - detect_build_type(MYBUILD_TYPE) + detect_os(os os_api_level os_sdk os_subsystem os_version) + detect_arch(arch) + detect_compiler(compiler compiler_version compiler_runtime compiler_runtime_type) + detect_cxx_standard(compiler_cppstd) + detect_lib_cxx(compiler_libcxx) + detect_build_type(build_type) - set(PROFILE "") - string(APPEND PROFILE "[settings]\n") - if(MYARCH) - string(APPEND PROFILE arch=${MYARCH} "\n") + set(profile "") + string(APPEND profile "[settings]\n") + if(arch) + string(APPEND profile arch=${arch} "\n") endif() - if(MYOS) - string(APPEND PROFILE os=${MYOS} "\n") + if(os) + string(APPEND profile os=${os} "\n") endif() - if(MYOS_API_LEVEL) - string(APPEND PROFILE os.api_level=${MYOS_API_LEVEL} "\n") + if(os_api_level) + string(APPEND profile os.api_level=${os_api_level} "\n") endif() - if(MYOS_VERSION) - string(APPEND PROFILE os.version=${MYOS_VERSION} "\n") + if(os_version) + string(APPEND profile os.version=${os_version} "\n") endif() - if(MYOS_SDK) - string(APPEND PROFILE os.sdk=${MYOS_SDK} "\n") + if(os_sdk) + string(APPEND profile os.sdk=${os_sdk} "\n") endif() - if(MYOS_SUBSYSTEM) - string(APPEND PROFILE os.subsystem=${MYOS_SUBSYSTEM} "\n") + if(os_subsystem) + string(APPEND profile os.subsystem=${os_subsystem} "\n") endif() - if(MYCOMPILER) - string(APPEND PROFILE compiler=${MYCOMPILER} "\n") + if(compiler) + string(APPEND profile compiler=${compiler} "\n") endif() - if(MYCOMPILER_VERSION) - string(APPEND PROFILE compiler.version=${MYCOMPILER_VERSION} "\n") + if(compiler_version) + string(APPEND profile compiler.version=${compiler_version} "\n") endif() - if(MYCOMPILER_RUNTIME) - string(APPEND PROFILE compiler.runtime=${MYCOMPILER_RUNTIME} "\n") + if(compiler_runtime) + string(APPEND profile compiler.runtime=${compiler_runtime} "\n") endif() - if(MYCOMPILER_RUNTIME_TYPE) - string(APPEND PROFILE compiler.runtime_type=${MYCOMPILER_RUNTIME_TYPE} "\n") + if(compiler_runtime_type) + string(APPEND profile compiler.runtime_type=${compiler_runtime_type} "\n") endif() - if(MYCXX_STANDARD) - string(APPEND PROFILE compiler.cppstd=${MYCXX_STANDARD} "\n") + if(compiler_cppstd) + string(APPEND profile compiler.cppstd=${compiler_cppstd} "\n") endif() - if(MYLIB_CXX) - string(APPEND PROFILE compiler.libcxx=${MYLIB_CXX} "\n") + if(compiler_libcxx) + string(APPEND profile compiler.libcxx=${compiler_libcxx} "\n") endif() - if(MYBUILD_TYPE) - string(APPEND PROFILE "build_type=${MYBUILD_TYPE}\n") + if(build_type) + string(APPEND profile "build_type=${build_type}\n") endif() if(NOT DEFINED output_file) - set(_FN "${CMAKE_BINARY_DIR}/profile") + set(file_name "${CMAKE_BINARY_DIR}/profile") else() - set(_FN ${output_file}) + set(file_name ${output_file}) endif() - string(APPEND PROFILE "[conf]\n") - string(APPEND PROFILE "tools.cmake.cmaketoolchain:generator=${CMAKE_GENERATOR}\n") + string(APPEND profile "[conf]\n") + string(APPEND profile "tools.cmake.cmaketoolchain:generator=${CMAKE_GENERATOR}\n") # propagate compilers via profile append_compiler_executables_configuration() - if(MYOS STREQUAL "Android") - string(APPEND PROFILE "tools.android:ndk_path=${CMAKE_ANDROID_NDK}\n") + if(os STREQUAL "Android") + string(APPEND profile "tools.android:ndk_path=${CMAKE_ANDROID_NDK}\n") endif() - message(STATUS "CMake-Conan: Creating profile ${_FN}") - file(WRITE ${_FN} ${PROFILE}) - message(STATUS "CMake-Conan: Profile: \n${PROFILE}") + message(STATUS "CMake-Conan: Creating profile ${file_name}") + file(WRITE ${file_name} ${profile}) + message(STATUS "CMake-Conan: Profile: \n${profile}") endfunction() @@ -452,21 +454,21 @@ endfunction() function(conan_install) - cmake_parse_arguments(ARGS CONAN_ARGS ${ARGN}) - set(CONAN_OUTPUT_FOLDER ${CMAKE_BINARY_DIR}/conan) + cmake_parse_arguments(ARGS conan_args ${ARGN}) + set(conan_output_folder ${CMAKE_BINARY_DIR}/conan) # Invoke "conan install" with the provided arguments - set(CONAN_ARGS ${CONAN_ARGS} -of=${CONAN_OUTPUT_FOLDER}) - message(STATUS "CMake-Conan: conan install ${CMAKE_SOURCE_DIR} ${CONAN_ARGS} ${ARGN}") + set(conan_args ${conan_args} -of=${conan_output_folder}) + message(STATUS "CMake-Conan: conan install ${CMAKE_SOURCE_DIR} ${conan_args} ${ARGN}") # In case there was not a valid cmake executable in the PATH, we inject the # same we used to invoke the provider to the PATH if(DEFINED PATH_TO_CMAKE_BIN) - set(_OLD_PATH $ENV{PATH}) + set(old_path $ENV{PATH}) set(ENV{PATH} "$ENV{PATH}:${PATH_TO_CMAKE_BIN}") endif() - execute_process(COMMAND ${CONAN_COMMAND} install ${CMAKE_SOURCE_DIR} ${CONAN_ARGS} ${ARGN} --format=json + execute_process(COMMAND ${CONAN_COMMAND} install ${CMAKE_SOURCE_DIR} ${conan_args} ${ARGN} --format=json RESULT_VARIABLE return_code OUTPUT_VARIABLE conan_stdout ERROR_VARIABLE conan_stderr @@ -474,7 +476,7 @@ function(conan_install) WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) if(DEFINED PATH_TO_CMAKE_BIN) - set(ENV{PATH} "${_OLD_PATH}") + set(ENV{PATH} "${old_path}") endif() if(NOT "${return_code}" STREQUAL "0") @@ -484,15 +486,15 @@ function(conan_install) # the files are generated in a folder that depends on the layout used, if # one is specified, but we don't know a priori where this is. # TODO: this can be made more robust if Conan can provide this in the json output - string(JSON CONAN_GENERATORS_FOLDER GET "${conan_stdout}" graph nodes 0 generators_folder) - cmake_path(CONVERT ${CONAN_GENERATORS_FOLDER} TO_CMAKE_PATH_LIST CONAN_GENERATORS_FOLDER) - # message("conan stdout: ${conan_stdout}") - message(STATUS "CMake-Conan: CONAN_GENERATORS_FOLDER=${CONAN_GENERATORS_FOLDER}") - set_property(GLOBAL PROPERTY CONAN_GENERATORS_FOLDER "${CONAN_GENERATORS_FOLDER}") + string(JSON conan_generators_folder GET "${conan_stdout}" graph nodes 0 generators_folder) + cmake_path(CONVERT ${conan_generators_folder} TO_CMAKE_PATH_LIST conan_generators_folder) + + message(STATUS "CMake-Conan: CONAN_GENERATORS_FOLDER=${conan_generators_folder}") + set_property(GLOBAL PROPERTY CONAN_GENERATORS_FOLDER "${conan_generators_folder}") # reconfigure on conanfile changes - string(JSON CONANFILE GET "${conan_stdout}" graph nodes 0 label) - message(STATUS "CMake-Conan: CONANFILE=${CMAKE_SOURCE_DIR}/${CONANFILE}") - set_property(DIRECTORY ${CMAKE_SOURCE_DIR} APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/${CONANFILE}") + string(JSON conanfile GET "${conan_stdout}" graph nodes 0 label) + message(STATUS "CMake-Conan: CONANFILE=${CMAKE_SOURCE_DIR}/${conanfile}") + set_property(DIRECTORY ${CMAKE_SOURCE_DIR} APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/${conanfile}") # success set_property(GLOBAL PROPERTY CONAN_INSTALL_SUCCESS TRUE) @@ -517,20 +519,20 @@ endfunction() function(conan_version_check) set(options ) - set(oneValueArgs MINIMUM CURRENT) - set(multiValueArgs ) - cmake_parse_arguments(CONAN_VERSION_CHECK - "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + set(one_value_args MINIMUM CURRENT) + set(multi_value_args ) + cmake_parse_arguments(conan_version_check + "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN}) - if(NOT CONAN_VERSION_CHECK_MINIMUM) + if(NOT conan_version_check_MINIMUM) message(FATAL_ERROR "CMake-Conan: Required parameter MINIMUM not set!") endif() - if(NOT CONAN_VERSION_CHECK_CURRENT) + if(NOT conan_version_check_CURRENT) message(FATAL_ERROR "CMake-Conan: Required parameter CURRENT not set!") endif() - if(CONAN_VERSION_CHECK_CURRENT VERSION_LESS CONAN_VERSION_CHECK_MINIMUM) - message(FATAL_ERROR "CMake-Conan: Conan version must be ${CONAN_VERSION_CHECK_MINIMUM} or later") + if(conan_version_check_CURRENT VERSION_LESS conan_version_check_MINIMUM) + message(FATAL_ERROR "CMake-Conan: Conan version must be ${conan_version_check_MINIMUM} or later") endif() endfunction() @@ -640,19 +642,19 @@ cmake_language( macro(conan_provide_dependency_check) - set(_CONAN_PROVIDE_DEPENDENCY_INVOKED FALSE) - get_property(_CONAN_PROVIDE_DEPENDENCY_INVOKED GLOBAL PROPERTY CONAN_PROVIDE_DEPENDENCY_INVOKED) - if(NOT _CONAN_PROVIDE_DEPENDENCY_INVOKED) + set(_conan_provide_dependency_invoked FALSE) + get_property(_conan_provide_dependency_invoked GLOBAL PROPERTY CONAN_PROVIDE_DEPENDENCY_INVOKED) + if(NOT _conan_provide_dependency_invoked) message(WARNING "Conan is correctly configured as dependency provider, " "but Conan has not been invoked. Please add at least one " "call to `find_package()`.") if(DEFINED CONAN_COMMAND) # supress warning in case `CONAN_COMMAND` was specified but unused. - set(_CONAN_COMMAND ${CONAN_COMMAND}) - unset(_CONAN_COMMAND) + set(_conan_command ${CONAN_COMMAND}) + unset(_conan_command) endif() endif() - unset(_CONAN_PROVIDE_DEPENDENCY_INVOKED) + unset(_conan_provide_dependency_invoked) endmacro() diff --git a/tests/test_smoke.py b/tests/test_smoke.py index 91553d72..e4e8fd8d 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -473,8 +473,8 @@ def test_gnu_libstdcxx_linux(self, capfd, basic_cmake_project, compiler): run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} " f"-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER={compiler}") out, _ = capfd.readouterr() - assert "Performing Test _CONAN_IS_GNU_LIBSTDCXX - Success" in out - assert "Performing Test _CONAN_GNU_LIBSTDCXX_IS_CXX11_ABI - Success" in out + assert "Performing Test _conan_is_gnu_libstdcxx - Success" in out + assert "Performing Test _conan_gnu_libstdcxx_is_cxx11_abi - Success" in out assert "compiler.libcxx=libstdc++11" in out if compiler == "clang++": assert "The CXX compiler identification is Clang" in out @@ -490,8 +490,8 @@ def test_gnu_libstdcxx_old_abi_linux(self, capfd, basic_cmake_project): run(f'cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} ' '-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0"') out, _ = capfd.readouterr() - assert "Performing Test _CONAN_IS_GNU_LIBSTDCXX - Success" in out - assert "Performing Test _CONAN_GNU_LIBSTDCXX_IS_CXX11_ABI - Failed" in out + assert "Performing Test _conan_is_gnu_libstdcxx - Success" in out + assert "Performing Test _conan_gnu_libstdcxx_is_cxx11_abi - Failed" in out assert "compiler.libcxx=libstdc++" in out @linux @@ -503,7 +503,7 @@ def test_clang_libcxx_linux(self, capfd, basic_cmake_project): out, _ = capfd.readouterr() assert "The CXX compiler identification is Clang" in out assert "compiler=clang" in out - assert "Performing Test _CONAN_IS_LIBCXX - Success" in out + assert "Performing Test _conan_is_libcxx - Success" in out assert "compiler.libcxx=libc++" in out class TestOsVersion: