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
50if(BUILD_GL)
51 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gl.c)
52 if(NOT WIN32 OR USE_EPOXY)
53 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
54 endif()
55endif()
56
57if(BUILD_GLES2)
58 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
59endif()
60
61get_target_property(QT_TYPE Qt5::Core TYPE)
62if(QT_TYPE STREQUAL STATIC_LIBRARY)
63 set(QT_STATIC ON)
64 list(APPEND QT_DEFINES QT_STATIC)
65endif()
66
67set(SOURCE_FILES
68 AboutScreen.cpp
69 AbstractUpdater.cpp
70 AssetTile.cpp
71 AssetView.cpp
72 AudioProcessor.cpp
73 CheatsModel.cpp
74 CheatsView.cpp
75 ConfigController.cpp
76 ColorPicker.cpp
77 CoreManager.cpp
78 CoreController.cpp
79 Display.cpp
80 DisplayGL.cpp
81 DisplayQt.cpp
82 GBAApp.cpp
83 GBAKeyEditor.cpp
84 GIFView.cpp
85 GamepadAxisEvent.cpp
86 GamepadButtonEvent.cpp
87 GamepadHatEvent.cpp
88 IOViewer.cpp
89 InputController.cpp
90 InputProfile.cpp
91 KeyEditor.cpp
92 LoadSaveState.cpp
93 LogController.cpp
94 LogConfigModel.cpp
95 LogView.cpp
96 MapView.cpp
97 MemoryModel.cpp
98 MemorySearch.cpp
99 MemoryView.cpp
100 MessagePainter.cpp
101 MultiplayerController.cpp
102 ObjView.cpp
103 OverrideView.cpp
104 PaletteView.cpp
105 PlacementControl.cpp
106 RegisterView.cpp
107 ROMInfo.cpp
108 RotatedHeaderView.cpp
109 SavestateButton.cpp
110 SensorView.cpp
111 SettingsView.cpp
112 ShaderSelector.cpp
113 ShortcutController.cpp
114 ShortcutView.cpp
115 Swatch.cpp
116 TilePainter.cpp
117 TileView.cpp
118 utils.cpp
119 Window.cpp
120 VFileDevice.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 GIFView.ui
131 IOViewer.ui
132 LoadSaveState.ui
133 LogView.ui
134 MapView.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 GBOverride.cpp
158 PrinterView.cpp)
159
160set(QT_LIBRARIES)
161set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5")
162
163set(AUDIO_SRC)
164if(BUILD_SDL)
165 list(APPEND AUDIO_SRC AudioProcessorSDL.cpp)
166endif()
167
168if(M_CORE_GBA)
169 list(APPEND PLATFORM_SRC ${GBA_SRC})
170endif()
171
172if(M_CORE_GB)
173 list(APPEND PLATFORM_SRC ${GB_SRC})
174endif()
175
176set(QT_DEFINES)
177if(Qt5Multimedia_FOUND)
178 list(APPEND AUDIO_SRC
179 AudioProcessorQt.cpp
180 AudioDevice.cpp)
181 list(APPEND SOURCE_FILES
182 VideoDumper.cpp)
183 if (WIN32 AND QT_STATIC)
184 list(APPEND QT_LIBRARIES Qt5::QWindowsAudioPlugin Qt5::DSServicePlugin Qt5::QWindowsVistaStylePlugin
185 strmiids mfuuid mfplat mf ksguid dxva2 evr d3d9)
186 endif()
187 list(APPEND QT_LIBRARIES Qt5::Multimedia)
188 list(APPEND QT_DEFINES BUILD_QT_MULTIMEDIA)
189 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
190endif()
191
192if(NOT AUDIO_SRC)
193 message(WARNING "No supported audio modules found")
194 set(BUILD_QT OFF PARENT_SCOPE)
195 return()
196endif()
197
198if(USE_DEBUGGERS)
199 list(APPEND SOURCE_FILES
200 DebuggerController.cpp
201 DebuggerConsole.cpp
202 DebuggerConsoleController.cpp)
203endif()
204
205if(USE_GDB_STUB)
206 list(APPEND SOURCE_FILES GDBController.cpp GDBWindow.cpp)
207endif()
208
209if(USE_SQLITE3)
210 list(APPEND SOURCE_FILES
211 ArchiveInspector.cpp
212 library/LibraryController.cpp
213 library/LibraryGrid.cpp
214 library/LibraryTree.cpp)
215endif()
216
217if(USE_DISCORD_RPC)
218 message(STATUS What)
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)
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 list(APPEND QT_QM_FILES "${QT_QM_LOCATION}/${QT_QM}")
272 endforeach()
273 list(APPEND TRANSLATION_FILES ${QT_QM_FILES})
274 endif()
275 add_custom_command(OUTPUT ${TRANSLATION_QRC}
276 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"
277 DEPENDS ${TRANSLATION_FILES})
278 qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
279 list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
280endif()
281
282qt5_wrap_ui(UI_SRC ${UI_FILES})
283
284add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_SRC} ${AUDIO_SRC} ${RESOURCES})
285set_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}")
286
287list(APPEND QT_LIBRARIES Qt5::Widgets)
288if(BUILD_GL OR BUILD_GLES2)
289 list(APPEND QT_LIBRARIES Qt5::OpenGL ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
290endif()
291if(QT_STATIC)
292 find_library(QTPCRE NAMES qtpcre2 qtpcre)
293 if(WIN32)
294 list(APPEND QT_LIBRARIES qwindows dwmapi imm32 uxtheme Qt5EventDispatcherSupport Qt5FontDatabaseSupport Qt5ThemeSupport Qt5WindowsUIAutomationSupport)
295 set_target_properties(Qt5::Core PROPERTIES INTERFACE_LINK_LIBRARIES "${QTPCRE};version;winmm;ssl;crypto;ws2_32;iphlpapi;crypt32;userenv;netapi32;wtsapi32")
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()