all repos — mgba @ a1acf8bcef00cbc2c3a8f7506d6e9db70a943c28

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	if (WIN32 AND QT_STATIC)
161		list(APPEND QT_LIBRARIES qtaudio_windows strmiids winmm)
162	endif()
163	list(APPEND QT_LIBRARIES Qt5::Multimedia)
164	list(APPEND QT_DEFINES BUILD_QT_MULTIMEDIA)
165	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
166endif()
167
168if(NOT AUDIO_SRC)
169	message(WARNING "No supported audio modules found")
170	set(BUILD_QT OFF PARENT_SCOPE)
171	return()
172endif()
173
174if(USE_DEBUGGERS)
175	list(APPEND SOURCE_FILES
176		DebuggerController.cpp
177		DebuggerConsole.cpp
178		DebuggerConsoleController.cpp)
179endif()
180
181if(USE_GDB_STUB)
182	list(APPEND SOURCE_FILES GDBController.cpp GDBWindow.cpp)
183endif()
184
185if(USE_SQLITE3)
186	list(APPEND SOURCE_FILES
187		ArchiveInspector.cpp
188		library/LibraryController.cpp
189		library/LibraryGrid.cpp
190		library/LibraryTree.cpp)
191endif()
192
193qt5_add_resources(RESOURCES resources.qrc)
194if(APPLE)
195	set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
196	set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
197	set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
198	set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
199	set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
200endif()
201if(WIN32)
202	configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
203	list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
204	set_source_files_properties(${CMAKE_BINARY_DIR}/res/mgba.rc PROPERTIES OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/res/mgba.ico)
205	if(QT_STATIC)
206		list(APPEND QT_LIBRARIES qwindows Qt5PlatformSupport imm32)
207	endif()
208endif()
209if(NOT DEFINED DATADIR)
210	if(APPLE)
211		set(DATADIR Applications/${PROJECT_NAME}.app/Contents/Resources)
212	else()
213		set(DATADIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME})
214	endif()
215endif()
216if(BUILD_GL OR BUILD_GLES2)
217	install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
218endif()
219install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
220if(NOT WIN32 AND NOT APPLE)
221	list(APPEND QT_DEFINES DATADIR="${CMAKE_INSTALL_PREFIX}/${DATADIR}")
222endif()
223
224find_package(Qt5LinguistTools)
225if(Qt5LinguistTools_FOUND)
226	set(TRANSLATION_FILES)
227	set(TRANSLATION_QRC "${CMAKE_CURRENT_BINARY_DIR}/ts.qrc")
228	file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ts/${BINARY_NAME}-*.ts")
229	if(UPDATE_TRANSLATIONS)
230		qt5_create_translation(TRANSLATION_FILES ${SOURCE_FILES} ${UI_FILES} ${TS_FILES} OPTIONS -locations absolute -no-obsolete)
231	else()
232		qt5_add_translation(TRANSLATION_FILES ${TS_FILES})
233	endif()
234	set(QT_QM_FILES)
235	if(QT_STATIC)
236		get_target_property(QT_CORE_LOCATION Qt5::Core LOCATION)
237		get_filename_component(QT_CORE_LOCATION ${QT_CORE_LOCATION} DIRECTORY)
238		get_filename_component(QT_QM_LOCATION "${QT_CORE_LOCATION}/../translations" ABSOLUTE)
239		foreach(TS ${TS_FILES})
240			get_filename_component(TS ${TS} NAME)
241			string(REGEX REPLACE "${BINARY_NAME}-(.*).ts$" "qtbase_\\1.qm" QT_QM "${TS}")
242			list(APPEND QT_QM_FILES "${QT_QM_LOCATION}/${QT_QM}")
243		endforeach()
244		list(APPEND TRANSLATION_FILES ${QT_QM_FILES})
245	endif()
246	add_custom_command(OUTPUT ${TRANSLATION_QRC}
247		               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"
248		               DEPENDS ${TRANSLATION_FILES})
249	qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
250	list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
251endif()
252
253qt5_wrap_ui(UI_SRC ${UI_FILES})
254
255add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_SRC} ${AUDIO_SRC} ${RESOURCES})
256set_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}")
257
258list(APPEND QT_LIBRARIES Qt5::Widgets)
259if(BUILD_GL OR BUILD_GLES2)
260	list(APPEND QT_LIBRARIES Qt5::OpenGL ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
261endif()
262target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES})
263set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
264
265install(TARGETS ${BINARY_NAME}-qt
266	RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-qt
267	BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
268if(UNIX AND NOT APPLE)
269	find_program(DESKTOP_FILE_INSTALL desktop-file-install)
270	if(DESKTOP_FILE_INSTALL)
271		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/\")")
272	endif()
273endif()
274if(UNIX)
275	install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
276endif()
277if(APPLE OR WIN32)
278	set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
279endif()
280if(APPLE)
281	if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
282		get_target_property(QTCOCOA Qt5::QCocoaIntegrationPlugin LOCATION)
283		get_target_property(COREAUDIO Qt5::CoreAudioPlugin LOCATION)
284		set(BUNDLE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.app)
285		target_sources(${BINARY_NAME}-qt PRIVATE "${PLUGINS}")
286		set_source_files_properties("${QTCOCOA}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
287		set_source_files_properties("${COREAUDIO}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
288		install(CODE "
289		   include(BundleUtilities)
290		   set(BU_CHMOD_BUNDLE_ITEMS ON)
291		   file(GLOB_RECURSE PLUGINS \"${BUNDLE_PATH}/Contents/PlugIns/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
292		   fixup_bundle(\"${BUNDLE_PATH}\"   \"${PLUGINS}\"   \"\")
293		   " COMPONENT ${BINARY_NAME}-qt)
294	else()
295		set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib)
296		if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
297			set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I "${CMAKE_INSTALL_NAME_TOOL}")
298		endif()
299		if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
300			set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O "${CMAKE_OTOOL}")
301		endif()
302		if(DEFINED CROSS_ROOT)
303			set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R "${CROSS_ROOT}")
304		endif()
305		install(CODE "execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/tools/deploy-mac.py\" -v ${DEPLOY_OPTIONS} \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/Applications/${PROJECT_NAME}.app\")")
306	endif()
307endif()
308if(WIN32 AND CMAKE_MAJOR_VERSION GREATER 2 AND CMAKE_MINOR_VERSION GREATER 7)
309	# Work around CMake issue #16907
310	set_target_properties(${BINARY_NAME}-qt PROPERTIES AUTORCC ON SKIP_AUTORCC ON)
311endif()