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 if(NOT SDL_FOUND AND NOT SDL2_FOUND)
10 find_package(SDL 1.2 REQUIRED)
11 endif()
12 if(SDL2_FOUND)
13 link_directories(${SDL2_LIBDIR})
14 endif()
15 list(APPEND PLATFORM_LIBRARY ${SDL_LIBRARY})
16 list(APPEND PLATFORM_SRC ${PLATFORM_SRC} ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-events.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-audio.c)
17 include_directories(${SDL_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src/platform/sdl)
18endif()
19
20if(POLICY CMP0071)
21 cmake_policy(SET CMP0071 OLD)
22endif()
23
24set(CMAKE_AUTOMOC ON)
25set(CMAKE_INCLUDE_CURRENT_DIR ON)
26
27find_package(Qt5Multimedia)
28find_package(Qt5OpenGL)
29find_package(Qt5Widgets)
30
31if(NOT BUILD_GL AND NOT BUILD_GLES2)
32 message(WARNING "OpenGL is recommended to build the Qt port")
33endif()
34
35if(NOT Qt5Widgets_FOUND)
36 message(WARNING "Cannot find Qt modules")
37 set(BUILD_QT OFF PARENT_SCOPE)
38 return()
39endif()
40
41if(APPLE)
42 if(Qt5Widgets_VERSION MATCHES "^5.1[0-9]")
43 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.8")
44 else()
45 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.7")
46 endif()
47 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
48 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
49 endif()
50endif()
51
52if(BUILD_GL)
53 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gl.c)
54 if(NOT WIN32 OR USE_EPOXY)
55 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
56 endif()
57endif()
58
59if(BUILD_GLES2)
60 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
61endif()
62
63get_target_property(QT_TYPE Qt5::Core TYPE)
64if(QT_TYPE STREQUAL STATIC_LIBRARY)
65 set(QT_STATIC ON)
66 list(APPEND QT_DEFINES QT_STATIC)
67endif()
68
69set(SOURCE_FILES
70 AboutScreen.cpp
71 AssetTile.cpp
72 AssetView.cpp
73 AudioProcessor.cpp
74 CheatsModel.cpp
75 CheatsView.cpp
76 ConfigController.cpp
77 ColorPicker.cpp
78 CoreManager.cpp
79 CoreController.cpp
80 Display.cpp
81 DisplayGL.cpp
82 DisplayQt.cpp
83 GBAApp.cpp
84 GBAKeyEditor.cpp
85 GIFView.cpp
86 GamepadAxisEvent.cpp
87 GamepadButtonEvent.cpp
88 GamepadHatEvent.cpp
89 IOViewer.cpp
90 InputController.cpp
91 InputProfile.cpp
92 KeyEditor.cpp
93 LoadSaveState.cpp
94 LogController.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 PrinterView.cpp
107 RegisterView.cpp
108 ROMInfo.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 CheatsView.ui
128 DebuggerConsole.ui
129 GIFView.ui
130 IOViewer.ui
131 LoadSaveState.ui
132 LogView.ui
133 MapView.ui
134 MemorySearch.ui
135 MemoryView.ui
136 ObjView.ui
137 OverrideView.ui
138 PaletteView.ui
139 PlacementControl.ui
140 PrinterView.ui
141 ROMInfo.ui
142 SensorView.ui
143 SettingsView.ui
144 ShaderSelector.ui
145 ShortcutView.ui
146 TileView.ui
147 VideoView.ui)
148
149set(GBA_SRC
150 GBAOverride.cpp)
151
152set(GB_SRC
153 GBOverride.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
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
212qt5_add_resources(RESOURCES resources.qrc)
213if(APPLE)
214 set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
215 set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
216 set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
217 set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
218 set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
219endif()
220if(WIN32)
221 configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
222 list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
223 set_source_files_properties(${CMAKE_BINARY_DIR}/res/mgba.rc PROPERTIES OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/res/mgba.ico)
224endif()
225if(NOT DEFINED DATADIR)
226 if(APPLE)
227 set(DATADIR Applications/${PROJECT_NAME}.app/Contents/Resources)
228 elseif(WIN32 AND NOT WIN32_UNIX_PATHS)
229 set(DATADIR ".")
230 else()
231 set(DATADIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME})
232 endif()
233endif()
234if(BUILD_GL OR BUILD_GLES2)
235 install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
236endif()
237install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
238if(NOT WIN32 AND NOT APPLE)
239 list(APPEND QT_DEFINES DATADIR="${CMAKE_INSTALL_PREFIX}/${DATADIR}")
240endif()
241
242find_package(Qt5LinguistTools)
243if(Qt5LinguistTools_FOUND)
244 set(TRANSLATION_FILES)
245 set(TRANSLATION_QRC "${CMAKE_CURRENT_BINARY_DIR}/ts.qrc")
246 file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ts/${BINARY_NAME}-*.ts")
247 if(UPDATE_TRANSLATIONS)
248 qt5_create_translation(TRANSLATION_FILES ${SOURCE_FILES} ${UI_FILES} ${TS_FILES} OPTIONS -locations absolute -no-obsolete)
249 else()
250 qt5_add_translation(TRANSLATION_FILES ${TS_FILES})
251 endif()
252 set(QT_QM_FILES)
253 if(QT_STATIC)
254 get_target_property(QT_CORE_LOCATION Qt5::Core LOCATION)
255 get_filename_component(QT_CORE_LOCATION ${QT_CORE_LOCATION} DIRECTORY)
256 get_filename_component(QT_QM_LOCATION "${QT_CORE_LOCATION}/../translations" ABSOLUTE)
257 foreach(TS ${TS_FILES})
258 get_filename_component(TS ${TS} NAME)
259 string(REGEX REPLACE "${BINARY_NAME}-(.*).ts$" "qtbase_\\1.qm" QT_QM "${TS}")
260 list(APPEND QT_QM_FILES "${QT_QM_LOCATION}/${QT_QM}")
261 endforeach()
262 list(APPEND TRANSLATION_FILES ${QT_QM_FILES})
263 endif()
264 add_custom_command(OUTPUT ${TRANSLATION_QRC}
265 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"
266 DEPENDS ${TRANSLATION_FILES})
267 qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
268 list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
269endif()
270
271qt5_wrap_ui(UI_SRC ${UI_FILES})
272
273add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_SRC} ${AUDIO_SRC} ${RESOURCES})
274set_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}")
275
276list(APPEND QT_LIBRARIES Qt5::Widgets)
277if(BUILD_GL OR BUILD_GLES2)
278 list(APPEND QT_LIBRARIES Qt5::OpenGL ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
279endif()
280if(WIN32 AND QT_STATIC)
281 list(APPEND QT_LIBRARIES qwindows dwmapi imm32 uxtheme Qt5EventDispatcherSupport Qt5FontDatabaseSupport Qt5ThemeSupport)
282 set_target_properties(Qt5::Core PROPERTIES INTERFACE_LINK_LIBRARIES "qtpcre2;version;winmm;ws2_32")
283endif()
284target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES})
285set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
286
287install(TARGETS ${BINARY_NAME}-qt
288 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-qt
289 BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
290if(UNIX AND NOT APPLE)
291 find_program(DESKTOP_FILE_INSTALL desktop-file-install)
292 if(DESKTOP_FILE_INSTALL)
293 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/\")")
294 endif()
295endif()
296if(UNIX)
297 install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
298endif()
299if(APPLE OR WIN32)
300 set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
301endif()
302if(APPLE)
303 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
304 get_target_property(QTCOCOA Qt5::QCocoaIntegrationPlugin LOCATION)
305 get_target_property(COREAUDIO Qt5::CoreAudioPlugin LOCATION)
306 get_target_property(QTAVFSERVICE Qt5::AVFServicePlugin LOCATION)
307 set(BUNDLE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.app)
308 target_sources(${BINARY_NAME}-qt PRIVATE "${PLUGINS}")
309 set_source_files_properties("${QTCOCOA}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
310 set_source_files_properties("${COREAUDIO}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
311 set_source_files_properties("${QTAVFSERVICE}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
312 install(CODE "
313 include(BundleUtilities)
314 set(BU_CHMOD_BUNDLE_ITEMS ON)
315 file(GLOB_RECURSE PLUGINS \"${BUNDLE_PATH}/Contents/PlugIns/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
316 fixup_bundle(\"${BUNDLE_PATH}\" \"${PLUGINS}\" \"\")
317 " COMPONENT ${BINARY_NAME}-qt)
318 else()
319 set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib,mediaservice/libqavfcamera.dylib)
320 if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
321 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I "${CMAKE_INSTALL_NAME_TOOL}")
322 endif()
323 if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
324 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O "${CMAKE_OTOOL}")
325 endif()
326 if(DEFINED CROSS_ROOT)
327 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R "${CROSS_ROOT}")
328 endif()
329 install(CODE "execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/tools/deploy-mac.py\" -v ${DEPLOY_OPTIONS} \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/Applications/${PROJECT_NAME}.app\")")
330 endif()
331elseif(WIN32)
332 if(CMAKE_MAJOR_VERSION EQUAL 3 AND CMAKE_MINOR_VERSION EQUAL 8)
333 # Work around CMake issue #16907
334 set_target_properties(${BINARY_NAME}-qt PROPERTIES AUTORCC ON SKIP_AUTORCC ON)
335 endif()
336 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
337 find_program(BASH bash)
338 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)
339 endif()
340endif()