Skip to content
Snippets Groups Projects
Commit edbb3580 authored by Lars Bilke's avatar Lars Bilke Committed by Dmitri Naumov
Browse files
parent ea0485a4
No related branches found
No related tags found
No related merge requests found
# The MIT License (MIT)
# Copyright (c) 2018 JFrog
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# This file comes from: https://github.com/conan-io/cmake-conan. Please refer
# to this repository for issues and documentation.
# Its purpose is to wrap and launch Conan C/C++ Package Manager when cmake is called.
# It will take CMake current settings (os, compiler, compiler version, architecture)
# and translate them to conan settings for installing and retrieving dependencies.
# It is intended to facilitate developers building projects that have conan dependencies,
# but it is only necessary on the end-user side. It is not necessary to create conan
# packages, in fact it shouldn't be use for that. Check the project documentation.
include(CMakeParseArguments) include(CMakeParseArguments)
function(_get_msvc_ide_version result) function(_get_msvc_ide_version result)
...@@ -34,12 +70,17 @@ function(conan_cmake_settings result) ...@@ -34,12 +70,17 @@ function(conan_cmake_settings result)
message(STATUS "Conan ** WARNING** : This detection of settings from cmake is experimental and incomplete. " message(STATUS "Conan ** WARNING** : This detection of settings from cmake is experimental and incomplete. "
"Please check 'conan.cmake' and contribute") "Please check 'conan.cmake' and contribute")
parse_arguments(${ARGV})
set(arch ${ARGUMENTS_ARCH})
if(CONAN_CMAKE_MULTI) if(CONAN_CMAKE_MULTI)
set(_SETTINGS -g cmake_multi) set(_SETTINGS -g cmake_multi)
else() else()
set(_SETTINGS -g cmake) set(_SETTINGS -g cmake)
endif() endif()
if(CMAKE_BUILD_TYPE) if(ARGUMENTS_BUILD_TYPE)
set(_SETTINGS ${_SETTINGS} -s build_type=${ARGUMENTS_BUILD_TYPE})
elseif(CMAKE_BUILD_TYPE)
set(_SETTINGS ${_SETTINGS} -s build_type=${CMAKE_BUILD_TYPE}) set(_SETTINGS ${_SETTINGS} -s build_type=${CMAKE_BUILD_TYPE})
else() else()
message(FATAL_ERROR "Please specify in command line CMAKE_BUILD_TYPE (-DCMAKE_BUILD_TYPE=Release)") message(FATAL_ERROR "Please specify in command line CMAKE_BUILD_TYPE (-DCMAKE_BUILD_TYPE=Release)")
...@@ -73,6 +114,10 @@ function(conan_cmake_settings result) ...@@ -73,6 +114,10 @@ function(conan_cmake_settings result)
message(FATAL_ERROR "Conan: Neither C or C++ was detected as a language for the project. Unabled to detect compiler version.") message(FATAL_ERROR "Conan: Neither C or C++ was detected as a language for the project. Unabled to detect compiler version.")
endif() endif()
if(arch)
set(_SETTINGS ${_SETTINGS} -s arch=${arch})
endif()
if (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL GNU) if (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL GNU)
# using GCC # using GCC
# TODO: Handle other params # TODO: Handle other params
...@@ -128,24 +173,36 @@ function(conan_cmake_settings result) ...@@ -128,24 +173,36 @@ function(conan_cmake_settings result)
set(_SETTINGS ${_SETTINGS} -s compiler=${_VISUAL} -s compiler.version=${_VISUAL_VERSION}) set(_SETTINGS ${_SETTINGS} -s compiler=${_VISUAL} -s compiler.version=${_VISUAL_VERSION})
endif() endif()
if (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "64") if(NOT arch)
set(_SETTINGS ${_SETTINGS} -s arch=x86_64) if (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "64")
elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "^ARM") set(_SETTINGS ${_SETTINGS} -s arch=x86_64)
message(STATUS "Conan: Using default ARM architecture from MSVC") elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "^ARM")
set(_SETTINGS ${_SETTINGS} -s arch=armv6) message(STATUS "Conan: Using default ARM architecture from MSVC")
elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "86") set(_SETTINGS ${_SETTINGS} -s arch=armv6)
set(_SETTINGS ${_SETTINGS} -s arch=x86) elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "86")
else () set(_SETTINGS ${_SETTINGS} -s arch=x86)
message(FATAL_ERROR "Conan: Unknown MSVC architecture [${MSVC_${LANGUAGE}_ARCHITECTURE_ID}]") else ()
message(FATAL_ERROR "Conan: Unknown MSVC architecture [${MSVC_${LANGUAGE}_ARCHITECTURE_ID}]")
endif()
endif() endif()
conan_cmake_detect_vs_runtime(_vs_runtime) conan_cmake_detect_vs_runtime(_vs_runtime)
message(STATUS "Detected VS runtime: ${_vs_runtime}") message(STATUS "Detected VS runtime: ${_vs_runtime}")
set(_SETTINGS ${_SETTINGS} -s compiler.runtime=${_vs_runtime}) set(_SETTINGS ${_SETTINGS} -s compiler.runtime=${_vs_runtime})
if (CMAKE_GENERATOR_TOOLSET)
set(_SETTINGS ${_SETTINGS} -s compiler.toolset=${CMAKE_VS_PLATFORM_TOOLSET})
elseif(CMAKE_VS_PLATFORM_TOOLSET AND (CMAKE_GENERATOR STREQUAL "Ninja"))
set(_SETTINGS ${_SETTINGS} -s compiler.toolset=${CMAKE_VS_PLATFORM_TOOLSET})
endif()
else() else()
message(FATAL_ERROR "Conan: compiler setup not recognized") message(FATAL_ERROR "Conan: compiler setup not recognized")
endif() endif()
foreach(ARG ${ARGUMENTS_SETTINGS})
set(_SETTINGS ${_SETTINGS} -s ${ARG})
endforeach()
set(${result} ${_SETTINGS} PARENT_SCOPE) set(${result} ${_SETTINGS} PARENT_SCOPE)
endfunction() endfunction()
...@@ -202,9 +259,9 @@ endfunction() ...@@ -202,9 +259,9 @@ endfunction()
macro(parse_arguments) macro(parse_arguments)
set(options BASIC_SETUP CMAKE_TARGETS UPDATE KEEP_RPATHS) set(options BASIC_SETUP CMAKE_TARGETS UPDATE KEEP_RPATHS NO_OUTPUT_DIRS)
set(oneValueArgs CONANFILE DEBUG_PROFILE RELEASE_PROFILE PROFILE) set(oneValueArgs CONANFILE DEBUG_PROFILE RELEASE_PROFILE RELWITHDEBINFO_PROFILE MINSIZEREL_PROFILE PROFILE ARCH BUILD_TYPE INSTALL_FOLDER)
set(multiValueArgs REQUIRES OPTIONS IMPORTS BUILD CONAN_COMMAND) set(multiValueArgs REQUIRES OPTIONS IMPORTS SETTINGS BUILD CONAN_COMMAND)
cmake_parse_arguments(ARGUMENTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) cmake_parse_arguments(ARGUMENTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
endmacro() endmacro()
...@@ -246,13 +303,23 @@ function(conan_cmake_install) ...@@ -246,13 +303,23 @@ function(conan_cmake_install)
if(CMAKE_BUILD_TYPE STREQUAL "Release" AND ARGUMENTS_RELEASE_PROFILE) if(CMAKE_BUILD_TYPE STREQUAL "Release" AND ARGUMENTS_RELEASE_PROFILE)
set(settings -pr ${ARGUMENTS_RELEASE_PROFILE}) set(settings -pr ${ARGUMENTS_RELEASE_PROFILE})
endif() endif()
if(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" AND ARGUMENTS_RELWITHDEBINFO_PROFILE)
set(settings -pr ${ARGUMENTS_RELWITHDEBINFO_PROFILE})
endif()
if(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" AND ARGUMENTS_MINSIZEREL_PROFILE)
set(settings -pr ${ARGUMENTS_MINSIZEREL_PROFILE})
endif()
if(ARGUMENTS_PROFILE) if(ARGUMENTS_PROFILE)
set(settings -pr ${ARGUMENTS_PROFILE}) set(settings -pr ${ARGUMENTS_PROFILE})
endif() endif()
if(ARGUMENTS_UPDATE) if(ARGUMENTS_UPDATE)
set(CONAN_INSTALL_UPDATE --update) set(CONAN_INSTALL_UPDATE --update)
endif() endif()
set(conan_args install ${CONANFILE} ${settings} ${CONAN_BUILD_POLICY} ${CONAN_INSTALL_UPDATE} ${CONAN_OPTIONS}) set(CONAN_INSTALL_FOLDER "")
if(ARGUMENTS_INSTALL_FOLDER)
set(CONAN_INSTALL_FOLDER -if ${ARGUMENTS_INSTALL_FOLDER})
endif()
set(conan_args install ${CONANFILE} ${settings} ${CONAN_BUILD_POLICY} ${CONAN_INSTALL_UPDATE} ${CONAN_OPTIONS} ${CONAN_INSTALL_FOLDER})
string (REPLACE ";" " " _conan_args "${conan_args}") string (REPLACE ";" " " _conan_args "${conan_args}")
message(STATUS "Conan executing: ${conan_command} ${_conan_args}") message(STATUS "Conan executing: ${conan_command} ${_conan_args}")
...@@ -333,12 +400,13 @@ macro(conan_cmake_run) ...@@ -333,12 +400,13 @@ macro(conan_cmake_run)
conan_cmake_setup_conanfile(${ARGV}) conan_cmake_setup_conanfile(${ARGV})
if(CONAN_CMAKE_MULTI) if(CONAN_CMAKE_MULTI)
foreach(CMAKE_BUILD_TYPE "Release" "Debug") foreach(CMAKE_BUILD_TYPE "Release" "Debug")
conan_cmake_settings(settings) set(ENV{CONAN_IMPORT_PATH} ${CMAKE_BUILD_TYPE})
conan_cmake_settings(settings ${ARGV})
conan_cmake_install(SETTINGS ${settings} ${ARGV}) conan_cmake_install(SETTINGS ${settings} ${ARGV})
endforeach() endforeach()
set(CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE)
else() else()
conan_cmake_settings(settings) conan_cmake_settings(settings ${ARGV})
conan_cmake_install(SETTINGS ${settings} ${ARGV}) conan_cmake_install(SETTINGS ${settings} ${ARGV})
endif() endif()
endif() endif()
...@@ -346,18 +414,15 @@ macro(conan_cmake_run) ...@@ -346,18 +414,15 @@ macro(conan_cmake_run)
conan_load_buildinfo() conan_load_buildinfo()
if(ARGUMENTS_BASIC_SETUP) if(ARGUMENTS_BASIC_SETUP)
if(ARGUMENTS_CMAKE_TARGETS) foreach(_option CMAKE_TARGETS KEEP_RPATHS NO_OUTPUT_DIRS)
if(ARGUMENTS_KEEP_RPATHS) if(ARGUMENTS_${_option})
conan_basic_setup(TARGETS KEEP_RPATHS) if(${_option} STREQUAL "CMAKE_TARGETS")
else() list(APPEND _setup_options "TARGETS")
conan_basic_setup(TARGETS) else()
endif() list(APPEND _setup_options ${_option})
else() endif()
if(ARGUMENTS_KEEP_RPATHS) endif()
conan_basic_setup(KEEP_RPATHS) endforeach()
else() conan_basic_setup(${_setup_options})
conan_basic_setup()
endif()
endif()
endif() endif()
endmacro() endmacro()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment