all repos — mgba @ 8aaa6105020f2ecae1b0cef29dbdb90c0a53cd57

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	RegisterView.cpp
103	ROMInfo.cpp
104	SavestateButton.cpp
105	SensorView.cpp
106	SettingsView.cpp
107	ShaderSelector.cpp
108	ShortcutController.cpp
109	ShortcutView.cpp
110	Swatch.cpp
111	TilePainter.cpp
112	TileView.cpp
113	utils.cpp
114	Window.cpp
115	VFileDevice.cpp
116	VideoView.cpp)
117
118set(UI_FILES
119	AboutScreen.ui
120	ArchiveInspector.ui
121	AssetTile.ui
122	CheatsView.ui
123	DebuggerConsole.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	PrinterView.ui
135	ROMInfo.ui
136	SensorView.ui
137	SettingsView.ui
138	ShaderSelector.ui
139	ShortcutView.ui
140	TileView.ui
141	VideoView.ui)
142
143set(GBA_SRC
144	GBAOverride.cpp)
145
146set(GB_SRC
147	GBOverride.cpp)
148
149set(QT_LIBRARIES)
150set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5")
151
152set(AUDIO_SRC)
153if(BUILD_SDL)
154	list(APPEND AUDIO_SRC AudioProcessorSDL.cpp)
155endif()
156
157if(M_CORE_GBA)
158	list(APPEND PLATFORM_SRC ${GBA_SRC})
159endif()
160
161if(M_CORE_GB)
162	list(APPEND PLATFORM_SRC ${GB_SRC})
163endif()
164
165set(QT_DEFINES)
166if(Qt5Multimedia_FOUND)
167	list(APPEND AUDIO_SRC
168		AudioProcessorQt.cpp
169		AudioDevice.cpp)
170	list(APPEND SOURCE_FILES
171		VideoDumper.cpp)
172	if (WIN32 AND QT_STATIC)
173		list(APPEND QT_LIBRARIES Qt5::QWindowsAudioPlugin Qt5::DSServicePlugin
174                                 strmiids winmm mfuuid mfplat mf ksguid dxva2 evr d3d9)
175	endif()
176	list(APPEND QT_LIBRARIES Qt5::Multimedia)
177	list(APPEND QT_DEFINES BUILD_QT_MULTIMEDIA)
178	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
179endif()
180
181if(NOT AUDIO_SRC)
182	message(WARNING "No supported audio modules found")
183	set(BUILD_QT OFF PARENT_SCOPE)
184	return()
185endif()
186
187if(USE_DEBUGGERS)
188	list(APPEND SOURCE_FILES
189		DebuggerController.cpp
190		DebuggerConsole.cpp
191		DebuggerConsoleController.cpp)
192endif()
193
194if(USE_GDB_STUB)
195	list(APPEND SOURCE_FILES GDBController.cpp GDBWindow.cpp)
196endif()
197
198if(USE_SQLITE3)
199	list(APPEND SOURCE_FILES
200		ArchiveInspector.cpp
201		library/LibraryController.cpp
202		library/LibraryGrid.cpp
203		library/LibraryTree.cpp)
204endif()
205
206qt5_add_resources(RESOURCES resources.qrc)
207if(APPLE)
208	set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
209	set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
210	set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
211	set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
212	set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
213endif()
214if(WIN32)
215	configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
216	list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
217	set_source_files_properties(${CMAKE_BINARY_DIR}/res/mgba.rc PROPERTIES OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/res/mgba.ico)
218	if(QT_STATIC)
219		list(APPEND QT_LIBRARIES qwindows Qt5PlatformSupport imm32)
220	endif()
221endif()
222if(NOT DEFINED DATADIR)
223	if(APPLE)
224		set(DATADIR Applications/${PROJECT_NAME}.app/Contents/Resources)
225	else()
226		set(DATADIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME})
227	endif()
228endif()
229if(BUILD_GL OR BUILD_GLES2)
230	install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
231endif()
232install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
233if(NOT WIN32 AND NOT APPLE)
234	list(APPEND QT_DEFINES DATADIR="${CMAKE_INSTALL_PREFIX}/${DATADIR}")
235endif()
236
237find_package(Qt5LinguistTools)
238if(Qt5LinguistTools_FOUND)
239	set(TRANSLATION_FILES)
240	set(TRANSLATION_QRC "${CMAKE_CURRENT_BINARY_DIR}/ts.qrc")
241	file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ts/${BINARY_NAME}-*.ts")
242	if(UPDATE_TRANSLATIONS)
243		qt5_create_translation(TRANSLATION_FILES ${SOURCE_FILES} ${UI_FILES} ${TS_FILES} OPTIONS -locations absolute -no-obsolete)
244	else()
245		qt5_add_translation(TRANSLATION_FILES ${TS_FILES})
246	endif()
247	set(QT_QM_FILES)
248	if(QT_STATIC)
249		get_target_property(QT_CORE_LOCATION Qt5::Core LOCATION)
250		get_filename_component(QT_CORE_LOCATION ${QT_CORE_LOCATION} DIRECTORY)
251		get_filename_component(QT_QM_LOCATION "${QT_CORE_LOCATION}/../translations" ABSOLUTE)
252		foreach(TS ${TS_FILES})
253			get_filename_component(TS ${TS} NAME)
254			string(REGEX REPLACE "${BINARY_NAME}-(.*).ts$" "qtbase_\\1.qm" QT_QM "${TS}")
255			list(APPEND QT_QM_FILES "${QT_QM_LOCATION}/${QT_QM}")
256		endforeach()
257		list(APPEND TRANSLATION_FILES ${QT_QM_FILES})
258	endif()
259	add_custom_command(OUTPUT ${TRANSLATION_QRC}
260		               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"
261		               DEPENDS ${TRANSLATION_FILES})
262	qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
263	list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
264endif()
265
266qt5_wrap_ui(UI_SRC ${UI_FILES})
267
268add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_SRC} ${AUDIO_SRC} ${RESOURCES})
269set_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}")
270
271list(APPEND QT_LIBRARIES Qt5::Widgets)
272if(BUILD_GL OR BUILD_GLES2)
273	list(APPEND QT_LIBRARIES Qt5::OpenGL ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
274endif()
275target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES})
276set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
277
278install(TARGETS ${BINARY_NAME}-qt
279	RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-qt
280	BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
281if(UNIX AND NOT APPLE)
282	find_program(DESKTOP_FILE_INSTALL desktop-file-install)
283	if(DESKTOP_FILE_INSTALL)
284		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/\")")
285	endif()
286endif()
287if(UNIX)
288	install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
289endif()
290if(APPLE OR WIN32)
291	set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
292endif()
293if(APPLE)
294	if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
295		get_target_property(QTCOCOA Qt5::QCocoaIntegrationPlugin LOCATION)
296		get_target_property(COREAUDIO Qt5::CoreAudioPlugin LOCATION)
297		get_target_property(QTAVFSERVICE Qt5::AVFServicePlugin LOCATION)
298		set(BUNDLE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.app)
299		target_sources(${BINARY_NAME}-qt PRIVATE "${PLUGINS}")
300		set_source_files_properties("${QTCOCOA}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
301		set_source_files_properties("${COREAUDIO}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
302		set_source_files_properties("${QTAVFSERVICE}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
303		install(CODE "
304		   include(BundleUtilities)
305		   set(BU_CHMOD_BUNDLE_ITEMS ON)
306		   file(GLOB_RECURSE PLUGINS \"${BUNDLE_PATH}/Contents/PlugIns/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
307		   fixup_bundle(\"${BUNDLE_PATH}\"   \"${PLUGINS}\"   \"\")
308		   " COMPONENT ${BINARY_NAME}-qt)
309	else()
310		set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib,mediaservice/libqavfcamera.dylib)
311		if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
312			set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I "${CMAKE_INSTALL_NAME_TOOL}")
313		endif()
314		if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
315			set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O "${CMAKE_OTOOL}")
316		endif()
317		if(DEFINED CROSS_ROOT)
318			set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R "${CROSS_ROOT}")
319		endif()
320		install(CODE "execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/tools/deploy-mac.py\" -v ${DEPLOY_OPTIONS} \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/Applications/${PROJECT_NAME}.app\")")
321	endif()
322endif()
323if(WIN32 AND CMAKE_MAJOR_VERSION GREATER 2 AND CMAKE_MINOR_VERSION GREATER 7)
324	# Work around CMake issue #16907
325	set_target_properties(${BINARY_NAME}-qt PROPERTIES AUTORCC ON SKIP_AUTORCC ON)
326endif()