Skip to content

Commit 4314ed0

Browse files
committed
WIP: add some cmake framework
1 parent a8ce8f6 commit 4314ed0

13 files changed

+1200
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ testserver.log
2424
/toolchain_build/src/
2525

2626
# Ignore these absolute directories (relative to native_client directory)
27+
/build/
2728
/build/Debug/
2829
/build/Release/
2930
/chromebinaries/
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
elseif(ARCH STREQUAL "unsupported")
64+
message(FATAL_ERROR "Architecture not supported")
65+
endif()
66+
67+
message(STATUS "Detected architecture: ${ARCH}")
68+
69+
add_definitions(-D${ARCH_DEFINE})
70+
71+
# This string can be modified without breaking compatibility.
72+
daemon_add_buildinfo("char*" "DAEMON_ARCH_STRING" "\"${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(NACL_ARCH "${ARCH}")
77+
if (LINUX OR FREEBSD)
78+
set(ARMHF_USAGE arm64 armel)
79+
if (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(NACL_ARCH "armhf")
83+
endif()
84+
elseif(APPLE)
85+
if ("${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(NACL_ARCH "amd64")
89+
endif()
90+
endif()
91+
92+
daemon_add_buildinfo("char*" "DAEMON_NACL_ARCH_STRING" "\"${NACL_ARCH}\"")
93+
94+
option(USE_ARCH_INTRINSICS "Enable custom code using intrinsics functions or asm declarations" ON)
95+
mark_as_advanced(USE_ARCH_INTRINSICS)
96+
97+
macro(set_arch_intrinsics name)
98+
if (USE_ARCH_INTRINSICS)
99+
message(STATUS "Enabling ${name} architecture intrinsics")
100+
add_definitions(-DDAEMON_USE_ARCH_INTRINSICS_${name}=1)
101+
else()
102+
message(STATUS "Disabling ${name} architecture intrinsics")
103+
endif()
104+
endmacro()
105+
106+
if (USE_ARCH_INTRINSICS)
107+
add_definitions(-DDAEMON_USE_ARCH_INTRINSICS=1)
108+
endif()
109+
110+
set_arch_intrinsics(${ARCH})
111+
112+
set(amd64_PARENT "i686")
113+
set(arm64_PARENT "armhf")
114+
115+
if (${ARCH}_PARENT)
116+
set_arch_intrinsics(${${ARCH}_PARENT})
117+
endif()
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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+
/* Devices like:
102+
- SiFive HiFive Unmatched, Horse Creek… */
103+
104+
#elif defined(Q_PROCESSOR_RISCV_64)
105+
#pragma message("DAEMON_ARCH_riscv64")
106+
107+
#else
108+
#pragma message("DAEMON_ARCH_unknown")
109+
#endif
110+
111+
// Make the compilation succeeds if architecture is supported.
112+
int main(int argc, char** argv) {
113+
return 0;
114+
}

0 commit comments

Comments
 (0)