-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathqdk-uarch.cmake
More file actions
45 lines (42 loc) · 2.12 KB
/
Copy pathqdk-uarch.cmake
File metadata and controls
45 lines (42 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# --- Step 1: Resolve QDK_UARCH ---
# Check environment variable first, then CMake variable
if(NOT DEFINED QDK_UARCH AND DEFINED ENV{QDK_UARCH})
set(QDK_UARCH $ENV{QDK_UARCH})
endif()
if(DEFINED QDK_UARCH)
message(STATUS "Using user-defined uarch: ${QDK_UARCH}")
else()
# Auto-detect based on the target platform
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
set(QDK_UARCH "x86-64" CACHE STRING "Target microarchitecture")
message(STATUS "Auto-detected x86_64 architecture, using: ${QDK_UARCH}")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64")
set(QDK_UARCH "armv8-a" CACHE STRING "Target microarchitecture")
message(STATUS "Auto-detected ARM64 architecture, using: ${QDK_UARCH}")
else()
message(WARNING "Unknown architecture ${CMAKE_SYSTEM_PROCESSOR}. QDK_UARCH not set. This may degrade performance")
return()
endif()
endif()
# --- Step 2: Set QDK_UARCH_FLAGS based on compiler and uarch ---
set(QDK_UARCH_USED ${QDK_UARCH} CACHE STRING "Target microarchitecture for optimization")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
set(QDK_UARCH_FLAGS "-march=${QDK_UARCH}" CACHE STRING "Compiler flags for target microarchitecture")
elseif(MSVC)
# Users should set QDK_UARCH to a valid MSVC /arch: argument (e.g. AVX2, AVX512)
set(QDK_UARCH_FLAGS "/arch:${QDK_UARCH}" CACHE STRING "Compiler flags for target microarchitecture")
else()
message(WARNING "Compiler ${CMAKE_CXX_COMPILER_ID}: unknown flag syntax for ISA selection. QDK_UARCH_FLAGS will not be set.")
set(QDK_UARCH_USED "NONE" CACHE STRING "Target microarchitecture for optimization")
endif()
# --- Step 3: Validate the flags ---
if(QDK_UARCH_FLAGS)
message(STATUS "Testing QDK_UARCH_FLAGS: ${QDK_UARCH_FLAGS}")
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("${QDK_UARCH_FLAGS}" COMPILER_SUPPORTS_QDK_UARCH_FLAGS)
if(NOT COMPILER_SUPPORTS_QDK_UARCH_FLAGS)
message(WARNING "The compiler does not support the specified QDK_UARCH_FLAGS: ${QDK_UARCH_FLAGS}. Unsetting these flags.")
unset(QDK_UARCH_FLAGS CACHE)
set(QDK_UARCH_USED "NONE" CACHE STRING "Target microarchitecture for optimization")
endif()
endif()