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