src/platform/qt/CMakeLists.txt (view raw)
1set(CMAKE_CXX_STANDARD 14)
2set(CMAKE_CXX_STANDARD_REQUIRED ON)
3set(CMAKE_CXX_EXTENSIONS OFF)
4
5set(PLATFORM_SRC)
6set(QT_STATIC OFF)
7
8if(BUILD_SDL)
9 add_definitions(-DBUILD_SDL)
10 if(SDL2_FOUND)
11 link_directories(${SDL2_LIBDIR})
12 endif()
13 list(APPEND PLATFORM_LIBRARY ${SDL_LIBRARY})
14 list(APPEND PLATFORM_SRC ${PLATFORM_SRC} ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-events.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-audio.c)
15 include_directories(${SDL_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src/platform/sdl)
16endif()
17
18if(POLICY CMP0071)
19 cmake_policy(SET CMP0071 OLD)
20endif()
21
22set(CMAKE_AUTOMOC ON)
23set(CMAKE_INCLUDE_CURRENT_DIR ON)
24
25find_package(Qt5Multimedia)
26find_package(Qt5OpenGL)
27find_package(Qt5Widgets)
28
29if(NOT BUILD_GL AND NOT BUILD_GLES2)
30 message(WARNING "OpenGL is recommended to build the Qt port")
31endif()
32
33set(FOUND_QT ${Qt5Widgets_FOUND} PARENT_SCOPE)
34if(NOT Qt5Widgets_FOUND)
35 message(WARNING "Cannot find Qt modules")
36 return()
37endif()
38
39if(APPLE)
40 if(Qt5Widgets_VERSION MATCHES "^5.1[0-9]")
41 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.8")
42 else()
43 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.7")
44 endif()
45 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
46 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
47 endif()
48endif()
49
50if(BUILD_GL)
51 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gl.c)
52 if(NOT WIN32 OR USE_EPOXY)
53 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
54 endif()
55endif()
56
57if(BUILD_GLES2)
58 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
59endif()
60
61get_target_property(QT_TYPE Qt5::Core TYPE)
62if(QT_TYPE STREQUAL STATIC_LIBRARY)
63 set(QT_STATIC ON)
64 list(APPEND QT_DEFINES QT_STATIC)
65endif()
66
67set(SOURCE_FILES
68 AboutScreen.cpp
69 AbstractUpdater.cpp
70 Action.cpp
71 ActionMapper.cpp
72 AssetTile.cpp
73 AssetView.cpp
74 AudioProcessor.cpp
75 CheatsModel.cpp
76 CheatsView.cpp
77 ConfigController.cpp
78 ColorPicker.cpp
79 CoreManager.cpp
80 CoreController.cpp
81 Display.cpp
82 DisplayGL.cpp
83 DisplayQt.cpp
84 GBAApp.cpp
85 GBAKeyEditor.cpp
86 GIFView.cpp
87 GamepadAxisEvent.cpp
88 GamepadButtonEvent.cpp
89 GamepadHatEvent.cpp
90 IOViewer.cpp
91 InputController.cpp
92 InputProfile.cpp
93 KeyEditor.cpp
94 LoadSaveState.cpp
95 LogController.cpp
96 LogConfigModel.cpp
97 LogView.cpp
98 MapView.cpp
99 MemoryModel.cpp
100 MemorySearch.cpp
101 MemoryView.cpp
102 MessagePainter.cpp
103 MultiplayerController.cpp
104 ObjView.cpp
105 OverrideView.cpp
106 PaletteView.cpp
107 PlacementControl.cpp
108 RegisterView.cpp
109 ROMInfo.cpp
110 RotatedHeaderView.cpp
111 SavestateButton.cpp
112 SensorView.cpp
113 SettingsView.cpp
114 ShaderSelector.cpp
115 ShortcutController.cpp
116 ShortcutModel.cpp
117 ShortcutView.cpp
118 Swatch.cpp
119 TilePainter.cpp
120 TileView.cpp
121 utils.cpp
122 Window.cpp
123 VFileDevice.cpp
124 VideoView.cpp)
125
126set(UI_FILES
127 AboutScreen.ui
128 ArchiveInspector.ui
129 AssetTile.ui
130 BattleChipView.ui
131 CheatsView.ui
132 DebuggerConsole.ui
133 GIFView.ui
134 IOViewer.ui
135 LoadSaveState.ui
136 LogView.ui
137 MapView.ui
138 MemorySearch.ui
139 MemoryView.ui
140 ObjView.ui
141 OverrideView.ui
142 PaletteView.ui
143 PlacementControl.ui
144 PrinterView.ui
145 ROMInfo.ui
146 SensorView.ui
147 SettingsView.ui
148 ShaderSelector.ui
149 ShortcutView.ui
150 TileView.ui
151 VideoView.ui)
152
153set(GBA_SRC
154 BattleChipModel.cpp
155 BattleChipUpdater.cpp
156 BattleChipView.cpp
157 GBAOverride.cpp)
158
159set(GB_SRC
160 GBOverride.cpp
161 PrinterView.cpp)
162
163set(QT_LIBRARIES)
164set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5")
165
166set(AUDIO_SRC)
167if(BUILD_SDL)
168 list(APPEND AUDIO_SRC AudioProcessorSDL.cpp)
169endif()
170
171if(M_CORE_GBA)
172 list(APPEND PLATFORM_SRC ${GBA_SRC})
173endif()
174
175if(M_CORE_GB)
176 list(APPEND PLATFORM_SRC ${GB_SRC})
177endif()
178
179set(QT_DEFINES)
180if(Qt5Multimedia_FOUND)
181 list(APPEND AUDIO_SRC
182 AudioProcessorQt.cpp
183 AudioDevice.cpp)
184 list(APPEND SOURCE_FILES
185 VideoDumper.cpp)
186 if (WIN32 AND QT_STATIC)
187 list(APPEND QT_LIBRARIES Qt5::QWindowsAudioPlugin Qt5::DSServicePlugin Qt5::QWindowsVistaStylePlugin
188 strmiids mfuuid mfplat mf ksguid dxva2 evr d3d9)
189 endif()
190 list(APPEND QT_LIBRARIES Qt5::Multimedia)
191 list(APPEND QT_DEFINES BUILD_QT_MULTIMEDIA)
192 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
193endif()
194
195if(NOT AUDIO_SRC)
196 message(WARNING "No supported audio modules found")
197 set(BUILD_QT OFF PARENT_SCOPE)
198 return()
199endif()
200
201if(USE_DEBUGGERS)
202 list(APPEND SOURCE_FILES
203 DebuggerController.cpp
204 DebuggerConsole.cpp
205 DebuggerConsoleController.cpp)
206endif()
207
208if(USE_GDB_STUB)
209 list(APPEND SOURCE_FILES GDBController.cpp GDBWindow.cpp)
210endif()
211
212if(USE_SQLITE3)
213 list(APPEND SOURCE_FILES
214 ArchiveInspector.cpp
215 library/LibraryController.cpp
216 library/LibraryGrid.cpp
217 library/LibraryTree.cpp)
218endif()
219
220if(USE_DISCORD_RPC)
221 list(APPEND QT_LIBRARIES discord-rpc)
222 list(APPEND SOURCE_FILES DiscordCoordinator.cpp)
223endif()
224
225qt5_add_resources(RESOURCES resources.qrc)
226if(APPLE)
227 set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
228 set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
229 set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
230 set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
231 set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
232endif()
233if(WIN32)
234 configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
235 list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
236 set_source_files_properties(${CMAKE_BINARY_DIR}/res/mgba.rc PROPERTIES OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/res/mgba.ico)
237endif()
238if(NOT DEFINED DATADIR)
239 if(APPLE)
240 set(DATADIR Applications/${PROJECT_NAME}.app/Contents/Resources)
241 elseif(WIN32 AND NOT WIN32_UNIX_PATHS)
242 set(DATADIR ".")
243 else()
244 set(DATADIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME})
245 endif()
246endif()
247if(BUILD_GL OR BUILD_GLES2)
248 install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
249endif()
250install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
251if(NOT WIN32 AND NOT APPLE)
252 list(APPEND QT_DEFINES DATADIR="${CMAKE_INSTALL_PREFIX}/${DATADIR}")
253endif()
254
255find_package(Qt5LinguistTools)
256if(Qt5LinguistTools_FOUND)
257 set(TRANSLATION_FILES)
258 set(TRANSLATION_QRC "${CMAKE_CURRENT_BINARY_DIR}/ts.qrc")
259 file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ts/${BINARY_NAME}-*.ts")
260 if(UPDATE_TRANSLATIONS)
261 qt5_create_translation(TRANSLATION_FILES ${SOURCE_FILES} ${UI_FILES} ${TS_FILES} OPTIONS -locations absolute -no-obsolete)
262 else()
263 qt5_add_translation(TRANSLATION_FILES ${TS_FILES})
264 endif()
265 set(QT_QM_FILES)
266 if(QT_STATIC)
267 get_target_property(QT_CORE_LOCATION Qt5::Core LOCATION)
268 get_filename_component(QT_CORE_LOCATION ${QT_CORE_LOCATION} DIRECTORY)
269 get_filename_component(QT_QM_LOCATION "${QT_CORE_LOCATION}/../translations" ABSOLUTE)
270 foreach(TS ${TS_FILES})
271 get_filename_component(TS ${TS} NAME)
272 string(REGEX REPLACE "${BINARY_NAME}-(.*).ts$" "qtbase_\\1.qm" QT_QM "${TS}")
273 set(QT_QM "${QT_QM_LOCATION}/${QT_QM}")
274 if(EXISTS "${QT_QM}")
275 list(APPEND QT_QM_FILES "${QT_QM}")
276 endif()
277 endforeach()
278 list(APPEND TRANSLATION_FILES ${QT_QM_FILES})
279 endif()
280 add_custom_command(OUTPUT ${TRANSLATION_QRC}
281 COMMAND ${CMAKE_COMMAND} -DTRANSLATION_QRC:FILEPATH="${TRANSLATION_QRC}" -DQM_BASE="${CMAKE_CURRENT_BINARY_DIR}" "-DTRANSLATION_FILES='${TRANSLATION_FILES}'" -P "${CMAKE_CURRENT_SOURCE_DIR}/ts.cmake"
282 DEPENDS ${TRANSLATION_FILES})
283 qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
284 list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
285endif()
286
287qt5_wrap_ui(UI_SRC ${UI_FILES})
288
289add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_SRC} ${AUDIO_SRC} ${RESOURCES})
290set_target_properties(${BINARY_NAME}-qt PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/res/info.plist.in COMPILE_DEFINITIONS "${FEATURE_DEFINES};${FUNCTION_DEFINES};${OS_DEFINES};${QT_DEFINES}" COMPILE_OPTIONS "${FEATURE_FLAGS}")
291
292list(APPEND QT_LIBRARIES Qt5::Widgets)
293if(BUILD_GL OR BUILD_GLES2)
294 list(APPEND QT_LIBRARIES Qt5::OpenGL ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
295endif()
296if(QT_STATIC)
297 find_library(QTPCRE NAMES qtpcre2 qtpcre)
298 if(WIN32)
299 list(APPEND QT_LIBRARIES qwindows dwmapi imm32 uxtheme Qt5EventDispatcherSupport Qt5FontDatabaseSupport Qt5ThemeSupport Qt5WindowsUIAutomationSupport)
300 set_target_properties(Qt5::Core PROPERTIES INTERFACE_LINK_LIBRARIES "${QTPCRE};version;winmm;ssl;crypto;ws2_32;iphlpapi;crypt32;userenv;netapi32;wtsapi32")
301 elseif(APPLE)
302 find_package(Cups)
303 find_package(Qt5PrintSupport)
304 find_library(QTFREETYPE NAMES qtfreetype)
305 find_library(QTHARFBUZZ NAMES qtharfbuzzng qtharfbuzz)
306 find_library(QTPLATFORMSUPPORT NAMES Qt5PlatformSupport)
307 list(APPEND QT_LIBRARIES Cups Qt5::PrintSupport Qt5::QCocoaIntegrationPlugin Qt5::CoreAudioPlugin Qt5::AVFServicePlugin Qt5::QCocoaPrinterSupportPlugin ${QTPLATFORMSUPPORT} "-framework AVFoundation" "-framework CoreMedia" "-framework SystemConfiguration" "-framework Security")
308 set_target_properties(Qt5::Core PROPERTIES INTERFACE_LINK_LIBRARIES "${QTPCRE};${QTHARFBUZZ};${QTFREETYPE}")
309 link_directories()
310 endif()
311endif()
312target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES})
313set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
314
315install(TARGETS ${BINARY_NAME}-qt
316 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-qt
317 BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
318if(UNIX AND NOT APPLE)
319 find_program(DESKTOP_FILE_INSTALL desktop-file-install)
320 if(DESKTOP_FILE_INSTALL)
321 install(CODE "execute_process(COMMAND ${DESKTOP_FILE_INSTALL} \"${CMAKE_SOURCE_DIR}/res/mgba-qt.desktop\" --dir \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/applications/\")" COMPONENT ${BINARY_NAME}-qt)
322 endif()
323endif()
324if(UNIX)
325 install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
326endif()
327if(APPLE OR WIN32)
328 set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
329endif()
330if(APPLE)
331 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
332 get_target_property(QTCOCOA Qt5::QCocoaIntegrationPlugin LOCATION)
333 get_target_property(COREAUDIO Qt5::CoreAudioPlugin LOCATION)
334 get_target_property(QTAVFSERVICE Qt5::AVFServicePlugin LOCATION)
335 set(BUNDLE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.app)
336 target_sources(${BINARY_NAME}-qt PRIVATE "${PLUGINS}")
337 set_source_files_properties("${QTCOCOA}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
338 set_source_files_properties("${COREAUDIO}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
339 set_source_files_properties("${QTAVFSERVICE}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
340 install(CODE "
341 include(BundleUtilities)
342 set(BU_CHMOD_BUNDLE_ITEMS ON)
343 file(GLOB_RECURSE PLUGINS \"${BUNDLE_PATH}/Contents/PlugIns/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
344 fixup_bundle(\"${BUNDLE_PATH}\" \"${PLUGINS}\" \"\")
345 " COMPONENT ${BINARY_NAME}-qt)
346 else()
347 set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib,mediaservice/libqavfcamera.dylib)
348 if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
349 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I "${CMAKE_INSTALL_NAME_TOOL}")
350 endif()
351 if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
352 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O "${CMAKE_OTOOL}")
353 endif()
354 if(DEFINED CROSS_ROOT)
355 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R "${CROSS_ROOT}")
356 endif()
357 install(CODE "execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/tools/deploy-mac.py\" -v ${DEPLOY_OPTIONS} \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/Applications/${PROJECT_NAME}.app\")")
358 endif()
359elseif(WIN32)
360 if(CMAKE_MAJOR_VERSION EQUAL 3 AND CMAKE_MINOR_VERSION EQUAL 8)
361 # Work around CMake issue #16907
362 set_target_properties(${BINARY_NAME}-qt PROPERTIES AUTORCC ON SKIP_AUTORCC ON)
363 endif()
364 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
365 find_program(BASH bash)
366 install(CODE "execute_process(COMMAND \"${BASH}\" \"${CMAKE_SOURCE_DIR}/tools/deploy-win.sh\" \"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.exe\" \"\${CMAKE_INSTALL_PREFIX}\" \"\$ENV{PWD}\" WORKING_DIRECTORY \"${CMAKE_BINARY_DIR}\")" COMPONENT ${BINARY_NAME}-qt)
367 endif()
368 if(DISTBUILD)
369 file(WRITE "${CMAKE_BINARY_DIR}/portable.ini" "")
370 install(FILES "${CMAKE_BINARY_DIR}/portable.ini" DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${BINARY_NAME}-qt)
371 endif()
372endif()
373
374if(DISTBUILD AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
375 if(NOT APPLE)
376 add_custom_command(TARGET ${BINARY_NAME}-qt POST_BUILD COMMAND "${OBJCOPY}" --only-keep-debug "$<TARGET_FILE:${BINARY_NAME}-qt>" "$<TARGET_FILE:${BINARY_NAME}-qt>.dSYM")
377 add_custom_command(TARGET ${BINARY_NAME}-qt POST_BUILD COMMAND "${STRIP}" -S "$<TARGET_FILE:${BINARY_NAME}-qt>")
378 install(FILES "$<TARGET_FILE:${BINARY_NAME}-qt>.dSYM" DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-qt-dbg)
379 endif()
380endif()