Skip to content

Commit

Permalink
Merge pull request conan-io#51 from conan-io/patch-1
Browse files Browse the repository at this point in the history
Improve VS detection with Version and Architecture
  • Loading branch information
memsharded authored Dec 5, 2017
2 parents 78b3594 + c442813 commit 3e5410e
Showing 1 changed file with 26 additions and 54 deletions.
80 changes: 26 additions & 54 deletions conan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,22 @@ include(CMakeParseArguments)

function(_get_msvc_ide_version result)
set(${result} "" PARENT_SCOPE)
if(${CMAKE_GENERATOR} STREQUAL "Ninja")
string(REGEX MATCHALL "[0-9]+" output "$ENV{VisualStudioVersion}")
list(GET output 0 _msvc_version)
set(${result} ${_msvc_version} PARENT_SCOPE)
if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500)
set(${result} 8 PARENT_SCOPE)
elseif(NOT MSVC_VERSION VERSION_LESS 1500 AND MSVC_VERSION VERSION_LESS 1600)
set(${result} 9 PARENT_SCOPE)
elseif(NOT MSVC_VERSION VERSION_LESS 1600 AND MSVC_VERSION VERSION_LESS 1700)
set(${result} 10 PARENT_SCOPE)
elseif(NOT MSVC_VERSION VERSION_LESS 1700 AND MSVC_VERSION VERSION_LESS 1800)
set(${result} 11 PARENT_SCOPE)
elseif(NOT MSVC_VERSION VERSION_LESS 1800 AND MSVC_VERSION VERSION_LESS 1900)
set(${result} 12 PARENT_SCOPE)
elseif(NOT MSVC_VERSION VERSION_LESS 1900 AND MSVC_VERSION VERSION_LESS 1910)
set(${result} 14 PARENT_SCOPE)
elseif(NOT MSVC_VERSION VERSION_LESS 1910 AND MSVC_VERSION VERSION_LESS 1920)
set(${result} 15 PARENT_SCOPE)
else()
if(CMAKE_VS_PLATFORM_TOOLSET)
string(REGEX MATCHALL "[0-9]+" output "${CMAKE_VS_PLATFORM_TOOLSET}")
list(GET output 0 _toolset_version)
if(_toolset_version LESS 142)
if ("${_toolset_version}" EQUAL "141")
set(_msvc_version "15")
else()
string(SUBSTRING ${_toolset_version} 0 2 _msvc_version)
endif()
set(${result} ${_msvc_version} PARENT_SCOPE)
return()
else()
message(STATUS "Conan **WARNING** : Unknown MSVC toolset ${_toolset_version}")
endif()
endif()

string(REGEX MATCHALL "[0-9]+" output "${CMAKE_GENERATOR}")
list(GET output 0 _msvc_version)
set(${result} ${_msvc_version} PARENT_SCOPE)
message(FATAL_ERROR "Conan: Unknown MSVC compiler version [${MSVC_VERSION}]")
endif()
endfunction()

Expand Down Expand Up @@ -55,7 +47,7 @@ function(conan_cmake_settings result)

#handle -s os setting
if(CMAKE_SYSTEM_NAME)
#use default conan os setting if CMAKE_SYSTEM_NAME is not defined
#use default conan os setting if CMAKE_SYSTEM_NAME is not defined
set(CONAN_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(CONAN_SYSTEM_NAME Macos)
Expand Down Expand Up @@ -104,40 +96,20 @@ function(conan_cmake_settings result)
set(_VISUAL "Visual Studio")
_get_msvc_ide_version(_VISUAL_VERSION)
if("${_VISUAL_VERSION}" STREQUAL "")
message(FATAL_ERROR "Visual Studio not recognized")
message(FATAL_ERROR "Conan: Visual Studio not recognized")
else()
set(_SETTINGS ${_SETTINGS} -s compiler=${_VISUAL} -s compiler.version=${_VISUAL_VERSION})
endif()

if(${CMAKE_GENERATOR} STREQUAL "Ninja")
if(DEFINED ENV{Platform})
if($ENV{Platform} STREQUAL "X64")
set(_SETTINGS ${_SETTINGS} -s arch=x86_64)
elseif($ENV{Platform} STREQUAL "ARM")
message(STATUS "Conan: Using default ARM architecture from MSVC")
set(_SETTINGS ${_SETTINGS} -s arch=armv6)
else()
set(_SETTINGS ${_SETTINGS} -s arch=x86)
endif()
else()
if(_MSVC_CXX_ARCHITECTURE_FAMILY STREQUAL "X64" OR _MSVC_C_ARCHITECTURE_FAMILY STREQUAL "X64")
set(_SETTINGS ${_SETTINGS} -s arch=x86_64)
elseif(_MSVC_CXX_ARCHITECTURE_FAMILY MATCHES "ARM" OR _MSVC_C_ARCHITECTURE_FAMILY MATCHES "ARM")
message(STATUS "Conan: Using default ARM architecture from MSVC")
set(_SETTINGS ${_SETTINGS} -s arch=armv6)
else()
set(_SETTINGS ${_SETTINGS} -s arch=x86)
endif()
endif()
else()
if(${CMAKE_GENERATOR} MATCHES "Win64")
set(_SETTINGS ${_SETTINGS} -s arch=x86_64)
elseif (${CMAKE_GENERATOR} MATCHES "ARM")
message(STATUS "Conan: Using default ARM architecture from MSVC")
set(_SETTINGS ${_SETTINGS} -s arch=armv6)
else()
set(_SETTINGS ${_SETTINGS} -s arch=x86)
endif()
if (MSVC_CXX_ARCHITECTURE_ID MATCHES "64")
set(_SETTINGS ${_SETTINGS} -s arch=x86_64)
elseif (MSVC_CXX_ARCHITECTURE_ID MATCHES "^ARM")
message(STATUS "Conan: Using default ARM architecture from MSVC")
set(_SETTINGS ${_SETTINGS} -s arch=armv6)
elseif (MSVC_CXX_ARCHITECTURE_ID MATCHES "86")
set(_SETTINGS ${_SETTINGS} -s arch=x86)
else ()
message(FATAL_ERROR "Conan: Unknown MSVC architecture [${MSVC_CXX_ARCHITECTURE_ID}]")
endif()

conan_cmake_detect_vs_runtime(_vs_runtime)
Expand Down

0 comments on commit 3e5410e

Please sign in to comment.