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 ArchiveInspector.cpp
72 AudioProcessor.cpp
73 CheatsModel.cpp
74 CheatsView.cpp
75 ConfigController.cpp
76 Display.cpp
77 DisplayGL.cpp
78 DisplayQt.cpp
79 GBAApp.cpp
80 GBAKeyEditor.cpp
81 GIFView.cpp
82 GameController.cpp
83 GamepadAxisEvent.cpp
84 GamepadButtonEvent.cpp
85 IOViewer.cpp
86 InputController.cpp
87 InputProfile.cpp
88 KeyEditor.cpp
89 LibraryModel.cpp
90 LoadSaveState.cpp
91 LogController.cpp
92 LogView.cpp
93 MemoryModel.cpp
94 MemoryView.cpp
95 MessagePainter.cpp
96 MultiplayerController.cpp
97 OverrideView.cpp
98 PaletteView.cpp
99 ROMInfo.cpp
100 SavestateButton.cpp
101 SensorView.cpp
102 SettingsView.cpp
103 ShaderSelector.cpp
104 ShortcutController.cpp
105 ShortcutView.cpp
106 Swatch.cpp
107 TilePainter.cpp
108 TileView.cpp
109 Window.cpp
110 VFileDevice.cpp
111 VideoView.cpp)
112
113set(UI_FILES
114 AboutScreen.ui
115 ArchiveInspector.ui
116 CheatsView.ui
117 GIFView.ui
118 IOViewer.ui
119 LoadSaveState.ui
120 LogView.ui
121 MemoryView.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
138qt5_wrap_ui(UI_SRC ${UI_FILES})
139
140set(QT_LIBRARIES)
141set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5,libqt5network5")
142
143set(AUDIO_SRC)
144if(BUILD_SDL)
145 list(APPEND AUDIO_SRC AudioProcessorSDL.cpp)
146endif()
147
148if(M_CORE_GBA)
149 list(APPEND PLATFORM_SRC ${GBA_SRC})
150endif()
151
152if(M_CORE_GB)
153 list(APPEND PLATFORM_SRC ${GB_SRC})
154endif()
155
156set(QT_DEFINES)
157if(Qt5Multimedia_FOUND)
158 list(APPEND AUDIO_SRC
159 AudioProcessorQt.cpp
160 AudioDevice.cpp)
161 if (WIN32 AND QT_STATIC)
162 list(APPEND QT_LIBRARIES qtaudio_windows strmiids winmm)
163 endif()
164 list(APPEND QT_LIBRARIES Qt5::Multimedia)
165 list(APPEND QT_DEFINES BUILD_QT_MULTIMEDIA)
166 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
167endif()
168
169if(NOT AUDIO_SRC)
170 message(WARNING "No supported audio modules found")
171 set(BUILD_QT OFF PARENT_SCOPE)
172 return()
173endif()
174
175if(USE_GDB_STUB)
176 list(APPEND PLATFORM_SRC GDBController.cpp GDBWindow.cpp)
177endif()
178set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
179set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
180set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
181set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
182set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
183
184qt5_add_resources(RESOURCES resources.qrc)
185if(WIN32)
186 configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
187 list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
188 if(QT_STATIC)
189 list(APPEND QT_LIBRARIES qwindows Qt5PlatformSupport imm32)
190 endif()
191endif()
192if(NOT DEFINED DATADIR)
193 if(APPLE)
194 set(DATADIR Applications/${PROJECT_NAME}.app/Contents/Resources)
195 else()
196 set(DATADIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME})
197 endif()
198endif()
199install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
200install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
201if(NOT WIN32 AND NOT APPLE)
202 list(APPEND QT_DEFINES DATADIR="${DATADIR}")
203endif()
204
205find_package(Qt5LinguistTools)
206if(Qt5LinguistTools_FOUND)
207 set(TRANSLATION_FILES)
208 set(TRANSLATION_QRC "${CMAKE_CURRENT_BINARY_DIR}/ts.qrc")
209 file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ts/${BINARY_NAME}-*.ts")
210 if(UPDATE_TRANSLATIONS)
211 qt5_create_translation(TRANSLATION_FILES ${SOURCE_FILES} ${UI_FILES} ${TS_FILES} OPTIONS -locations absolute -no-obsolete)
212 else()
213 qt5_add_translation(TRANSLATION_FILES ${TS_FILES})
214 endif()
215 add_custom_command(OUTPUT ${TRANSLATION_QRC}
216 COMMAND ${CMAKE_COMMAND} -DTRANSLATION_QRC:FILEPATH="${TRANSLATION_QRC}" -DTRANSLATION_FILES="${TRANSLATION_FILES}" -P "${CMAKE_CURRENT_SOURCE_DIR}/ts.cmake"
217 DEPENDS ${TRANSLATION_FILES})
218 qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
219 list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
220endif()
221
222add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_SRC} ${AUDIO_SRC} ${RESOURCES})
223set_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}")
224
225list(APPEND QT_LIBRARIES Qt5::Widgets Qt5::OpenGL Qt5::Network)
226target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
227set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
228
229install(TARGETS ${BINARY_NAME}-qt
230 RUNTIME DESTINATION bin COMPONENT ${BINARY_NAME}-qt
231 BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
232if(UNIX AND NOT APPLE)
233 find_program(DESKTOP_FILE_INSTALL desktop-file-install)
234 if(DESKTOP_FILE_INSTALL)
235 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/\")")
236 endif()
237endif()
238if(UNIX)
239 install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
240endif()
241if(APPLE OR WIN32)
242 set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
243endif()
244if(APPLE)
245 set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib)
246 if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
247 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I ${CMAKE_INSTALL_NAME_TOOL})
248 endif()
249 if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
250 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O ${CMAKE_OTOOL})
251 endif()
252 if(DEFINED CROSS_ROOT)
253 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R ${CROSS_ROOT})
254 endif()
255 add_custom_command(TARGET ${BINARY_NAME}-qt POST_BUILD COMMAND ${CMAKE_SOURCE_DIR}/tools/deploy-mac.py ${DEPLOY_OPTIONS} ${PROJECT_NAME}.app)
256endif()