Apply https://github.com/conan-io/cmake-conan/pull/258 (commit 3df8d20b401528629d0486e577b6c9b4e22b3ae4): Make "SETTINGS compiler.libcxx=libstdc++11" do the right thing (see https://github.com/conan-io/cmake-conan/issues/255)

This commit is contained in:
Sebastian Messmer 2020-06-30 20:13:12 -07:00
parent 9deca117f5
commit 3b0d46e01e

View File

@ -1,6 +1,8 @@
# Taken from https://github.com/conan-io/cmake-conan/blob/v0.15/conan.cmake # Taken from https://github.com/conan-io/cmake-conan/blob/v0.15/conan.cmake
# Changes: # Changes:
# - https://github.com/conan-io/cmake-conan/pull/259: Add a "Please install conan" sentence to the error message when conan wasn't found. # - https://github.com/conan-io/cmake-conan/pull/259 (commit 285082078488592d3ca6ec3b718fe54bf5804951): Add a "Please install conan" sentence to the error message when conan wasn't found.
# - https://github.com/conan-io/cmake-conan/pull/258 (commit 3df8d20b401528629d0486e577b6c9b4e22b3ae4): Make "SETTINGS compiler.libcxx=libstdc++11" do the right thing (see https://github.com/conan-io/cmake-conan/issues/255)
# The MIT License (MIT) # The MIT License (MIT)
@ -230,9 +232,16 @@ function(conan_cmake_settings result)
if(NOT _SETTINGS OR ARGUMENTS_PROFILE_AUTO STREQUAL "ALL") if(NOT _SETTINGS OR ARGUMENTS_PROFILE_AUTO STREQUAL "ALL")
set(ARGUMENTS_PROFILE_AUTO arch build_type compiler compiler.version set(ARGUMENTS_PROFILE_AUTO arch build_type compiler compiler.version
compiler.runtime compiler.libcxx compiler.toolset) compiler.runtime compiler.libcxx compiler.toolset)
endif() endif()
# remove any manually specified settings from the autodetected settings
foreach(ARG ${ARGUMENTS_SETTINGS})
string(REGEX MATCH "[^=]*" MANUAL_SETTING "${ARG}")
message(STATUS "Conan: ${MANUAL_SETTING} was added as an argument. Not using the autodetected one.")
list(REMOVE_ITEM ARGUMENTS_PROFILE_AUTO "${MANUAL_SETTING}")
endforeach()
# Automatic from CMake # Automatic from CMake
foreach(ARG ${ARGUMENTS_PROFILE_AUTO}) foreach(ARG ${ARGUMENTS_PROFILE_AUTO})
string(TOUPPER ${ARG} _arg_name) string(TOUPPER ${ARG} _arg_name)
@ -269,9 +278,9 @@ function(conan_cmake_detect_unix_libcxx result)
endforeach() endforeach()
execute_process( execute_process(
COMMAND ${CMAKE_COMMAND} -E echo "#include <string>" COMMAND ${CMAKE_COMMAND} -E echo "#include <string>"
COMMAND ${CMAKE_CXX_COMPILER} -x c++ ${compile_options} -E -dM - COMMAND ${CMAKE_CXX_COMPILER} -x c++ ${compile_options} -E -dM -
OUTPUT_VARIABLE string_defines OUTPUT_VARIABLE string_defines
) )
if(string_defines MATCHES "#define __GLIBCXX__") if(string_defines MATCHES "#define __GLIBCXX__")
@ -323,12 +332,12 @@ endfunction()
macro(parse_arguments) macro(parse_arguments)
set(options BASIC_SETUP CMAKE_TARGETS UPDATE KEEP_RPATHS NO_LOAD NO_OUTPUT_DIRS OUTPUT_QUIET NO_IMPORTS SKIP_STD) set(options BASIC_SETUP CMAKE_TARGETS UPDATE KEEP_RPATHS NO_LOAD NO_OUTPUT_DIRS OUTPUT_QUIET NO_IMPORTS SKIP_STD)
set(oneValueArgs CONANFILE ARCH BUILD_TYPE INSTALL_FOLDER CONAN_COMMAND) set(oneValueArgs CONANFILE ARCH BUILD_TYPE INSTALL_FOLDER CONAN_COMMAND)
set(multiValueArgs DEBUG_PROFILE RELEASE_PROFILE RELWITHDEBINFO_PROFILE MINSIZEREL_PROFILE set(multiValueArgs DEBUG_PROFILE RELEASE_PROFILE RELWITHDEBINFO_PROFILE MINSIZEREL_PROFILE
PROFILE REQUIRES OPTIONS IMPORTS SETTINGS BUILD ENV GENERATORS PROFILE_AUTO PROFILE REQUIRES OPTIONS IMPORTS SETTINGS BUILD ENV GENERATORS PROFILE_AUTO
INSTALL_ARGS CONFIGURATION_TYPES) INSTALL_ARGS CONFIGURATION_TYPES)
cmake_parse_arguments(ARGUMENTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) cmake_parse_arguments(ARGUMENTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
endmacro() endmacro()
function(conan_cmake_install) function(conan_cmake_install)
@ -355,29 +364,29 @@ function(conan_cmake_install)
endif() endif()
endforeach() endforeach()
if(ARGUMENTS_CONAN_COMMAND) if(ARGUMENTS_CONAN_COMMAND)
set(CONAN_CMD ${ARGUMENTS_CONAN_COMMAND}) set(CONAN_CMD ${ARGUMENTS_CONAN_COMMAND})
else() else()
conan_check(REQUIRED) conan_check(REQUIRED)
endif() endif()
set(CONAN_OPTIONS "") set(CONAN_OPTIONS "")
if(ARGUMENTS_CONANFILE) if(ARGUMENTS_CONANFILE)
set(CONANFILE ${CMAKE_CURRENT_SOURCE_DIR}/${ARGUMENTS_CONANFILE}) set(CONANFILE ${CMAKE_CURRENT_SOURCE_DIR}/${ARGUMENTS_CONANFILE})
# A conan file has been specified - apply specified options as well if provided # A conan file has been specified - apply specified options as well if provided
foreach(ARG ${ARGUMENTS_OPTIONS}) foreach(ARG ${ARGUMENTS_OPTIONS})
set(CONAN_OPTIONS ${CONAN_OPTIONS} -o=${ARG}) set(CONAN_OPTIONS ${CONAN_OPTIONS} -o=${ARG})
endforeach() endforeach()
else() else()
set(CONANFILE ".") set(CONANFILE ".")
endif() endif()
if(ARGUMENTS_UPDATE) if(ARGUMENTS_UPDATE)
set(CONAN_INSTALL_UPDATE --update) set(CONAN_INSTALL_UPDATE --update)
endif() endif()
if(ARGUMENTS_NO_IMPORTS) if(ARGUMENTS_NO_IMPORTS)
set(CONAN_INSTALL_NO_IMPORTS --no-imports) set(CONAN_INSTALL_NO_IMPORTS --no-imports)
endif() endif()
set(CONAN_INSTALL_FOLDER "") set(CONAN_INSTALL_FOLDER "")
if(ARGUMENTS_INSTALL_FOLDER) if(ARGUMENTS_INSTALL_FOLDER)
set(CONAN_INSTALL_FOLDER -if=${ARGUMENTS_INSTALL_FOLDER}) set(CONAN_INSTALL_FOLDER -if=${ARGUMENTS_INSTALL_FOLDER})
endif() endif()
foreach(ARG ${ARGUMENTS_GENERATORS}) foreach(ARG ${ARGUMENTS_GENERATORS})
set(CONAN_GENERATORS ${CONAN_GENERATORS} -g=${ARG}) set(CONAN_GENERATORS ${CONAN_GENERATORS} -g=${ARG})
@ -392,64 +401,64 @@ function(conan_cmake_install)
if(ARGUMENTS_OUTPUT_QUIET) if(ARGUMENTS_OUTPUT_QUIET)
execute_process(COMMAND ${CONAN_CMD} ${conan_args} execute_process(COMMAND ${CONAN_CMD} ${conan_args}
RESULT_VARIABLE return_code RESULT_VARIABLE return_code
OUTPUT_VARIABLE conan_output OUTPUT_VARIABLE conan_output
ERROR_VARIABLE conan_output ERROR_VARIABLE conan_output
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
else() else()
execute_process(COMMAND ${CONAN_CMD} ${conan_args} execute_process(COMMAND ${CONAN_CMD} ${conan_args}
RESULT_VARIABLE return_code RESULT_VARIABLE return_code
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif() endif()
if(NOT "${return_code}" STREQUAL "0") if(NOT "${return_code}" STREQUAL "0")
message(FATAL_ERROR "Conan install failed='${return_code}'") message(FATAL_ERROR "Conan install failed='${return_code}'")
endif() endif()
endfunction() endfunction()
function(conan_cmake_setup_conanfile) function(conan_cmake_setup_conanfile)
parse_arguments(${ARGV}) parse_arguments(${ARGV})
if(ARGUMENTS_CONANFILE) if(ARGUMENTS_CONANFILE)
get_filename_component(_CONANFILE_NAME ${ARGUMENTS_CONANFILE} NAME) get_filename_component(_CONANFILE_NAME ${ARGUMENTS_CONANFILE} NAME)
# configure_file will make sure cmake re-runs when conanfile is updated # configure_file will make sure cmake re-runs when conanfile is updated
configure_file(${ARGUMENTS_CONANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk COPYONLY) configure_file(${ARGUMENTS_CONANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk COPYONLY)
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk) file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk)
else() else()
conan_cmake_generate_conanfile(${ARGV}) conan_cmake_generate_conanfile(${ARGV})
endif() endif()
endfunction() endfunction()
function(conan_cmake_generate_conanfile) function(conan_cmake_generate_conanfile)
# Generate, writing in disk a conanfile.txt with the requires, options, and imports # Generate, writing in disk a conanfile.txt with the requires, options, and imports
# specified as arguments # specified as arguments
# This will be considered as temporary file, generated in CMAKE_CURRENT_BINARY_DIR) # This will be considered as temporary file, generated in CMAKE_CURRENT_BINARY_DIR)
parse_arguments(${ARGV}) parse_arguments(${ARGV})
set(_FN "${CMAKE_CURRENT_BINARY_DIR}/conanfile.txt") set(_FN "${CMAKE_CURRENT_BINARY_DIR}/conanfile.txt")
file(WRITE ${_FN} "[generators]\ncmake\n\n[requires]\n") file(WRITE ${_FN} "[generators]\ncmake\n\n[requires]\n")
foreach(ARG ${ARGUMENTS_REQUIRES}) foreach(ARG ${ARGUMENTS_REQUIRES})
file(APPEND ${_FN} ${ARG} "\n") file(APPEND ${_FN} ${ARG} "\n")
endforeach() endforeach()
file(APPEND ${_FN} ${ARG} "\n[options]\n") file(APPEND ${_FN} ${ARG} "\n[options]\n")
foreach(ARG ${ARGUMENTS_OPTIONS}) foreach(ARG ${ARGUMENTS_OPTIONS})
file(APPEND ${_FN} ${ARG} "\n") file(APPEND ${_FN} ${ARG} "\n")
endforeach() endforeach()
file(APPEND ${_FN} ${ARG} "\n[imports]\n") file(APPEND ${_FN} ${ARG} "\n[imports]\n")
foreach(ARG ${ARGUMENTS_IMPORTS}) foreach(ARG ${ARGUMENTS_IMPORTS})
file(APPEND ${_FN} ${ARG} "\n") file(APPEND ${_FN} ${ARG} "\n")
endforeach() endforeach()
endfunction() endfunction()
macro(conan_load_buildinfo) macro(conan_load_buildinfo)
if(CONAN_CMAKE_MULTI) if(CONAN_CMAKE_MULTI)
set(_CONANBUILDINFO conanbuildinfo_multi.cmake) set(_CONANBUILDINFO conanbuildinfo_multi.cmake)
else() else()
set(_CONANBUILDINFO conanbuildinfo.cmake) set(_CONANBUILDINFO conanbuildinfo.cmake)
endif() endif()
if(ARGUMENTS_INSTALL_FOLDER) if(ARGUMENTS_INSTALL_FOLDER)
set(_CONANBUILDINFOFOLDER ${ARGUMENTS_INSTALL_FOLDER}) set(_CONANBUILDINFOFOLDER ${ARGUMENTS_INSTALL_FOLDER})
@ -459,17 +468,17 @@ macro(conan_load_buildinfo)
# Checks for the existence of conanbuildinfo.cmake, and loads it # Checks for the existence of conanbuildinfo.cmake, and loads it
# important that it is macro, so variables defined at parent scope # important that it is macro, so variables defined at parent scope
if(EXISTS "${_CONANBUILDINFOFOLDER}/${_CONANBUILDINFO}") if(EXISTS "${_CONANBUILDINFOFOLDER}/${_CONANBUILDINFO}")
message(STATUS "Conan: Loading ${_CONANBUILDINFO}") message(STATUS "Conan: Loading ${_CONANBUILDINFO}")
include(${_CONANBUILDINFOFOLDER}/${_CONANBUILDINFO}) include(${_CONANBUILDINFOFOLDER}/${_CONANBUILDINFO})
else() else()
message(FATAL_ERROR "${_CONANBUILDINFO} doesn't exist in ${CMAKE_CURRENT_BINARY_DIR}") message(FATAL_ERROR "${_CONANBUILDINFO} doesn't exist in ${CMAKE_CURRENT_BINARY_DIR}")
endif() endif()
endmacro() endmacro()
macro(conan_cmake_run) macro(conan_cmake_run)
parse_arguments(${ARGV}) parse_arguments(${ARGV})
if(ARGUMENTS_CONFIGURATION_TYPES AND NOT CMAKE_CONFIGURATION_TYPES) if(ARGUMENTS_CONFIGURATION_TYPES AND NOT CMAKE_CONFIGURATION_TYPES)
message(WARNING "CONFIGURATION_TYPES should only be specified for multi-configuration generators") message(WARNING "CONFIGURATION_TYPES should only be specified for multi-configuration generators")
elseif(ARGUMENTS_CONFIGURATION_TYPES AND ARGUMENTS_BUILD_TYPE) elseif(ARGUMENTS_CONFIGURATION_TYPES AND ARGUMENTS_BUILD_TYPE)
@ -503,7 +512,7 @@ macro(conan_cmake_run)
endif() endif()
if (NOT ARGUMENTS_NO_LOAD) if (NOT ARGUMENTS_NO_LOAD)
conan_load_buildinfo() conan_load_buildinfo()
endif() endif()
if(ARGUMENTS_BASIC_SETUP) if(ARGUMENTS_BASIC_SETUP)
@ -536,13 +545,13 @@ macro(conan_check)
endif() endif()
message(STATUS "Conan: Found program ${CONAN_CMD}") message(STATUS "Conan: Found program ${CONAN_CMD}")
execute_process(COMMAND ${CONAN_CMD} --version execute_process(COMMAND ${CONAN_CMD} --version
OUTPUT_VARIABLE CONAN_VERSION_OUTPUT OUTPUT_VARIABLE CONAN_VERSION_OUTPUT
ERROR_VARIABLE CONAN_VERSION_OUTPUT) ERROR_VARIABLE CONAN_VERSION_OUTPUT)
message(STATUS "Conan: Version found ${CONAN_VERSION_OUTPUT}") message(STATUS "Conan: Version found ${CONAN_VERSION_OUTPUT}")
if(DEFINED CONAN_VERSION) if(DEFINED CONAN_VERSION)
string(REGEX MATCH ".*Conan version ([0-9]+\.[0-9]+\.[0-9]+)" FOO string(REGEX MATCH ".*Conan version ([0-9]+\.[0-9]+\.[0-9]+)" FOO
"${CONAN_VERSION_OUTPUT}") "${CONAN_VERSION_OUTPUT}")
if(${CMAKE_MATCH_1} VERSION_LESS ${CONAN_VERSION}) if(${CMAKE_MATCH_1} VERSION_LESS ${CONAN_VERSION})
message(FATAL_ERROR "Conan outdated. Installed: ${CMAKE_MATCH_1}, \ message(FATAL_ERROR "Conan outdated. Installed: ${CMAKE_MATCH_1}, \
required: ${CONAN_VERSION}. Consider updating via 'pip \ required: ${CONAN_VERSION}. Consider updating via 'pip \
@ -564,13 +573,13 @@ function(conan_add_remote)
set(CONAN_INDEX_ARG "-i ${CONAN_INDEX}") set(CONAN_INDEX_ARG "-i ${CONAN_INDEX}")
endif() endif()
if(CONAN_COMMAND) if(CONAN_COMMAND)
set(CONAN_CMD ${CONAN_COMMAND}) set(CONAN_CMD ${CONAN_COMMAND})
else() else()
conan_check(REQUIRED) conan_check(REQUIRED)
endif() endif()
message(STATUS "Conan: Adding ${CONAN_NAME} remote repository (${CONAN_URL})") message(STATUS "Conan: Adding ${CONAN_NAME} remote repository (${CONAN_URL})")
execute_process(COMMAND ${CONAN_CMD} remote add ${CONAN_NAME} ${CONAN_URL} execute_process(COMMAND ${CONAN_CMD} remote add ${CONAN_NAME} ${CONAN_URL}
${CONAN_INDEX_ARG} -f) ${CONAN_INDEX_ARG} -f)
endfunction() endfunction()
macro(conan_config_install) macro(conan_config_install)