all repos — mgba @ 96ac3752767923535052840ec978bbd3d873236c

mGBA Game Boy Advance Emulator

src/platform/qt/CMakeLists.txt (view raw)

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