all repos — mgba @ fbda6d8a1cd76de2385c894bf9182f41af08b71d

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} ${SDLMAIN_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(Qt5Network)
 36find_package(Qt5Widgets)
 37
 38if(NOT BUILD_GL AND NOT BUILD_GLES2)
 39	message(WARNING "OpenGL is required to build the Qt port")
 40	set(BUILD_QT OFF PARENT_SCOPE)
 41	return()
 42endif()
 43
 44if(NOT Qt5OpenGL_FOUND OR NOT Qt5Widgets_FOUND OR NOT Qt5Network_FOUND)
 45	message(WARNING "Cannot find Qt modules")
 46	set(BUILD_QT OFF PARENT_SCOPE)
 47	return()
 48endif()
 49
 50if(BUILD_GL)
 51	list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gl.c)
 52	if(NOT WIN32 OR USE_EPOXY)
 53		list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
 54	endif()
 55endif()
 56
 57if(BUILD_GLES2)
 58	list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
 59endif()
 60
 61get_target_property(QT_TYPE Qt5::Core TYPE)
 62if(QT_TYPE STREQUAL STATIC_LIBRARY)
 63	set(QT_STATIC ON)
 64	list(APPEND QT_DEFINES QT_STATIC)
 65endif()
 66
 67set(SOURCE_FILES
 68	AboutScreen.cpp
 69	AssetTile.cpp
 70	AssetView.cpp
 71	AudioProcessor.cpp
 72	CheatsModel.cpp
 73	CheatsView.cpp
 74	ConfigController.cpp
 75	Display.cpp
 76	DisplayGL.cpp
 77	DisplayQt.cpp
 78	GBAApp.cpp
 79	GBAKeyEditor.cpp
 80	GIFView.cpp
 81	GameController.cpp
 82	GamepadAxisEvent.cpp
 83	GamepadButtonEvent.cpp
 84	GamepadHatEvent.cpp
 85	IOViewer.cpp
 86	InputController.cpp
 87	InputProfile.cpp
 88	KeyEditor.cpp
 89	LoadSaveState.cpp
 90	LogController.cpp
 91	LogView.cpp
 92	MemoryModel.cpp
 93	MemoryView.cpp
 94	MessagePainter.cpp
 95	MultiplayerController.cpp
 96	ObjView.cpp
 97	OverrideView.cpp
 98	PaletteView.cpp
 99	ROMInfo.cpp
100	SavestateButton.cpp
101	SensorView.cpp
102	SettingsView.cpp
103	ShaderSelector.cpp
104	ShortcutController.cpp
105	ShortcutView.cpp
106	Swatch.cpp
107	TilePainter.cpp
108	TileView.cpp
109	Window.cpp
110	VFileDevice.cpp
111	VideoView.cpp)
112
113set(UI_FILES
114	AboutScreen.ui
115	ArchiveInspector.ui
116	AssetTile.ui
117	CheatsView.ui
118	DebuggerConsole.ui
119	GIFView.ui
120	IOViewer.ui
121	LibraryView.ui
122	LoadSaveState.ui
123	LogView.ui
124	MemoryView.ui
125	ObjView.ui
126	OverrideView.ui
127	PaletteView.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
142qt5_wrap_ui(UI_SRC ${UI_FILES})
143
144set(QT_LIBRARIES)
145set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5,libqt5network5")
146
147set(AUDIO_SRC)
148if(BUILD_SDL)
149	list(APPEND AUDIO_SRC AudioProcessorSDL.cpp)
150endif()
151
152if(M_CORE_GBA)
153	list(APPEND PLATFORM_SRC ${GBA_SRC})
154endif()
155
156if(M_CORE_GB)
157	list(APPEND PLATFORM_SRC ${GB_SRC})
158endif()
159
160set(QT_DEFINES)
161if(Qt5Multimedia_FOUND)
162	list(APPEND AUDIO_SRC
163		AudioProcessorQt.cpp
164		AudioDevice.cpp)
165	if (WIN32 AND QT_STATIC)
166		list(APPEND QT_LIBRARIES qtaudio_windows strmiids winmm)
167	endif()
168	list(APPEND QT_LIBRARIES Qt5::Multimedia)
169	list(APPEND QT_DEFINES BUILD_QT_MULTIMEDIA)
170	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
171endif()
172
173if(NOT AUDIO_SRC)
174	message(WARNING "No supported audio modules found")
175	set(BUILD_QT OFF PARENT_SCOPE)
176	return()
177endif()
178
179if(USE_DEBUGGERS)
180	list(APPEND SOURCE_FILES
181		DebuggerController.cpp
182		DebuggerConsole.cpp
183		DebuggerConsoleController.cpp)
184endif()
185
186if(USE_GDB_STUB)
187	list(APPEND SOURCE_FILES GDBController.cpp GDBWindow.cpp)
188endif()
189
190if(USE_SQLITE3)
191	list(APPEND SOURCE_FILES
192		ArchiveInspector.cpp
193		LibraryModel.cpp
194		LibraryView.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()
220install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
221install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
222if(NOT WIN32 AND NOT APPLE)
223	list(APPEND QT_DEFINES DATADIR="${DATADIR}")
224endif()
225
226find_package(Qt5LinguistTools)
227if(Qt5LinguistTools_FOUND)
228	set(TRANSLATION_FILES)
229	set(TRANSLATION_QRC "${CMAKE_CURRENT_BINARY_DIR}/ts.qrc")
230	file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ts/${BINARY_NAME}-*.ts")
231	if(UPDATE_TRANSLATIONS)
232		qt5_create_translation(TRANSLATION_FILES ${SOURCE_FILES} ${UI_FILES} ${TS_FILES} OPTIONS -locations absolute -no-obsolete)
233	else()
234		qt5_add_translation(TRANSLATION_FILES ${TS_FILES})
235	endif()
236	add_custom_command(OUTPUT ${TRANSLATION_QRC}
237		               COMMAND ${CMAKE_COMMAND} -DTRANSLATION_QRC:FILEPATH="${TRANSLATION_QRC}" -DQM_BASE="${CMAKE_CURRENT_BINARY_DIR}" -P "${CMAKE_CURRENT_SOURCE_DIR}/ts.cmake"
238		               DEPENDS ${TRANSLATION_FILES})
239	qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
240	list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
241endif()
242
243add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_SRC} ${AUDIO_SRC} ${RESOURCES})
244set_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}")
245
246list(APPEND QT_LIBRARIES Qt5::Widgets Qt5::OpenGL Qt5::Network)
247target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
248set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
249
250install(TARGETS ${BINARY_NAME}-qt
251	RUNTIME DESTINATION bin COMPONENT ${BINARY_NAME}-qt
252	BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
253if(UNIX AND NOT APPLE)
254	find_program(DESKTOP_FILE_INSTALL desktop-file-install)
255	if(DESKTOP_FILE_INSTALL)
256		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/\")")
257	endif()
258endif()
259if(UNIX)
260	install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
261endif()
262if(APPLE OR WIN32)
263	set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
264endif()
265if(APPLE)
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)
278endif()