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 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)
218endif()
219if(NOT DEFINED DATADIR)
220 if(APPLE)
221 set(DATADIR Applications/${PROJECT_NAME}.app/Contents/Resources)
222 elseif(WIN32 AND NOT WIN32_UNIX_PATHS)
223 set(DATADIR ".")
224 else()
225 set(DATADIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME})
226 endif()
227endif()
228if(BUILD_GL OR BUILD_GLES2)
229 install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
230endif()
231install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
232if(NOT WIN32 AND NOT APPLE)
233 list(APPEND QT_DEFINES DATADIR="${CMAKE_INSTALL_PREFIX}/${DATADIR}")
234endif()
235
236find_package(Qt5LinguistTools)
237if(Qt5LinguistTools_FOUND)
238 set(TRANSLATION_FILES)
239 set(TRANSLATION_QRC "${CMAKE_CURRENT_BINARY_DIR}/ts.qrc")
240 file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ts/${BINARY_NAME}-*.ts")
241 if(UPDATE_TRANSLATIONS)
242 qt5_create_translation(TRANSLATION_FILES ${SOURCE_FILES} ${UI_FILES} ${TS_FILES} OPTIONS -locations absolute -no-obsolete)
243 else()
244 qt5_add_translation(TRANSLATION_FILES ${TS_FILES})
245 endif()
246 set(QT_QM_FILES)
247 if(QT_STATIC)
248 get_target_property(QT_CORE_LOCATION Qt5::Core LOCATION)
249 get_filename_component(QT_CORE_LOCATION ${QT_CORE_LOCATION} DIRECTORY)
250 get_filename_component(QT_QM_LOCATION "${QT_CORE_LOCATION}/../translations" ABSOLUTE)
251 foreach(TS ${TS_FILES})
252 get_filename_component(TS ${TS} NAME)
253 string(REGEX REPLACE "${BINARY_NAME}-(.*).ts$" "qtbase_\\1.qm" QT_QM "${TS}")
254 list(APPEND QT_QM_FILES "${QT_QM_LOCATION}/${QT_QM}")
255 endforeach()
256 list(APPEND TRANSLATION_FILES ${QT_QM_FILES})
257 endif()
258 add_custom_command(OUTPUT ${TRANSLATION_QRC}
259 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"
260 DEPENDS ${TRANSLATION_FILES})
261 qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
262 list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
263endif()
264
265qt5_wrap_ui(UI_SRC ${UI_FILES})
266
267add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_SRC} ${AUDIO_SRC} ${RESOURCES})
268set_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}")
269
270list(APPEND QT_LIBRARIES Qt5::Widgets)
271if(BUILD_GL OR BUILD_GLES2)
272 list(APPEND QT_LIBRARIES Qt5::OpenGL ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
273endif()
274if(WIN32 AND QT_STATIC)
275 list(APPEND QT_LIBRARIES qwindows dwmapi imm32 uxtheme Qt5EventDispatcherSupport Qt5FontDatabaseSupport Qt5ThemeSupport)
276 set_target_properties(Qt5::Core PROPERTIES INTERFACE_LINK_LIBRARIES "qtpcre2;version;winmm;ws2_32")
277endif()
278target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES})
279set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
280
281install(TARGETS ${BINARY_NAME}-qt
282 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-qt
283 BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
284if(UNIX AND NOT APPLE)
285 find_program(DESKTOP_FILE_INSTALL desktop-file-install)
286 if(DESKTOP_FILE_INSTALL)
287 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/\")")
288 endif()
289endif()
290if(UNIX)
291 install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
292endif()
293if(APPLE OR WIN32)
294 set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
295endif()
296if(APPLE)
297 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
298 get_target_property(QTCOCOA Qt5::QCocoaIntegrationPlugin LOCATION)
299 get_target_property(COREAUDIO Qt5::CoreAudioPlugin LOCATION)
300 get_target_property(QTAVFSERVICE Qt5::AVFServicePlugin LOCATION)
301 set(BUNDLE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.app)
302 target_sources(${BINARY_NAME}-qt PRIVATE "${PLUGINS}")
303 set_source_files_properties("${QTCOCOA}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
304 set_source_files_properties("${COREAUDIO}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
305 set_source_files_properties("${QTAVFSERVICE}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
306 install(CODE "
307 include(BundleUtilities)
308 set(BU_CHMOD_BUNDLE_ITEMS ON)
309 file(GLOB_RECURSE PLUGINS \"${BUNDLE_PATH}/Contents/PlugIns/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
310 fixup_bundle(\"${BUNDLE_PATH}\" \"${PLUGINS}\" \"\")
311 " COMPONENT ${BINARY_NAME}-qt)
312 else()
313 set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib,mediaservice/libqavfcamera.dylib)
314 if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
315 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I "${CMAKE_INSTALL_NAME_TOOL}")
316 endif()
317 if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
318 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O "${CMAKE_OTOOL}")
319 endif()
320 if(DEFINED CROSS_ROOT)
321 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R "${CROSS_ROOT}")
322 endif()
323 install(CODE "execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/tools/deploy-mac.py\" -v ${DEPLOY_OPTIONS} \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/Applications/${PROJECT_NAME}.app\")")
324 endif()
325elseif(WIN32)
326 if(CMAKE_MAJOR_VERSION EQUAL 3 AND CMAKE_MINOR_VERSION EQUAL 8)
327 # Work around CMake issue #16907
328 set_target_properties(${BINARY_NAME}-qt PROPERTIES AUTORCC ON SKIP_AUTORCC ON)
329 endif()
330 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
331 find_program(BASH bash)
332 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)
333 endif()
334endif()