all repos — mgba @ c6f0d6c5dbb9c77047439fdea8f7b2e28e207428

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