-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
212 lines (166 loc) · 4.32 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
CMAKE_MINIMUM_REQUIRED(VERSION 3.15 FATAL_ERROR)
# Allow for custom CMake modules
LIST(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/CMake)
INCLUDE(SourceFolders)
INCLUDE(Version)
###
### Project
###
PROJECT(
NESx
LANGUAGES C
DESCRIPTION "A Toy Nintendo Entertainment System Emulator"
VERSION ${PROJECT_VERSION}
)
# Enable testing if we are not a subdirectory
IF(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
INCLUDE(CTest)
ENDIF()
###
### Options
###
OPTION(BUILD_TOOLS "Build Tools" OFF)
OPTION(BUILD_THIRDPARTY "Build Missing Third-Party Dependencies" ON)
###
### Configuration
###
# Allow for custom organization of files in IDEs
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
###
### Macros
###
MACRO(DOWNLOAD_IF_NOT_EXIST URL FILENAME)
IF(NOT EXISTS ${FILENAME})
FILE(DOWNLOAD ${URL} ${FILENAME})
ENDIF()
ENDMACRO()
###
### Third Party Dependencies
###
IF(BUILD_THIRDPARTY)
SET(THIRDPARTY_SOURCE_DIR ${CMAKE_SOURCE_DIR}/ThirdParty)
SET(THIRDPARTY_BINARY_DIR ${CMAKE_BINARY_DIR}/ThirdParty)
FILE(MAKE_DIRECTORY ${THIRDPARTY_BINARY_DIR})
# Set _ROOT variables for config-based packages
SET(cflags_ROOT ${THIRDPARTY_BINARY_DIR}/cflags)
SET(portaudio_ROOT ${THIRDPARTY_BINARY_DIR}/portaudio)
SET(SDL2_ROOT ${THIRDPARTY_BINARY_DIR}/SDL2)
EXECUTE_PROCESS(
COMMAND ${CMAKE_COMMAND}
-G "${CMAKE_GENERATOR}"
-A "${CMAKE_GENERATOR_PLATFORM}"
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
${THIRDPARTY_SOURCE_DIR}
WORKING_DIRECTORY ${THIRDPARTY_BINARY_DIR}
RESULT_VARIABLE _result
)
IF(_result)
MESSAGE("${_result}")
MESSAGE(FATAL_ERROR "Failed to configure ThirdParty projects")
ENDIF()
SET(THIRDPARTY_BUILD_COMMAND ${CMAKE_COMMAND} --build . )
IF(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
# If we are using make, build in parallel
SET(THIRDPARTY_BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} -l )
ENDIF()
EXECUTE_PROCESS(
COMMAND ${THIRDPARTY_BUILD_COMMAND}
WORKING_DIRECTORY ${THIRDPARTY_BINARY_DIR}
RESULT_VARIABLE _result
)
IF(_result)
MESSAGE("${_result}")
MESSAGE(FATAL_ERROR "Failed to build ThirdParty projects")
ENDIF()
ENDIF()
FIND_PACKAGE(cflags CONFIG REQUIRED)
FIND_PACKAGE(SDL2 2.0.6 CONFIG QUIET)
FIND_PACKAGE(GTK3 QUIET)
FIND_PACKAGE(portaudio CONFIG)
FIND_PACKAGE(ClangFormat)
###
### Automation
###
IF(ClangFormat_FOUND)
ADD_CUSTOM_TARGET(format)
SET_TARGET_PROPERTIES(
format
PROPERTIES
FOLDER "Automation"
)
ENDIF()
###
### Libraries
###
ADD_SUBDIRECTORY(libMOS6502)
ADD_SUBDIRECTORY(libNESx)
###
### Executables
###
IF(BUILD_TOOLS)
ADD_SUBDIRECTORY(Assembler)
ENDIF()
IF(GTK3_FOUND AND portaudio_FOUND)
ADD_SUBDIRECTORY(NESx)
ELSE()
MESSAGE(WARNING "Unable to build main emulator. Make sure you have GTK3 and portaudio configured properly.")
ENDIF()
IF(SDL2_FOUND)
ADD_SUBDIRECTORY(NESxSDL)
ELSE()
MESSAGE(WARNING "Unable to build SDL2 emulator. Make sure you have SDL2 configured properly.")
ENDIF()
IF(NOT TARGET NESx AND NOT TARGET NESxSDL)
MESSAGE(ERROR "Unable to build any emulators.")
ENDIF()
# Set VisualStudio startup project
#SET_PROPERTY(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT "")
###
### Install
###
SET(exports
libMOS6502
libNESx
)
IF(TARGET NESx)
LIST(APPEND exports NESx)
ENDIF()
IF(TARGET NESxSDL)
LIST(APPEND exports NESxSDL)
ENDIF()
INSTALL(
TARGETS
libMOS6502
libNESx
NESx
NESxSDL
EXPORT NESxTargets
)
INCLUDE(CMakePackageConfigHelpers)
WRITE_BASIC_PACKAGE_VERSION_FILE(
${CMAKE_BINARY_DIR}/NESxConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
INSTALL(
EXPORT NESxTargets
NAMESPACE NESx::
DESTINATION lib/cmake/NESx
)
CONFIGURE_PACKAGE_CONFIG_FILE(
${CMAKE_SOURCE_DIR}/CMake/NESxConfig.cmake.in
${CMAKE_BINARY_DIR}/NESxConfig.cmake
INSTALL_DESTINATION lib/cmake/NESx
)
FIND_PACKAGE(PkgConfig QUIET)
IF(PKG_CONFIG_FOUND)
CONFIGURE_FILE(
${CMAKE_SOURCE_DIR}/CMake/MOS6502.pc.in
${CMAKE_BINARY_DIR}/MOS6502.pc
)
INSTALL(
FILES
${CMAKE_BINARY_DIR}/MOS6502.pc
DESTINATION share/pkgconfig
)
ENDIF()