all repos — mgba @ b8d29a0ce8d237aa7eac32b1486d31dac869cab0

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