all repos — mgba @ 36fb807687480a75085559889d4796e093185d1b

mGBA Game Boy Advance Emulator

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

  1cmake_minimum_required(VERSION 2.8.11)
  2enable_language(CXX)
  3
  4if(NOT MSVC)
  5	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  6endif()
  7
  8if(APPLE)
  9	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.7")
 10	if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
 11		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
 12	endif()
 13endif()
 14
 15set(PLATFORM_SRC)
 16set(QT_STATIC OFF)
 17
 18if(BUILD_SDL)
 19	if(NOT SDL_FOUND AND NOT SDL2_FOUND)
 20		find_package(SDL 1.2 REQUIRED)
 21	endif()
 22	if(SDL2_FOUND)
 23		link_directories(${SDL2_LIBDIR})
 24	endif()
 25	list(APPEND PLATFORM_LIBRARY ${SDL_LIBRARY})
 26	list(APPEND PLATFORM_SRC ${PLATFORM_SRC} ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-events.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-audio.c)
 27	include_directories(${SDL_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src/platform/sdl)
 28endif()
 29
 30set(CMAKE_AUTOMOC ON)
 31set(CMAKE_INCLUDE_CURRENT_DIR ON)
 32
 33find_package(Qt5Multimedia)
 34find_package(Qt5OpenGL)
 35find_package(Qt5Widgets)
 36
 37if(NOT BUILD_GL AND NOT BUILD_GLES2)
 38	message(WARNING "OpenGL is recommended to build the Qt port")
 39endif()
 40
 41if(NOT Qt5Widgets_FOUND)
 42	message(WARNING "Cannot find Qt modules")
 43	set(BUILD_QT OFF PARENT_SCOPE)
 44	return()
 45endif()
 46
 47if(BUILD_GL)
 48	list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gl.c)
 49	if(NOT WIN32 OR USE_EPOXY)
 50		list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
 51	endif()
 52endif()
 53
 54if(BUILD_GLES2)
 55	list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
 56endif()
 57
 58get_target_property(QT_TYPE Qt5::Core TYPE)
 59if(QT_TYPE STREQUAL STATIC_LIBRARY)
 60	set(QT_STATIC ON)
 61	list(APPEND QT_DEFINES QT_STATIC)
 62endif()
 63
 64set(SOURCE_FILES
 65	AboutScreen.cpp
 66	AssetTile.cpp
 67	AssetView.cpp
 68	AudioProcessor.cpp
 69	CheatsModel.cpp
 70	CheatsView.cpp
 71	ConfigController.cpp
 72	Display.cpp
 73	DisplayGL.cpp
 74	DisplayQt.cpp
 75	GBAApp.cpp
 76	GBAKeyEditor.cpp
 77	GIFView.cpp
 78	GameController.cpp
 79	GamepadAxisEvent.cpp
 80	GamepadButtonEvent.cpp
 81	GamepadHatEvent.cpp
 82	IOViewer.cpp
 83	InputController.cpp
 84	InputProfile.cpp
 85	KeyEditor.cpp
 86	LoadSaveState.cpp
 87	LogController.cpp
 88	LogView.cpp
 89	MemoryModel.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	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()
216install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
217install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
218if(NOT WIN32 AND NOT APPLE)
219	list(APPEND QT_DEFINES DATADIR="${DATADIR}")
220endif()
221
222find_package(Qt5LinguistTools)
223if(Qt5LinguistTools_FOUND)
224	set(TRANSLATION_FILES)
225	set(TRANSLATION_QRC "${CMAKE_CURRENT_BINARY_DIR}/ts.qrc")
226	file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ts/${BINARY_NAME}-*.ts")
227	if(UPDATE_TRANSLATIONS)
228		qt5_create_translation(TRANSLATION_FILES ${SOURCE_FILES} ${UI_FILES} ${TS_FILES} OPTIONS -locations absolute -no-obsolete)
229	else()
230		qt5_add_translation(TRANSLATION_FILES ${TS_FILES})
231	endif()
232	add_custom_command(OUTPUT ${TRANSLATION_QRC}
233		               COMMAND ${CMAKE_COMMAND} -DTRANSLATION_QRC:FILEPATH="${TRANSLATION_QRC}" -DQM_BASE="${CMAKE_CURRENT_BINARY_DIR}" -P "${CMAKE_CURRENT_SOURCE_DIR}/ts.cmake"
234		               DEPENDS ${TRANSLATION_FILES})
235	qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
236	list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
237endif()
238
239qt5_wrap_ui(UI_SRC ${UI_FILES})
240
241add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_SRC} ${AUDIO_SRC} ${RESOURCES})
242set_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}")
243
244list(APPEND QT_LIBRARIES Qt5::Widgets)
245if(BUILD_GL OR BUILD_GLES2)
246	list(APPEND QT_LIBRARIES Qt5::OpenGL ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
247endif()
248target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES})
249set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
250
251install(TARGETS ${BINARY_NAME}-qt
252	RUNTIME DESTINATION bin COMPONENT ${BINARY_NAME}-qt
253	BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
254if(UNIX AND NOT APPLE)
255	find_program(DESKTOP_FILE_INSTALL desktop-file-install)
256	if(DESKTOP_FILE_INSTALL)
257		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/\")")
258	endif()
259endif()
260if(UNIX)
261	install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
262endif()
263if(APPLE OR WIN32)
264	set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
265endif()
266if(APPLE)
267	message(STATUS ${CMAKE_SYSTEM_NAME})
268	if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
269		get_target_property(QTCOCOA Qt5::QCocoaIntegrationPlugin LOCATION)
270		get_target_property(COREAUDIO Qt5::CoreAudioPlugin LOCATION)
271		get_target_property(BUNDLE_PATH ${BINARY_NAME}-qt LOCATION)
272		target_sources(${BINARY_NAME}-qt PRIVATE "${PLUGINS}")
273		set_source_files_properties("${QTCOCOA}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
274		set_source_files_properties("${COREAUDIO}" PROPERTIES MACOSX_PACKAGE_LOCATION Contents/PlugIns)
275		install(CODE "
276		   include(BundleUtilities)
277		   set(BU_CHMOD_BUNDLE_ITEMS ON)
278		   file(GLOB_RECURSE PLUGINS \"${BUNDLE_PATH}/Contents/PlugIns/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
279		   fixup_bundle(\"${BUNDLE_PATH}\"   \"${PLUGINS}\"   \"\")
280		   " COMPONENT ${BINARY_NAME}-qt)
281	else()
282		set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib)
283		if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
284			set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I "${CMAKE_INSTALL_NAME_TOOL}")
285		endif()
286		if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
287			set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O "${CMAKE_OTOOL}")
288		endif()
289		if(DEFINED CROSS_ROOT)
290			set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R "${CROSS_ROOT}")
291		endif()
292		install(CODE "execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/tools/deploy-mac.py\" -v ${DEPLOY_OPTIONS} \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/Applications/${PROJECT_NAME}.app\")")
293	endif()
294endif()