src/platform/qt/CMakeLists.txt (view raw)
1cmake_minimum_required(VERSION 2.8.11)
2enable_language(CXX)
3
4set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11")
5
6if(APPLE)
7 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.7")
8 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
9 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
10 endif()
11endif()
12
13set(PLATFORM_SRC)
14set(QT_STATIC OFF)
15
16if(BUILD_SDL)
17 if(NOT SDL_FOUND AND NOT SDL2_FOUND)
18 find_package(SDL 1.2 REQUIRED)
19 endif()
20 if(SDL2_FOUND)
21 link_directories(${SDL2_LIBDIR})
22 endif()
23 list(APPEND PLATFORM_LIBRARY ${SDL_LIBRARY} ${SDLMAIN_LIBRARY})
24 list(APPEND PLATFORM_SRC ${PLATFORM_SRC} ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-events.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-audio.c)
25 include_directories(${SDL_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src/platform/sdl)
26endif()
27
28set(CMAKE_AUTOMOC ON)
29set(CMAKE_INCLUDE_CURRENT_DIR ON)
30
31if(NOT WIN32 OR NOT BUILD_SDL)
32 find_package(Qt5Multimedia)
33endif()
34find_package(Qt5OpenGL)
35find_package(Qt5Widgets)
36
37if(NOT BUILD_GL AND NOT BUILD_GLES2)
38 message(WARNING "OpenGL is required to build the Qt port")
39 set(BUILD_QT OFF PARENT_SCOPE)
40 return()
41endif()
42
43if(NOT Qt5OpenGL_FOUND OR NOT Qt5Widgets_FOUND)
44 message(WARNING "Cannot find Qt modules")
45 set(BUILD_QT OFF PARENT_SCOPE)
46 return()
47endif()
48
49if(BUILD_GL)
50 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gl.c)
51 if(NOT WIN32 OR USE_EPOXY)
52 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
53 endif()
54endif()
55
56if(BUILD_GLES2)
57 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
58endif()
59
60get_target_property(QT_TYPE Qt5::Core TYPE)
61if(QT_TYPE STREQUAL STATIC_LIBRARY)
62 set(QT_STATIC ON)
63 list(APPEND QT_DEFINES QT_STATIC)
64endif()
65
66set(SOURCE_FILES
67 AboutScreen.cpp
68 AudioProcessor.cpp
69 CheatsModel.cpp
70 CheatsView.cpp
71 ConfigController.cpp
72 DatDownloadView.cpp
73 Display.cpp
74 DisplayGL.cpp
75 DisplayQt.cpp
76 GBAApp.cpp
77 GBAKeyEditor.cpp
78 GIFView.cpp
79 GameController.cpp
80 GamepadAxisEvent.cpp
81 GamepadButtonEvent.cpp
82 IOViewer.cpp
83 InputController.cpp
84 InputProfile.cpp
85 KeyEditor.cpp
86 LoadSaveState.cpp
87 LogController.cpp
88 LogView.cpp
89 MemoryModel.cpp
90 MemoryView.cpp
91 MessagePainter.cpp
92 MultiplayerController.cpp
93 OverrideView.cpp
94 PaletteView.cpp
95 ROMInfo.cpp
96 SavestateButton.cpp
97 SensorView.cpp
98 SettingsView.cpp
99 ShaderSelector.cpp
100 ShortcutController.cpp
101 ShortcutView.cpp
102 Swatch.cpp
103 Window.cpp
104 VFileDevice.cpp
105 VideoView.cpp)
106
107qt5_wrap_ui(UI_FILES
108 AboutScreen.ui
109 CheatsView.ui
110 DatDownloadView.ui
111 GIFView.ui
112 IOViewer.ui
113 LoadSaveState.ui
114 LogView.ui
115 MemoryView.ui
116 OverrideView.ui
117 PaletteView.ui
118 ROMInfo.ui
119 SensorView.ui
120 SettingsView.ui
121 ShaderSelector.ui
122 ShortcutView.ui
123 VideoView.ui)
124
125set(QT_LIBRARIES)
126set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5")
127
128set(AUDIO_SRC)
129if(BUILD_SDL)
130 list(APPEND AUDIO_SRC AudioProcessorSDL.cpp)
131endif()
132
133set(QT_DEFINES)
134if(Qt5Multimedia_FOUND)
135 list(APPEND AUDIO_SRC
136 AudioProcessorQt.cpp
137 AudioDevice.cpp)
138 if (WIN32 AND QT_STATIC)
139 list(APPEND QT_LIBRARIES qtaudio_windows strmiids winmm)
140 endif()
141 list(APPEND QT_LIBRARIES Qt5::Multimedia)
142 list(APPEND QT_DEFINES BUILD_QT_MULTIMEDIA)
143 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
144endif()
145
146if(NOT AUDIO_SRC)
147 message(WARNING "No supported audio modules found")
148 set(BUILD_QT OFF PARENT_SCOPE)
149 return()
150endif()
151
152if(USE_GDB_STUB)
153 list(APPEND PLATFORM_SRC GDBController.cpp GDBWindow.cpp)
154endif()
155set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
156set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
157set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
158set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
159set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
160
161qt5_add_resources(RESOURCES resources.qrc)
162if(WIN32)
163 configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
164 list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
165 if(QT_STATIC)
166 list(APPEND QT_LIBRARIES qwindows imm32)
167 endif()
168endif()
169if(APPLE)
170 set(SHADER_DIR Applications/${PROJECT_NAME}.app/Contents/Resources)
171else()
172 set(SHADER_DIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME})
173endif()
174install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${SHADER_DIR} COMPONENT ${BINARY_NAME}-qt)
175if(NOT WIN32 AND NOT APPLE)
176 list(APPEND QT_DEFINES QT_SHADER_DIR="${SHADER_DIR}/shaders")
177endif()
178
179add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_FILES} ${AUDIO_SRC} ${RESOURCES})
180set_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}")
181
182list(APPEND QT_LIBRARIES Qt5::Widgets Qt5::OpenGL)
183target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
184set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
185
186install(TARGETS ${BINARY_NAME}-qt
187 RUNTIME DESTINATION bin COMPONENT ${BINARY_NAME}-qt
188 BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
189if(UNIX AND NOT APPLE)
190 find_program(DESKTOP_FILE_INSTALL desktop-file-install)
191 if(DESKTOP_FILE_INSTALL)
192 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/\")")
193 endif()
194endif()
195if(UNIX)
196 install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
197endif()
198if(APPLE OR WIN32)
199 set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
200endif()
201if(APPLE)
202 set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib)
203 if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
204 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I ${CMAKE_INSTALL_NAME_TOOL})
205 endif()
206 if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
207 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O ${CMAKE_OTOOL})
208 endif()
209 if(DEFINED CROSS_ROOT)
210 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R ${CROSS_ROOT})
211 endif()
212 add_custom_command(TARGET ${BINARY_NAME}-qt POST_BUILD COMMAND ${CMAKE_SOURCE_DIR}/tools/deploy-mac.py ${DEPLOY_OPTIONS} ${PROJECT_NAME}.app)
213endif()