Skip to content

Commit 782d78f

Browse files
committed
Merge branch 'master' into for-0.56.0/sync
2 parents 54b1c86 + 4313b20 commit 782d78f

9 files changed

+508
-10
lines changed

CMakeLists.txt

+31-5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ if (NOT CMAKE_OSX_ARCHITECTURES)
6767
set(CMAKE_OSX_ARCHITECTURES x86_64)
6868
endif()
6969

70+
# FIXME: this reports an unused architecture if only vms are built.
71+
# We may not be able to avoid this for now without doing a huge rewrite
72+
# of this file.
73+
# FIXME: this reports an unused compiler if only vms are built.
74+
# We cannot avoid this for now without doing a huge rewrite of this files
75+
# since we also set useless flags using informations provided by this.
76+
if (NOT (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER OR BUILD_DUMMY_APP))
77+
message(NOTICE "You can safely ignore the following reported architecture, it is not used.")
78+
message(NOTICE "You can safely ignore the following reported compilers, they are unused.")
79+
endif()
7080
include(DaemonPlatform)
7181

7282
if (Daemon_OUT)
@@ -288,8 +298,17 @@ endif()
288298
# Compile and link flags
289299
################################################################################
290300

301+
# FIXME: This sets unused flags for an unused compiler if only nacl vms
302+
# are built and we are not yet running the chainloaded build. We cannot
303+
# avoid this for now or we would have to do a large rewrite of that file.
304+
# FIXME: This defines the try_flag function that is used in
305+
# Unvanquished CMakeLists.txt even if the engine is not built,
306+
# meaning we have to detect useless engine compiler to set
307+
# useless engine flags when only building vms.
291308
include(DaemonFlags)
292309

310+
# FIXME: Once engine flags would be only set when building the engine
311+
# this would be likely unused by vms as they are built by DaemonGame.
293312
# Warning options (for Daemon only)
294313
# Note the different scopes used for warning options:
295314
# * set_c_cxx_flag(xxx) or try_c_cxx_flag(xxx) sets it for all code including dependencies
@@ -396,9 +415,16 @@ function(ADD_PRECOMPILED_HEADER Target)
396415
set(Header ${COMMON_DIR}/Common.h)
397416

398417
# Compiler-specific PCH support
399-
if (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR NACL)
418+
try_c_cxx_flag(PCH "-pch")
419+
420+
if (PCH)
421+
# CMAKE_CXX_COMPILER_ARG1 is used with compilers using subcommands.
422+
# For example when doing: cmake -D'CMAKE_CXX_COMPILER'='zig;c++'
423+
# CMAKE_CXX_COMPILER will be "zig",
424+
# CMAKE_CXX_COMPILER_ARG1 will be "c++".
400425
add_custom_command(OUTPUT "${OBJ_DIR}/${Target}.h.gch"
401-
COMMAND ${PNACLPYTHON_PREFIX2} ${CMAKE_CXX_COMPILER} ${Defs} ${Flags} -x c++-header ${Header} -o "${OBJ_DIR}/${Target}.h.gch"
426+
COMMAND ${PNACLPYTHON_PREFIX2} ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}
427+
${Defs} ${Flags} -x c++-header ${Header} -o "${OBJ_DIR}/${Target}.h.gch"
402428
DEPENDS ${Header}
403429
IMPLICIT_DEPENDS CXX ${Header}
404430
)
@@ -407,10 +433,10 @@ function(ADD_PRECOMPILED_HEADER Target)
407433
add_dependencies(${Target} ${Target}-pch)
408434

409435
# PNaCl clang doesn't support -include-pch properly
410-
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND NOT NACL)
411-
set_property(TARGET ${Target} APPEND PROPERTY COMPILE_OPTIONS "-include-pch;${OBJ_DIR}/${Target}.h.gch")
412-
else()
436+
if (DAEMON_CXX_COMPILER_NAME STREQUAL "PNaCl")
413437
set_property(TARGET ${Target} APPEND PROPERTY COMPILE_OPTIONS "-include;${OBJ_DIR}/${Target}.h;-Winvalid-pch")
438+
else()
439+
set_property(TARGET ${Target} APPEND PROPERTY COMPILE_OPTIONS "-include-pch;${OBJ_DIR}/${Target}.h.gch")
414440
endif()
415441
elseif (MSVC)
416442
# /Fp sets the PCH path used by either of the /Yc and /Yu options.

