Skip to content

Commit

Permalink
Merge pull request #39 from cpp-best-practices/detect-arch
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Jan 1, 2022
2 parents 7e4b7c2 + f8b59b9 commit c88a46f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Index.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ macro(project_options)

# set warning message level
if(${ProjectOptions_WARNINGS_AS_ERRORS})
set(WARNINGS_AS_ERRORS ${ProjectOptions_WARNINGS_AS_ERRORS})
set(WARNINGS_AS_ERRORS ${ProjectOptions_WARNINGS_AS_ERRORS})
set(WARNING_MESSAGE SEND_ERROR)
else()
set(WARNING_MESSAGE WARNING)
Expand Down Expand Up @@ -114,7 +114,7 @@ macro(project_options)
MSVC_WARNINGS=${ProjectOptions_MSVC_WARNINGS}
CLANG_WARNINGS=${ProjectOptions_CLANG_WARNINGS}
GCC_WARNINGS=${ProjectOptions_GCC_WARNINGS})

include("${ProjectOptions_SRC_DIR}/Tests.cmake")
if(${ProjectOptions_ENABLE_COVERAGE})
enable_coverage(project_options)
Expand Down
37 changes: 25 additions & 12 deletions src/VCEnvironment.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
include("${ProjectOptions_SRC_DIR}/Utilities.cmake")

macro(detect_architecture)
# detect the architecture
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" CMAKE_SYSTEM_PROCESSOR_LOWER)
if(CMAKE_SYSTEM_PROCESSOR_LOWER STREQUAL x86 OR CMAKE_SYSTEM_PROCESSOR_LOWER MATCHES "^i[3456]86$")
set(VCVARSALL_ARCH x86)
elseif(
CMAKE_SYSTEM_PROCESSOR_LOWER STREQUAL x64
OR CMAKE_SYSTEM_PROCESSOR_LOWER STREQUAL x86_64
OR CMAKE_SYSTEM_PROCESSOR_LOWER STREQUAL amd64)
set(VCVARSALL_ARCH x64)
elseif(CMAKE_SYSTEM_PROCESSOR_LOWER STREQUAL arm)
set(VCVARSALL_ARCH arm)
elseif(CMAKE_SYSTEM_PROCESSOR_LOWER STREQUAL arm64 OR CMAKE_SYSTEM_PROCESSOR_LOWER STREQUAL aarch64)
set(VCVARSALL_ARCH arm64)
else()
if(CMAKE_HOST_SYSTEM_PROCESSOR)
set(VCVARSALL_ARCH ${CMAKE_HOST_SYSTEM_PROCESSOR})
else()
set(VCVARSALL_ARCH x64)
message(STATUS "Unkown architecture CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR_LOWER} - using x64")
endif()
endif()
endmacro()

# Run vcvarsall.bat and set CMake environment variables
function(run_vcvarsall)
# if MSVC but VSCMD_VER is not set, which means vcvarsall has not run
Expand All @@ -19,18 +43,7 @@ function(run_vcvarsall)

if(EXISTS ${VCVARSALL_FILE})
# detect the architecture
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" CMAKE_SYSTEM_PROCESSOR_LOWER)
if(CMAKE_SYSTEM_PROCESSOR_LOWER STREQUAL x86 OR CMAKE_SYSTEM_PROCESSOR_LOWER MATCHES "^i[3456]86$")
set(VCVARSALL_ARCH x86)
elseif(CMAKE_SYSTEM_PROCESSOR_LOWER STREQUAL x86_64 OR CMAKE_SYSTEM_PROCESSOR_LOWER STREQUAL amd64)
set(VCVARSALL_ARCH x64)
elseif(CMAKE_SYSTEM_PROCESSOR_LOWER STREQUAL arm)
set(VCVARSALL_ARCH arm)
elseif(CMAKE_SYSTEM_PROCESSOR_LOWER STREQUAL arm64 OR CMAKE_SYSTEM_PROCESSOR_LOWER STREQUAL aarch64)
set(VCVARSALL_ARCH arm64)
else()
message(WARNING "Unkown architecture: ${lowercase_CMAKE_HOST_SYSTEM_PROCESSOR}")
endif()
detect_architecture()

# run vcvarsall and print the environment variables
message(STATUS "Running `${VCVARSALL_FILE} ${VCVARSALL_ARCH}` to set up the MSVC environment")
Expand Down

0 comments on commit c88a46f

Please sign in to comment.