CMake: Fix architecture detection on MSVC
CMAKE_SYSTEM_ARCHICTETURE always returns the *host* not target arch when using the MSVC generators. (CMake bugs 15170 and 14342.)
This commit is contained in:
parent
2aad510c84
commit
eb26a1941e
|
@ -2,6 +2,23 @@
|
||||||
# dependent libraries.
|
# dependent libraries.
|
||||||
cmake_minimum_required(VERSION 2.8.11)
|
cmake_minimum_required(VERSION 2.8.11)
|
||||||
|
|
||||||
|
include(CheckSymbolExists)
|
||||||
|
function(detect_architecture symbol arch)
|
||||||
|
if (NOT DEFINED ARCHITECTURE)
|
||||||
|
set(CMAKE_REQUIRED_QUIET 1)
|
||||||
|
check_symbol_exists("${symbol}" "" ARCHITECTURE_${arch})
|
||||||
|
unset(CMAKE_REQUIRED_QUIET)
|
||||||
|
|
||||||
|
# The output variable needs to be unique across invocations otherwise
|
||||||
|
# CMake's crazy scope rules will keep it defined
|
||||||
|
if (ARCHITECTURE_${arch})
|
||||||
|
set(ARCHITECTURE "${arch}" PARENT_SCOPE)
|
||||||
|
set(ARCHITECTURE_${arch} 1 PARENT_SCOPE)
|
||||||
|
add_definitions(-DARCHITECTURE_${arch}=1)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
project(citra)
|
project(citra)
|
||||||
|
|
||||||
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit)
|
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit)
|
||||||
|
@ -10,12 +27,21 @@ if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit)
|
||||||
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks)
|
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Platform-agnostic definition to check if we are on x86_64
|
if (MSVC)
|
||||||
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "[xX]86_64" OR
|
detect_architecture("_M_AMD64" x86_64)
|
||||||
${CMAKE_SYSTEM_PROCESSOR} MATCHES "[aA][mM][dD]64")
|
detect_architecture("_M_IX86" x86)
|
||||||
set(ARCHITECTURE_x86_64 1)
|
detect_architecture("_M_ARM" ARM)
|
||||||
add_definitions(-DARCHITECTURE_x86_64=1)
|
else()
|
||||||
|
detect_architecture("__x86_64__" x86_64)
|
||||||
|
detect_architecture("__i386__" x86)
|
||||||
|
detect_architecture("__arm__" ARM)
|
||||||
endif()
|
endif()
|
||||||
|
if (NOT DEFINED ARCHITECTURE)
|
||||||
|
set(ARCHITECTURE "GENERIC")
|
||||||
|
set(ARCHITECTURE_GENERIC 1)
|
||||||
|
add_definitions(-DARCHITECTURE_GENERIC=1)
|
||||||
|
endif()
|
||||||
|
message(STATUS "Target architecture: ${ARCHITECTURE}")
|
||||||
|
|
||||||
if (NOT MSVC)
|
if (NOT MSVC)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-attributes -pthread")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-attributes -pthread")
|
||||||
|
|
Reference in New Issue