cmake/DaemonCompiler.cmake

+240
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
# Daemon BSD Source Code
2+
# Copyright (c) 2024, 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 compiler
29+
################################################################################
30+
31+
# FIXME: Force -W#pragma-messages and -Wno-error
32+
# In case there is -Wno-#pragma-messages or -Werror in CFLAGS/CXXFLAGS
33+
34+
function(detect_daemon_compiler lang)
35+
set(C_NAME "C")
36+
set(CXX_NAME "C++")
37+
set(C_EXT ".c")
38+
set(CXX_EXT ".cpp")
39+
40+
try_compile(BUILD_RESULT
41+
"${CMAKE_BINARY_DIR}"
42+
"${DAEMON_DIR}/cmake/DaemonCompiler/DaemonCompiler${${lang}_EXT}"
43+
CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
44+
OUTPUT_VARIABLE BUILD_LOG
45+
)
46+
47+
get_filename_component(compiler_basename "${CMAKE_${lang}_COMPILER}" NAME)
48+
49+
if (NOT BUILD_RESULT)
50+
message(WARNING "Failed to build DaemonCompiler${${lang}_EXT}, relying on CMake builtin detection.")
51+
set(compiler_name "Unknown")
52+
else()
53+
set(BUILD_LOG "\n${BUILD_LOG}\n")
54+
string(REGEX REPLACE "\n[^\n]*<REPORT<" "\n" BUILD_LOG "${BUILD_LOG}")
55+
string(REGEX REPLACE ">REPORT>[^\n]*\n" "\n" BUILD_LOG "${BUILD_LOG}")
56+
57+
string(REGEX REPLACE ".*\nDAEMON_COMPILER_NAME=([^\n]*)\n.*" "\\1"
58+
compiler_name "${BUILD_LOG}")
59+
60+
foreach(name GCC;Clang;generic;${compiler_name})
61+
set(compatibility_regex ".*\nDAEMON_COMPILER_${name}_COMPATIBILITY=([^\n]*)\n.*")
62+
if ("${BUILD_LOG}" MATCHES ${compatibility_regex})
63+
string(REGEX REPLACE ${compatibility_regex} "\\1"
64+
compiler_${name}_compatibility "${BUILD_LOG}")
65+
endif()
66+
67+
set(version_regex ".*\nDAEMON_COMPILER_${name}_VERSION=([^\n]*)\n.*")
68+
if ("${BUILD_LOG}" MATCHES ${version_regex})
69+
string(REGEX REPLACE ${version_regex} "\\1"
70+
compiler_${name}_version "${BUILD_LOG}")
71+
endif()
72+
73+
set(version_string_regex ".*\nDAEMON_COMPILER_${name}_VERSION_STRING=([^\n]*)\n.*")
74+
if ("${BUILD_LOG}" MATCHES ${version_string_regex})
75+
string(REGEX REPLACE ${version_string_regex} "\\1"
76+
compiler_${name}_version_string "${BUILD_LOG}")
77+
endif()
78+
79+
set(DAEMON_${lang}_COMPILER_${name}_VERSION
80+
"${compiler_${name}_version}"
81+
PARENT_SCOPE)
82+
83+
set(DAEMON_${lang}_COMPILER_${name}_COMPATIBILITY
84+
"${compiler_${name}_compatibility}"
85+
PARENT_SCOPE)
86+
endforeach()
87+
endif()
88+
89+
if (compiler_name STREQUAL "Unknown")
90+
if (CMAKE_${lang}_COMPILER_ID)
91+
set(compiler_name "${CMAKE_${lang}_COMPILER_ID}")
92+
# Compiler version is done below.
93+
else()
94+
message(WARNING "Unknown ${${lang}_NAME} compiler")
95+
endif()
96+
endif()
97+
98+
# AOCC
99+
if (compiler_Clang_version_string)
100+
set(aocc_version_regex ".*CLANG: AOCC_([^ )]+).*")
101+
if (compiler_Clang_version_string MATCHES ${aocc_version_regex})
102+
set(compiler_name "AOCC")
103+
string(REGEX REPLACE ${aocc_version_regex} "\\1"
104+
compiler_AOCC_version "${compiler_Clang_version_string}")
105+
string(REGEX REPLACE "(.*)-Build.*" "\\1"
106+
compiler_AOCC_version "${compiler_AOCC_version}")
107+
endif()
108+
endif()
109+
110+
# Zig
111+
if (compiler_Clang_version_string)
112+
set(zig_version_regex ".*[(]https://github.com/ziglang/zig-bootstrap .*[)]")
113+
if (compiler_Clang_version_string MATCHES ${zig_version_regex})
114+
set(compiler_name "Zig")
115+
endif()
116+
117+
# Parse “zig version”
118+
execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" version
119+
OUTPUT_VARIABLE CUSTOM_${lang}_ZIG_OUTPUT
120+
RESULT_VARIABLE CUSTOM_${lang}_ZIG_RETURN_CODE
121+
ERROR_QUIET
122+
OUTPUT_STRIP_TRAILING_WHITESPACE)
123+
124+
if (NOT CUSTOM_${lang}_ZIG_RETURN_CODE) # Success
125+
set(compiler_Zig_version "${CUSTOM_${lang}_ZIG_OUTPUT}")
126+
endif()
127+
endif()
128+
129+
# Compilers that use underlying Clang version as their own version.
130+
foreach(name in AppleClang)
131+
if (compiler_name STREQUAL "${name}")
132+
set(compiler_${name}_version "${compiler_Clang_version}")
133+
endif()
134+
endforeach()
135+
136+
# Compilers that write the version number at the beginning of the VERSION string.
137+
set(string_version_regex "([^ ]+).*")
138+
foreach(name in PNaCl)
139+
if (compiler_name STREQUAL "${name}")
140+
if (compiler_generic_version_string)
141+
if (compiler_generic_version_string MATCHES ${string_version_regex})
142+
string(REGEX REPLACE ${string_version_regex} "\\1"
143+
compiler_${name}_version "${compiler_generic_version_string}")
144+
endif()
145+
endif()
146+
endif()
147+
endforeach()
148+
149+
if (compiler_ARMClang_version_string)
150+
# There is no __armclang_patchlevel__ so we should parse __armclang_version__ to get it.
151+
if (compiler_ARMClang_version_string MATCHES ${string_version_regex})
152+
string(REGEX REPLACE ${string_version_regex} "\\1"
153+
compiler_ARMClang_version "${compiler_ARMClang_version_string}")
154+
endif()
155+
endif()
156+
157+
if (compiler_ICX_version)
158+
# 20240000 becomes 2024.0.0
159+
string(REGEX REPLACE "(....)(..)(..)" "\\1.\\2.\\3"
160+
compiler_ICX_version "${compiler_ICX_version}")
161+
string(REGEX REPLACE "\\.0" "."
162+
compiler_ICX_version "${compiler_ICX_version}")
163+
endif()
164+
165+
if (compiler_${compiler_name}_version)
166+
set(compiler_version "${compiler_${compiler_name}_version}")
167+
elseif (CMAKE_${lang}_COMPILER_VERSION)
168+
set(compiler_version "${CMAKE_${lang}_COMPILER_VERSION}")
169+
else()
170+
set(compiler_version "Unknown")
171+
message(WARNING "Unknown ${${lang}_NAME} compiler version")
172+
endif()
173+
174+
set(DAEMON_${lang}_COMPILER_BASENAME "${compiler_basename}" PARENT_SCOPE)
175+
set(DAEMON_${lang}_COMPILER_NAME "${compiler_name}" PARENT_SCOPE)
176+
set(DAEMON_${lang}_COMPILER_VERSION "${compiler_version}" PARENT_SCOPE)
177+
endfunction()
178+
179+
message(STATUS "CMake generator: ${CMAKE_GENERATOR}")
180+
181+
foreach(lang C;CXX)
182+
set(C_NAME "C")
183+
set(CXX_NAME "C++")
184+
185+
if (MSVC)
186+
# Let CMake do the job, it does it very well,
187+
# and there is probably no variant to take care about.
188+
set(DAEMON_${lang}_COMPILER_NAME "${CMAKE_${lang}_COMPILER_ID}")
189+
set(DAEMON_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}")
190+
get_filename_component(DAEMON_${lang}_COMPILER_BASENAME "${CMAKE_${lang}_COMPILER}" NAME)
191+
else()
192+
detect_daemon_compiler(${lang})
193+
194+
if (DAEMON_${lang}_COMPILER_Clang_COMPATIBILITY)
195+
if (NOT DAEMON_${lang}_COMPILER_NAME STREQUAL "Clang")
196+
set(DAEMON_${lang}_COMPILER_EXTENDED_VERSION
197+
"${DAEMON_${lang}_COMPILER_VERSION}/clang-${DAEMON_${lang}_COMPILER_Clang_VERSION}")
198+
endif()
199+
elseif (DAEMON_${lang}_COMPILER_GCC_COMPATIBILITY)
200+
if (NOT DAEMON_${lang}_COMPILER_NAME STREQUAL "GCC")
201+
# Almost all compilers on Earth pretend to be GCC compatible.
202+
# So we first have to check it's really a GCC variant.
203+
# Parse “<compiler> -v”
204+
execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" -v
205+
ERROR_VARIABLE CUSTOM_${lang}_GCC_OUTPUT
206+
RESULT_VARIABLE CUSTOM_${lang}_GCC_RETURN_CODE
207+
OUTPUT_QUIET)
208+
209+
if (NOT CUSTOM_${lang}_GCC_RETURN_CODE) # Success
210+
# The existence of this string tells us it's a GCC variant.
211+
# The version in this string is the same as __VERSION__,
212+
# the version of the GCC variant, not the version of the upstream
213+
# GCC we are looking for.
214+
if ("${CUSTOM_${lang}_GCC_OUTPUT}" MATCHES "\ngcc version ")
215+
set(DAEMON_${lang}_COMPILER_EXTENDED_VERSION
216+
"${DAEMON_${lang}_COMPILER_VERSION}/gcc-${DAEMON_${lang}_COMPILER_GCC_VERSION}")
217+
endif()
218+
endif()
219+
endif()
220+
endif()
221+
endif()
222+
223+
if (NOT DAEMON_${lang}_COMPILER_EXTENDED_VERSION)
224+
set(DAEMON_${lang}_COMPILER_EXTENDED_VERSION "${DAEMON_${lang}_COMPILER_VERSION}")
225+
endif()
226+
227+
set(DAEMON_${lang}_COMPILER_STRING
228+
"${DAEMON_${lang}_COMPILER_NAME} ${DAEMON_${lang}_COMPILER_EXTENDED_VERSION} ${DAEMON_${lang}_COMPILER_BASENAME}")
229+
230+
message(STATUS "Detected ${${lang}_NAME} compiler: ${DAEMON_${lang}_COMPILER_STRING}")
231+
232+
add_definitions(-DDAEMON_${lang}_COMPILER_${DAEMON_${lang}_COMPILER_NAME}=1)
233+
234+
# Preprocessor definitions containing '#' may not be passed on the compiler
235+
# command line because many compilers do not support it.
236+
string(REGEX REPLACE "\#" "~" DAEMON_DEFINE_${lang}_COMPILER_STRING "${DAEMON_${lang}_COMPILER_STRING}")
237+
238+
# Quotes cannot be part of the define as support for them is not reliable.
239+
add_definitions(-DDAEMON_${lang}_COMPILER_STRING=${DAEMON_DEFINE_${lang}_COMPILER_STRING})
240+
endforeach()

0 commit comments

Comments
 (0)