Skip to content

Commit

Permalink
Avoid setting MSVC_VERSION in the toolchain, rely on CMake setting it…
Browse files Browse the repository at this point in the history
… (and others) (#91)
  • Loading branch information
MarkSchofield authored Jan 19, 2024
1 parent 32813ad commit 0ee6ff2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
20 changes: 0 additions & 20 deletions Windows.MSVC.toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,6 @@ set(VS_TOOLSET_PATH "${VS_INSTALLATION_PATH}/VC/Tools/MSVC/${CMAKE_VS_PLATFORM_T

# Set the tooling variables, include_directories and link_directories
#
function(getMsvcVersion COMPILER MSVC_VERSION_OUTPUT)
execute_process(
COMMAND "${COMPILER}" -Bv
ERROR_VARIABLE COMPILER_OUTPUT
OUTPUT_QUIET
)

if(COMPILER_OUTPUT MATCHES "cl\\.exe[^0-9]*(([0-9]+)\\.([0-9]+)\\.([0-9]+)(\\.([0-9]+))?)")
set(COMPILER_VERSION ${CMAKE_MATCH_1})
set(COMPILER_VERSION_MAJOR ${CMAKE_MATCH_2})
set(COMPILER_VERSION_MINOR ${CMAKE_MATCH_3})
endif()

set(${MSVC_VERSION_OUTPUT} "${COMPILER_VERSION_MAJOR}${COMPILER_VERSION_MINOR}" PARENT_SCOPE)
endfunction()

# Map CMAKE_SYSTEM_PROCESSOR values to CMAKE_VS_PLATFORM_TOOLSET_ARCHITECTURE that identifies the tools that should
# be used to produce code for the CMAKE_SYSTEM_PROCESSOR.
Expand All @@ -187,11 +172,6 @@ if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} /EHsc")
endif()

getMsvcVersion(${CMAKE_CXX_COMPILER} MSVC_VERSION)
if(NOT MSVC_VERSION)
message(FATAL_ERROR "Unable to obtain the compiler version from: ${CMAKE_CXX_COMPILER}")
endif()

# Compiler
foreach(LANG C CXX RC)
list(APPEND CMAKE_${LANG}_STANDARD_INCLUDE_DIRECTORIES "${VS_TOOLSET_PATH}/ATLMFC/include")
Expand Down
5 changes: 5 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ cmake_minimum_required(VERSION 3.20)

project(WindowsToolchainExample)

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message(STATUS "MSVC_VERSION = ${MSVC_VERSION}")
message(STATUS "MSVC_TOOLSET_VERSION = ${MSVC_TOOLSET_VERSION}")
endif()

add_compile_definitions(
UNICODE
_UNICODE
Expand Down

0 comments on commit 0ee6ff2

Please sign in to comment.