1 # - Determines the target architecture of the compilation
3 # This function checks the architecture that will be built by the compiler
4 # and sets a variable to the architecture
6 # determine_target_architecture(<OUTPUT_VAR>)
10 # include(DetermineTargetArchitecture)
11 # determine_target_architecture(PROJECT_NAME_ARCHITECTURE)
13 if(__determine_target_architecture)
16 set(__determine_target_architecture INCLUDED)
18 function(determine_target_architecture FLAG)
20 if("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "X86")
22 elseif("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "x64")
24 elseif("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "ARM")
27 message(FATAL_ERROR "Failed to determine the MSVC target architecture: ${MSVC_C_ARCHITECTURE_ID}")
31 COMMAND ${CMAKE_C_COMPILER} -dumpmachine
32 RESULT_VARIABLE RESULT
37 message(FATAL_ERROR "Failed to determine target architecture triplet: ${RESULT}")
39 string(REGEX MATCH "([^-]+).*" ARCH_MATCH ${ARCH})
40 if (NOT CMAKE_MATCH_1 OR NOT ARCH_MATCH)
41 message(FATAL_ERROR "Failed to match the target architecture triplet: ${ARCH}")
43 set(ARCH ${CMAKE_MATCH_1})
45 message(STATUS "Target architecture - ${ARCH}")
46 set(FLAG ${ARCH} PARENT_SCOPE)