src/platform/qt/CMakeLists.txt (view raw)
1if(NOT MSVC)
2 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
3endif()
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 Display.cpp
70 DisplayGL.cpp
71 DisplayQt.cpp
72 GBAApp.cpp
73 GBAKeyEditor.cpp
74 GIFView.cpp
75 GameController.cpp
76 GamepadAxisEvent.cpp
77 GamepadButtonEvent.cpp
78 GamepadHatEvent.cpp
79 IOViewer.cpp
80 InputController.cpp
81 InputProfile.cpp
82 KeyEditor.cpp
83 LoadSaveState.cpp
84 LogController.cpp
85 LogView.cpp
86 MemoryModel.cpp
87 MemorySearch.cpp
88 MemoryView.cpp
89 MessagePainter.cpp
90 MultiplayerController.cpp
91 ObjView.cpp
92 OverrideView.cpp
93 PaletteView.cpp
94 ROMInfo.cpp
95 SavestateButton.cpp
96 SensorView.cpp
97 SettingsView.cpp
98 ShaderSelector.cpp
99 ShortcutController.cpp
100 ShortcutView.cpp
101 Swatch.cpp
102 TilePainter.cpp
103 TileView.cpp
104 utils.cpp
105 Window.cpp
106 VFileDevice.cpp
107 VideoView.cpp)
108
109set(UI_FILES
110 AboutScreen.ui
111 ArchiveInspector.ui
112 AssetTile.ui
113 CheatsView.ui
114 DebuggerConsole.ui
115 GIFView.ui
116 IOViewer.ui
117 LoadSaveState.ui
118 LogView.ui
119 MemorySearch.ui
120 MemoryView.ui
121 ObjView.ui
122 OverrideView.ui
123 PaletteView.ui
124 ROMInfo.ui
125 SensorView.ui
126 SettingsView.ui
127 ShaderSelector.ui
128 ShortcutView.ui
129 TileView.ui
130 VideoView.ui)
131
132set(GBA_SRC
133 GBAOverride.cpp)
134
135set(GB_SRC
136 GBOverride.cpp)
137
138set(QT_LIBRARIES)
139set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5")
140
141set(AUDIO_SRC)
142if(BUILD_SDL)
143 list(APPEND AUDIO_SRC AudioProcessorSDL.cpp)
144endif()
145
146if(M_CORE_GBA)
147 list(APPEND PLATFORM_SRC ${GBA_SRC})
148endif()
149
150if(M_CORE_GB)
151 list(APPEND PLATFORM_SRC ${GB_SRC})
152endif()
153
154set(QT_DEFINES)
155if(Qt5Multimedia_FOUND)
156 list(APPEND AUDIO_SRC
157 AudioProcessorQt.cpp
158 AudioDevice.cpp)
159 if (WIN32 AND QT_STATIC)
160 list(APPEND QT_LIBRARIES qtaudio_windows strmiids winmm)
161 endif()
162 list(APPEND QT_LIBRARIES Qt5::Multimedia)
163 list(APPEND QT_DEFINES BUILD_QT_MULTIMEDIA)
164 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
165endif()
166
167if(NOT AUDIO_SRC)
168 message(WARNING "No supported audio modules found")
169 set(BUILD_QT OFF PARENT_SCOPE)
170 return()
171endif()
172
173if(USE_DEBUGGERS)
174 list(APPEND SOURCE_FILES
175 DebuggerController.cpp
176 DebuggerConsole.cpp
177 DebuggerConsoleController.cpp)
178endif()
179
180if(USE_GDB_STUB)
181 list(APPEND SOURCE_FILES GDBController.cpp GDBWindow.cpp)
182endif()
183
184if(USE_SQLITE3)
185 list(APPEND SOURCE_FILES
186 ArchiveInspector.cpp
187 library/LibraryController.cpp
188 library/LibraryGrid.cpp
189 library/LibraryTree.cpp)
190endif()
191
192qt5_add_resources(RESOURCES resources.qrc)
193if(APPLE)
194 set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
195 set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
196 set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
197 set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
198 set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
199endif()
200if(WIN32)
201 configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
202 list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
203 set_source_files_properties(${CMAKE_BINARY_DIR}/res/mgba.rc PROPERTIES OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/res/mgba.ico)
204 if(QT_STATIC)
205 list(APPEND QT_LIBRARIES qwindows Qt5PlatformSupport imm32)
206 endif()
207endif()
208if(NOT DEFINED DATADIR)
209 if(APPLE)
210 set(DATADIR Applications/${PROJECT_NAME}.app/Contents/Resources)
211 else()
212 set(DATADIR ${CMAKE_INSTALL_FULL_DATADIR}/${BINARY_NAME})
213 endif()
214endif()
215install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
216install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
217if(NOT WIN32 AND NOT APPLE)
218 list(APPEND QT_DEFINES DATADIR="${DATADIR}")
219endif()
220
221find_package(Qt5LinguistTools)
222if(Qt5LinguistTools_FOUND)
223 set(TRANSLATION_FILES)
224 set(TRANSLATION_QRC "${CMAKE_CURRENT_BINARY_DIR}/ts.qrc")
225 file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ts/${BINARY_NAME}-*.ts")
226 if(UPDATE_TRANSLATIONS)
227 qt5_create_translation(TRANSLATION_FILES ${SOURCE_FILES} ${UI_FILES} ${TS_FILES} OPTIONS -locations absolute -no-obsolete)
228 else()
229 qt5_add_translation(TRANSLATION_FILES ${TS_FILES})
230 endif()
231 add_custom_command(OUTPUT ${TRANSLATION_QRC}
232 COMMAND ${CMAKE_COMMAND} -DTRANSLATION_QRC:FILEPATH="${TRANSLATION_QRC}" -DQM_BASE="${CMAKE_CURRENT_BINARY_DIR}" -P "${CMAKE_CURRENT_SOURCE_DIR}/ts.cmake"
233 DEPENDS ${TRANSLATION_FILES})
234 qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
235 list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
236endif()
237
238qt5_wrap_ui(UI_SRC ${UI_FILES})
239
240add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_SRC} ${AUDIO_SRC} ${RESOURCES})
241set_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}")
242
243list(APPEND QT_LIBRARIES Qt5::Widgets)
244if(BUILD_GL OR BUILD_GLES2)
245 list(APPEND QT_LIBRARIES Qt5::OpenGL ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
246endif()
247target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES})
248set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
249
250install(TARGETS ${BINARY_NAME}-qt
251 RUNTIME DESTINATION bin COMPONENT ${BINARY_NAME}-qt
252 BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
253if(UNIX AND NOT APPLE)
254 find_program(DESKTOP_FILE_INSTALL desktop-file-install)
255 if(DESKTOP_FILE_INSTALL)
256 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/\")")
257 endif()
258endif()
259if(UNIX)
260 install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
261endif()
262if(APPLE OR WIN32)
263 set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
264endif()
265if(APPLE)
266 message(STATUS ${CMAKE_SYSTEM_NAME})
267 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
268 get_target_property(QTCOCOA Qt5::QCocoaIntegrationPlugin LOCATION)
269 get_target_property(COREAUDIO Qt5::CoreAudioPlugin LOCATION)
270 get_target_property(BUNDLE_PATH ${BINARY_NAME}-qt LOCATION)
271 target_sources(${BINARY_NAME}-qt PRIVATE "${PLUGINS}")
272 set_source_files_properties("${QTCOCOA}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
273 set_source_files_properties("${COREAUDIO}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
274 install(CODE "
275 include(BundleUtilities)
276 set(BU_CHMOD_BUNDLE_ITEMS ON)
277 file(GLOB_RECURSE PLUGINS \"${BUNDLE_PATH}/Contents/PlugIns/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
278 fixup_bundle(\"${BUNDLE_PATH}\" \"${PLUGINS}\" \"\")
279 " COMPONENT ${BINARY_NAME}-qt)
280 else()
281 set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib)
282 if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
283 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I "${CMAKE_INSTALL_NAME_TOOL}")
284 endif()
285 if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
286 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O "${CMAKE_OTOOL}")
287 endif()
288 if(DEFINED CROSS_ROOT)
289 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R "${CROSS_ROOT}")
290 endif()
291 install(CODE "execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/tools/deploy-mac.py\" -v ${DEPLOY_OPTIONS} \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/Applications/${PROJECT_NAME}.app\")")
292 endif()
293endif()
294if(WIN32 AND CMAKE_MAJOR_VERSION GREATER 2 AND CMAKE_MINOR_VERSION GREATER 7)
295 # Work around CMake issue #16907
296 set_target_properties(${BINARY_NAME}-qt PROPERTIES AUTORCC ON SKIP_AUTORCC ON)
297endif()