all repos — mgba @ 4681a823b7f8e19febf230e3d5add00378cee9d5

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