-
Notifications
You must be signed in to change notification settings - Fork 15
/
CMakeLists.txt
executable file
·375 lines (302 loc) · 11.6 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
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
cmake_minimum_required(VERSION 2.8.12)
#compiler settings
#set(CMAKE_CXX_STANDARD 11)
#set(CMAKE_CXX_STANDARD_REQUIRED ON)
#set(CMAKE_CXX_EXTENSIONS OFF)
#set(CMAKE_C_COMPILER gcc)
#set(CMAKE_CXX_COMPILER g++)
# common
set(PROJECT_NAME "xpeccy")
project(${PROJECT_NAME})
file(STRINGS "Release" XVER)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
# endianess
include (TestBigEndian)
test_big_endian(BIG_ENDIAN)
if (BIG_ENDIAN)
add_definitions(-DWORDS_BIG_ENDIAN)
else()
add_definitions(-DWORDS_LITTLE_ENDIAN)
endif()
# compilation flags
set(CMAKE_C_FLAGS "-std=gnu99 -Wall -O2 ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG ${CMAKE_C_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_DEBUG "-g -DISDEBUG ${CMAKE_C_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -O2 ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_DEBUG "-g -DISDEBUG ${CMAKE_CXX_FLAGS_DEBUG}")
# OS-depended section
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VERSION ${XVER})
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CMAKE_SYSTEM_PROCESSOR}")
set(CPACK_PACKAGE_DESCRIPTION "ZX Spectrum emulator")
set(CPACK_PACKAGE_VENDOR "SAM style")
set(CPACK_PACKAGE_CONTACT "samstyle@list.ru")
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(INC_PATHS local/include include)
set(LIB_PATHS lib lib64 local/lib local/lib64)
if ("${PACK}" STREQUAL "rpm")
# RPM package
message(STATUS "Package type : RPM")
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
set(CPACK_RPM_PACKAGE_GROUP "Games")
else ()
# DEB package
message(STATUS "Package type : DEB")
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_SECTION "Games")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
endif()
install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME} DESTINATION bin
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE WORLD_READ WORLD_EXECUTE GROUP_READ GROUP_EXECUTE
)
install(FILES images/xpeccy.png DESTINATION share/icons)
install(FILES Xpeccy.desktop DESTINATION share/applications)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "/BSD$/")
set(INC_PATHS pkg/include include)
set(LIB_PATHS lib lib64 pkg/lib local/lib64)
add_definitions("-D__BSD")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(INC_PATHS local/include include)
set(LIB_PATHS lib lib64 local/lib local/lib64)
set(CPACK_GENERATOR "DragNDrop")
set(CPACK_DMG_NAME ${PROJECT_NAME})
set(CPACK_DMG_FORMAT UDZO)
# set(CPACK_DMG_BACKGROUND_IMAGE ${CMAKE_SOURCE_DIR}/background.png)
set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME}.app)
set(MACOSX_BUNDLE_ICON_FILE ${PROJECT_NAME}.icns)
set(MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/Info.plist)
set(MACOSX_BUNDLE_BUNDLE_VERSION ${XVER})
set(BUNDLE_ICON_PATH ${CMAKE_SOURCE_DIR}/images/${MACOSX_BUNDLE_ICON_FILE})
set(BUNDLE_PATH ${CMAKE_BINARY_DIR}/${MACOSX_BUNDLE_BUNDLE_NAME})
set_source_files_properties(${CMAKE_BINARY_DIR}/${PROJECT_NAME} PROPERTIES MACOSX_PACKAGE_LOCATION MacOSX)
set_source_files_properties(${BUNDLE_ICON_PATH} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(CPACK_GENERATOR "ZIP")
set(LIBRARIES ${LIBRARIES} winmm.dll)
set(INC_PATHS $ENV{INCLUDE} $ENV{PATH})
set(LIB_PATHS $ENV{LIBPATH} $ENV{PATH})
else()
message(FATAL_ERROR "Unsupported system : ${CMAKE_SYSTEM_NAME}")
endif()
set(INCLUDIRS
${CMAKE_BINARY_DIR}
./src
)
# sources
file(GLOB_RECURSE SOURCES
./src/*.cpp
./src/*.c
)
# headers
file(GLOB_RECURSE HEADERS
./src/*.h
)
# Qt user interface
file(GLOB_RECURSE UIFILES
./ui/*.ui
)
# Qt resources
set(QRCFILES ./xpeccy.qrc)
# Qt moc files
set(MOCFILES
./src/ethread.h
./src/emulwin.h
./src/xapp.h
./src/xgui/debuga/debuger.h
./src/xgui/debuga/dbg_sprscan.h
./src/xgui/debuga/dbg_memfill.h
./src/xgui/debuga/dbg_finder.h
./src/xgui/debuga/dbg_dump.h
./src/xgui/debuga/dbg_disasm.h
./src/xgui/debuga/dbg_brkpoints.h
./src/xgui/debuga/dbg_diskdump.h
./src/xgui/debuga/dbg_vmem_dump.h
./src/xgui/debuga/dbg_widgets.h
./src/xgui/debuga/dbg_rdump.h
./src/watcher.h
./src/xgui/options/setupwin.h
./src/xgui/options/padbinder.h
./src/xgui/options/opt_romset.h
./src/xgui/options/opt_diskcat.h
./src/xgui/options/opt_tapecat.h
./src/xgui/options/opt_hotkeytab.h
./src/vkeyboard.h
./src/xgui/xgui.h
./src/xgui/classes.h
./src/xgui/labelist.h
)
# Qt4 / Qt5 / Qt6
if (DEFINED QT4BUILD)
if (${QT4BUILD})
set(QTVERSION 4)
else(${QT4BUILD})
set(QTVERSION 5)
endif(${QT4BUILD})
elseif(NOT DEFINED QTVERSION)
set(QTVERSION 5)
endif()
if(${QTVERSION} EQUAL 4)
find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED)
include(${QT_USE_FILE})
qt4_add_resources(RESOURCES ${QRCFILES})
qt4_wrap_ui(UIHEADERS ${UIFILES})
qt4_wrap_cpp(MOCHEADERS ${MOCFILES})
set(CPACK_RPM_PACKAGE_REQUIRES "libqt4 >= 4.6, libqt4-x11 >= 4.6")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libqtcore4 (>=4.6), libqtgui4 (>=4.6)")
if(${USEQTNETWORK})
find_package(Qt4 COMPONENTS QtNetwork REQUIRED)
set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, libqt4-network >= 4.6")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libqt4-network (>=4.6)")
add_definitions("-DUSENETWORK")
endif()
if(${USEOPENGL})
find_package(Qt4 COMPONENTS QtOpenGL REQUIRED)
set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, libqt4-opengl >= 4.6")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libqt4-opengl (>=4.6)")
add_definitions("-DUSEOPENGL")
endif()
set(LIBRARIES ${LIBRARIES} ${QT_LIBRARIES})
set(QT_VER ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH})
elseif(${QTVERSION} EQUAL 5)
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
set(LIBRARIES ${LIBRARIES} Qt5::Widgets)
qt5_add_resources(RESOURCES ${QRCFILES})
qt5_wrap_ui(UIHEADERS ${UIFILES})
qt5_wrap_cpp(MOCHEADERS ${MOCFILES})
set(CPACK_RPM_PACKAGE_REQUIRES "libQt5Gui5 >= 5.3, libQt5Widgets5 >= 5.3")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libqt5gui5 (>=5.3), libqt5widgets5 (>=5.3)")
if(${USEQTNETWORK})
find_package(Qt5 COMPONENTS Network REQUIRED)
set(LIBRARIES ${LIBRARIES} Qt5::Network)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libqt5network5 (>=5.3)")
set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, libQt5Network5 >= 5.3")
add_definitions("-DUSENETWORK")
endif()
if (${USEOPENGL})
find_package(OpenGL REQUIRED)
find_package(Qt5 COMPONENTS OpenGL REQUIRED)
set(LIBRARIES ${LIBRARIES} Qt5::OpenGL ${OPENGL_LIBRARIES})
set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, libQt5OpenGL5 >= 5.3")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libqt5opengl5 (>=5.3)")
add_definitions("-DUSEOPENGL")
endif()
set(QT_VER ${Qt5Widgets_VERSION})
elseif(${QTVERSION} EQUAL 6)
# message(FATAL_ERROR "Qt6 usage is not implemented yet")
# Qt6 requires c++17 standart
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 COMPONENTS Core Gui Widgets Core5Compat REQUIRED)
set(LIBRARIES ${LIBRARIES} Qt6::Widgets Qt6::Core Qt6::Gui Qt6::Core5Compat)
qt6_add_resources(RESOURCES ${QRCFILES})
qt6_wrap_ui(UIHEADERS ${UIFILES})
qt6_wrap_cpp(MOCHEADERS ${MOCFILES})
set(CPACK_RPM_PACKAGE_REQUIRES "libQt6Gui6 >= 6.1, libQt6Widgets6 >= 6.1, libQt6Core5Compat6 >= 6.1")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libqt6gui6 (>=6.1), libqt6widgets6 (>=6.1), libqt6core5compat6 >= 6.1")
if(${USEQTNETWORK})
find_package(Qt6 COMPONENTS Network REQUIRED)
set(LIBRARIES ${LIBRARIES} Qt6::Network)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libqt6network6 (>=6.1)")
set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, libQt6Network6 >= 6.1")
add_definitions("-DUSENETWORK")
endif()
if (${USEOPENGL})
find_package(OpenGL REQUIRED)
find_package(Qt6 COMPONENTS OpenGLWidgets REQUIRED)
set(LIBRARIES ${LIBRARIES} Qt6::OpenGLWidgets ${OPENGL_LIBRARIES})
set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, libQt6OpenGL6 >= 6.1")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libqt6opengl6 (>=6.1)")
add_definitions("-DUSEOPENGL")
endif()
set(QT_VER ${Qt6Widgets_VERSION})
else()
message(FATAL_ERROR "Unknown Qt version defined")
endif()
# SDL
if(${SDL1BUILD})
find_package(SDL REQUIRED)
if(${SDL_FOUND})
add_definitions(-DHAVESDL1)
include_directories(${SDL_INCLUDE_DIR})
set(LIBRARIES ${LIBRARIES} ${SDL_LIBRARY})
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libSDL1.2debian (>=1.2)")
set(CPACK_RPM_PACKAGE_DEPENDS "${CPACK_RPM_PACKAGE_DEPENDS}, SDL >= 1.2")
set(SDL_VER ${SDL_VERSION_STRING})
set(SDL_NAME "SDL")
endif(${SDL_FOUND})
else(${SDL1BUILD})
find_package(SDL2 REQUIRED)
if (${SDL2_FOUND})
add_definitions(-DHAVESDL2)
include_directories(${SDL2_INCLUDE_DIR})
set(LIBRARIES ${LIBRARIES} ${SDL2_LIBRARY})
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libsdl2-2.0-0 (>=2.0) | libSDL2 (>=2.0)")
set(CPACK_RPM_PACKAGE_DEPENDS "${CPACK_RPM_PACKAGE_DEPENDS}, SDL2 >= 2.0")
set(SDL_VER "2.x")
set(SDL_NAME "SDL2")
message(STATUS "SDL2_INCLUDE_DIR = " ${SDL2_INCLUDE_DIR})
endif(${SDL2_FOUND})
endif(${SDL1BUILD})
# zlib (for rzx)
find_package(ZLIB)
if(ZLIB_FOUND)
add_definitions(-DHAVEZLIB)
set(INCLUDIRS ${INCLUDIRS} ${ZLIB_INCLUDE_DIR})
set(LIBRARIES ${LIBRARIES} ${ZLIB_LIBRARY})
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, zlib1g (>=1.2)")
set(CPACK_RPM_PACKAGE_DEPENDS "${CPACK_RPM_PACKAGE_DEPENDS}, zlib >= 1.2")
endif(ZLIB_FOUND)
# flags
if(${IBM})
add_definitions(-DUSEIBM=1)
endif()
# other
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${UIHEADERS} ${RESOURCES} ${MOCHEADERS})
elseif(${CMAKE_SYSTEM_NAME} MATCHES "/BSD$/")
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${UIHEADERS} ${RESOURCES} ${MOCHEADERS})
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
add_executable(${PROJECT_NAME} MACOSX_BUNDLE ${SOURCES} ${HEADERS} ${UIHEADERS} ${RESOURCES} ${MOCHEADERS} ${BUNDLE_ICON_PATH})
find_program(MACDEPLOYQTEXE macdeployqt)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${MACDEPLOYQTEXE} ARGS ${BUNDLE_PATH} -always-overwrite
COMMAND mkdir ARGS -p ${BUNDLE_PATH}/Contents/Frameworks
COMMAND cp ARGS -R -X /Library/Frameworks/${SDL_NAME}.framework ${BUNDLE_PATH}/Contents/Frameworks
COMMAND install_name_tool -change @rpath/${SDL_NAME}.framework/Versions/A/${SDL_NAME} @executable_path/../Frameworks/${SDL_NAME}.framework/Versions/A/${SDL_NAME} ${BUNDLE_PATH}/Contents/MacOS/xpeccy
)
set(CMAKE_INSTALL_PREFIX "/Applications")
install(TARGETS ${PROJECT_NAME} BUNDLE DESTINATION .)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
add_executable(${PROJECT_NAME} WIN32 ${SOURCES} ${HEADERS} ${UIHEADERS} ${RESOURCES} ${MOCHEADERS} ${CMAKE_SOURCE_DIR}/xpeccy.rc)
endif()
include_directories(${INCLUDIRS})
target_link_libraries(${PROJECT_NAME} ${LIBRARIES})
include(${CMAKE_ROOT}/Modules/CPack.cmake)
# install
# print messages
message(STATUS "\n")
message(STATUS "Project will be compiled with following options:\n")
message(STATUS "Build type : ${CMAKE_BUILD_TYPE}")
message(STATUS "Xpeccy version : ${XVER}")
message(STATUS "OS : ${CMAKE_SYSTEM_NAME}")
message(STATUS "Qt version : ${QT_VER}")
message(STATUS "SDL version : ${SDL_VER}")
if (${USEQTNETWORK})
message(STATUS "Network: yes")
else()
message(STATUS "Network: no")
endif()
if (${USEOPENGL})
message(STATUS "OpenGL: yes")
else()
message(STATUS "OpenGL: no")
endif()
if (BIG_ENDIAN)
message(STATUS "Endianness: BE")
else ()
message(STATUS "Endianness: LE")
endif()
message(STATUS "\n")