src/platform/qt/CMakeLists.txt (view raw)
1set(CMAKE_CXX_STANDARD 14)
2set(CMAKE_CXX_STANDARD_REQUIRED ON)
3set(CMAKE_CXX_EXTENSIONS OFF)
4
5if(APPLE)
6 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.7")
7 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
8 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
9 endif()
10endif()
11
12set(PLATFORM_SRC)
13set(QT_STATIC OFF)
14
15if(BUILD_SDL)
16 if(NOT SDL_FOUND AND NOT SDL2_FOUND)
17 find_package(SDL 1.2 REQUIRED)
18 endif()
19 if(SDL2_FOUND)
20 link_directories(${SDL2_LIBDIR})
21 endif()
22 list(APPEND PLATFORM_LIBRARY ${SDL_LIBRARY})
23 list(APPEND PLATFORM_SRC ${PLATFORM_SRC} ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-events.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-audio.c)
24 include_directories(${SDL_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src/platform/sdl)
25endif()
26
27set(CMAKE_AUTOMOC ON)
28set(CMAKE_INCLUDE_CURRENT_DIR ON)
29
30find_package(Qt5Multimedia)
31find_package(Qt5OpenGL)
32find_package(Qt5Widgets)
33
34if(NOT BUILD_GL AND NOT BUILD_GLES2)
35 message(WARNING "OpenGL is recommended to build the Qt port")
36endif()
37
38if(NOT Qt5Widgets_FOUND)
39 message(WARNING "Cannot find Qt modules")
40 set(BUILD_QT OFF PARENT_SCOPE)
41 return()
42endif()
43
44if(BUILD_GL)
45 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gl.c)
46 if(NOT WIN32 OR USE_EPOXY)
47 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
48 endif()
49endif()
50
51if(BUILD_GLES2)
52 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
53endif()
54
55get_target_property(QT_TYPE Qt5::Core TYPE)
56if(QT_TYPE STREQUAL STATIC_LIBRARY)
57 set(QT_STATIC ON)
58 list(APPEND QT_DEFINES QT_STATIC)
59endif()
60
61set(SOURCE_FILES
62 AboutScreen.cpp
63 AssetTile.cpp
64 AssetView.cpp
65 AudioProcessor.cpp
66 CheatsModel.cpp
67 CheatsView.cpp
68 ConfigController.cpp
69 CoreManager.cpp
70 CoreController.cpp
71 Display.cpp
72 DisplayGL.cpp
73 DisplayQt.cpp
74 GBAApp.cpp
75 GBAKeyEditor.cpp
76 GIFView.cpp
77 GamepadAxisEvent.cpp
78 GamepadButtonEvent.cpp
79 GamepadHatEvent.cpp
80 IOViewer.cpp
81 InputController.cpp
82 InputProfile.cpp
83 KeyEditor.cpp
84 LoadSaveState.cpp
85 LogController.cpp
86 LogView.cpp
87 MemoryModel.cpp
88 MemorySearch.cpp
89 MemoryView.cpp
90 MessagePainter.cpp
91 MultiplayerController.cpp
92 ObjView.cpp
93 OverrideView.cpp
94 PaletteView.cpp
95 ROMInfo.cpp
96 SavestateButton.cpp
97 SensorView.cpp
98 SettingsView.cpp
99 ShaderSelector.cpp
100 ShortcutController.cpp
101 ShortcutView.cpp
102 Swatch.cpp
103 TilePainter.cpp
104 TileView.cpp
105 utils.cpp
106 Window.cpp
107 VFileDevice.cpp
108 VideoView.cpp)
109
110set(UI_FILES
111 AboutScreen.ui
112 ArchiveInspector.ui
113 AssetTile.ui
114 CheatsView.ui
115 DebuggerConsole.ui
116 GIFView.ui
117 IOViewer.ui
118 LoadSaveState.ui
119 LogView.ui
120 MemorySearch.ui
121 MemoryView.ui
122 ObjView.ui
123 OverrideView.ui
124 PaletteView.ui
125 ROMInfo.ui
126 SensorView.ui
127 SettingsView.ui
128 ShaderSelector.ui
129 ShortcutView.ui
130 TileView.ui
131 VideoView.ui)
132
133set(GBA_SRC
134 GBAOverride.cpp)
135
136set(GB_SRC
137 GBOverride.cpp)
138
139set(QT_LIBRARIES)
140set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5")
141
142set(AUDIO_SRC)
143if(BUILD_SDL)
144 list(APPEND AUDIO_SRC AudioProcessorSDL.cpp)
145endif()
146
147if(M_CORE_GBA)
148 list(APPEND PLATFORM_SRC ${GBA_SRC})
149endif()
150
151if(M_CORE_GB)
152 list(APPEND PLATFORM_SRC ${GB_SRC})
153endif()
154
155set(QT_DEFINES)
156if(Qt5Multimedia_FOUND)
157 list(APPEND AUDIO_SRC
158 AudioProcessorQt.cpp
159 AudioDevice.cpp)
160 list(APPEND SOURCE_FILES
161 VideoDumper.cpp)
162 if (WIN32 AND QT_STATIC)
163 list(APPEND QT_LIBRARIES qtaudio_windows strmiids winmm)
164 endif()
165 list(APPEND QT_LIBRARIES Qt5::Multimedia)
166 list(APPEND QT_DEFINES BUILD_QT_MULTIMEDIA)
167 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
168endif()
169
170if(NOT AUDIO_SRC)
171 message(WARNING "No supported audio modules found")
172 set(BUILD_QT OFF PARENT_SCOPE)
173 return()
174endif()
175
176if(USE_DEBUGGERS)
177 list(APPEND SOURCE_FILES
178 DebuggerController.cpp
179 DebuggerConsole.cpp
180 DebuggerConsoleController.cpp)
181endif()
182
183if(USE_GDB_STUB)
184 list(APPEND SOURCE_FILES GDBController.cpp GDBWindow.cpp)
185endif()
186
187if(USE_SQLITE3)
188 list(APPEND SOURCE_FILES
189 ArchiveInspector.cpp
190 library/LibraryController.cpp
191 library/LibraryGrid.cpp
192 library/LibraryTree.cpp)
193endif()
194
195qt5_add_resources(RESOURCES resources.qrc)
196if(APPLE)
197 set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
198 set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
199 set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
200 set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
201 set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
202endif()
203if(WIN32)
204 configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
205 list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
206 set_source_files_properties(${CMAKE_BINARY_DIR}/res/mgba.rc PROPERTIES OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/res/mgba.ico)
207 if(QT_STATIC)
208 list(APPEND QT_LIBRARIES qwindows Qt5PlatformSupport imm32)
209 endif()
210endif()
211if(NOT DEFINED DATADIR)
212 if(APPLE)
213 set(DATADIR Applications/${PROJECT_NAME}.app/Contents/Resources)
214 else()
215 set(DATADIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME})
216 endif()
217endif()
218if(BUILD_GL OR BUILD_GLES2)
219 install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
220endif()
221install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
222if(NOT WIN32 AND NOT APPLE)
223 list(APPEND QT_DEFINES DATADIR="${CMAKE_INSTALL_PREFIX}/${DATADIR}")
224endif()
225
226find_package(Qt5LinguistTools)
227if(Qt5LinguistTools_FOUND)
228 set(TRANSLATION_FILES)
229 set(TRANSLATION_QRC "${CMAKE_CURRENT_BINARY_DIR}/ts.qrc")
230 file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ts/${BINARY_NAME}-*.ts")
231 if(UPDATE_TRANSLATIONS)
232 qt5_create_translation(TRANSLATION_FILES ${SOURCE_FILES} ${UI_FILES} ${TS_FILES} OPTIONS -locations absolute -no-obsolete)
233 else()
234 qt5_add_translation(TRANSLATION_FILES ${TS_FILES})
235 endif()
236 set(QT_QM_FILES)
237 if(QT_STATIC)
238 get_target_property(QT_CORE_LOCATION Qt5::Core LOCATION)
239 get_filename_component(QT_CORE_LOCATION ${QT_CORE_LOCATION} DIRECTORY)
240 get_filename_component(QT_QM_LOCATION "${QT_CORE_LOCATION}/../translations" ABSOLUTE)
241 foreach(TS ${TS_FILES})
242 get_filename_component(TS ${TS} NAME)
243 string(REGEX REPLACE "${BINARY_NAME}-(.*).ts$" "qtbase_\\1.qm" QT_QM "${TS}")
244 list(APPEND QT_QM_FILES "${QT_QM_LOCATION}/${QT_QM}")
245 endforeach()
246 list(APPEND TRANSLATION_FILES ${QT_QM_FILES})
247 endif()
248 add_custom_command(OUTPUT ${TRANSLATION_QRC}
249 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"
250 DEPENDS ${TRANSLATION_FILES})
251 qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
252 list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
253endif()
254
255qt5_wrap_ui(UI_SRC ${UI_FILES})
256
257add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_SRC} ${AUDIO_SRC} ${RESOURCES})
258set_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}")
259
260list(APPEND QT_LIBRARIES Qt5::Widgets)
261if(BUILD_GL OR BUILD_GLES2)
262 list(APPEND QT_LIBRARIES Qt5::OpenGL ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
263endif()
264target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES})
265set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
266
267install(TARGETS ${BINARY_NAME}-qt
268 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-qt
269 BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
270if(UNIX AND NOT APPLE)
271 find_program(DESKTOP_FILE_INSTALL desktop-file-install)
272 if(DESKTOP_FILE_INSTALL)
273 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/\")")
274 endif()
275endif()
276if(UNIX)
277 install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
278endif()
279if(APPLE OR WIN32)
280 set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
281endif()
282if(APPLE)
283 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
284 get_target_property(QTCOCOA Qt5::QCocoaIntegrationPlugin LOCATION)
285 get_target_property(COREAUDIO Qt5::CoreAudioPlugin LOCATION)
286 set(BUNDLE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.app)
287 target_sources(${BINARY_NAME}-qt PRIVATE "${PLUGINS}")
288 set_source_files_properties("${QTCOCOA}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
289 set_source_files_properties("${COREAUDIO}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
290 install(CODE "
291 include(BundleUtilities)
292 set(BU_CHMOD_BUNDLE_ITEMS ON)
293 file(GLOB_RECURSE PLUGINS \"${BUNDLE_PATH}/Contents/PlugIns/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
294 fixup_bundle(\"${BUNDLE_PATH}\" \"${PLUGINS}\" \"\")
295 " COMPONENT ${BINARY_NAME}-qt)
296 else()
297 set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib)
298 if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
299 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I "${CMAKE_INSTALL_NAME_TOOL}")
300 endif()
301 if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
302 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O "${CMAKE_OTOOL}")
303 endif()
304 if(DEFINED CROSS_ROOT)
305 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R "${CROSS_ROOT}")
306 endif()
307 install(CODE "execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/tools/deploy-mac.py\" -v ${DEPLOY_OPTIONS} \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/Applications/${PROJECT_NAME}.app\")")
308 endif()
309endif()
310if(WIN32 AND CMAKE_MAJOR_VERSION GREATER 2 AND CMAKE_MINOR_VERSION GREATER 7)
311 # Work around CMake issue #16907
312 set_target_properties(${BINARY_NAME}-qt PROPERTIES AUTORCC ON SKIP_AUTORCC ON)
313endif()