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
113qt5_wrap_ui(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(QT_LIBRARIES)
133set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5,libqt5network5")
134
135set(AUDIO_SRC)
136if(BUILD_SDL)
137 list(APPEND AUDIO_SRC AudioProcessorSDL.cpp)
138endif()
139
140set(QT_DEFINES)
141if(Qt5Multimedia_FOUND)
142 list(APPEND AUDIO_SRC
143 AudioProcessorQt.cpp
144 AudioDevice.cpp)
145 if (WIN32 AND QT_STATIC)
146 list(APPEND QT_LIBRARIES qtaudio_windows strmiids winmm)
147 endif()
148 list(APPEND QT_LIBRARIES Qt5::Multimedia)
149 list(APPEND QT_DEFINES BUILD_QT_MULTIMEDIA)
150 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
151endif()
152
153if(NOT AUDIO_SRC)
154 message(WARNING "No supported audio modules found")
155 set(BUILD_QT OFF PARENT_SCOPE)
156 return()
157endif()
158
159if(USE_GDB_STUB)
160 list(APPEND PLATFORM_SRC GDBController.cpp GDBWindow.cpp)
161endif()
162set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
163set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
164set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
165set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
166set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
167
168qt5_add_resources(RESOURCES resources.qrc)
169if(WIN32)
170 configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
171 list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
172 if(QT_STATIC)
173 list(APPEND QT_LIBRARIES qwindows imm32)
174 endif()
175endif()
176if(NOT DEFINED DATADIR)
177 if(APPLE)
178 set(DATADIR Applications/${PROJECT_NAME}.app/Contents/Resources)
179 else()
180 set(DATADIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME})
181 endif()
182endif()
183install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
184install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
185if(NOT WIN32 AND NOT APPLE)
186 list(APPEND QT_DEFINES DATADIR="${DATADIR}")
187endif()
188
189find_package(Qt5LinguistTools)
190if(Qt5LinguistTools_FOUND)
191 set(TRANSLATION_FILES)
192 set(TRANSLATION_QRC "${CMAKE_CURRENT_BINARY_DIR}/ts.qrc")
193 file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ts/${BINARY_NAME}-*.ts")
194 if(UPDATE_TRANSLATIONS)
195 qt5_create_translation(TRANSLATION_FILES ${SOURCE_FILES} ${UI_FILES} ${TS_FILES})
196 else()
197 qt5_add_translation(TRANSLATION_FILES ${TS_FILES})
198 endif()
199 add_custom_command(OUTPUT ${TRANSLATION_QRC}
200 COMMAND ${CMAKE_COMMAND} -DTRANSLATION_QRC:FILEPATH="${TRANSLATION_QRC}" -DTRANSLATION_FILES="${TRANSLATION_FILES}" -P "${CMAKE_CURRENT_SOURCE_DIR}/ts.cmake"
201 DEPENDS ${TRANSLATION_FILES})
202 qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
203 list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
204endif()
205
206add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_FILES} ${AUDIO_SRC} ${RESOURCES})
207set_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}")
208
209list(APPEND QT_LIBRARIES Qt5::Widgets Qt5::OpenGL Qt5::Network)
210target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
211set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
212
213install(TARGETS ${BINARY_NAME}-qt
214 RUNTIME DESTINATION bin COMPONENT ${BINARY_NAME}-qt
215 BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
216if(UNIX AND NOT APPLE)
217 find_program(DESKTOP_FILE_INSTALL desktop-file-install)
218 if(DESKTOP_FILE_INSTALL)
219 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/\")")
220 endif()
221endif()
222if(UNIX)
223 install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
224endif()
225if(APPLE OR WIN32)
226 set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
227endif()
228if(APPLE)
229 set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib)
230 if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
231 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I ${CMAKE_INSTALL_NAME_TOOL})
232 endif()
233 if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
234 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O ${CMAKE_OTOOL})
235 endif()
236 if(DEFINED CROSS_ROOT)
237 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R ${CROSS_ROOT})
238 endif()
239 add_custom_command(TARGET ${BINARY_NAME}-qt POST_BUILD COMMAND ${CMAKE_SOURCE_DIR}/tools/deploy-mac.py ${DEPLOY_OPTIONS} ${PROJECT_NAME}.app)
240endif()