11cmake_minimum_required (VERSION 3.23)
22
3- message (STATUS "CMAKE_VERSION: ${CMAKE_VERSION} " )
4-
5- cmake_policy (SET CMP0048 NEW)
6- cmake_policy (SET CMP0095 NEW)
7-
83list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake" )
4+ include (PreProjectInit)
95
10- include (utils)
116calculate_xray_build_id(XRAY_BUILD_ID)
12-
137project (OpenXRay
148 DESCRIPTION "OpenXRay is an improved version of the X-Ray Engine, \
159 the game engine used in the world-famous S.T.A.L.K.E.R. game series by GSC Game World."
@@ -18,290 +12,16 @@ project(OpenXRay
1812 LANGUAGES CXX C
1913)
2014
21- message (STATUS "CMAKE_PROJECT_VERSION: ${CMAKE_PROJECT_VERSION} " )
22-
23- set (CMAKE_CXX_STANDARD 17)
24- set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
25-
26- option (CMAKE_VERBOSE_MAKEFILE "Verbose build output" OFF )
27- message (STATUS "CMAKE_VERBOSE_MAKEFILE: ${CMAKE_VERBOSE_MAKEFILE} " )
28-
29- if (CMAKE_VERBOSE_MAKEFILE )
30- set (CMAKE_EXECUTE_PROCESS_COMMAND_ECHO STDOUT)
31- endif ()
32-
33- if (CMAKE_VERSION VERSION_EQUAL "3.28.2" AND CMAKE_UNITY_BUILD)
34- # https://gitlab.kitware.com/cmake/cmake/-/issues/25650
35- message (WARNING "In CMake 3.28.2, precompiled headers are broken when Unity build is enabled. This breaks project from compiling. \
36- Please, update to CMake 3.28.3 or downgrade to 3.28.1." )
37- set (CMAKE_UNITY_BUILD OFF )
38- endif ()
39-
40- if (NOT CMAKE_BUILD_TYPE )
41- set (CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
42- endif ()
43-
44- # Redirecting the default installation path /usr/local to /usr no need to use -DCMAKE_INSTALL_PREFIX =/usr
45- if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
46- set (CMAKE_INSTALL_PREFIX "/usr" )
47- endif ()
48-
49- include (GNUInstallDirs)
50- include (packaging)
51-
52- set_git_info()
53-
54- # Output all libraries and executable to one folder
55- set (COMPILE_OUTPUT_FOLDER "${CMAKE_SOURCE_DIR} /bin/${CMAKE_SYSTEM_PROCESSOR} /${CMAKE_BUILD_TYPE} " )
56- set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${COMPILE_OUTPUT_FOLDER} " )
57- set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${COMPILE_OUTPUT_FOLDER} " )
58- set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${COMPILE_OUTPUT_FOLDER} " )
59- set (CMAKE_PDB_OUTPUT_DIRECTORY "${COMPILE_OUTPUT_FOLDER} " )
60- set (CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY "${COMPILE_OUTPUT_FOLDER} " )
61-
62- if (DISABLE_PORTABLE_MODE)
63- add_compile_definitions (DISABLE_PORTABLE_MODE)
64- endif ()
65-
66- set (CMAKE_BUILD_RPATH_USE_ORIGIN TRUE )
67- set (CMAKE_MACOSX_RPATH TRUE )
68-
69- message (STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR} " )
70- if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" )
71- set (PROJECT_PLATFORM_ARM64 TRUE )
72- elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "armv*" )
73- set (PROJECT_PLATFORM_ARM TRUE )
74- elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "e2k" )
75- set (PROJECT_PLATFORM_E2K TRUE )
76- elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64le" )
77- set (PROJECT_PLATFORM_PPC TRUE )
78- endif ()
79-
80- if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
81- set (MASTER_GOLD_DEFAULT_VALUE ON )
82- else ()
83- set (MASTER_GOLD_DEFAULT_VALUE OFF )
84- endif ()
85- message (STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE} " )
86-
87- option (MASTER_GOLD "Build with MASTER_GOLD" ${MASTER_GOLD_DEFAULT_VALUE} )
88- if (MASTER_GOLD)
89- add_compile_definitions (MASTER_GOLD)
90- endif ()
91- message (STATUS "MASTER_GOLD: ${MASTER_GOLD} " )
92-
93- option (STATIC_BUILD "Use static build" ${MASTER_GOLD} )
94- if (STATIC_BUILD)
95- # XXX: Uncomment only after build with XRAY_STATIC_BUILD is fixed
96- #add_compile_definitions(XRAY_STATIC_BUILD)
97- endif ()
98- message (STATUS "STATIC_BUILD: ${STATIC_BUILD} " )
99-
100- option (CMAKE_UNITY_BUILD "Use unity build" OFF )
101- message (STATUS "CMAKE_UNITY_BUILD: ${CMAKE_UNITY_BUILD} " )
102-
103- find_program (CCACHE_FOUND ccache)
104- if (CCACHE_FOUND)
105- set_property (GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
106- set_property (GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
107- set (ENV{CCACHE_SLOPPINESS} pch_defines,time_macros)
108- endif ()
109-
110- if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
111- if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0 AND NOT PROJECT_PLATFORM_E2K)
112- message (FATAL_ERROR "Building with a gcc version less than 8.0 is not supported." )
113- elseif (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0 AND PROJECT_PLATFORM_E2K)
114- message (FATAL_ERROR "Building with a MCST lcc version less than 1.25 is not supported." )
115- endif ()
116- elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
117- # XXX: Remove -fdelayed-template-parsing
118- add_compile_options (
119- -fdelayed-template-parsing
120- -Wno-unused-command -line-argument
121- -Wno-inconsistent-missing-override
122- )
123- endif ()
124-
125- if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT XRAY_USE_DEFAULT_CXX_LIB)
126- if (NOT XRAY_CXX_LIB)
127- include (CheckCXXCompilerFlag)
128- CHECK_CXX_COMPILER_FLAG("-stdlib=libc++" LIBCPP_AVAILABLE)
129- CHECK_CXX_COMPILER_FLAG("-stdlib=libstdc++" LIBSTDCPP_AVAILABLE)
130-
131- if (LIBCPP_AVAILABLE)
132- set (XRAY_CXX_LIB "libc++" CACHE STRING "" FORCE)
133- elseif (LIBSTDCPP_AVAILABLE)
134- set (XRAY_CXX_LIB "libstdc++" CACHE STRING "" FORCE)
135- else ()
136- message ("Neither libstdc++ nor libc++ are available. Hopefully, system has another custom stdlib?" )
137- endif ()
138- endif ()
15+ option (BUILD_SHARED_LIBS "Build shared libraries" ${BUILD_SHARED_LIBS_DEFAULT_VALUE} )
13916
140- if (XRAY_CXX_LIB STREQUAL "libstdc++" )
141- add_compile_options (-stdlib=libstdc++)
142- elseif (XRAY_CXX_LIB STREQUAL "libc++" )
143- add_compile_options (-stdlib=libc++)
144- if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" )
145- add_compile_options (-lcxxrt)
146- else ()
147- add_compile_options (-lc++abi)
148- endif ()
149- endif ()
150- endif ()
17+ option (XRAY_USE_LUAJIT "Use LuaJIT" ON )
18+ option (XRAY_USE_ASAN "Use AddressSanitizer" OFF )
19+ option (XRAY_ENABLE_TRACY "Enable tracy profiler" OFF )
15120
152- add_compile_options (-Wno-attributes)
153- if (APPLE )
154- add_compile_options (-Wl,-undefined,error)
155- else ()
156- add_compile_options (-Wl,--no -undefined)
157- endif ()
158-
159- # TODO test
160- option (USE_ADDRESS_SANITIZER "Use AddressSanitizer" OFF )
161-
162- if (USE_ADDRESS_SANITIZER)
163- add_compile_options (
164- -fsanitize=address
165- -fsanitize=leak
166- -fsanitize=undefined
167- -fno-omit-frame-pointer
168- -fno-optimize-sibling-calls
169- -fno-sanitize=vptr
170- )
171-
172- add_link_options (
173- $<$<CXX_COMPILER_ID:Clang>:-shared-libasan>
174- -fsanitize=address
175- -fsanitize=leak
176- -fsanitize=undefined
177- )
178- endif ()
179-
180- message (STATUS "USE_ADDRESS_SANITIZER: ${USE_ADDRESS_SANITIZER} " )
181-
182- option (USE_LTO "Use Link Time Optimization" ${MASTER_GOLD} )
183- if (USE_LTO)
184- include (CheckIPOSupported)
185- check_ipo_supported(RESULT LTO_SUPPORTED)
186-
187- if (LTO_SUPPORTED)
188- # With clang cmake only enables '-flto=thin' but we want full LTO
189- if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
190- add_compile_options (-flto=full)
191- else ()
192- set (CMAKE_INTERPROCEDURAL_OPTIMIZATION ON )
193- endif ()
194- endif ()
195- endif ()
196-
197- message (STATUS "USE_LTO: ${USE_LTO} " )
198-
199- if (PROJECT_PLATFORM_ARM)
200- add_compile_options (-mfpu=neon)
201- elseif (PROJECT_PLATFORM_ARM64)
202- #add_compile_options()
203- elseif (PROJECT_PLATFORM_E2K)
204- add_compile_options (-Wno-unknown-pragmas)
205- elseif (PROJECT_PLATFORM_PPC)
206- add_compile_options (
207- -maltivec
208- -mabi=altivec
209- )
210- add_compile_definitions (NO_WARN_X86_INTRINSICS)
211- else ()
212- add_compile_options (
213- -mfpmath=sse
214- -msse3
215- )
216- endif ()
217-
218- if (XRAY_LINKER)
219- add_link_options (-fuse-ld=${XRAY_LINKER} )
220- endif ()
221-
222- if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
223- add_compile_definitions (
224- DEBUG
225- MIXED
226- )
227- add_compile_options (-Og)
228- endif ()
229-
230- add_compile_definitions (
231- _MT
232- _CPPUNWIND
233- )
234-
235- if (NOT WIN32 )
236- find_package (SDL2 2.0.18 REQUIRED)
237- # Fix to support older SDL2
238- # https://github.com/OpenXRay/xray-16/issues/1595
239- if (NOT TARGET SDL2::SDL2 AND DEFINED SDL2_LIBRARIES)
240- add_library (SDL2::SDL2 UNKNOWN IMPORTED )
241- set_target_properties (
242- SDL2::SDL2 PROPERTIES
243- IMPORTED_LOCATION "${SDL2_LIBRARIES} "
244- INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS} "
245- )
246- endif ()
247- find_package (OpenAL REQUIRED)
248- find_package (JPEG)
249- find_package (Ogg REQUIRED)
250- find_package (Vorbis REQUIRED)
251- find_package (Theora REQUIRED)
252- find_package (LZO REQUIRED)
253- find_package (mimalloc NAMES mimalloc2 mimalloc2.0 mimalloc)
254- endif ()
255-
256- # Memory allocator option
257- if (mimalloc_FOUND)
258- set (MEMORY_ALLOCATOR "mimalloc" CACHE STRING "Use specific memory allocator (mimalloc/standard)" )
259- else ()
260- set (MEMORY_ALLOCATOR "standard" CACHE STRING "Use specific memory allocator (mimalloc/standard)" )
261- endif ()
262- set_property (CACHE MEMORY_ALLOCATOR PROPERTY STRINGS "mimalloc" "standard" )
263-
264- if (MEMORY_ALLOCATOR STREQUAL "mimalloc" AND NOT mimalloc_FOUND)
265- message (FATAL_ERROR "mimalloc allocator requested but not found. Please, install mimalloc package or select standard allocator." )
266- endif ()
267-
268- message ("Using ${MEMORY_ALLOCATOR} memory allocator" )
269-
270- option (XRAY_USE_LUAJIT "Use LuaJIT" ON )
21+ include (XRay.Build )
22+ include (XRay.Packaging)
27123
27224add_subdirectory (Externals)
273-
274- add_compile_options (
275- -Wall
276- #-Werror
277- -Wextra
278- #-pedantic
279- -Wno-unknown-pragmas
280- -Wno-strict-aliasing
281- -Wno-parentheses
282- -Wno-unused-label
283- -Wno-unused-parameter
284- -Wno-switch
285- #-Wno-padded
286- #-Wno-c++98-compat
287- #-Wno-c++98-compat-pedantic
288- #-Wno-c++11-compat
289- #-Wno-c++11-compat-pedantic
290- #-Wno-c++14-compat
291- #-Wno-c++14-compat-pedantic
292- #-Wno-newline-eof
293- $<$<CXX_COMPILER_ID:GNU>:$<$<COMPILE_LANGUAGE:CXX>:-Wno-class-memaccess>>
294- $<$<CXX_COMPILER_ID:GNU>:$<$<COMPILE_LANGUAGE:CXX>:-Wno-interference-size>>
295- )
296-
29725add_subdirectory (src)
29826add_subdirectory (res)
29927add_subdirectory (misc)
300-
301- get_property (LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS )
302-
303- if ("${LIB64} " STREQUAL "TRUE" )
304- set (LIBSUFFIX 64)
305- else ()
306- set (LIBSUFFIX "" )
307- endif ()
0 commit comments