all repos — mgba @ 8219b70c2eb34cd6eb3dbe6e1ccaea7f4d01f81f

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	add_definitions(-DBUILD_SDL)
 10	if(SDL2_FOUND)
 11		link_directories(${SDL2_LIBDIR})
 12	endif()
 13	list(APPEND PLATFORM_LIBRARY ${SDL_LIBRARY})
 14	list(APPEND PLATFORM_SRC ${PLATFORM_SRC} ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-events.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-audio.c)
 15	include_directories(${SDL_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src/platform/sdl)
 16endif()
 17
 18if(POLICY CMP0071)
 19	cmake_policy(SET CMP0071 OLD)
 20endif()
 21
 22set(CMAKE_AUTOMOC ON)
 23set(CMAKE_INCLUDE_CURRENT_DIR ON)
 24
 25find_package(Qt5 COMPONENTS Core Widgets OpenGL Network Multimedia)
 26
 27if(NOT BUILD_GL AND NOT BUILD_GLES2)
 28	message(WARNING "OpenGL is recommended to build the Qt port")
 29endif()
 30
 31set(FOUND_QT ${Qt5Widgets_FOUND} PARENT_SCOPE)
 32if(NOT Qt5Widgets_FOUND)
 33	message(WARNING "Cannot find Qt modules")
 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
 48get_target_property(QT_TYPE Qt5::Core TYPE)
 49if(QT_TYPE STREQUAL STATIC_LIBRARY)
 50	set(QT_STATIC ON)
 51	list(APPEND QT_DEFINES QT_STATIC)
 52endif()
 53
 54set(SOURCE_FILES
 55	AboutScreen.cpp
 56	AbstractUpdater.cpp
 57	Action.cpp
 58	ActionMapper.cpp
 59	AssetInfo.cpp
 60	AssetTile.cpp
 61	AssetView.cpp
 62	AudioProcessor.cpp
 63	CheatsModel.cpp
 64	CheatsView.cpp
 65	ConfigController.cpp
 66	ColorPicker.cpp
 67	CoreManager.cpp
 68	CoreController.cpp
 69	Display.cpp
 70	DisplayGL.cpp
 71	DisplayQt.cpp
 72	FrameView.cpp
 73	GBAApp.cpp
 74	GBAKeyEditor.cpp
 75	GIFView.cpp
 76	GamepadAxisEvent.cpp
 77	GamepadButtonEvent.cpp
 78	GamepadHatEvent.cpp
 79	IOViewer.cpp
 80	InputController.cpp
 81	InputProfile.cpp
 82	KeyEditor.cpp
 83	LoadSaveState.cpp
 84	LogController.cpp
 85	LogConfigModel.cpp
 86	LogView.cpp
 87	MapView.cpp
 88	MemoryModel.cpp
 89	MemorySearch.cpp
 90	MemoryView.cpp
 91	MessagePainter.cpp
 92	MultiplayerController.cpp
 93	ObjView.cpp
 94	OverrideView.cpp
 95	PaletteView.cpp
 96	PlacementControl.cpp
 97	RegisterView.cpp
 98	ROMInfo.cpp
 99	RotatedHeaderView.cpp
100	SavestateButton.cpp
101	SensorView.cpp
102	SettingsView.cpp
103	ShaderSelector.cpp
104	ShortcutController.cpp
105	ShortcutModel.cpp
106	ShortcutView.cpp
107	Swatch.cpp
108	TilePainter.cpp
109	TileView.cpp
110	utils.cpp
111	Window.cpp
112	VFileDevice.cpp
113	VideoProxy.cpp
114	VideoView.cpp)
115
116set(UI_FILES
117	AboutScreen.ui
118	ArchiveInspector.ui
119	AssetTile.ui
120	BattleChipView.ui
121	CheatsView.ui
122	DebuggerConsole.ui
123	FrameView.ui
124	GIFView.ui
125	IOViewer.ui
126	LoadSaveState.ui
127	LogView.ui
128	MapView.ui
129	MemorySearch.ui
130	MemoryView.ui
131	ObjView.ui
132	OverrideView.ui
133	PaletteView.ui
134	PlacementControl.ui
135	PrinterView.ui
136	ROMInfo.ui
137	SensorView.ui
138	SettingsView.ui
139	ShaderSelector.ui
140	ShortcutView.ui
141	TileView.ui
142	VideoView.ui)
143
144set(GBA_SRC
145	BattleChipModel.cpp
146	BattleChipUpdater.cpp
147	BattleChipView.cpp
148	GBAOverride.cpp)
149
150set(GB_SRC
151	GBOverride.cpp
152	PrinterView.cpp)
153
154set(QT_LIBRARIES)
155set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5")
156
157set(AUDIO_SRC)
158if(BUILD_SDL)
159	list(APPEND AUDIO_SRC AudioProcessorSDL.cpp)
160endif()
161
162if(M_CORE_GBA)
163	list(APPEND PLATFORM_SRC ${GBA_SRC})
164endif()
165
166if(M_CORE_GB)
167	list(APPEND PLATFORM_SRC ${GB_SRC})
168endif()
169
170set(QT_DEFINES)
171if(Qt5Multimedia_FOUND)
172	list(APPEND AUDIO_SRC
173		AudioProcessorQt.cpp
174		AudioDevice.cpp)
175	list(APPEND SOURCE_FILES
176		VideoDumper.cpp)
177	if (WIN32 AND QT_STATIC)
178		list(APPEND QT_LIBRARIES Qt5::QWindowsAudioPlugin Qt5::DSServicePlugin Qt5::QWindowsVistaStylePlugin
179                                 strmiids mfuuid mfplat mf ksguid dxva2 evr d3d9)
180	endif()
181	list(APPEND QT_LIBRARIES Qt5::Multimedia)
182	list(APPEND QT_DEFINES BUILD_QT_MULTIMEDIA)
183	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
184endif()
185
186if(NOT AUDIO_SRC)
187	message(WARNING "No supported audio modules found")
188	set(BUILD_QT OFF PARENT_SCOPE)
189	return()
190endif()
191
192if(USE_DEBUGGERS)
193	list(APPEND SOURCE_FILES
194		DebuggerController.cpp
195		DebuggerConsole.cpp
196		DebuggerConsoleController.cpp)
197endif()
198
199if(USE_GDB_STUB)
200	list(APPEND SOURCE_FILES GDBController.cpp GDBWindow.cpp)
201endif()
202
203if(USE_SQLITE3)
204	list(APPEND SOURCE_FILES
205		ArchiveInspector.cpp
206		library/LibraryController.cpp
207		library/LibraryGrid.cpp
208		library/LibraryTree.cpp)
209endif()
210
211if(USE_DISCORD_RPC)
212	list(APPEND QT_LIBRARIES discord-rpc)
213	list(APPEND SOURCE_FILES DiscordCoordinator.cpp)
214endif()
215
216qt5_add_resources(RESOURCES resources.qrc)
217if(APPLE)
218	set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
219	set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
220	set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
221	set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
222	set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
223endif()
224if(WIN32)
225	configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
226	list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
227	set_source_files_properties(${CMAKE_BINARY_DIR}/res/mgba.rc PROPERTIES OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/res/mgba.ico)
228endif()
229if(NOT DEFINED DATADIR)
230	if(APPLE)
231		set(DATADIR Applications/${PROJECT_NAME}.app/Contents/Resources)
232	elseif(WIN32 AND NOT WIN32_UNIX_PATHS)
233		set(DATADIR ".")
234	else()
235		set(DATADIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME})
236	endif()
237endif()
238if(BUILD_GL OR BUILD_GLES2 OR BUILD_EPOXY)
239	install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
240endif()
241install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
242if(NOT WIN32 AND NOT APPLE)
243	list(APPEND QT_DEFINES DATADIR="${CMAKE_INSTALL_PREFIX}/${DATADIR}")
244endif()
245
246find_package(Qt5LinguistTools)
247if(Qt5LinguistTools_FOUND)
248	set(TRANSLATION_FILES)
249	set(TRANSLATION_QRC "${CMAKE_CURRENT_BINARY_DIR}/ts.qrc")
250	file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ts/${BINARY_NAME}-*.ts")
251	if(UPDATE_TRANSLATIONS)
252		qt5_create_translation(TRANSLATION_FILES ${SOURCE_FILES} ${UI_FILES} ${TS_FILES} OPTIONS -locations absolute -no-obsolete)
253	else()
254		qt5_add_translation(TRANSLATION_FILES ${TS_FILES})
255	endif()
256	set(QT_QM_FILES)
257	if(QT_STATIC)
258		get_target_property(QT_CORE_LOCATION Qt5::Core LOCATION)
259		get_filename_component(QT_CORE_LOCATION ${QT_CORE_LOCATION} DIRECTORY)
260		get_filename_component(QT_QM_LOCATION "${QT_CORE_LOCATION}/../translations" ABSOLUTE)
261		foreach(TS ${TS_FILES})
262			get_filename_component(TS ${TS} NAME)
263			string(REGEX REPLACE "${BINARY_NAME}-(.*).ts$" "qtbase_\\1.qm" QT_QM "${TS}")
264			set(QT_QM "${QT_QM_LOCATION}/${QT_QM}")
265			if(EXISTS "${QT_QM}")
266				list(APPEND QT_QM_FILES "${QT_QM}")
267			endif()
268		endforeach()
269		list(APPEND TRANSLATION_FILES ${QT_QM_FILES})
270	endif()
271	add_custom_command(OUTPUT ${TRANSLATION_QRC}
272		               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"
273		               DEPENDS ${TRANSLATION_FILES})
274	qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
275	list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
276endif()
277
278qt5_wrap_ui(UI_SRC ${UI_FILES})
279
280add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_SRC} ${AUDIO_SRC} ${RESOURCES})
281set_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}" COMPILE_OPTIONS "${FEATURE_FLAGS}")
282
283list(APPEND QT_LIBRARIES Qt5::Widgets Qt5::Network)
284if(BUILD_GL OR BUILD_GLES2 OR BUILD_EPOXY)
285	list(APPEND QT_LIBRARIES Qt5::OpenGL ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
286endif()
287if(QT_STATIC)
288	find_library(QTPCRE NAMES qtpcre2 qtpcre)
289	if(WIN32)
290		list(APPEND QT_LIBRARIES qwindows dwmapi imm32 uxtheme Qt5EventDispatcherSupport Qt5FontDatabaseSupport Qt5ThemeSupport Qt5WindowsUIAutomationSupport)
291		set_target_properties(Qt5::Core PROPERTIES INTERFACE_LINK_LIBRARIES "${QTPCRE};version;winmm;ssl;crypto;ws2_32;iphlpapi;crypt32;userenv;netapi32;wtsapi32")
292		set_target_properties(Qt5::Gui PROPERTIES INTERFACE_LINK_LIBRARIES ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
293	elseif(APPLE)
294		find_package(Cups)
295		find_package(Qt5PrintSupport)
296		find_library(QTFREETYPE NAMES qtfreetype)
297		find_library(QTHARFBUZZ NAMES qtharfbuzzng qtharfbuzz)
298		find_library(QTPLATFORMSUPPORT NAMES Qt5PlatformSupport)
299		list(APPEND QT_LIBRARIES Cups Qt5::PrintSupport Qt5::QCocoaIntegrationPlugin Qt5::CoreAudioPlugin Qt5::AVFServicePlugin Qt5::QCocoaPrinterSupportPlugin ${QTPLATFORMSUPPORT} "-framework AVFoundation" "-framework CoreMedia" "-framework SystemConfiguration" "-framework Security")
300		set_target_properties(Qt5::Core PROPERTIES INTERFACE_LINK_LIBRARIES "${QTPCRE};${QTHARFBUZZ};${QTFREETYPE}")
301		link_directories()
302	endif()
303endif()
304target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES})
305set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
306
307install(TARGETS ${BINARY_NAME}-qt
308	RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-qt
309	BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
310if(UNIX AND NOT APPLE)
311	find_program(DESKTOP_FILE_INSTALL desktop-file-install)
312	if(DESKTOP_FILE_INSTALL)
313		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/\")" COMPONENT ${BINARY_NAME}-qt)
314	endif()
315endif()
316if(UNIX)
317	install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
318endif()
319if(APPLE OR WIN32)
320	set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
321endif()
322if(APPLE)
323	if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
324		get_target_property(QTCOCOA Qt5::QCocoaIntegrationPlugin LOCATION)
325		get_target_property(COREAUDIO Qt5::CoreAudioPlugin LOCATION)
326		get_target_property(QTAVFSERVICE Qt5::AVFServicePlugin LOCATION)
327		set(BUNDLE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.app)
328		target_sources(${BINARY_NAME}-qt PRIVATE "${PLUGINS}")
329		set_source_files_properties("${QTCOCOA}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
330		set_source_files_properties("${COREAUDIO}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
331		set_source_files_properties("${QTAVFSERVICE}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
332		install(CODE "
333		   include(BundleUtilities)
334		   set(BU_CHMOD_BUNDLE_ITEMS ON)
335		   file(GLOB_RECURSE PLUGINS \"${BUNDLE_PATH}/Contents/PlugIns/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
336		   fixup_bundle(\"${BUNDLE_PATH}\"   \"${PLUGINS}\"   \"\")
337		   " COMPONENT ${BINARY_NAME}-qt)
338	else()
339		set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib,mediaservice/libqavfcamera.dylib)
340		if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
341			set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I "${CMAKE_INSTALL_NAME_TOOL}")
342		endif()
343		if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
344			set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O "${CMAKE_OTOOL}")
345		endif()
346		if(DEFINED CROSS_ROOT)
347			set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R "${CROSS_ROOT}")
348		endif()
349		install(CODE "execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/tools/deploy-mac.py\" -v ${DEPLOY_OPTIONS} \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/Applications/${PROJECT_NAME}.app\")")
350	endif()
351elseif(WIN32)
352	if(CMAKE_MAJOR_VERSION EQUAL 3 AND CMAKE_MINOR_VERSION EQUAL 8)
353		# Work around CMake issue #16907
354		set_target_properties(${BINARY_NAME}-qt PROPERTIES AUTORCC ON SKIP_AUTORCC ON)
355	endif()
356	if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
357		find_program(BASH bash)
358		install(CODE "execute_process(COMMAND \"${BASH}\" \"${CMAKE_SOURCE_DIR}/tools/deploy-win.sh\" \"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.exe\" \"\${CMAKE_INSTALL_PREFIX}\" \"\$ENV{PWD}\" WORKING_DIRECTORY \"${CMAKE_BINARY_DIR}\")" COMPONENT ${BINARY_NAME}-qt)
359	endif()
360	if(DISTBUILD)
361		file(WRITE "${CMAKE_BINARY_DIR}/portable.ini" "")
362		install(FILES "${CMAKE_BINARY_DIR}/portable.ini" DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${BINARY_NAME}-qt)
363	endif()
364endif()
365
366if(DISTBUILD AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
367	if(NOT APPLE)
368		add_custom_command(TARGET ${BINARY_NAME}-qt POST_BUILD COMMAND "${OBJCOPY}" --only-keep-debug "$<TARGET_FILE:${BINARY_NAME}-qt>" "$<TARGET_FILE:${BINARY_NAME}-qt>.debug")
369		add_custom_command(TARGET ${BINARY_NAME}-qt POST_BUILD COMMAND "${STRIP}" "$<TARGET_FILE:${BINARY_NAME}-qt>")
370		add_custom_command(TARGET ${BINARY_NAME}-qt POST_BUILD COMMAND "${OBJCOPY}" --add-gnu-debuglink "$<TARGET_FILE:${BINARY_NAME}-qt>.debug" "$<TARGET_FILE:${BINARY_NAME}-qt>")
371		install(FILES "$<TARGET_FILE:${BINARY_NAME}-qt>.debug" DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-qt-dbg)
372	endif()
373endif()