-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
198 lines (174 loc) · 6.26 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.14)
# Enable CMAKE_MSVC_RUNTIME_LIBRARY, requires CMake >=3.15
if (POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif ()
project(System3 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
# In msys, `pkg-config --libs` returns `-lmingw32` but find_library() cannot
# find it in default search paths.
if (MSYS)
list(APPEND CMAKE_LIBRARY_PATH $ENV{MINGW_PREFIX}/$ENV{MINGW_CHOST}/lib)
endif ()
if (MSVC)
# Use statically-linked runtime library.
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
option(BUILD_SHARED_LIBS "Build as shared library" OFF)
endif ()
add_library(ymfm
deps/ymfm/src/ymfm_opn.cpp
deps/ymfm/src/ymfm_adpcm.cpp
deps/ymfm/src/ymfm_ssg.cpp)
target_include_directories(ymfm PUBLIC deps/ymfm/src)
if (ANDROID)
add_library(system3 SHARED)
target_sources(system3 PRIVATE
src/android/nact_android.cpp
src/generic/mako.cpp
)
target_link_libraries(system3 PRIVATE SDL2 SDL2_ttf SDL2_mixer ymfm)
elseif (EMSCRIPTEN)
add_executable(system3)
target_sources(system3 PRIVATE
src/emscripten/nact_emscripten.cpp
src/emscripten/mako.cpp
)
set(LIBS -sUSE_SDL=2 -sUSE_SDL_TTF=2)
target_compile_options(system3 PRIVATE ${LIBS})
target_link_options(system3 PRIVATE ${LIBS})
target_link_libraries(system3 PRIVATE idbfs.js ymfm)
# Without optimizations, Asyncify generates very large code.
list(APPEND CMAKE_EXE_LINKER_FLAGS_DEBUG "-O1")
target_link_options(system3 PRIVATE
-sENVIRONMENT=web
-sMODULARIZE=1
-sEXPORT_ES6=1
-sASYNCIFY=1
-sASYNCIFY_IGNORE_INDIRECT=1
-sASYNCIFY_REMOVE=SDL_Delay
-sALLOW_MEMORY_GROWTH=1
-sNO_EXIT_RUNTIME=1
"-sASYNCIFY_ADD=NACT::execute()"
-sEXPORTED_FUNCTIONS=_main,_malloc
-sEXPORTED_RUNTIME_METHODS=FS,IDBFS,getValue,addRunDependency,removeRunDependency
--emit-tsd=system3.d.ts
)
else() # NOT (ANDROID OR EMSCRIPTEN)
add_executable(system3)
target_link_libraries(system3 PRIVATE ymfm)
if (MSVC)
include(FetchContent)
FetchContent_Declare(sdl2
URL https://github.com/libsdl-org/SDL/releases/download/release-2.30.6/SDL2-devel-2.30.6-VC.zip
URL_HASH SHA1=038ffed56e04fbc4c6236187472c671596963fdb)
FetchContent_MakeAvailable(sdl2)
find_package(SDL2 REQUIRED CONFIG PATHS ${sdl2_SOURCE_DIR}/cmake NO_DEFAULT_PATH)
get_target_property(SDL2_DLL SDL2::SDL2 IMPORTED_LOCATION)
FetchContent_Declare(sdl2_ttf
URL https://github.com/libsdl-org/SDL_ttf/releases/download/release-2.22.0/SDL2_ttf-devel-2.22.0-VC.zip
URL_HASH SHA1=2d4f131909af2985b5ebc5ed296d28628c87c243)
FetchContent_MakeAvailable(sdl2_ttf)
find_package(SDL2_ttf REQUIRED CONFIG PATHS ${sdl2_ttf_SOURCE_DIR}/cmake NO_DEFAULT_PATH)
get_target_property(SDL2TTF_DLL SDL2_ttf::SDL2_ttf IMPORTED_LOCATION)
get_filename_component(SDL2TTF_LIBDIR ${SDL2TTF_DLL} DIRECTORY)
FetchContent_Declare(rtmidi
URL https://github.com/thestk/rtmidi/archive/refs/tags/6.0.0.zip
URL_HASH SHA1=43287aff8c2c03d3b38cff4d44611763f5e149fa
EXCLUDE_FROM_ALL)
set(RTMIDI_BUILD_TESTING OFF CACHE BOOL "Build test programs" FORCE)
FetchContent_MakeAvailable(rtmidi)
set_property(TARGET rtmidi PROPERTY COMPILE_WARNING_AS_ERROR OFF)
target_compile_definitions(system3 PRIVATE USE_MIDI)
target_link_libraries(system3 PRIVATE rtmidi)
target_sources(system3 PRIVATE src/sys/mako_midi.cpp)
target_compile_definitions(system3 PRIVATE _CRT_NONSTDC_NO_DEPRECATE _CRT_SECURE_NO_WARNINGS)
target_compile_options(system3 PRIVATE /utf-8 /wd4244)
target_link_libraries(system3 PRIVATE SDL2::SDL2main SDL2::SDL2 SDL2_ttf::SDL2_ttf)
set_target_properties(system3 PROPERTIES
WIN32_EXECUTABLE TRUE
VS_DEBUGGER_ENVIRONMENT "PATH=${SDL2_LIBDIR}$<SEMICOLON>${SDL2TTF_LIBDIR}$<SEMICOLON>$ENV{PATH}")
set_directory_properties(PROPERTIES VS_STARTUP_PROJECT system3)
install(FILES ${SDL2_DLL} ${SDL2TTF_DLL} DESTINATION .)
install(TARGETS system3 RUNTIME DESTINATION .)
else()
include(FindPkgConfig)
pkg_check_modules(SDL2 REQUIRED IMPORTED_TARGET sdl2)
pkg_check_modules(SDL2TTF REQUIRED IMPORTED_TARGET SDL2_ttf)
target_link_libraries(system3 PRIVATE PkgConfig::SDL2 PkgConfig::SDL2TTF)
pkg_check_modules(RTMIDI IMPORTED_TARGET rtmidi)
if (RTMIDI_FOUND)
target_compile_definitions(system3 PRIVATE USE_MIDI)
target_link_libraries(system3 PRIVATE PkgConfig::RTMIDI)
target_sources(system3 PRIVATE src/sys/mako_midi.cpp)
endif()
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_sources(system3 PRIVATE
src/win/nact_win.cpp
src/win/mako.cpp
src/win/resource.rc
)
target_link_libraries(system3 PRIVATE winmm)
if (MSYS)
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
endif()
else()
pkg_check_modules(SDL2MIXER REQUIRED IMPORTED_TARGET SDL2_mixer)
target_sources(system3 PRIVATE
src/generic/nact_generic.cpp
src/generic/mako.cpp
)
target_link_libraries(system3 PRIVATE PkgConfig::SDL2MIXER)
set(RESOURCE_PATH ${CMAKE_INSTALL_PREFIX}/share/system3/)
install(TARGETS system3 RUNTIME DESTINATION bin)
install(DIRECTORY resources/
DESTINATION share/system3
FILES_MATCHING PATTERN *.MDA PATTERN *.ttf)
endif()
endif()
target_sources(system3 PRIVATE
src/sdlmain.cpp
src/config.cpp
src/fileio.cpp
src/resource.cpp
src/encoding.cpp
src/texthook.cpp
src/fm/makofm.cpp
src/fm/mako_ymfm.cpp
src/sys/ags.cpp
src/sys/ags_bmp.cpp
src/sys/ags_cursor.cpp
src/sys/ags_draw.cpp
src/sys/ags_gl3.cpp
src/sys/ags_gm3.cpp
src/sys/ags_pms.cpp
src/sys/ags_text.cpp
src/sys/ags_vsp.cpp
src/sys/ags_vsp2l.cpp
src/sys/ags_window.cpp
src/sys/dri.cpp
src/sys/msgskip.cpp
src/sys/nact.cpp
src/sys/nact_crc32.cpp
src/sys/nact_input.cpp
src/sys/nact_sys1.cpp
src/sys/nact_sys2.cpp
src/sys/nact_sys3.cpp
)
if(NINTENDO_SWITCH)
set(RESOURCE_PATH romfs:/)
nx_generate_nacp(system3.nacp
NAME "system3"
AUTHOR "kichikuou"
VERSION "0.8.0"
)
nx_create_nro(system3
NACP system3.nacp
ICON "switch/icon.jpg"
ROMFS "resources"
)
endif()
target_compile_definitions(system3 PRIVATE
$<$<CONFIG:Debug>:_DEBUG_CONSOLE>
RESOURCE_PATH="${RESOURCE_PATH}")
target_include_directories(system3 PRIVATE src src/sys)