all repos — mgba @ bfb674fb4f42fd7050257aeb196c3831ab89feb0

mGBA Game Boy Advance Emulator

src/platform/qt/CMakeLists.txt (view raw)

  1set(CMAKE_CXX_STANDARD 14)
  2set(CMAKE_CXX_STANDARD_REQUIRED ON)
  3set(CMAKE_CXX_EXTENSIONS OFF)
  4
  5set(PLATFORM_SRC)
  6set(QT_STATIC OFF)
  7
  8if(BUILD_SDL)
  9	if(NOT SDL_FOUND AND NOT SDL2_FOUND)
 10		find_package(SDL 1.2 REQUIRED)
 11	endif()
 12	if(SDL2_FOUND)
 13		link_directories(${SDL2_LIBDIR})
 14	endif()
 15	list(APPEND PLATFORM_LIBRARY ${SDL_LIBRARY})
 16	list(APPEND PLATFORM_SRC ${PLATFORM_SRC} ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-events.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-audio.c)
 17	include_directories(${SDL_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src/platform/sdl)
 18endif()
 19
 20set(CMAKE_AUTOMOC ON)
 21set(CMAKE_INCLUDE_CURRENT_DIR ON)
 22
 23find_package(Qt5Multimedia)
 24find_package(Qt5OpenGL)
 25find_package(Qt5Widgets)
 26
 27if(NOT BUILD_GL AND NOT BUILD_GLES2)
 28	message(WARNING "OpenGL is recommended to build the Qt port")
 29endif()
 30
 31if(NOT Qt5Widgets_FOUND)
 32	message(WARNING "Cannot find Qt modules")
 33	set(BUILD_QT OFF PARENT_SCOPE)
 34	return()
 35endif()
 36
 37if(APPLE)
 38	if(Qt5Widgets_VERSION MATCHES "^5.1[0-9]")
 39		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.8")
 40	else()
 41		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.7")
 42	endif()
 43	if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
 44		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
 45	endif()
 46endif()
 47
 48if(BUILD_GL)
 49	list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gl.c)
 50	if(NOT WIN32 OR USE_EPOXY)
 51		list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
 52	endif()
 53endif()
 54
 55if(BUILD_GLES2)
 56	list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
 57endif()
 58
 59get_target_property(QT_TYPE Qt5::Core TYPE)
 60if(QT_TYPE STREQUAL STATIC_LIBRARY)
 61	set(QT_STATIC ON)
 62	list(APPEND QT_DEFINES QT_STATIC)
 63endif()
 64
 65set(SOURCE_FILES
 66	AboutScreen.cpp
 67	AssetTile.cpp
 68	AssetView.cpp
 69	AudioProcessor.cpp
 70	CheatsModel.cpp
 71	CheatsView.cpp
 72	ConfigController.cpp
 73	ColorPicker.cpp
 74	CoreManager.cpp
 75	CoreController.cpp
 76	Display.cpp
 77	DisplayGL.cpp
 78	DisplayQt.cpp
 79	GBAApp.cpp
 80	GBAKeyEditor.cpp
 81	GIFView.cpp
 82	GamepadAxisEvent.cpp
 83	GamepadButtonEvent.cpp
 84	GamepadHatEvent.cpp
 85	IOViewer.cpp
 86	InputController.cpp
 87	InputProfile.cpp
 88	KeyEditor.cpp
 89	LoadSaveState.cpp
 90	LogController.cpp
 91	LogView.cpp
 92	MapView.cpp
 93	MemoryModel.cpp
 94	MemorySearch.cpp
 95	MemoryView.cpp
 96	MessagePainter.cpp
 97	MultiplayerController.cpp
 98	ObjView.cpp
 99	OverrideView.cpp
100	PaletteView.cpp
101	PrinterView.cpp
102	ROMInfo.cpp
103	SavestateButton.cpp
104	SensorView.cpp
105	SettingsView.cpp
106	ShaderSelector.cpp
107	ShortcutController.cpp
108	ShortcutView.cpp
109	Swatch.cpp
110	TilePainter.cpp
111	TileView.cpp
112	utils.cpp
113	Window.cpp
114	VFileDevice.cpp
115	VideoView.cpp)
116
117set(UI_FILES
118	AboutScreen.ui
119	ArchiveInspector.ui
120	AssetTile.ui
121	CheatsView.ui
122	DebuggerConsole.ui
123	GIFView.ui
124	IOViewer.ui
125	LoadSaveState.ui
126	LogView.ui
127	MapView.ui
128	MemorySearch.ui
129	MemoryView.ui
130	ObjView.ui
131	OverrideView.ui
132	PaletteView.ui
133	PrinterView.ui
134	ROMInfo.ui
135	SensorView.ui
136	SettingsView.ui
137	ShaderSelector.ui
138	ShortcutView.ui
139	TileView.ui
140	VideoView.ui)
141
142set(GBA_SRC
143	GBAOverride.cpp)
144
145set(GB_SRC
146	GBOverride.cpp)
147
148set(QT_LIBRARIES)
149set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5")
150
151set(AUDIO_SRC)
152if(BUILD_SDL)
153	list(APPEND AUDIO_SRC AudioProcessorSDL.cpp)
154endif()
155
156if(M_CORE_GBA)
157	list(APPEND PLATFORM_SRC ${GBA_SRC})
158endif()
159
160if(M_CORE_GB)
161	list(APPEND PLATFORM_SRC ${GB_SRC})
162endif()
163
164set(QT_DEFINES)
165if(Qt5Multimedia_FOUND)
166	list(APPEND AUDIO_SRC
167		AudioProcessorQt.cpp
168		AudioDevice.cpp)
169	list(APPEND SOURCE_FILES
170		VideoDumper.cpp)
171	if (WIN32 AND QT_STATIC)
172		list(APPEND QT_LIBRARIES Qt5::QWindowsAudioPlugin Qt5::DSServicePlugin
173                                 strmiids winmm mfuuid mfplat mf ksguid dxva2 evr d3d9)
174	endif()
175	list(APPEND QT_LIBRARIES Qt5::Multimedia)
176	list(APPEND QT_DEFINES BUILD_QT_MULTIMEDIA)
177	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
178endif()
179
180if(NOT AUDIO_SRC)
181	message(WARNING "No supported audio modules found")
182	set(BUILD_QT OFF PARENT_SCOPE)
183	return()
184endif()
185
186if(USE_DEBUGGERS)
187	list(APPEND SOURCE_FILES
188		DebuggerController.cpp
189		DebuggerConsole.cpp
190		DebuggerConsoleController.cpp)
191endif()
192
193if(USE_GDB_STUB)
194	list(APPEND SOURCE_FILES GDBController.cpp GDBWindow.cpp)
195endif()
196
197if(USE_SQLITE3)
198	list(APPEND SOURCE_FILES
199		ArchiveInspector.cpp
200		library/LibraryController.cpp
201		library/LibraryGrid.cpp
202		library/LibraryTree.cpp)
203endif()
204
205qt5_add_resources(RESOURCES resources.qrc)
206if(APPLE)
207	set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
208	set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
209	set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
210	set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
211	set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
212endif()
213if(WIN32)
214	configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
215	list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
216	set_source_files_properties(${CMAKE_BINARY_DIR}/res/mgba.rc PROPERTIES OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/res/mgba.ico)
217	if(QT_STATIC)
218		list(APPEND QT_LIBRARIES qwindows Qt5PlatformSupport imm32)
219	endif()
220endif()
221if(NOT DEFINED DATADIR)
222	if(APPLE)
223		set(DATADIR Applications/${PROJECT_NAME}.app/Contents/Resources)
224	else()
225		set(DATADIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME})
226	endif()
227endif()
228if(BUILD_GL OR BUILD_GLES2)
229	install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
230endif()
231install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
232if(NOT WIN32 AND NOT APPLE)
233	list(APPEND QT_DEFINES DATADIR="${CMAKE_INSTALL_PREFIX}/${DATADIR}")
234endif()
235
236find_package(Qt5LinguistTools)
237if(Qt5LinguistTools_FOUND)
238	set(TRANSLATION_FILES)
239	set(TRANSLATION_QRC "${CMAKE_CURRENT_BINARY_DIR}/ts.qrc")
240	file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ts/${BINARY_NAME}-*.ts")
241	if(UPDATE_TRANSLATIONS)
242		qt5_create_translation(TRANSLATION_FILES ${SOURCE_FILES} ${UI_FILES} ${TS_FILES} OPTIONS -locations absolute -no-obsolete)
243	else()
244		qt5_add_translation(TRANSLATION_FILES ${TS_FILES})
245	endif()
246	set(QT_QM_FILES)
247	if(QT_STATIC)
248		get_target_property(QT_CORE_LOCATION Qt5::Core LOCATION)
249		get_filename_component(QT_CORE_LOCATION ${QT_CORE_LOCATION} DIRECTORY)
250		get_filename_component(QT_QM_LOCATION "${QT_CORE_LOCATION}/../translations" ABSOLUTE)
251		foreach(TS ${TS_FILES})
252			get_filename_component(TS ${TS} NAME)
253			string(REGEX REPLACE "${BINARY_NAME}-(.*).ts$" "qtbase_\\1.qm" QT_QM "${TS}")
254			list(APPEND QT_QM_FILES "${QT_QM_LOCATION}/${QT_QM}")
255		endforeach()
256		list(APPEND TRANSLATION_FILES ${QT_QM_FILES})
257	endif()
258	add_custom_command(OUTPUT ${TRANSLATION_QRC}
259		               COMMAND ${CMAKE_COMMAND} -DTRANSLATION_QRC:FILEPATH="${TRANSLATION_QRC}" -DQM_BASE="${CMAKE_CURRENT_BINARY_DIR}" "-DTRANSLATION_FILES='${TRANSLATION_FILES}'" -P "${CMAKE_CURRENT_SOURCE_DIR}/ts.cmake"
260		               DEPENDS ${TRANSLATION_FILES})
261	qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
262	list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
263endif()
264
265qt5_wrap_ui(UI_SRC ${UI_FILES})
266
267add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_SRC} ${AUDIO_SRC} ${RESOURCES})
268set_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}")
269
270list(APPEND QT_LIBRARIES Qt5::Widgets)
271if(BUILD_GL OR BUILD_GLES2)
272	list(APPEND QT_LIBRARIES Qt5::OpenGL ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
273endif()
274target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES})
275set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
276
277install(TARGETS ${BINARY_NAME}-qt
278	RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-qt
279	BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
280if(UNIX AND NOT APPLE)
281	find_program(DESKTOP_FILE_INSTALL desktop-file-install)
282	if(DESKTOP_FILE_INSTALL)
283		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/\")")
284	endif()
285endif()
286if(UNIX)
287	install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
288endif()
289if(APPLE OR WIN32)
290	set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
291endif()
292if(APPLE)
293	if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
294		get_target_property(QTCOCOA Qt5::QCocoaIntegrationPlugin LOCATION)
295		get_target_property(COREAUDIO Qt5::CoreAudioPlugin LOCATION)
296		get_target_property(QTAVFSERVICE Qt5::AVFServicePlugin LOCATION)
297		set(BUNDLE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.app)
298		target_sources(${BINARY_NAME}-qt PRIVATE "${PLUGINS}")
299		set_source_files_properties("${QTCOCOA}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
300		set_source_files_properties("${COREAUDIO}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
301		set_source_files_properties("${QTAVFSERVICE}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
302		install(CODE "
303		   include(BundleUtilities)
304		   set(BU_CHMOD_BUNDLE_ITEMS ON)
305		   file(GLOB_RECURSE PLUGINS \"${BUNDLE_PATH}/Contents/PlugIns/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
306		   fixup_bundle(\"${BUNDLE_PATH}\"   \"${PLUGINS}\"   \"\")
307		   " COMPONENT ${BINARY_NAME}-qt)
308	else()
309		set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib,mediaservice/libqavfcamera.dylib)
310		if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
311			set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I "${CMAKE_INSTALL_NAME_TOOL}")
312		endif()
313		if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
314			set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O "${CMAKE_OTOOL}")
315		endif()
316		if(DEFINED CROSS_ROOT)
317			set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R "${CROSS_ROOT}")
318		endif()
319		install(CODE "execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/tools/deploy-mac.py\" -v ${DEPLOY_OPTIONS} \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/Applications/${PROJECT_NAME}.app\")")
320	endif()
321endif()
322if(WIN32 AND CMAKE_MAJOR_VERSION GREATER 2 AND CMAKE_MINOR_VERSION GREATER 7)
323	# Work around CMake issue #16907
324	set_target_properties(${BINARY_NAME}-qt PROPERTIES AUTORCC ON SKIP_AUTORCC ON)
325endif()