all repos — mgba @ 2c59cb8211c4bf46665d12ed174cf7efe512e0d0

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