all repos — mgba @ 13b6adee5653d733c2c1d2031fb20a774802a1fe

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
 33if(NOT WIN32 OR NOT BUILD_SDL)
 34	find_package(Qt5Multimedia)
 35endif()
 36find_package(Qt5OpenGL)
 37find_package(Qt5Network)
 38find_package(Qt5Widgets)
 39
 40if(NOT BUILD_GL AND NOT BUILD_GLES2)
 41	message(WARNING "OpenGL is required to build the Qt port")
 42	set(BUILD_QT OFF PARENT_SCOPE)
 43	return()
 44endif()
 45
 46if(NOT Qt5OpenGL_FOUND OR NOT Qt5Widgets_FOUND OR NOT Qt5Network_FOUND)
 47	message(WARNING "Cannot find Qt modules")
 48	set(BUILD_QT OFF PARENT_SCOPE)
 49	return()
 50endif()
 51
 52if(BUILD_GL)
 53	list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gl.c)
 54	if(NOT WIN32 OR USE_EPOXY)
 55		list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
 56	endif()
 57endif()
 58
 59if(BUILD_GLES2)
 60	list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
 61endif()
 62
 63get_target_property(QT_TYPE Qt5::Core TYPE)
 64if(QT_TYPE STREQUAL STATIC_LIBRARY)
 65	set(QT_STATIC ON)
 66	list(APPEND QT_DEFINES QT_STATIC)
 67endif()
 68
 69set(SOURCE_FILES
 70	AboutScreen.cpp
 71	ArchiveInspector.cpp
 72	AudioProcessor.cpp
 73	CheatsModel.cpp
 74	CheatsView.cpp
 75	ConfigController.cpp
 76	Display.cpp
 77	DisplayGL.cpp
 78	DisplayQt.cpp
 79	GBAApp.cpp
 80	GBAKeyEditor.cpp
 81	GIFView.cpp
 82	GameController.cpp
 83	GamepadAxisEvent.cpp
 84	GamepadButtonEvent.cpp
 85	IOViewer.cpp
 86	InputController.cpp
 87	InputProfile.cpp
 88	KeyEditor.cpp
 89	LibraryModel.cpp
 90	LoadSaveState.cpp
 91	LogController.cpp
 92	LogView.cpp
 93	MemoryModel.cpp
 94	MemoryView.cpp
 95	MessagePainter.cpp
 96	MultiplayerController.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	CheatsView.ui
117	GIFView.ui
118	IOViewer.ui
119	LoadSaveState.ui
120	LogView.ui
121	MemoryView.ui
122	OverrideView.ui
123	PaletteView.ui
124	ROMInfo.ui
125	SensorView.ui
126	SettingsView.ui
127	ShaderSelector.ui
128	ShortcutView.ui
129	TileView.ui
130	VideoView.ui)
131
132set(GBA_SRC
133	GBAOverride.cpp)
134
135set(GB_SRC
136	GBOverride.cpp)
137
138qt5_wrap_ui(UI_SRC ${UI_FILES})
139
140set(QT_LIBRARIES)
141set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5,libqt5network5")
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	if (WIN32 AND QT_STATIC)
162		list(APPEND QT_LIBRARIES qtaudio_windows strmiids winmm)
163	endif()
164	list(APPEND QT_LIBRARIES Qt5::Multimedia)
165	list(APPEND QT_DEFINES BUILD_QT_MULTIMEDIA)
166	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
167endif()
168
169if(NOT AUDIO_SRC)
170	message(WARNING "No supported audio modules found")
171	set(BUILD_QT OFF PARENT_SCOPE)
172	return()
173endif()
174
175if(USE_GDB_STUB)
176	list(APPEND PLATFORM_SRC GDBController.cpp GDBWindow.cpp)
177endif()
178
179qt5_add_resources(RESOURCES resources.qrc)
180if(APPLE)
181	set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
182	set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
183	set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
184	set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
185	set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
186endif()
187if(WIN32)
188	configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
189	list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
190	set_source_files_properties(${CMAKE_BINARY_DIR}/res/mgba.rc PROPERTIES OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/res/mgba.ico)
191	if(QT_STATIC)
192		list(APPEND QT_LIBRARIES qwindows Qt5PlatformSupport imm32)
193	endif()
194endif()
195if(NOT DEFINED DATADIR)
196	if(APPLE)
197		set(DATADIR Applications/${PROJECT_NAME}.app/Contents/Resources)
198	else()
199		set(DATADIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME})
200	endif()
201endif()
202install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
203install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
204if(NOT WIN32 AND NOT APPLE)
205	list(APPEND QT_DEFINES DATADIR="${DATADIR}")
206endif()
207
208find_package(Qt5LinguistTools)
209if(Qt5LinguistTools_FOUND)
210	set(TRANSLATION_FILES)
211	set(TRANSLATION_QRC "${CMAKE_CURRENT_BINARY_DIR}/ts.qrc")
212	file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ts/${BINARY_NAME}-*.ts")
213	if(UPDATE_TRANSLATIONS)
214		qt5_create_translation(TRANSLATION_FILES ${SOURCE_FILES} ${UI_FILES} ${TS_FILES} OPTIONS -locations absolute -no-obsolete)
215	else()
216		qt5_add_translation(TRANSLATION_FILES ${TS_FILES})
217	endif()
218	add_custom_command(OUTPUT ${TRANSLATION_QRC}
219		               COMMAND ${CMAKE_COMMAND} -DTRANSLATION_QRC:FILEPATH="${TRANSLATION_QRC}" -DTRANSLATION_FILES="${TRANSLATION_FILES}" -P "${CMAKE_CURRENT_SOURCE_DIR}/ts.cmake"
220		               DEPENDS ${TRANSLATION_FILES})
221	qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
222	list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
223endif()
224
225add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_SRC} ${AUDIO_SRC} ${RESOURCES})
226set_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}")
227
228list(APPEND QT_LIBRARIES Qt5::Widgets Qt5::OpenGL Qt5::Network)
229target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
230set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
231
232install(TARGETS ${BINARY_NAME}-qt
233	RUNTIME DESTINATION bin COMPONENT ${BINARY_NAME}-qt
234	BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
235if(UNIX AND NOT APPLE)
236	find_program(DESKTOP_FILE_INSTALL desktop-file-install)
237	if(DESKTOP_FILE_INSTALL)
238		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/\")")
239	endif()
240endif()
241if(UNIX)
242	install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
243endif()
244if(APPLE OR WIN32)
245	set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
246endif()
247if(APPLE)
248	set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib)
249	if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
250		set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I ${CMAKE_INSTALL_NAME_TOOL})
251	endif()
252	if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
253		set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O ${CMAKE_OTOOL})
254	endif()
255	if(DEFINED CROSS_ROOT)
256		set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R ${CROSS_ROOT})
257	endif()
258	add_custom_command(TARGET ${BINARY_NAME}-qt POST_BUILD COMMAND ${CMAKE_SOURCE_DIR}/tools/deploy-mac.py ${DEPLOY_OPTIONS} ${PROJECT_NAME}.app)
259endif()