all repos — mgba @ 6b2eaed35ace3f2a71990fb90b2b22ff97c371e2

mGBA Game Boy Advance Emulator

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