all repos — mgba @ 9b7521cceaa5130466a32eea6a70aa43352abaef

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