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