-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
263 lines (228 loc) · 9.51 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
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
cmake_minimum_required(VERSION 3.24)
include(FetchContent)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
##########################################################
# Global project setup
##########################################################
message("Setting up project...")
project(use)
# Windows target specifics ================================================
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(BUILD_FOR_WIN TRUE)
endif()
option(STATIC_BUILD "Build a static binary." ${BUILD_FOR_WIN})
if (STATIC_BUILD)
set(CMAKE_EXE_LINKER_FLAGS "-static")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" CONFIG)
set(BUILD_SHARED_LIBS OFF)
endif()
# Project descriptions =====================================================
set(PROJECT_FULL_NAME "Universal System Emulator")
set(PROJECT_FULL_COPYRIGHT "2023 Ondrej Golasowski")
set(PROJECT_FULL_AUTHOR "Ondrej Golasowski")
# Project directories ======================================================
set(PROJECT_INCLUDE_DIR include)
set(DOCS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/docs)
# Warning: following directory will be removed with CMake 'clean' command!
set(DOCS_OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/docs/_build)
set(DOCS_DOXYGEN_SUBDIRECTORY docs_doxygen)
set(DOCS_SPHINX_SUBDIRECTORY docs_sphinx)
# Docs generators' config files ============================================
set(DOCS_CONF_DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
set(DOCS_CONF_DOXYGEN_OUT ${CMAKE_CURRENT_SOURCE_DIR}/docs/_build/Doxyfile)
set(DOCS_CONF_SPHINX_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/conf.in.py)
set(DOCS_CONF_SPHINX_OUT ${CMAKE_CURRENT_SOURCE_DIR}/docs/_build/conf.py)
# Include additional modules.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_src")
# Including headers.
include_directories(${PROJECT_INCLUDE_DIR})
# Including sources.
file(GLOB projectSources src/*.cpp src/*/*.cpp src/*/*/*.cpp)
message("Included source files: ${projectSources}")
##########################################################
# Dependencies setup
##########################################################
# Download imgui_bundle
Set(FETCHCONTENT_QUIET FALSE)
FetchContent_Declare(
imgui_bundle
GIT_REPOSITORY https://github.com/pthom/imgui_bundle.git
GIT_PROGRESS TRUE
# Enter the desired git tag below
GIT_TAG main
)
FetchContent_MakeAvailable(imgui_bundle)
# Make cmake function `imgui_bundle_add_app` available
list(APPEND CMAKE_MODULE_PATH ${IMGUIBUNDLE_CMAKE_PATH})
include(imgui_bundle_add_app)
# Download imgui memory editor.
FetchContent_Declare(
imgui_memedit
GIT_REPOSITORY https://github.com/ocornut/imgui_club.git
GIT_PROGRESS TRUE
GIT_TAG main
)
FetchContent_MakeAvailable(imgui_memedit)
include_directories(${imgui_memedit_SOURCE_DIR}/imgui_memory_editor)
# Download googletest
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_PROGRESS TRUE
GIT_TAG main
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing()
# Download ImGuiFileDialog
FetchContent_Declare(
imgui_filedialog
GIT_REPOSITORY https://github.com/aiekick/ImGuiFileDialog
GIT_PROGRESS TRUE
GIT_TAG Lib_Only
)
FetchContent_MakeAvailable(imgui_filedialog)
include_directories(${imgui_filedialog_SOURCE_DIR})
file(GLOB imgui_filedialog_sources ${imgui_filedialog_SOURCE_DIR}/*.cpp)
list(APPEND projectSources ${imgui_filedialog_sources})
# Download miniaudio.
FetchContent_Declare(
miniaudio
GIT_REPOSITORY https://github.com/mackron/miniaudio.git
GIT_PROGRESS TRUE
GIT_TAG master
)
FetchContent_MakeAvailable(miniaudio)
include_directories(${miniaudio_SOURCE_DIR})
# Download ImInputBinder
FetchContent_Declare(
ImInputBinder
GIT_REPOSITORY https://github.com/andreondra/ImInputBinder
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(ImInputBinder)
include_directories(${ImInputBinder_SOURCE_DIR})
file(GLOB ImInputBinder_sources ${ImInputBinder_SOURCE_DIR}/ImInputBinder.cpp)
list(APPEND projectSources ${ImInputBinder_sources})
##########################################################
# Build setup
##########################################################
imgui_bundle_add_app(use main.cpp ${projectSources})
##########################################################
# Tests setup
##########################################################
# Download test binaries
message("Downloading 6502 test binaries...")
file(
DOWNLOAD
https://github.com/andreondra/use-tests-6502-65C02/releases/download/latest/6502_functional_test.bin
${CMAKE_CURRENT_BINARY_DIR}/testfiles/6502_functional_test.bin
SHOW_PROGRESS
)
file(
DOWNLOAD
https://github.com/andreondra/use-tests-6502-65C02/releases/download/latest/6502_interrupt_test.bin
${CMAKE_CURRENT_BINARY_DIR}/testfiles/6502_interrupt_test.bin
SHOW_PROGRESS
)
# Download test binaries
message("Downloading NES test binaries...")
file(
DOWNLOAD
http://nickmass.com/images/nestest.nes
${CMAKE_CURRENT_BINARY_DIR}/testfiles/nestest.nes
SHOW_PROGRESS
)
# Copy test assets to build.
file(COPY tests/testfiles DESTINATION .)
file(GLOB unitTests tests/unit/*)
imgui_bundle_add_app(UnitTests ${unitTests} ${projectSources})
target_link_libraries(UnitTests PRIVATE GTest::gtest_main)
file(GLOB integrationTests tests/integration/*)
imgui_bundle_add_app(IntegrationTests ${integrationTests} ${projectSources})
target_link_libraries(IntegrationTests PRIVATE GTest::gtest_main)
include(GoogleTest)
gtest_discover_tests(UnitTests)
gtest_discover_tests(IntegrationTests)
##########################################################
# Docs generator setup
##########################################################
find_package(Doxygen)
if (DOXYGEN_FOUND)
# Doxygen ============================================================
message("[Doxygen] Configuring...")
# Make docs build directory
file(MAKE_DIRECTORY ${DOCS_OUTPUT_DIR})
# Request to configure the file.
# This will replace all @VARIABLES@ with the ones configured in CMake. See global project conf at the top.
configure_file(${DOCS_CONF_DOXYGEN_IN} ${DOCS_CONF_DOXYGEN_OUT} @ONLY)
message("[Doxygen] Adding Doxygen target...")
# Note: do not put "ALL" - this builds docs together with application EVERY TIME!
add_custom_target(docs
COMMAND ${DOXYGEN_EXECUTABLE} ${DOCS_CONF_DOXYGEN_OUT}
WORKING_DIRECTORY ${DOCS_OUTPUT_DIR}
COMMENT "Generating API documentation with Doxygen..."
VERBATIM)
# Add docs output directory to CMake 'clean' target.
set_property(
TARGET docs
APPEND
PROPERTY ADDITIONAL_CLEAN_FILES ${DOCS_OUTPUT_DIR} ${DOCS_SOURCE_DIR}/_exhale
)
message("[Doxygen] Set up successfully!")
# ReadTheDocs ============================================================
# Set Python packages to check
set(REQUIRED_PYTHON_PACKAGES "breathe" "exhale" "sphinx-rtd-theme" "sphinx-sitemap")
set(PYTHON_PACKAGE_MISSING FALSE)
# Find Python and Sphinx
message("[ReadTheDocs] Looking for Python3 and Sphinx")
find_package (Python3 COMPONENTS Interpreter)
find_package(Sphinx)
if(Python3_FOUND AND Sphinx_FOUND)
# Find pip
message("[ReadTheDocs] Looking for pip")
execute_process(
COMMAND ${Python3_EXECUTABLE} -m pip
RESULT_VARIABLE EXIT_CODE
OUTPUT_QUIET
)
if (NOT ${EXIT_CODE} EQUAL 0)
message(WARNING "[ReadTheDocs] pip not installed, can't automatically check dependencies.")
else()
# Check if all the required packages are installed with pip
message("[ReadTheDocs] Looking for required Python packages")
foreach(PACKAGE IN LISTS REQUIRED_PYTHON_PACKAGES)
execute_process(
COMMAND ${Python3_EXECUTABLE} -m pip show ${PACKAGE}
RESULT_VARIABLE EXIT_CODE
OUTPUT_QUIET
)
if (NOT ${EXIT_CODE} EQUAL 0)
message(WARNING "[ReadTheDocs] Python package ${PACKAGE} not found, terminating.")
set(PYTHON_PACKAGE_MISSING TRUE)
break()
endif()
endforeach()
endif()
# Configure RTD target
if(NOT PYTHON_PACKAGE_MISSING)
message("[ReadTheDocs] Configuring target...")
# This will replace all @VARIABLES@ with the ones configured in CMake. See global project conf at the top.
configure_file(${DOCS_CONF_SPHINX_IN} ${DOCS_CONF_SPHINX_OUT} @ONLY)
add_custom_target(sphinxdocs
COMMAND ${SPHINX_EXECUTABLE} -b html -c ${DOCS_OUTPUT_DIR} . ${DOCS_OUTPUT_DIR}/${DOCS_SPHINX_SUBDIRECTORY}
WORKING_DIRECTORY ${DOCS_SOURCE_DIR}
COMMENT "Generating API documentation with Sphinx using RTD theme..."
VERBATIM
DEPENDS docs)
else()
message(WARNING "[ReadTheDocs] Couldn't find some required packages. RTD won't be available.")
endif()
else()
message(WARNING "[ReadTheDocs] Python3 and Sphinx needs to be installed. RTD won't be available.")
endif()
else (DOXYGEN_FOUND)
message(WARNING "[Doxygen] Doxygen not found, can't generate docs.")
endif (DOXYGEN_FOUND)