diff --git a/CMakeLists.txt b/CMakeLists.txt index 603f542..49363f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,47 @@ function(check_submodules_present) endfunction() check_submodules_present() +# Detect current compilation architecture and create standard definitions +# ======================================================================= + +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() + +if (NOT ENABLE_GENERIC) + if (MSVC) + detect_architecture("_M_AMD64" x86_64) + detect_architecture("_M_IX86" x86) + detect_architecture("_M_ARM" ARM) + detect_architecture("_M_ARM64" ARM64) + else() + detect_architecture("__x86_64__" x86_64) + detect_architecture("__i386__" x86) + detect_architecture("__arm__" ARM) + detect_architecture("__aarch64__" ARM64) + endif() +endif() +if (NOT DEFINED ARCHITECTURE) + set(ARCHITECTURE "GENERIC") + set(ARCHITECTURE_GENERIC 1) + add_definitions(-DARCHITECTURE_GENERIC=1) +endif() +message(STATUS "Target architecture: ${ARCHITECTURE}") + + # Configure C++ standard # =========================== set(CMAKE_CXX_STANDARD 17) @@ -51,7 +92,7 @@ if (USE_BUNDLED_QT) if ((MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS 1930) AND ARCHITECTURE_x86_64) set(QT_VER qt-5.10.0-msvc2017_64) else() - message(FATAL_ERROR "No bundled Qt binaries for your toolchain. Disable CITRA_USE_BUNDLED_QT and provide your own.") + message(FATAL_ERROR "No bundled Qt binaries for your toolchain. Disable USE_BUNDLED_QT and provide your own.") endif() if (DEFINED QT_VER)