@@ -5,6 +5,17 @@ project(duckstation C CXX)
5
5
cmake_policy (SET CMP0069 NEW )
6
6
set (CMAKE_POLICY_DEFAULT_CMP0069 NEW )
7
7
8
+ if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} )
9
+ message (FATAL_ERROR "DuckStation does not support in-tree builds. Please make a build directory that is not the source"
10
+ "directory and generate your CMake project there using either `cmake -B build_directory` or by "
11
+ "running cmake from the build directory." )
12
+ endif ()
13
+
14
+ if (NOT CMAKE_BUILD_TYPE MATCHES "Debug|Devel|MinSizeRel|RelWithDebInfo|Release" )
15
+ message (STATUS "CMAKE_BUILD_TYPE not set, defaulting to Release." )
16
+ set (CMAKE_BUILD_TYPE "Release" )
17
+ endif ()
18
+
8
19
message (STATUS "CMake Version: ${CMAKE_VERSION} " )
9
20
message (STATUS "CMake System Name: ${CMAKE_SYSTEM_NAME} " )
10
21
message (STATUS "Build Type: ${CMAKE_BUILD_TYPE} " )
@@ -13,58 +24,19 @@ message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
13
24
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR} /CMakeModules/" )
14
25
include (DuckStationUtils )
15
26
16
- # Platform detection.
17
- if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
18
- set (LINUX TRUE )
19
- elseif (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" )
20
- set (FREEBSD TRUE )
21
- endif ()
22
-
23
- # Renderer options.
24
- option (ENABLE_OPENGL "Build with OpenGL renderer" ON )
25
- option (ENABLE_VULKAN "Build with Vulkan renderer" ON )
26
-
27
- # Global options.
28
- if (NOT ANDROID )
29
- option (BUILD_NOGUI_FRONTEND "Build the NoGUI frontend" OFF )
30
- option (BUILD_QT_FRONTEND "Build the Qt frontend" ON )
31
- option (BUILD_REGTEST "Build regression test runner" OFF )
32
- option (BUILD_TESTS "Build unit tests" OFF )
33
-
34
- set (ENABLE_CUBEB ON )
35
- set (ENABLE_DISCORD_PRESENCE ON )
36
- set (ENABLE_SDL2 ON )
37
-
38
- if (LINUX OR FREEBSD )
39
- option (ENABLE_X11 "Support X11 window system" ON )
40
- option (ENABLE_WAYLAND "Support Wayland window system" ON )
41
- endif ()
42
- if (APPLE )
43
- option (SKIP_POSTPROCESS_BUNDLE "Disable bundle post-processing, including Qt additions" OFF )
44
- endif ()
45
- endif ()
46
-
47
- # Everything except Windows/Mac use EGL.
48
- if (ENABLE_OPENGL AND (LINUX OR FREEBSD OR ANDROID ))
49
- set (ENABLE_EGL TRUE )
50
- endif ()
51
-
52
- if (ENABLE_X11 )
53
- find_package (X11 REQUIRED )
54
- if (NOT X11_Xrandr_FOUND )
55
- message (FATAL_ERROR "XRandR extension is required" )
56
- endif ()
57
- endif ()
58
- if (ENABLE_WAYLAND )
59
- message (STATUS "Wayland support enabled" )
60
- endif ()
27
+ # Detect system attributes.
28
+ detect_operating_system ()
29
+ detect_compiler ()
30
+ detect_architecture ()
31
+ detect_page_size ()
61
32
33
+ # Build options. Depends on system attributes.
34
+ include (DuckStationBuildOptions )
62
35
63
36
# Set _DEBUG macro for Debug builds.
64
37
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG" )
65
38
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG" )
66
39
67
-
68
40
# Release build optimizations for MSVC.
69
41
if (MSVC )
70
42
add_definitions ("/D_CRT_SECURE_NO_WARNINGS" )
@@ -88,101 +60,16 @@ if(MSVC)
88
60
set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /OPT:REF /OPT:ICF" )
89
61
endif ()
90
62
91
-
92
- # Default symbol visibility to hidden, that way we don't go through the PLT for intra-library calls.
93
- if (ANDROID )
94
- cmake_policy (SET CMP0063 NEW )
95
- set (CMAKE_POLICY_DEFAULT_CMP0063 NEW )
96
- set (CMAKE_C_VISIBILITY_PRESET hidden )
97
- set (CMAKE_CXX_VISIBILITY_PRESET hidden )
98
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-semantic-interposition" )
99
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-semantic-interposition" )
100
- endif ()
101
-
102
-
103
63
# Warning disables.
104
- if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
105
- include (CheckCXXFlag )
106
- check_cxx_flag (-Wall COMPILER_SUPPORTS_WALL )
107
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-switch" )
108
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch" )
109
- if (NOT ANDROID )
110
- check_cxx_flag (-Wno-class-memaccess COMPILER_SUPPORTS_MEMACCESS )
111
- check_cxx_flag (-Wno-invalid-offsetof COMPILER_SUPPORTS_OFFSETOF )
112
- endif ()
113
- endif ()
114
-
115
-
116
- # Detect processor type.
117
- if (APPLE AND NOT "${CMAKE_OSX_ARCHITECTURES} " STREQUAL "" )
118
- # Universal binaries.
119
- if ("x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES )
120
- set (CPU_ARCH_X64 TRUE )
121
- message (STATUS "Building x86_64 MacOS binaries." )
122
- endif ()
123
- if ("arm64" IN_LIST CMAKE_OSX_ARCHITECTURES )
124
- set (CPU_ARCH_ARM64 TRUE )
125
- message (STATUS "Building ARM64 MacOS binaries." )
126
- endif ()
127
- elseif ("${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "amd64" OR
128
- "${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "AMD64" OR "${CMAKE_OSX_ARCHITECTURES} " STREQUAL "x86_64" )
129
- if (CMAKE_SIZEOF_VOID_P EQUAL 8 )
130
- set (CPU_ARCH_X64 TRUE )
131
- message (STATUS "Building x86_64 binaries." )
132
- else ()
133
- # Cross-compiling 32-bit build. 32-bit hosts are not supported.
134
- set (CPU_ARCH_X86 TRUE )
135
- message (FATAL_ERROR "Building x86_32 binaries is not supported." )
136
- endif ()
137
- elseif ("${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "x86" OR "${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "i386" OR
138
- "${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "i686" )
139
- set (CPU_ARCH_X86 TRUE )
140
- message (FATAL_ERROR "Building x86_32 binaries is not supported." )
141
- elseif ("${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "aarch64" OR "${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "arm64" )
142
- if (CMAKE_SIZEOF_VOID_P EQUAL 8 ) # Might have an A64 kernel, e.g. Raspbian.
143
- set (CPU_ARCH_ARM64 TRUE )
144
- message (STATUS "Building ARM64 binaries." )
145
- else ()
146
- set (CPU_ARCH_ARM32 TRUE )
147
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm -march=armv7-a" )
148
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -marm -march=armv7-a" )
149
- message (STATUS "Building ARM32 binaries on ARM64." )
150
- endif ()
151
- elseif ("${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "arm" OR "${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "armv7-a" OR
152
- "${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "armv7l" )
153
- set (CPU_ARCH_ARM32 TRUE )
154
- message (STATUS "Building ARM32 binaries." )
155
- if (ANDROID )
156
- # Force ARM mode, since apparently ANDROID_ARM_MODE isn't working..
157
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm" )
158
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -marm" )
159
- else ()
160
- # Enable NEON.
161
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm -march=armv7-a" )
162
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -marm -march=armv7-a" )
163
- endif ()
164
- elseif ("${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "riscv64" )
165
- set (CPU_ARCH_RISCV64 TRUE )
166
- message (STATUS "Building RISC-V 64 binaries." )
167
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -finline-atomics" )
168
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -finline-atomics" )
169
-
170
- # Still need this, apparently.
171
- link_libraries ("-latomic" )
172
-
173
- if (NOT "${CMAKE_BUILD_TYPE} " STREQUAL "Debug" )
174
- # Frame pointers generate an annoying amount of code on leaf functions.
175
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer" )
176
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fomit-frame-pointer" )
177
- endif ()
178
- else ()
179
- message (FATAL_ERROR "Unknown system processor: ${CMAKE_SYSTEM_PROCESSOR} " )
64
+ if (COMPILER_CLANG OR COMPILER_CLANG_CL OR COMPILER_GCC )
65
+ include (CheckCXXFlag )
66
+ check_cxx_flag (-Wall COMPILER_SUPPORTS_WALL )
67
+ check_cxx_flag (-Wno-class-memaccess COMPILER_SUPPORTS_MEMACCESS )
68
+ check_cxx_flag (-Wno-invalid-offsetof COMPILER_SUPPORTS_OFFSETOF )
69
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-switch" )
70
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch" )
180
71
endif ()
181
72
182
- # Detect page size if needed.
183
- detect_page_size ()
184
-
185
-
186
73
# We don't need exceptions, disable them to save a bit of code size.
187
74
if (MSVC )
188
75
string (REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} " )
@@ -193,29 +80,15 @@ else()
193
80
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti" )
194
81
endif ()
195
82
196
-
197
83
# Write binaries to a seperate directory.
198
- if (WIN32 )
199
- set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR} /bin/${CPU_ARCH} " )
200
- else ()
201
- set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} /bin" )
202
- endif ()
203
-
204
- # Needed for Linux - put shared libraries in the binary directory.
205
- set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY} " )
206
-
207
-
208
- # Enable threads everywhere.
209
- set (THREADS_PREFER_PTHREAD_FLAG ON )
210
- find_package (Threads REQUIRED )
211
-
84
+ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} /bin" )
212
85
213
86
# Enable large file support on Linux 32-bit platforms.
214
- # Android is deliberately ommitted here as it didn't support 64-bit ops on files until Android 7/N.
215
- if ((LINUX OR FREEBSD ) AND (CPU_ARCH_X86 OR CPU_ARCH_ARM32 ))
87
+ if (CMAKE_SIZEOF_VOID_P EQUAL 4 )
216
88
add_definitions ("-D_FILE_OFFSET_BITS=64" )
217
89
endif ()
218
90
91
+ # Optional unit tests.
219
92
if (BUILD_TESTS )
220
93
enable_testing ()
221
94
endif ()
@@ -232,6 +105,5 @@ include(DuckStationDependencies)
232
105
add_subdirectory (dep )
233
106
add_subdirectory (src )
234
107
235
- if (ANDROID )
236
- add_subdirectory (android/app/src/cpp )
237
- endif ()
108
+ # Output build summary.
109
+ include (DuckStationBuildSummary )
0 commit comments