all repos — mgba @ 874ad93f4dba11722ccfb02aa7a3533777d8e03e

mGBA Game Boy Advance Emulator

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
 33find_package(Qt5Multimedia)
 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	AssetTile.cpp
 69	AssetView.cpp
 70	AudioProcessor.cpp
 71	CheatsModel.cpp
 72	CheatsView.cpp
 73	ConfigController.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	GamepadHatEvent.cpp
 84	IOViewer.cpp
 85	InputController.cpp
 86	InputProfile.cpp
 87	KeyEditor.cpp
 88	LoadSaveState.cpp
 89	LogController.cpp
 90	LogView.cpp
 91	MemoryModel.cpp
 92	MemoryView.cpp
 93	MessagePainter.cpp
 94	MultiplayerController.cpp
 95	ObjView.cpp
 96	OverrideView.cpp
 97	PaletteView.cpp
 98	ROMInfo.cpp
 99	SavestateButton.cpp
100	SensorView.cpp
101	SettingsView.cpp
102	ShaderSelector.cpp
103	ShortcutController.cpp
104	ShortcutView.cpp
105	Swatch.cpp
106	TilePainter.cpp
107	TileView.cpp
108	Window.cpp
109	VFileDevice.cpp
110	VideoView.cpp)
111
112set(UI_FILES
113	AboutScreen.ui
114	ArchiveInspector.ui
115	AssetTile.ui
116	CheatsView.ui
117	DebuggerConsole.ui
118	GIFView.ui
119	IOViewer.ui
120	LibraryView.ui
121	LoadSaveState.ui
122	LogView.ui
123	MemoryView.ui
124	ObjView.ui
125	OverrideView.ui
126	PaletteView.ui
127	ROMInfo.ui
128	SensorView.ui
129	SettingsView.ui
130	ShaderSelector.ui
131	ShortcutView.ui
132	TileView.ui
133	VideoView.ui)
134
135set(GBA_SRC
136	GBAOverride.cpp)
137
138set(GB_SRC
139	GBOverride.cpp)
140
141qt5_wrap_ui(UI_SRC ${UI_FILES})
142
143set(QT_LIBRARIES)
144set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5,libqt5network5")
145
146set(AUDIO_SRC)
147if(BUILD_SDL)
148	list(APPEND AUDIO_SRC AudioProcessorSDL.cpp)
149endif()
150
151if(M_CORE_GBA)
152	list(APPEND PLATFORM_SRC ${GBA_SRC})
153endif()
154
155if(M_CORE_GB)
156	list(APPEND PLATFORM_SRC ${GB_SRC})
157endif()
158
159set(QT_DEFINES)
160if(Qt5Multimedia_FOUND)
161	list(APPEND AUDIO_SRC
162		AudioProcessorQt.cpp
163		AudioDevice.cpp)
164	if (WIN32 AND QT_STATIC)
165		list(APPEND QT_LIBRARIES qtaudio_windows strmiids winmm)
166	endif()
167	list(APPEND QT_LIBRARIES Qt5::Multimedia)
168	list(APPEND QT_DEFINES BUILD_QT_MULTIMEDIA)
169	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
170endif()
171
172if(NOT AUDIO_SRC)
173	message(WARNING "No supported audio modules found")
174	set(BUILD_QT OFF PARENT_SCOPE)
175	return()
176endif()
177
178if(USE_DEBUGGERS)
179	list(APPEND SOURCE_FILES
180		DebuggerController.cpp
181		DebuggerConsole.cpp
182		DebuggerConsoleController.cpp)
183endif()
184
185if(USE_GDB_STUB)
186	list(APPEND SOURCE_FILES GDBController.cpp GDBWindow.cpp)
187endif()
188
189if(USE_SQLITE3)
190	list(APPEND SOURCE_FILES
191		ArchiveInspector.cpp
192		LibraryModel.cpp
193		LibraryView.cpp)
194endif()
195
196qt5_add_resources(RESOURCES resources.qrc)
197if(APPLE)
198	set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
199	set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
200	set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
201	set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
202	set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
203endif()
204if(WIN32)
205	configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
206	list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
207	set_source_files_properties(${CMAKE_BINARY_DIR}/res/mgba.rc PROPERTIES OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/res/mgba.ico)
208	if(QT_STATIC)
209		list(APPEND QT_LIBRARIES qwindows Qt5PlatformSupport imm32)
210	endif()
211endif()
212if(NOT DEFINED DATADIR)
213	if(APPLE)
214		set(DATADIR Applications/${PROJECT_NAME}.app/Contents/Resources)
215	else()
216		set(DATADIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME})
217	endif()
218endif()
219install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
220install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
221if(NOT WIN32 AND NOT APPLE)
222	list(APPEND QT_DEFINES DATADIR="${DATADIR}")
223endif()
224
225find_package(Qt5LinguistTools)
226if(Qt5LinguistTools_FOUND)
227	set(TRANSLATION_FILES)
228	set(TRANSLATION_QRC "${CMAKE_CURRENT_BINARY_DIR}/ts.qrc")
229	file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ts/${BINARY_NAME}-*.ts")
230	if(UPDATE_TRANSLATIONS)
231		qt5_create_translation(TRANSLATION_FILES ${SOURCE_FILES} ${UI_FILES} ${TS_FILES} OPTIONS -locations absolute -no-obsolete)
232	else()
233		qt5_add_translation(TRANSLATION_FILES ${TS_FILES})
234	endif()
235	add_custom_command(OUTPUT ${TRANSLATION_QRC}
236		               COMMAND ${CMAKE_COMMAND} -DTRANSLATION_QRC:FILEPATH="${TRANSLATION_QRC}" -DQM_BASE="${CMAKE_CURRENT_BINARY_DIR}" -P "${CMAKE_CURRENT_SOURCE_DIR}/ts.cmake"
237		               DEPENDS ${TRANSLATION_FILES})
238	qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
239	list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
240endif()
241
242add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_SRC} ${AUDIO_SRC} ${RESOURCES})
243set_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}")
244
245list(APPEND QT_LIBRARIES Qt5::Widgets Qt5::OpenGL Qt5::Network)
246target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
247set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
248
249install(TARGETS ${BINARY_NAME}-qt
250	RUNTIME DESTINATION bin COMPONENT ${BINARY_NAME}-qt
251	BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
252if(UNIX AND NOT APPLE)
253	find_program(DESKTOP_FILE_INSTALL desktop-file-install)
254	if(DESKTOP_FILE_INSTALL)
255		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/\")")
256	endif()
257endif()
258if(UNIX)
259	install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
260endif()
261if(APPLE OR WIN32)
262	set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
263endif()
264if(APPLE)
265	message(STATUS ${CMAKE_SYSTEM_NAME})
266	if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
267		get_target_property(QTCOCOA Qt5::QCocoaIntegrationPlugin LOCATION)
268		get_target_property(COREAUDIO Qt5::CoreAudioPlugin LOCATION)
269		get_target_property(BUNDLE_PATH ${BINARY_NAME}-qt LOCATION)
270		target_sources(${BINARY_NAME}-qt PRIVATE "${PLUGINS}")
271		set_source_files_properties("${QTCOCOA}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
272		set_source_files_properties("${COREAUDIO}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
273		install(CODE "
274		   include(BundleUtilities)
275		   set(BU_CHMOD_BUNDLE_ITEMS ON)
276		   file(GLOB_RECURSE PLUGINS \"${BUNDLE_PATH}/Contents/PlugIns/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
277		   fixup_bundle(\"${BUNDLE_PATH}\"   \"${PLUGINS}\"   \"\")
278		   " COMPONENT ${BINARY_NAME}-qt)
279	else()
280		set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib)
281		if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
282			set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I "${CMAKE_INSTALL_NAME_TOOL}")
283		endif()
284		if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
285			set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O "${CMAKE_OTOOL}")
286		endif()
287		if(DEFINED CROSS_ROOT)
288			set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R "${CROSS_ROOT}")
289		endif()
290		install(CODE "execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/tools/deploy-mac.py\" -v ${DEPLOY_OPTIONS} \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/Applications/${PROJECT_NAME}.app\")")
291	endif()
292endif()