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