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