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 ROMInfo.cpp
104 RotatedHeaderView.cpp
105 SavestateButton.cpp
106 SensorView.cpp
107 SettingsView.cpp
108 ShaderSelector.cpp
109 ShortcutController.cpp
110 ShortcutModel.cpp
111 ShortcutView.cpp
112 Swatch.cpp
113 TilePainter.cpp
114 TileView.cpp
115 utils.cpp
116 Window.cpp
117 VFileDevice.cpp
118 VideoProxy.cpp
119 VideoView.cpp)
120
121set(UI_FILES
122 AboutScreen.ui
123 ArchiveInspector.ui
124 AssetTile.ui
125 BattleChipView.ui
126 CheatsView.ui
127 DebuggerConsole.ui
128 FrameView.ui
129 GIFView.ui
130 IOViewer.ui
131 LoadSaveState.ui
132 LogView.ui
133 MapView.ui
134 MemoryDump.ui
135 MemorySearch.ui
136 MemoryView.ui
137 ObjView.ui
138 OverrideView.ui
139 PaletteView.ui
140 PlacementControl.ui
141 PrinterView.ui
142 ROMInfo.ui
143 SensorView.ui
144 SettingsView.ui
145 ShaderSelector.ui
146 ShortcutView.ui
147 TileView.ui
148 VideoView.ui)
149
150set(GBA_SRC
151 BattleChipModel.cpp
152 BattleChipUpdater.cpp
153 BattleChipView.cpp
154 GBAOverride.cpp)
155
156set(GB_SRC
157 GameBoy.cpp
158 GBOverride.cpp
159 PrinterView.cpp)
160
161set(QT_LIBRARIES)
162set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5")
163
164set(AUDIO_SRC)
165if(BUILD_SDL)
166 list(APPEND AUDIO_SRC AudioProcessorSDL.cpp)
167endif()
168
169if(M_CORE_GBA)
170 list(APPEND PLATFORM_SRC ${GBA_SRC})
171endif()
172
173if(M_CORE_GB)
174 list(APPEND PLATFORM_SRC ${GB_SRC})
175endif()
176
177set(QT_DEFINES)
178if(Qt5Multimedia_FOUND)
179 list(APPEND AUDIO_SRC
180 AudioProcessorQt.cpp
181 AudioDevice.cpp)
182 list(APPEND SOURCE_FILES
183 VideoDumper.cpp)
184 if (WIN32 AND QT_STATIC)
185 list(APPEND QT_LIBRARIES Qt5::QWindowsAudioPlugin Qt5::DSServicePlugin Qt5::QWindowsVistaStylePlugin
186 strmiids mfuuid mfplat mf ksguid dxva2 evr d3d9)
187 endif()
188 list(APPEND QT_LIBRARIES Qt5::Multimedia)
189 list(APPEND QT_DEFINES BUILD_QT_MULTIMEDIA)
190 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
191endif()
192
193if(NOT AUDIO_SRC)
194 message(WARNING "No supported audio modules found")
195 set(BUILD_QT OFF PARENT_SCOPE)
196 return()
197endif()
198
199if(USE_DEBUGGERS)
200 list(APPEND SOURCE_FILES
201 DebuggerController.cpp
202 DebuggerConsole.cpp
203 DebuggerConsoleController.cpp)
204endif()
205
206if(USE_GDB_STUB)
207 list(APPEND SOURCE_FILES GDBController.cpp GDBWindow.cpp)
208endif()
209
210if(USE_SQLITE3)
211 list(APPEND SOURCE_FILES
212 ArchiveInspector.cpp
213 library/LibraryController.cpp
214 library/LibraryGrid.cpp
215 library/LibraryTree.cpp)
216endif()
217
218if(USE_DISCORD_RPC)
219 list(APPEND QT_LIBRARIES discord-rpc)
220 list(APPEND SOURCE_FILES DiscordCoordinator.cpp)
221endif()
222
223qt5_add_resources(RESOURCES resources.qrc)
224if(APPLE)
225 set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
226 set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
227 set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
228 set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
229 set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
230endif()
231if(WIN32)
232 configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
233 list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
234 set_source_files_properties(${CMAKE_BINARY_DIR}/res/mgba.rc PROPERTIES OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/res/mgba.ico)
235endif()
236if(NOT DEFINED DATADIR)
237 if(APPLE)
238 set(DATADIR Applications/${PROJECT_NAME}.app/Contents/Resources)
239 elseif(WIN32 AND NOT WIN32_UNIX_PATHS)
240 set(DATADIR ".")
241 else()
242 set(DATADIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME})
243 endif()
244endif()
245if(BUILD_GL OR BUILD_GLES2 OR BUILD_EPOXY)
246 install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
247endif()
248install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
249if(NOT WIN32 AND NOT APPLE)
250 list(APPEND QT_DEFINES DATADIR="${CMAKE_INSTALL_PREFIX}/${DATADIR}")
251endif()
252
253find_package(Qt5LinguistTools)
254if(Qt5LinguistTools_FOUND)
255 set(TRANSLATION_FILES)
256 set(TRANSLATION_QRC "${CMAKE_CURRENT_BINARY_DIR}/ts.qrc")
257 file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ts/${BINARY_NAME}-*.ts")
258 if(UPDATE_TRANSLATIONS)
259 qt5_create_translation(TRANSLATION_FILES ${SOURCE_FILES} ${UI_FILES} ${TS_FILES} OPTIONS -locations absolute -no-obsolete)
260 else()
261 qt5_add_translation(TRANSLATION_FILES ${TS_FILES})
262 endif()
263 set(QT_QM_FILES)
264 if(QT_STATIC)
265 get_target_property(QT_CORE_LOCATION Qt5::Core LOCATION)
266 get_filename_component(QT_CORE_LOCATION ${QT_CORE_LOCATION} DIRECTORY)
267 get_filename_component(QT_QM_LOCATION "${QT_CORE_LOCATION}/../translations" ABSOLUTE)
268 foreach(TS ${TS_FILES})
269 get_filename_component(TS ${TS} NAME)
270 string(REGEX REPLACE "${BINARY_NAME}-(.*).ts$" "qtbase_\\1.qm" QT_QM "${TS}")
271 set(QT_QM "${QT_QM_LOCATION}/${QT_QM}")
272 if(EXISTS "${QT_QM}")
273 list(APPEND QT_QM_FILES "${QT_QM}")
274 endif()
275 endforeach()
276 list(APPEND TRANSLATION_FILES ${QT_QM_FILES})
277 endif()
278 add_custom_command(OUTPUT ${TRANSLATION_QRC}
279 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"
280 DEPENDS ${TRANSLATION_FILES})
281 qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
282 list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
283endif()
284
285qt5_wrap_ui(UI_SRC ${UI_FILES})
286
287add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_SRC} ${AUDIO_SRC} ${RESOURCES})
288set_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}")
289
290if(WIN32)
291 set_target_properties(${BINARY_NAME}-qt PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
292endif()
293
294list(APPEND QT_LIBRARIES Qt5::Widgets Qt5::Network)
295if(BUILD_GL OR BUILD_GLES2 OR BUILD_EPOXY)
296 list(APPEND QT_LIBRARIES Qt5::OpenGL ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
297endif()
298if(QT_STATIC)
299 find_library(QTPCRE NAMES qtpcre2 qtpcre)
300 if(WIN32)
301 if(CMAKE_CROSSCOMPILING)
302 set(QWINDOWS_DEPS Qt5EventDispatcherSupport Qt5FontDatabaseSupport Qt5ThemeSupport Qt5WindowsUIAutomationSupport)
303 endif()
304 list(APPEND QT_LIBRARIES Qt5::QWindowsIntegrationPlugin ${QWINDOWS_DEPS} amstrmid dwmapi uxtheme imm32 -static-libgcc -static-libstdc++)
305 set_target_properties(Qt5::Core PROPERTIES INTERFACE_LINK_LIBRARIES "${QTPCRE};version;winmm;ssl;crypto;ws2_32;iphlpapi;crypt32;userenv;netapi32;wtsapi32")
306 set_target_properties(Qt5::Gui PROPERTIES INTERFACE_LINK_LIBRARIES ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
307 elseif(APPLE)
308 find_package(Cups)
309 find_package(Qt5PrintSupport)
310 find_library(QTFREETYPE NAMES qtfreetype)
311 find_library(QTHARFBUZZ NAMES qtharfbuzzng qtharfbuzz)
312 find_library(QTPLATFORMSUPPORT NAMES Qt5PlatformSupport)
313 list(APPEND QT_LIBRARIES Cups Qt5::PrintSupport Qt5::QCocoaIntegrationPlugin Qt5::CoreAudioPlugin Qt5::AVFServicePlugin Qt5::QCocoaPrinterSupportPlugin ${QTPLATFORMSUPPORT} "-framework AVFoundation" "-framework CoreMedia" "-framework SystemConfiguration" "-framework Security")
314 set_target_properties(Qt5::Core PROPERTIES INTERFACE_LINK_LIBRARIES "${QTPCRE};${QTHARFBUZZ};${QTFREETYPE}")
315 link_directories()
316 endif()
317endif()
318target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES})
319set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
320
321install(TARGETS ${BINARY_NAME}-qt
322 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-qt
323 BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
324if(UNIX AND NOT APPLE)
325 find_program(DESKTOP_FILE_INSTALL desktop-file-install)
326 if(DESKTOP_FILE_INSTALL)
327 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)
328 endif()
329endif()
330if(UNIX)
331 install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
332endif()
333if(APPLE OR WIN32)
334 set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
335endif()
336if(APPLE)
337 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
338 get_target_property(QTCOCOA Qt5::QCocoaIntegrationPlugin LOCATION)
339 get_target_property(COREAUDIO Qt5::CoreAudioPlugin LOCATION)
340 get_target_property(QTAVFSERVICE Qt5::AVFServicePlugin LOCATION)
341 set(BUNDLE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.app)
342 target_sources(${BINARY_NAME}-qt PRIVATE "${PLUGINS}")
343 set_source_files_properties("${QTCOCOA}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
344 set_source_files_properties("${COREAUDIO}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
345 set_source_files_properties("${QTAVFSERVICE}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
346 install(CODE "
347 include(BundleUtilities)
348 set(BU_CHMOD_BUNDLE_ITEMS ON)
349 file(GLOB_RECURSE PLUGINS \"${BUNDLE_PATH}/Contents/PlugIns/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
350 fixup_bundle(\"${BUNDLE_PATH}\" \"${PLUGINS}\" \"\")
351 " COMPONENT ${BINARY_NAME}-qt)
352 else()
353 set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib,mediaservice/libqavfcamera.dylib)
354 if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
355 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I "${CMAKE_INSTALL_NAME_TOOL}")
356 endif()
357 if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
358 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O "${CMAKE_OTOOL}")
359 endif()
360 if(DEFINED CROSS_ROOT)
361 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R "${CROSS_ROOT}")
362 endif()
363 install(CODE "execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/tools/deploy-mac.py\" -v ${DEPLOY_OPTIONS} \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/Applications/${PROJECT_NAME}.app\")")
364 endif()
365elseif(WIN32)
366 if(CMAKE_MAJOR_VERSION EQUAL 3 AND CMAKE_MINOR_VERSION EQUAL 8)
367 # Work around CMake issue #16907
368 set_target_properties(${BINARY_NAME}-qt PROPERTIES AUTORCC ON SKIP_AUTORCC ON)
369 endif()
370 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
371 find_program(BASH bash)
372 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)
373 endif()
374 if(DISTBUILD)
375 file(WRITE "${CMAKE_BINARY_DIR}/portable.ini" "")
376 install(FILES "${CMAKE_BINARY_DIR}/portable.ini" DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${BINARY_NAME}-qt)
377 endif()
378endif()
379
380if(DISTBUILD AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
381 if(NOT APPLE)
382 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")
383 add_custom_command(TARGET ${BINARY_NAME}-qt POST_BUILD COMMAND "${STRIP}" "$<TARGET_FILE:${BINARY_NAME}-qt>")
384 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>")
385 install(FILES "$<TARGET_FILE:${BINARY_NAME}-qt>.debug" DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-qt-dbg)
386 endif()
387endif()