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