forked from visualboyadvance-m/visualboyadvance-m
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
401 lines (336 loc) · 14.5 KB
/
CMakeLists.txt
File metadata and controls
401 lines (336 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
cmake_minimum_required(VERSION 3.19)
cmake_policy(VERSION 3.19...3.28.3)
# Use new link library de-duplication behavior.
if(POLICY CMP0156)
cmake_policy(SET CMP0156 NEW)
endif()
if(POLICY CMP0179)
cmake_policy(SET CMP0179 NEW)
endif()
#if(POLICY CMP0181)
# cmake_policy(SET CMP0181 NEW)
#endif()
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
if(WIN32)
include(RemoveStrawberryPerlFromPATH)
find_program(POWERSHELL
NAMES pwsh.exe powershell.exe
HINTS
"/Program Files/PowerShell/7"
"/Windows/System32/WindowsPowerShell/v1.0"
REQUIRED)
else()
find_program(POWERSHELL pwsh)
endif()
if(UPDATE_APPCAST)
include(UpdateAppcast)
endif()
if(TAG_RELEASE)
include(MakeReleaseCommitAndTag)
endif()
set(MSYS2 OFF CACHE BOOL "Building in an MSYS2 environment" FORCE)
if(NOT "$ENV{MSYSTEM_PREFIX}" STREQUAL "")
set(MSYS2 ON CACHE BOOL "Building in an MSYS2 environment" FORCE)
# Clear env vars from Windows native dev environments that can break the build.
unset(ENV{LIB})
unset(ENV{INCLUDE})
endif()
option(VCPKG_BINARY_PACKAGES "Use vcpkg binary packages" TRUE)
set(VCPKG_DEPS zlib bzip2 "liblzma[tools]" pthreads gettext-libintl wxwidgets nanosvg)
set(VCPKG_DEPS_OPTIONAL
"sdl3[vulkan]" ENABLE_SDL3
openal-soft ENABLE_OPENAL
"ffmpeg[x264,x265]" ENABLE_FFMPEG
faudio ENABLE_FAUDIO
)
include(Set-Toolchain-vcpkg)
# Use ccache if available and not already enabled on the command line.
# This has to be done before the project() call.
if(NOT CMAKE_CXX_COMPILER_LAUNCHER)
find_program(CCACHE_EXECUTABLE ccache)
if(CCACHE_EXECUTABLE)
message(STATUS "Enabling ccache")
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE} CACHE STRING "C compiler launcher" FORCE)
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE} CACHE STRING "C++ compiler launcher" FORCE)
set(CMAKE_ASM_NASM_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE} CACHE STRING "nasm assembler launcher" FORCE)
endif()
endif()
find_package(Git)
# Make sure we pull in the submodules on windows and mingw.
if(GIT_FOUND AND WIN32)
# Win32 deps submodule
set(SUBMODULE_MANUAL_UPDATE FALSE)
if(EXISTS "${CMAKE_SOURCE_DIR}/.git" AND NOT EXISTS "${CMAKE_SOURCE_DIR}/win32-deps/mingw-xaudio/include")
set(SUBMODULE_MANUAL_UPDATE TRUE)
execute_process(
COMMAND "${GIT_EXECUTABLE}" submodule update --init --recursive -- win32-deps
RESULT_VARIABLE SUBMODULE_UPDATE_STATUS
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
endif()
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/win32-deps/mingw-xaudio/include")
if(NOT (SUBMODULE_MANUAL_UPDATE AND SUBMODULE_UPDATE_STATUS EQUAL 0))
message(FATAL_ERROR "Please pull in git submodules, e.g.\nrun: git submodule update --init --remote --recursive")
endif()
endif()
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED True)
project(VBA-M C CXX)
if(APPLE)
enable_language(OBJC)
enable_language(OBJCXX)
# Suppress "dylib was built for newer macOS version than being linked" and
# other ld warnings that fire when linking against Homebrew libraries.
# Apple's linker has no per-warning suppression for these diagnostics.
add_link_options(-Wl,-w)
endif()
if(CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg")
add_compile_definitions(-DVCPKG)
if(MSVC)
set(CMAKE_C_FLAGS "/I\"${VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/include\" ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "/I\"${VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/include\" ${CMAKE_CXX_FLAGS}")
set(CMAKE_OBJC_FLAGS "/I\"${VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/include\" ${CMAKE_OBJC_FLAGS}")
set(CMAKE_OBJCXX_FLAGS "/I\"${VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/include\" ${CMAKE_OBJCXX_FLAGS}")
else()
set(CMAKE_C_FLAGS "-I\"${VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/include\" ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-I\"${VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/include\" ${CMAKE_CXX_FLAGS}")
set(CMAKE_OBJC_FLAGS "-I\"${VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/include\" ${CMAKE_OBJC_FLAGS}")
set(CMAKE_OBJCXX_FLAGS "-I\"${VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/include\" ${CMAKE_OBJCXX_FLAGS}")
endif()
endif()
# When VS environment was auto-loaded by Set-Toolchain-vcpkg.cmake, embed the
# MSVC standard include and lib paths as explicit flags. ninja runs in a separate
# process that does not inherit cmake's environment, so INCLUDE/LIB would be unset.
if(MSVC AND DEFINED VBAM_VS_INCLUDE_DIRS)
foreach(inc_dir ${VBAM_VS_INCLUDE_DIRS})
string(APPEND VBAM_MSVC_INC_FLAGS " /I\"${inc_dir}\"")
endforeach()
set(CMAKE_C_FLAGS "${VBAM_MSVC_INC_FLAGS} ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${VBAM_MSVC_INC_FLAGS} ${CMAKE_CXX_FLAGS}")
# RC compilation uses cmcldeps which runs cl.exe for dependency scanning;
# it needs the same include paths.
set(CMAKE_RC_FLAGS "${VBAM_MSVC_INC_FLAGS} ${CMAKE_RC_FLAGS}")
unset(VBAM_MSVC_INC_FLAGS)
endif()
if(MSVC AND DEFINED VBAM_VS_LIB_DIRS)
foreach(lib_dir ${VBAM_VS_LIB_DIRS})
string(APPEND VBAM_MSVC_LIB_FLAGS " /LIBPATH:\"${lib_dir}\"")
endforeach()
set(CMAKE_EXE_LINKER_FLAGS "${VBAM_MSVC_LIB_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${VBAM_MSVC_LIB_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${VBAM_MSVC_LIB_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}")
unset(VBAM_MSVC_LIB_FLAGS)
endif()
# When VS environment was auto-loaded, generate wrappers that prepend VS tool
# paths (containing dumpbin, etc.) to PATH at build time. vcpkg's applocal.ps1
# post-build script needs dumpbin, but neither ninja nor the powershell process
# it spawns inherit cmake's configure-time environment.
if(MSVC AND DEFINED VBAM_VS_TOOL_PATHS)
# VBAM_VS_TOOL_PATHS is stored as a CMake list (semicolons become separators);
# string(JOIN) reconstitutes the semicolon-separated Windows PATH string.
string(JOIN ";" VBAM_VS_TOOL_PATHS_STR ${VBAM_VS_TOOL_PATHS})
# Wrap the build tool (ninja) so cmake --build gets VS tools in PATH.
if(NOT CMAKE_GENERATOR MATCHES "Visual Studio")
if(NOT DEFINED VBAM_REAL_NINJA)
set(VBAM_REAL_NINJA "${CMAKE_MAKE_PROGRAM}" CACHE FILEPATH "" FORCE)
endif()
file(TO_NATIVE_PATH "${VBAM_REAL_NINJA}" VBAM_NINJA_NATIVE)
set(VBAM_BUILD_WRAPPER "${CMAKE_BINARY_DIR}/vbam_build.cmd")
file(WRITE "${VBAM_BUILD_WRAPPER}"
"@echo off\r\nset \"PATH=${VBAM_VS_TOOL_PATHS_STR};%PATH%\"\r\n\"${VBAM_NINJA_NATIVE}\" %*\r\n"
)
set(CMAKE_MAKE_PROGRAM "${VBAM_BUILD_WRAPPER}" CACHE FILEPATH "" FORCE)
unset(VBAM_NINJA_NATIVE)
endif()
# Override vcpkg's powershell path with a wrapper that prepends VS tool paths.
# vcpkg's z_vcpkg_set_powershell_path() skips setup when Z_VCPKG_POWERSHELL_PATH
# is already defined, so pre-defining it here makes every applocal.ps1 invocation
# run with dumpbin available — even when ninja is called directly.
file(TO_NATIVE_PATH "${POWERSHELL}" VBAM_PS_NATIVE)
set(VBAM_PS_WRAPPER "${CMAKE_BINARY_DIR}/vbam_powershell.cmd")
file(WRITE "${VBAM_PS_WRAPPER}"
"@echo off\r\nset \"PATH=${VBAM_VS_TOOL_PATHS_STR};%PATH%\"\r\n\"${VBAM_PS_NATIVE}\" %*\r\n"
)
set(Z_VCPKG_POWERSHELL_PATH "${VBAM_PS_WRAPPER}" CACHE INTERNAL "" FORCE)
unset(VBAM_VS_TOOL_PATHS_STR)
unset(VBAM_PS_NATIVE)
endif()
if(APPLE)
include(CheckLanguage)
include(MetalShaderSupport)
execute_process(
COMMAND xcrun -f metal
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE CMAKE_Metal_COMPILER
)
if(NOT CMAKE_Metal_COMPILER)
check_language(Metal)
endif()
if(CMAKE_Metal_COMPILER)
enable_language(Metal)
endif()
endif()
include(CTest)
include(FetchContent)
include(GNUInstallDirs)
include(Architecture)
include(Options)
include(Toolchain)
include(Dependencies)
# We target Windows XP for 32 bit Windows builds.
if(WIN32 AND X86)
add_compile_definitions(-DWINVER=0x0501 -D_WIN32_WINNT=0x0501)
endif()
# Disable tests when not in a git checkout.
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(BUILD_TESTING OFF)
endif()
# Configure gtest
if(BUILD_TESTING)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/third_party/googletest/CMakeLists.txt)
execute_process(
COMMAND git submodule update --init --recursive -- third_party/googletest
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif()
if(EXISTS ${CMAKE_SOURCE_DIR}/third_party/googletest/CMakeLists.txt)
add_subdirectory(./third_party/googletest)
# Make sure not use fast-math optimizations for gtest
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
target_compile_options(gtest PRIVATE -O3 -fno-fast-math -Wno-error -w -DGTEST_API_=/**/)
target_compile_options(gtest_main PRIVATE -O3 -fno-fast-math -Wno-error -w -DGTEST_API_=/**/)
target_compile_options(gmock PRIVATE -O3 -fno-fast-math -Wno-error -w -DGTEST_API_=/**/)
target_compile_options(gmock_main PRIVATE -O3 -fno-fast-math -Wno-error -w -DGTEST_API_=/**/)
add_compile_definitions(-DGTEST_API_=/**/)
endif()
include(GoogleTest)
include(GTestDiscoverTests)
else()
set(BUILD_TESTING OFF)
endif()
endif()
if(NOT CMAKE_PREFIX_PATH AND (NOT ("$ENV{CMAKE_PREFIX_PATH}" STREQUAL "")))
set(CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH}")
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build Type" FORCE)
elseif(NOT CMAKE_BUILD_TYPE MATCHES "^(Release|Debug|RelWithDebInfo|MinSizeRel)$")
message(FATAL_ERROR "Invalid CMAKE_BUILD_TYPE: '${CMAKE_BUILD_TYPE}', must be one of: 'Release', 'Debug', 'RelWithDebInfo' or 'MinSizeRel'")
endif()
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
include(GitTagVersion)
git_version(VBAM_VERSION VBAM_REVISION VBAM_VERSION_RELEASE)
# only use the plugin to tie the configure state to the sha to force rebuilds
# of files that depend on version.h
include(GetGitRevisionDescription)
get_git_head_revision(REFSPEC COMMITHASH)
# Make sure old tags are gone from all clones.
execute_process(
COMMAND ${GIT_EXECUTABLE} tag -l
OUTPUT_VARIABLE git_tags
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
string(REGEX REPLACE ";" "\\\\;" git_tags_lines "${git_tags}")
string(REGEX REPLACE "\r?\n" ";" git_tags_lines "${git_tags_lines}")
set(found_old_tags FALSE)
foreach(tag ${git_tags_lines})
if(NOT tag MATCHES "^v[0-9]")
set(found_old_tags TRUE)
break()
endif()
endforeach()
if(found_old_tags)
# Delete all tags and fetch them from the origin.
foreach(tag ${git_tags_lines})
execute_process(
COMMAND ${GIT_EXECUTABLE} tag -d ${tag}
OUTPUT_QUIET
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endforeach()
execute_process(
COMMAND ${GIT_EXECUTABLE} fetch --tags origin
OUTPUT_QUIET
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif()
endif()
# no git or no tags, use ChangeLog
if(NOT VBAM_VERSION)
include(ChangeLogVersion)
changelog_version(VBAM_VERSION VBAM_REVISION VBAM_VERSION_RELEASE)
endif()
# Enable internationalization
set(LOCALEDIR share/locale)
# Set up the zip compressor program (used for release zips and translations).
if(NOT ZIP_PROGRAM)
find_program(ZIP_PROGRAM zip DOC "zip compressor executable")
if(WIN32 AND NOT ZIP_PROGRAM)
if(NOT DEFINED POWERSHELL)
message(FATAL_ERROR "Powershell is required for zip file support when the `zip` program is not available.")
endif()
# Build zip.exe from zip.ps1 using ps12exe
set(ZIP_EXE_DIR "${CMAKE_BINARY_DIR}/zip-bin")
set(ZIP_EXE "${ZIP_EXE_DIR}/zip.exe")
set(PS12EXE_DIR "${CMAKE_SOURCE_DIR}/third_party/ps12exe")
if(NOT EXISTS "${ZIP_EXE}")
file(MAKE_DIRECTORY "${ZIP_EXE_DIR}")
execute_process(
COMMAND ${POWERSHELL} -NoProfile -ExecutionPolicy Bypass -Command
"& '${PS12EXE_DIR}/ps12exe.ps1' -inputFile '${CMAKE_SOURCE_DIR}/src/wx/zip.ps1' -outputFile '${ZIP_EXE}' -noConsole:$false -architecture 'x86' -localize 'en' -skipVersionCheck:$true"
RESULT_VARIABLE PS12EXE_BUILD_RESULT
)
if(NOT PS12EXE_BUILD_RESULT EQUAL 0)
message(FATAL_ERROR "Failed to build zip.exe with ps12exe. The zip program is required for building.")
endif()
endif()
set(ZIP_PROGRAM "${ZIP_EXE}")
endif()
if(ZIP_PROGRAM)
set(ZIP_PROGRAM "${ZIP_PROGRAM}" CACHE STRING "zip compressor executable" FORCE)
else()
message(FATAL_ERROR "The zip compressor program is required for building.")
endif()
endif()
# When ZIP_PROGRAM is cached, ENV{PATH} must be set every time.
if(ZIP_PROGRAM)
get_filename_component(ZIP_PROGRAM_DIR ${ZIP_PROGRAM} DIRECTORY)
if(WIN32)
set(ENV{PATH} "${ZIP_PROGRAM_DIR};$ENV{PATH}")
else()
set(ENV{PATH} "${ZIP_PROGRAM_DIR}:$ENV{PATH}")
endif()
endif()
if(NOT TRANSLATIONS_ONLY)
add_subdirectory(third_party/include/nonstd)
add_subdirectory(third_party/include/stb)
add_subdirectory(third_party/include/ghc)
if(ENABLE_LINK)
include_directories(third_party/sfml/include)
add_subdirectory(third_party/sfml/src/SFML/System EXCLUDE_FROM_ALL)
add_subdirectory(third_party/sfml/src/SFML/Network EXCLUDE_FROM_ALL)
set(SFML_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/third_party/sfml/include)
set(SFML_LIBRARIES sfml-system sfml-network)
endif()
add_subdirectory(src/core)
add_subdirectory(src/components)
add_subdirectory(src/sdl)
add_subdirectory(src/libretro)
endif()
add_subdirectory(src/wx)
add_subdirectory(po/wxvbam)
set(CPACK_GENERATOR "ZIP")
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_PACKAGE_VERSION_MAJOR "2")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "0-Git-${COMMITHASH}")
list(APPEND CPACK_SOURCE_IGNORE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/win32-deps")
include(CPack)