src/platform/qt/CMakeLists.txt (view raw)
1cmake_minimum_required(VERSION 2.8.11)
2enable_language(CXX)
3
4if(NOT MSVC)
5 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
6endif()
7
8if(APPLE)
9 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.7")
10 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
11 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
12 endif()
13endif()
14
15set(PLATFORM_SRC)
16set(QT_STATIC OFF)
17
18if(BUILD_SDL)
19 if(NOT SDL_FOUND AND NOT SDL2_FOUND)
20 find_package(SDL 1.2 REQUIRED)
21 endif()
22 if(SDL2_FOUND)
23 link_directories(${SDL2_LIBDIR})
24 endif()
25 list(APPEND PLATFORM_LIBRARY ${SDL_LIBRARY} ${SDLMAIN_LIBRARY})
26 list(APPEND PLATFORM_SRC ${PLATFORM_SRC} ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-events.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-audio.c)
27 include_directories(${SDL_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src/platform/sdl)
28endif()
29
30set(CMAKE_AUTOMOC ON)
31set(CMAKE_INCLUDE_CURRENT_DIR ON)
32
33if(NOT WIN32 OR NOT BUILD_SDL)
34 find_package(Qt5Multimedia)
35endif()
36find_package(Qt5OpenGL)
37find_package(Qt5Network)
38find_package(Qt5Widgets)
39
40if(NOT BUILD_GL AND NOT BUILD_GLES2)
41 message(WARNING "OpenGL is required to build the Qt port")
42 set(BUILD_QT OFF PARENT_SCOPE)
43 return()
44endif()
45
46if(NOT Qt5OpenGL_FOUND OR NOT Qt5Widgets_FOUND OR NOT Qt5Network_FOUND)
47 message(WARNING "Cannot find Qt modules")
48 set(BUILD_QT OFF PARENT_SCOPE)
49 return()
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 Display.cpp
78 DisplayGL.cpp
79 DisplayQt.cpp
80 GBAApp.cpp
81 GBAKeyEditor.cpp
82 GIFView.cpp
83 GameController.cpp
84 GamepadAxisEvent.cpp
85 GamepadButtonEvent.cpp
86 GamepadHatEvent.cpp
87 IOViewer.cpp
88 InputController.cpp
89 InputProfile.cpp
90 KeyEditor.cpp
91 LoadSaveState.cpp
92 LogController.cpp
93 LogView.cpp
94 MemoryModel.cpp
95 MemoryView.cpp
96 MessagePainter.cpp
97 MultiplayerController.cpp
98 ObjView.cpp
99 OverrideView.cpp
100 PaletteView.cpp
101 ROMInfo.cpp
102 SavestateButton.cpp
103 SensorView.cpp
104 SettingsView.cpp
105 ShaderSelector.cpp
106 ShortcutController.cpp
107 ShortcutView.cpp
108 Swatch.cpp
109 TilePainter.cpp
110 TileView.cpp
111 Window.cpp
112 VFileDevice.cpp
113 VideoView.cpp)
114
115set(UI_FILES
116 AboutScreen.ui
117 ArchiveInspector.ui
118 AssetTile.ui
119 CheatsView.ui
120 DebuggerConsole.ui
121 GIFView.ui
122 IOViewer.ui
123 LibraryView.ui
124 LoadSaveState.ui
125 LogView.ui
126 MemoryView.ui
127 ObjView.ui
128 OverrideView.ui
129 PaletteView.ui
130 ROMInfo.ui
131 SensorView.ui
132 SettingsView.ui
133 ShaderSelector.ui
134 ShortcutView.ui
135 TileView.ui
136 VideoView.ui)
137
138set(GBA_SRC
139 GBAOverride.cpp)
140
141set(GB_SRC
142 GBOverride.cpp)
143
144qt5_wrap_ui(UI_SRC ${UI_FILES})
145
146set(QT_LIBRARIES)
147set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5,libqt5network5")
148
149set(AUDIO_SRC)
150if(BUILD_SDL)
151 list(APPEND AUDIO_SRC AudioProcessorSDL.cpp)
152endif()
153
154if(M_CORE_GBA)
155 list(APPEND PLATFORM_SRC ${GBA_SRC})
156endif()
157
158if(M_CORE_GB)
159 list(APPEND PLATFORM_SRC ${GB_SRC})
160endif()
161
162set(QT_DEFINES)
163if(Qt5Multimedia_FOUND)
164 list(APPEND AUDIO_SRC
165 AudioProcessorQt.cpp
166 AudioDevice.cpp)
167 if (WIN32 AND QT_STATIC)
168 list(APPEND QT_LIBRARIES qtaudio_windows strmiids winmm)
169 endif()
170 list(APPEND QT_LIBRARIES Qt5::Multimedia)
171 list(APPEND QT_DEFINES BUILD_QT_MULTIMEDIA)
172 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
173endif()
174
175if(NOT AUDIO_SRC)
176 message(WARNING "No supported audio modules found")
177 set(BUILD_QT OFF PARENT_SCOPE)
178 return()
179endif()
180
181if(USE_DEBUGGERS)
182 list(APPEND SOURCE_FILES
183 DebuggerController.cpp
184 DebuggerConsole.cpp
185 DebuggerConsoleController.cpp)
186endif()
187
188if(USE_GDB_STUB)
189 list(APPEND SOURCE_FILES GDBController.cpp GDBWindow.cpp)
190endif()
191
192if(USE_SQLITE3)
193 list(APPEND SOURCE_FILES
194 ArchiveInspector.cpp
195 LibraryModel.cpp
196 LibraryView.cpp)
197endif()
198
199qt5_add_resources(RESOURCES resources.qrc)
200if(APPLE)
201 set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
202 set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
203 set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
204 set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
205 set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
206endif()
207if(WIN32)
208 configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
209 list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
210 set_source_files_properties(${CMAKE_BINARY_DIR}/res/mgba.rc PROPERTIES OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/res/mgba.ico)
211 if(QT_STATIC)
212 list(APPEND QT_LIBRARIES qwindows Qt5PlatformSupport imm32)
213 endif()
214endif()
215if(NOT DEFINED DATADIR)
216 if(APPLE)
217 set(DATADIR Applications/${PROJECT_NAME}.app/Contents/Resources)
218 else()
219 set(DATADIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME})
220 endif()
221endif()
222install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
223install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
224if(NOT WIN32 AND NOT APPLE)
225 list(APPEND QT_DEFINES DATADIR="${DATADIR}")
226endif()
227
228find_package(Qt5LinguistTools)
229if(Qt5LinguistTools_FOUND)
230 set(TRANSLATION_FILES)
231 set(TRANSLATION_QRC "${CMAKE_CURRENT_BINARY_DIR}/ts.qrc")
232 file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ts/${BINARY_NAME}-*.ts")
233 if(UPDATE_TRANSLATIONS)
234 qt5_create_translation(TRANSLATION_FILES ${SOURCE_FILES} ${UI_FILES} ${TS_FILES} OPTIONS -locations absolute -no-obsolete)
235 else()
236 qt5_add_translation(TRANSLATION_FILES ${TS_FILES})
237 endif()
238 add_custom_command(OUTPUT ${TRANSLATION_QRC}
239 COMMAND ${CMAKE_COMMAND} -DTRANSLATION_QRC:FILEPATH="${TRANSLATION_QRC}" -DTRANSLATION_FILES="${TRANSLATION_FILES}" -P "${CMAKE_CURRENT_SOURCE_DIR}/ts.cmake"
240 DEPENDS ${TRANSLATION_FILES})
241 qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
242 list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
243endif()
244
245add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_SRC} ${AUDIO_SRC} ${RESOURCES})
246set_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}")
247
248list(APPEND QT_LIBRARIES Qt5::Widgets Qt5::OpenGL Qt5::Network)
249target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
250set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
251
252install(TARGETS ${BINARY_NAME}-qt
253 RUNTIME DESTINATION bin COMPONENT ${BINARY_NAME}-qt
254 BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
255if(UNIX AND NOT APPLE)
256 find_program(DESKTOP_FILE_INSTALL desktop-file-install)
257 if(DESKTOP_FILE_INSTALL)
258 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/\")")
259 endif()
260endif()
261if(UNIX)
262 install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
263endif()
264if(APPLE OR WIN32)
265 set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
266endif()
267if(APPLE)
268 set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib)
269 if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
270 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I ${CMAKE_INSTALL_NAME_TOOL})
271 endif()
272 if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
273 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O ${CMAKE_OTOOL})
274 endif()
275 if(DEFINED CROSS_ROOT)
276 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R ${CROSS_ROOT})
277 endif()
278 add_custom_command(TARGET ${BINARY_NAME}-qt POST_BUILD COMMAND ${CMAKE_SOURCE_DIR}/tools/deploy-mac.py ${DEPLOY_OPTIONS} ${PROJECT_NAME}.app)
279endif()