-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
110 lines (88 loc) · 4.16 KB
/
Copy pathCMakeLists.txt
File metadata and controls
110 lines (88 loc) · 4.16 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
#
# m o t i o n
# The SGI Emulator
#
# Copyright (c)2026 starfrost
#
# CMakeLists.txt: Main buildscript.
#
cmake_minimum_required(VERSION 3.20)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# $<CONFIG> rather than ${CMAKE_BUILD_TYPE}: specify with -DCMAKE_BUILD_TYPE
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/$<CONFIG>)
# mingw-w64 doesn't support static linking against the UCRT
# Install path
set(ROM_SRC_DIR "${CMAKE_SOURCE_DIR}/roms")
set(ROM_DST_DIR "${CMAKE_BINARY_DIR}/output/$<CONFIG>/roms")
set(ASSET_SRC_DIR "${CMAKE_SOURCE_DIR}/assets")
set(ASSET_DST_DIR "${CMAKE_BINARY_DIR}/output/$<CONFIG>/assets")
project(motion)
# Build SDL static, we like static libraries (esp. on Linux, where the system SDL3 might not be the same version!)
set(SDL_SHARED OFF CACHE BOOL "Build SDL shared library" FORCE)
set(SDL_STATIC ON CACHE BOOL "Build SDL static library" FORCE)
# Turn off bits of SDL we don't need
set(SDL_HAPTIC FALSE CACHE BOOL "Build SDL haptic subsystem" FORCE)
set(SDL_SENSOR FALSE CACHE BOOL "Build SDL sensor subsystem" FORCE)
set(SDL_CAMERA FALSE CACHE BOOL "Build SDL camera subsystem" FORCE)
set(SDL_DUMMYCAMERA FALSE CACHE BOOL "Build SDL dummy camera subsystem" FORCE)
set(SDL_POWER FALSE CACHE BOOL "Build SDL power subsystem" FORCE)
set(SDL_DIALOG FALSE CACHE BOOL "Build SDL dialog subsystem" FORCE)
# Add our SDL submodule directories
add_subdirectory(external/sdl3 EXCLUDE_FROM_ALL)
# Also allow us to use our own headers. At some point, we need to have a public/private header distinction...
add_subdirectory(src)
# Setup our build type info
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
target_compile_definitions(motion PRIVATE DEBUG)
# Turn on ASan, O1 level optimisation (recommended by GOogle). -fno-omit-frame-pointer -fno-inline gives us much better debugging
target_compile_options(motion PRIVATE -fsanitize=address -O0 -fno-omit-frame-pointer -fno-inline -U_FORTIFY_SOURCE)
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
target_compile_definitions(motion PRIVATE RELEASE)
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
target_compile_definitions(motion PRIVATE RELEASE)
target_compile_definitions(motion PRIVATE RELEASE_WITH_DEBUG_INFO)
endif()
if(WIN32 AND MINGW)
target_link_options(motion PRIVATE
-static -static-libgcc -static-libstdc++
-Wl,-Bstatic -lwinpthread -Wl,-Bdynamic
)
elseif(APPLE)
# Apple Clang hard-errors because libc++ is part of MacOS ABI
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# if you statically link everything basically pipewrie will KILL SDL lol
target_link_options(motion PRIVATE -static-libstdc++ -static-libgcc) # static stdc++
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
target_link_options(motion PRIVATE -fsanitize=address)
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Clang on Linux/BSD: -static-libstdc++ is fine, -static-libgcc is not reliable
target_link_options(motion PRIVATE -static-libstdc++)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
target_link_options(motion PRIVATE -fsanitize=address)
endif()
endif()
target_link_libraries(motion PRIVATE
SDL3::SDL3 # static sdl3
moira) # 68k lib
# install below is only used for 'official' builds. we want the files there regardless of what hte user does.
add_custom_target(InstallAssets
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different "${ROM_SRC_DIR}" "${ROM_DST_DIR}"
COMMENT "Updating ROMs..."
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different "${ASSET_SRC_DIR}" "${ASSET_DST_DIR}"
COMMENT "Updating assets..."
)
add_dependencies(motion InstallAssets)
# Flat so PROM is loaded from a path relative to the cwd
install(TARGETS motion RUNTIME DESTINATION .)
# On by default for releases, turn it off with -DMOTION_INSTALL_ROMS=OFF.
option(MOTION_INSTALL_ROMS "Bundle roms/ into the install tree" ON)
if(MOTION_INSTALL_ROMS)
install(DIRECTORY "${ROM_SRC_DIR}/" DESTINATION roms
PATTERN ".DS_Store" EXCLUDE
PATTERN "Thumbs.db" EXCLUDE
)
endif()
# install assets
install(DIRECTORY "${ASSET_SRC_DIR}/" DESTINATION assets)