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)
50list(APPEND PLATFORM_SRC ${PLATFORM_SRC} ${CMAKE_SOURCE_DIR}/src/platform/opengl/gl.c)
51endif()
52
53if(BUILD_GLES2)
54list(APPEND PLATFORM_SRC ${PLATFORM_SRC} ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
55endif()
56
57get_target_property(QT_TYPE Qt5::Core TYPE)
58if(QT_TYPE STREQUAL STATIC_LIBRARY)
59 set(QT_STATIC ON)
60 add_definitions(-DQT_STATIC)
61endif()
62
63set(SOURCE_FILES
64 AboutScreen.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 IOViewer.cpp
79 InputController.cpp
80 InputProfile.cpp
81 KeyEditor.cpp
82 LoadSaveState.cpp
83 LogController.cpp
84 LogView.cpp
85 MemoryModel.cpp
86 MemoryView.cpp
87 MessagePainter.cpp
88 MultiplayerController.cpp
89 OverrideView.cpp
90 PaletteView.cpp
91 SavestateButton.cpp
92 SensorView.cpp
93 SettingsView.cpp
94 ShortcutController.cpp
95 ShortcutView.cpp
96 Swatch.cpp
97 Window.cpp
98 VFileDevice.cpp
99 VideoView.cpp)
100
101qt5_wrap_ui(UI_FILES
102 AboutScreen.ui
103 CheatsView.ui
104 GIFView.ui
105 IOViewer.ui
106 LoadSaveState.ui
107 LogView.ui
108 MemoryView.ui
109 OverrideView.ui
110 PaletteView.ui
111 SensorView.ui
112 SettingsView.ui
113 ShortcutView.ui
114 VideoView.ui)
115
116set(QT_LIBRARIES)
117set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5")
118
119set(AUDIO_SRC)
120if(BUILD_SDL)
121 list(APPEND AUDIO_SRC AudioProcessorSDL.cpp)
122endif()
123
124if(Qt5Multimedia_FOUND)
125 list(APPEND AUDIO_SRC
126 AudioProcessorQt.cpp
127 AudioDevice.cpp)
128 if (WIN32 AND QT_STATIC)
129 list(APPEND QT_LIBRARIES qtaudio_windows strmiids winmm)
130 endif()
131 list(APPEND QT_LIBRARIES Qt5::Multimedia)
132 add_definitions(-DBUILD_QT_MULTIMEDIA)
133 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
134endif()
135
136if(NOT AUDIO_SRC)
137 message(WARNING "No supported audio modules found")
138 set(BUILD_QT OFF PARENT_SCOPE)
139 return()
140endif()
141
142if(USE_GDB_STUB)
143 list(APPEND PLATFORM_SRC GDBController.cpp GDBWindow.cpp)
144endif()
145set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
146set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
147set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
148set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
149set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
150
151qt5_add_resources(RESOURCES resources.qrc)
152if(WIN32)
153 configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
154 list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
155 if(QT_STATIC)
156 list(APPEND QT_LIBRARIES qwindows imm32)
157 endif()
158endif()
159add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_FILES} ${AUDIO_SRC} ${RESOURCES})
160set_target_properties(${BINARY_NAME}-qt PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/res/info.plist.in COMPILE_DEFINITIONS "${FEATURE_DEFINES};${FUNCTION_DEFINES}")
161
162list(APPEND QT_LIBRARIES Qt5::Widgets Qt5::OpenGL)
163target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
164set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
165
166install(TARGETS ${BINARY_NAME}-qt
167 RUNTIME DESTINATION bin COMPONENT ${BINARY_NAME}-qt
168 BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
169if(UNIX AND NOT APPLE)
170 find_program(DESKTOP_FILE_INSTALL desktop-file-install)
171 if(DESKTOP_FILE_INSTALL)
172 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/\")")
173 endif()
174endif()
175if(UNIX)
176 install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
177endif()
178if(APPLE OR WIN32)
179 set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
180endif()
181if(APPLE)
182 set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib)
183 if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
184 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I ${CMAKE_INSTALL_NAME_TOOL})
185 endif()
186 if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
187 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O ${CMAKE_OTOOL})
188 endif()
189 if(DEFINED CROSS_ROOT)
190 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R ${CROSS_ROOT})
191 endif()
192 add_custom_command(TARGET ${BINARY_NAME}-qt POST_BUILD COMMAND ${CMAKE_SOURCE_DIR}/tools/deploy-mac.py ${DEPLOY_OPTIONS} ${PROJECT_NAME}.app)
193endif()