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
31find_package(Qt5Multimedia)
32find_package(Qt5OpenGL)
33find_package(Qt5Widgets)
34
35if(NOT Qt5OpenGL_FOUND OR NOT Qt5Widgets_FOUND OR NOT OPENGL_FOUND)
36 message(WARNING "Cannot find Qt modules")
37 set(BUILD_QT OFF PARENT_SCOPE)
38 return()
39endif()
40
41list(APPEND PLATFORM_SRC ${PLATFORM_SRC} ${CMAKE_SOURCE_DIR}/src/platform/opengl/gl.c)
42
43get_target_property(QT_TYPE Qt5::Core TYPE)
44if(QT_TYPE STREQUAL STATIC_LIBRARY)
45 set(QT_STATIC ON)
46 add_definitions(-DQT_STATIC)
47endif()
48
49set(SOURCE_FILES
50 AboutScreen.cpp
51 AudioProcessor.cpp
52 CheatsModel.cpp
53 CheatsView.cpp
54 ConfigController.cpp
55 Display.cpp
56 DisplayGL.cpp
57 DisplayQt.cpp
58 GBAApp.cpp
59 GBAKeyEditor.cpp
60 GIFView.cpp
61 GameController.cpp
62 GamepadAxisEvent.cpp
63 GamepadButtonEvent.cpp
64 InputController.cpp
65 InputProfile.cpp
66 KeyEditor.cpp
67 LoadSaveState.cpp
68 LogController.cpp
69 LogView.cpp
70 MemoryModel.cpp
71 MemoryView.cpp
72 MessagePainter.cpp
73 MultiplayerController.cpp
74 OverrideView.cpp
75 PaletteView.cpp
76 SavestateButton.cpp
77 SensorView.cpp
78 SettingsView.cpp
79 ShortcutController.cpp
80 ShortcutView.cpp
81 Swatch.cpp
82 Window.cpp
83 VFileDevice.cpp
84 VideoView.cpp)
85
86qt5_wrap_ui(UI_FILES
87 AboutScreen.ui
88 CheatsView.ui
89 GIFView.ui
90 LoadSaveState.ui
91 LogView.ui
92 MemoryView.ui
93 OverrideView.ui
94 PaletteView.ui
95 SensorView.ui
96 SettingsView.ui
97 ShortcutView.ui
98 VideoView.ui)
99
100set(QT_LIBRARIES)
101set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5")
102
103set(AUDIO_SRC)
104if(BUILD_SDL)
105 list(APPEND AUDIO_SRC AudioProcessorSDL.cpp)
106endif()
107
108if(Qt5Multimedia_FOUND)
109 list(APPEND AUDIO_SRC
110 AudioProcessorQt.cpp
111 AudioDevice.cpp)
112 if (WIN32 AND QT_STATIC)
113 list(APPEND QT_LIBRARIES qtaudio_windows strmiids winmm)
114 endif()
115 list(APPEND QT_LIBRARIES Qt5::Multimedia)
116 add_definitions(-DBUILD_QT_MULTIMEDIA)
117 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
118endif()
119
120if(NOT AUDIO_SRC)
121 message(WARNING "No supported audio modules found")
122 set(BUILD_QT OFF PARENT_SCOPE)
123 return()
124endif()
125
126if(USE_GDB_STUB)
127 list(APPEND PLATFORM_SRC GDBController.cpp GDBWindow.cpp)
128endif()
129set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
130set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
131set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
132set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
133set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
134
135qt5_add_resources(RESOURCES resources.qrc)
136if(WIN32)
137 configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
138 list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
139 if(QT_STATIC)
140 list(APPEND QT_LIBRARIES qwindows imm32)
141 endif()
142endif()
143add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_FILES} ${AUDIO_SRC} ${RESOURCES})
144set_target_properties(${BINARY_NAME}-qt PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/res/info.plist.in COMPILE_DEFINITIONS "${FEATURE_DEFINES}")
145
146list(APPEND QT_LIBRARIES Qt5::Widgets Qt5::OpenGL)
147target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${OPENGL_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES})
148set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
149
150install(TARGETS ${BINARY_NAME}-qt
151 RUNTIME DESTINATION bin COMPONENT ${BINARY_NAME}-qt
152 BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
153if(UNIX AND NOT APPLE)
154 find_program(DESKTOP_FILE_INSTALL desktop-file-install)
155 if(DESKTOP_FILE_INSTALL)
156 install(CODE "execute_process(COMMAND ${DESKTOP_FILE_INSTALL} \"${CMAKE_SOURCE_DIR}/res/mgba-qt.desktop\" --dir \"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/share/applications/\")")
157 endif()
158endif()
159if(APPLE OR WIN32)
160 set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
161endif()
162if(APPLE)
163 set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib)
164 if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
165 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I ${CMAKE_INSTALL_NAME_TOOL})
166 endif()
167 if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
168 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O ${CMAKE_OTOOL})
169 endif()
170 if(DEFINED CROSS_ROOT)
171 set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R ${CROSS_ROOT})
172 endif()
173 add_custom_command(TARGET ${BINARY_NAME}-qt POST_BUILD COMMAND ${CMAKE_SOURCE_DIR}/tools/deploy-mac.py ${DEPLOY_OPTIONS} ${PROJECT_NAME}.app)
174endif()