Skip to content

Commit 04ead53

Browse files
committed
cmake: add the DaemonPlatform CMake framework
1 parent 293472f commit 04ead53

File tree

10 files changed

+1178
-0
lines changed

10 files changed

+1178
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Daemon BSD Source Code
2+
# Copyright (c) 2022, Daemon Developers
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
# * Redistributions of source code must retain the above copyright
8+
# notice, this list of conditions and the following disclaimer.
9+
# * Redistributions in binary form must reproduce the above copyright
10+
# notice, this list of conditions and the following disclaimer in the
11+
# documentation and/or other materials provided with the distribution.
12+
# * Neither the name of the <organization> nor the
13+
# names of its contributors may be used to endorse or promote products
14+
# derived from this software without specific prior written permission.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
################################################################################
28+
# Determine architecture
29+
################################################################################
30+
31+
# When adding a new architecture, look at all the places ARCH is used
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 unsupported 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_]+)" ARCH_DEFINE "${BUILD_LOG}")
56+
string(REPLACE "DAEMON_ARCH_" "" ARCH "${ARCH_DEFINE}")
57+
58+
if (NOT ARCH)
59+
message(FATAL_ERROR
60+
"Missing DAEMON_ARCH, there is a mistake in Architecture.cpp\n"
61+
"${BUILD_LOG}"
62+
)
63+
else()
64+
set(ARCH_${ARCH} ON)
65+
66+
if(ARCH_unsupported)
67+
message(FATAL_ERROR "Architecture not supported")
68+
endif()
69+
endif()
70+
71+
message(STATUS "Detected architecture: ${ARCH}")
72+
73+
add_definitions(-D${ARCH_DEFINE})
74+
75+
# This string can be modified without breaking compatibility.
76+
daemon_add_buildinfo("char*" "DAEMON_ARCH_STRING" "\"${ARCH}\"")
77+
78+
# Modifying NACL_ARCH breaks engine compatibility with nexe game binaries
79+
# since NACL_ARCH contributes to the nexe file name.
80+
set(NACL_ARCH "${ARCH}")
81+
if (LINUX OR FREEBSD)
82+
set(ARMHF_USAGE arm64 armel)
83+
if (ARCH IN_LIST ARMHF_USAGE)
84+
# Load 32-bit armhf nexe on 64-bit arm64 engine on Linux with multiarch.
85+
# The nexe is system agnostic so there should be no difference with armel.
86+
set(NACL_ARCH "armhf")
87+
endif()
88+
elseif(APPLE)
89+
if ("${ARCH}" STREQUAL arm64)
90+
# You can get emulated NaCl going like this:
91+
# cp external_deps/macos-amd64-default_10/{nacl_loader,irt_core-amd64.nexe} build/
92+
set(NACL_ARCH "amd64")
93+
endif()
94+
endif()
95+
96+
daemon_add_buildinfo("char*" "DAEMON_NACL_ARCH_STRING" "\"${NACL_ARCH}\"")
97+
98+
option(USE_ARCH_INTRINSICS "Enable custom code using intrinsics functions or asm declarations" ON)
99+
mark_as_advanced(USE_ARCH_INTRINSICS)
100+
101+
macro(set_arch_intrinsics name)
102+
if (USE_ARCH_INTRINSICS)
103+
message(STATUS "Enabling ${name} architecture intrinsics")
104+
add_definitions(-DDAEMON_USE_ARCH_INTRINSICS_${name}=1)
105+
else()
106+
message(STATUS "Disabling ${name} architecture intrinsics")
107+
endif()
108+
endmacro()
109+
110+
if (USE_ARCH_INTRINSICS)
111+
add_definitions(-DDAEMON_USE_ARCH_INTRINSICS=1)
112+
endif()
113+
114+
set_arch_intrinsics(${ARCH})
115+
116+
set(amd64_PARENT "i686")
117+
set(arm64_PARENT "armhf")
118+
119+
if (${ARCH}_PARENT)
120+
set_arch_intrinsics(${${ARCH}_PARENT})
121+
endif()
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
===========================================================================
3+
Daemon BSD Source Code
4+
Copyright (c) 2022, Daemon Developers
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
* Neither the name of the Daemon developers nor the
15+
names of its contributors may be used to endorse or promote products
16+
derived from this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
22+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
===========================================================================
29+
*/
30+
31+
/* The qprocessordetection.h file doesn't detect endianness for some
32+
platforms including ppc64, but we know how to do it for them. */
33+
34+
#include <stdint.h>
35+
36+
/* This source file includes qprocessordetection.h from Qt:
37+
38+
- https://github.com/qt/qtbase/blob/dev/src/corelib/global/qprocessordetection.h
39+
https://raw.githubusercontent.com/qt/qtbase/dev/src/corelib/global/qprocessordetection.h
40+
41+
Always update by downloading new version from Qt, do not edit by hand.
42+
43+
This source file and the qprocessordetection.h header do not contribute to the
44+
produced engine and game binaries in any way that can be subject to copyright. */
45+
46+
#include "qprocessordetection.h"
47+
48+
/* The architecture names are loosely inspired by Debian conventions:
49+
https://wiki.debian.org/ArchitectureSpecificsMemo
50+
51+
Except we don't have the same technical debt so we don't have
52+
to name i686 as i386 for backward compatibility purpose neither
53+
care of platform name variants that are meant to distinguish
54+
platform variants we cannot support anyway. */
55+
56+
/* PNaCl virtual machines. */
57+
#if defined(__native_client__)
58+
#pragma message("DAEMON_ARCH_nacl")
59+
60+
/* Wasm virtual machines, work in progress. */
61+
#elif defined(Q_PROCESSOR_WASM)
62+
#pragma message("DAEMON_ARCH_wasm")
63+
64+
/* Devices like:
65+
- IBM PC compatibles and derivatives,
66+
- Apple Intel-based mac,
67+
- Steam Deck, Atari VCS consoles… */
68+
69+
#elif defined(Q_PROCESSOR_X86_64)
70+
#pragma message("DAEMON_ARCH_amd64")
71+
72+
#elif defined(Q_PROCESSOR_X86_32)
73+
// Assume at least i686. Detecting older revisions would be unlikely to work here
74+
// because the revisions are likely configured by flags, but this file is "compiled"
75+
// without most command-line flags.
76+
#pragma message("DAEMON_ARCH_i686")
77+
78+
/* Devices like:
79+
- Raspberry Pi,
80+
- Apple M1-based mac,
81+
- Android phones and tablets… */
82+
83+
#elif defined(Q_PROCESSOR_ARM_64)
84+
#pragma message("DAEMON_ARCH_arm64")
85+
86+
#elif defined(Q_PROCESSOR_ARM_32) && defined(__ARM_PCS_VFP)
87+
#pragma message("DAEMON_ARCH_armhf")
88+
89+
#elif defined(Q_PROCESSOR_ARM_32) && !defined(__ARM_PCS_VFP)
90+
#pragma message("DAEMON_ARCH_armel")
91+
92+
/* Devices like:
93+
- Raptor Computing Systems Talos, Blackbird… */
94+
95+
#elif defined(Q_PROCESSOR_POWER_64) && Q_BYTE_ORDER == Q_BIG_ENDIAN
96+
#pragma message("DAEMON_ARCH_ppc64")
97+
98+
#elif defined(Q_PROCESSOR_POWER_64) && Q_BYTE_ORDER == Q_LITTLE_ENDIAN
99+
#pragma message("DAEMON_ARCH_ppc64el")
100+
101+
/* 32-bit MIPS devices. */
102+
#elif defined(Q_PROCESSOR_MIPS) && Q_BYTE_ORDER == Q_LITTLE_ENDIAN
103+
#pragma message("DAEMON_ARCH_mipsel")
104+
105+
/* Devices like:
106+
- SiFive HiFive Unmatched, Horse Creek… */
107+
108+
#elif defined(Q_PROCESSOR_RISCV_64)
109+
#pragma message("DAEMON_ARCH_riscv64")
110+
111+
#else
112+
#pragma message("DAEMON_ARCH_unknown")
113+
#endif
114+
115+
// Make the compilation succeeds if architecture is supported.
116+
int main(int argc, char** argv) {
117+
return 0;
118+
}

0 commit comments

Comments
 (0)