|
1 | 1 | # Daemon BSD Source Code |
2 | | -# Copyright (c) 2022, Daemon Developers |
| 2 | +# Copyright (c) 2022-2025, Daemon Developers |
3 | 3 | # All rights reserved. |
4 | 4 | # |
5 | 5 | # Redistribution and use in source and binary forms, with or without |
|
30 | 30 |
|
31 | 31 | # When adding a new architecture, look at all the places DAEMON_ARCH is used. |
32 | 32 |
|
33 | | -try_compile(BUILD_RESULT |
34 | | - "${CMAKE_BINARY_DIR}" |
35 | | - "${CMAKE_CURRENT_LIST_DIR}/Architecture/Architecture.cpp" |
36 | | - CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} |
37 | | - OUTPUT_VARIABLE BUILD_LOG |
38 | | -) |
39 | | - |
40 | | -# Setting -Werror in CXXFLAGS would produce errors instead of warning |
41 | | -# but that should not break the architecture detection, |
42 | | -# so we only print a CMake warning there and use BUILD_LOG content to |
43 | | -# detect unknown platforms. |
44 | | -# Catching compilation error is still useful, for example to detect |
45 | | -# undefined types, missing header or things like that. |
46 | | -# Setting USE_WERROR to ON doesn't print this warning. |
47 | | -if (NOT BUILD_RESULT) |
48 | | - message(WARNING |
49 | | - "Failed to build Architecture.cpp\n" |
50 | | - "Setting -Werror in CXXFLAGS can produce false positive errors\n" |
51 | | - "${BUILD_LOG}" |
52 | | - ) |
53 | | -endif() |
54 | | - |
55 | | -string(REGEX MATCH "DAEMON_ARCH_([a-zA-Z0-9_]+)" DAEMON_ARCH_DEFINE "${BUILD_LOG}") |
56 | | -string(REPLACE "DAEMON_ARCH_" "" DAEMON_ARCH "${DAEMON_ARCH_DEFINE}") |
57 | | - |
58 | | -set("DAEMON_ARCH_${DAEMON_ARCH}" ON) |
| 33 | +option(USE_ARCH_INTRINSICS "Enable custom code using intrinsics functions or asm declarations" ON) |
| 34 | +mark_as_advanced(USE_ARCH_INTRINSICS) |
59 | 35 |
|
60 | | -if (NOT DAEMON_ARCH) |
61 | | - message(FATAL_ERROR |
62 | | - "Missing DAEMON_ARCH, there is a mistake in Architecture.cpp\n" |
63 | | - "${BUILD_LOG}" |
64 | | - ) |
65 | | -endif() |
66 | | - |
67 | | -message(STATUS "Detected target architecture: ${DAEMON_ARCH}") |
68 | | - |
69 | | -add_definitions(-D${DAEMON_ARCH_DEFINE}) |
70 | | - |
71 | | -# This string can be modified without breaking compatibility. |
72 | | -daemon_add_buildinfo("char*" "DAEMON_ARCH_STRING" "\"${DAEMON_ARCH}\"") |
73 | | - |
74 | | -# Modifying NACL_ARCH breaks engine compatibility with nexe game binaries |
75 | | -# since NACL_ARCH contributes to the nexe file name. |
76 | | -set(DAEMON_NACL_ARCH "${DAEMON_ARCH}") |
77 | | -if (DAEMON_TARGET_SYSTEM_Unix_COMPATIBILITY) |
78 | | - set(ARMHF_USAGE arm64 armel) |
79 | | - if (DAEMON_ARCH IN_LIST ARMHF_USAGE) |
80 | | - # Load 32-bit armhf nexe on 64-bit arm64 engine on Linux with multiarch. |
81 | | - # The nexe is system agnostic so there should be no difference with armel. |
82 | | - set(DAEMON_NACL_ARCH "armhf") |
83 | | - endif() |
84 | | -elseif(DAEMON_TARGET_SYSTEM_macOS) |
85 | | - if ("${DAEMON_ARCH}" STREQUAL arm64) |
86 | | - # You can get emulated NaCl going like this: |
87 | | - # cp external_deps/macos-amd64-default_10/{nacl_loader,irt_core-amd64.nexe} build/ |
88 | | - set(DAEMON_NACL_ARCH "amd64") |
| 36 | +function(daemon_detect_arch) |
| 37 | + run_daemon_detection("" "ARCH" "Architecture.c" "") |
| 38 | + |
| 39 | + set(DAEMON_ARCH "${arch_name}" PARENT_SCOPE) |
| 40 | + |
| 41 | + message(STATUS "Detected target architecture: ${arch_name}") |
| 42 | + |
| 43 | + add_definitions(-DDAEMON_ARCH_${arch_name}) |
| 44 | + |
| 45 | + set(nacl_arch "${arch_name}") |
| 46 | + if (DAEMON_TARGET_SYSTEM_Unix_COMPATIBILITY) |
| 47 | + set(armhf_usage "arm64;armel") |
| 48 | + if ("${arch_name}" IN_LIST armhf_usage) |
| 49 | + # Load 32-bit armhf nexe on 64-bit arm64 engine on Linux with multiarch. |
| 50 | + # The nexe is system agnostic so there should be no difference with armel. |
| 51 | + set(nacl_arch "armhf") |
| 52 | + endif() |
| 53 | + elseif(DAEMON_TARGET_SYSTEM_macOS) |
| 54 | + if ("${arch_name}" STREQUAL "arm64") |
| 55 | + # You can get emulated NaCl going like this: |
| 56 | + # cp external_deps/macos-amd64-default_10/{nacl_loader,irt_core-amd64.nexe} build/ |
| 57 | + set(nacl_arch "amd64") |
| 58 | + endif() |
89 | 59 | endif() |
90 | | -endif() |
91 | 60 |
|
92 | | -set("DAEMON_NACL_ARCH_${DAEMON_NACL_ARCH}" ON) |
| 61 | + # The DAEMON_NACL_ARCH variable contributes to the nexe file name. |
| 62 | + set(DAEMON_NACL_ARCH "${nacl_arch}" PARENT_SCOPE) |
| 63 | +endfunction() |
93 | 64 |
|
94 | | -daemon_add_buildinfo("char*" "DAEMON_NACL_ARCH_STRING" "\"${DAEMON_NACL_ARCH}\"") |
| 65 | +function(daemon_set_arch_intrinsics name) |
| 66 | + message(STATUS "Enabling ${name} architecture intrinsics") |
| 67 | + add_definitions(-DDAEMON_USE_ARCH_INTRINSICS_${name}) |
| 68 | +endfunction() |
95 | 69 |
|
96 | | -option(USE_ARCH_INTRINSICS "Enable custom code using intrinsics functions or asm declarations" ON) |
97 | | -mark_as_advanced(USE_ARCH_INTRINSICS) |
98 | | - |
99 | | -macro(set_arch_intrinsics name) |
| 70 | +function(daemon_set_intrinsics) |
100 | 71 | if (USE_ARCH_INTRINSICS) |
101 | | - message(STATUS "Enabling ${name} architecture intrinsics") |
102 | | - add_definitions(-DDAEMON_USE_ARCH_INTRINSICS_${name}=1) |
| 72 | + # Makes possible to do things like that in C++ code: |
| 73 | + # > if defined(DAEMON_USER_ARCH_INTRINSICS) |
| 74 | + add_definitions(-DDAEMON_USE_ARCH_INTRINSICS) |
| 75 | + |
| 76 | + # Makes possible to do things like that in C++ code: |
| 77 | + # > if defined(DAEMON_USER_ARCH_INTRINSICS_amd64) |
| 78 | + # > if defined(DAEMON_USER_ARCH_INTRINSICS_i686) |
| 79 | + daemon_set_arch_intrinsics("${DAEMON_ARCH}") |
| 80 | + |
| 81 | + set(amd64_PARENT "i686") |
| 82 | + set(arm64_PARENT "armhf") |
| 83 | + |
| 84 | + if ("${DAEMON_ARCH}_PARENT") |
| 85 | + daemon_set_arch_intrinsics("${${DAEMON_ARCH}_PARENT}") |
| 86 | + endif() |
103 | 87 | else() |
104 | | - message(STATUS "Disabling ${name} architecture intrinsics") |
| 88 | + message(STATUS "Disabling ${DAEMON_ARCH} architecture intrinsics") |
105 | 89 | endif() |
106 | | -endmacro() |
| 90 | +endfunction() |
107 | 91 |
|
108 | | -if (USE_ARCH_INTRINSICS) |
109 | | - add_definitions(-DDAEMON_USE_ARCH_INTRINSICS=1) |
110 | | -endif() |
| 92 | +daemon_detect_arch() |
| 93 | +daemon_set_intrinsics() |
111 | 94 |
|
112 | | -set_arch_intrinsics(${DAEMON_ARCH}) |
113 | | - |
114 | | -set(amd64_PARENT "i686") |
115 | | -set(arm64_PARENT "armhf") |
| 95 | +# Makes possible to do things like that in CMake code: |
| 96 | +# > if (DAEMON_ARCH_arm64) |
| 97 | +# > if (DAEMON_NACL_ARCH_armhf) |
| 98 | +set("DAEMON_ARCH_${DAEMON_ARCH}" ON) |
| 99 | +set("DAEMON_NACL_ARCH_${DAEMON_NACL_ARCH}" ON) |
116 | 100 |
|
117 | | -if (${DAEMON_ARCH}_PARENT) |
118 | | - set_arch_intrinsics(${${DAEMON_ARCH}_PARENT}) |
119 | | -endif() |
| 101 | +# Add printable strings to the executable. |
| 102 | +daemon_add_buildinfo("char*" "DAEMON_ARCH_STRING" "\"${DAEMON_NACL_ARCH}\"") |
| 103 | +daemon_add_buildinfo("char*" "DAEMON_NACL_ARCH_STRING" "\"${DAEMON_NACL_ARCH}\"") |
0 commit comments