all repos — mgba @ ae578c0eaa8688346e91cf4d0a97cb6599021943

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	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	IOViewer.cpp
 85	InputController.cpp
 86	InputProfile.cpp
 87	KeyEditor.cpp
 88	LoadSaveState.cpp
 89	LogController.cpp
 90	LogView.cpp
 91	MemoryModel.cpp
 92	MemoryView.cpp
 93	MessagePainter.cpp
 94	MultiplayerController.cpp
 95	OverrideView.cpp
 96	PaletteView.cpp
 97	ROMInfo.cpp
 98	SavestateButton.cpp
 99	SensorView.cpp
100	SettingsView.cpp
101	ShaderSelector.cpp
102	ShortcutController.cpp
103	ShortcutView.cpp
104	Swatch.cpp
105	Window.cpp
106	VFileDevice.cpp
107	VideoView.cpp)
108
109qt5_wrap_ui(UI_FILES
110	AboutScreen.ui
111	CheatsView.ui
112	GIFView.ui
113	IOViewer.ui
114	LoadSaveState.ui
115	LogView.ui
116	MemoryView.ui
117	OverrideView.ui
118	PaletteView.ui
119	ROMInfo.ui
120	SensorView.ui
121	SettingsView.ui
122	ShaderSelector.ui
123	ShortcutView.ui
124	VideoView.ui)
125
126set(QT_LIBRARIES)
127set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5,libqt5network5")
128
129set(AUDIO_SRC)
130if(BUILD_SDL)
131	list(APPEND AUDIO_SRC AudioProcessorSDL.cpp)
132endif()
133
134set(QT_DEFINES)
135if(Qt5Multimedia_FOUND)
136	list(APPEND AUDIO_SRC
137		AudioProcessorQt.cpp
138		AudioDevice.cpp)
139	if (WIN32 AND QT_STATIC)
140		list(APPEND QT_LIBRARIES qtaudio_windows strmiids winmm)
141	endif()
142	list(APPEND QT_LIBRARIES Qt5::Multimedia)
143	list(APPEND QT_DEFINES BUILD_QT_MULTIMEDIA)
144	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
145endif()
146
147if(NOT AUDIO_SRC)
148	message(WARNING "No supported audio modules found")
149	set(BUILD_QT OFF PARENT_SCOPE)
150	return()
151endif()
152
153if(USE_GDB_STUB)
154	list(APPEND PLATFORM_SRC GDBController.cpp GDBWindow.cpp)
155endif()
156set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
157set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
158set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
159set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
160set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
161
162qt5_add_resources(RESOURCES resources.qrc)
163if(WIN32)
164	configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
165	list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
166	if(QT_STATIC)
167		list(APPEND QT_LIBRARIES qwindows imm32)
168	endif()
169endif()
170if(APPLE)
171	set(DATA_DIR Applications/${PROJECT_NAME}.app/Contents/Resources)
172else()
173	set(DATA_DIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME})
174endif()
175install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATA_DIR} COMPONENT ${BINARY_NAME}-qt)
176install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATA_DIR} COMPONENT ${BINARY_NAME}-qt)
177if(NOT WIN32 AND NOT APPLE)
178	list(APPEND QT_DEFINES DATA_DIR="${DATA_DIR}")
179endif()
180
181add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_FILES} ${AUDIO_SRC} ${RESOURCES})
182set_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}")
183
184list(APPEND QT_LIBRARIES Qt5::Widgets Qt5::OpenGL Qt5::Network)
185target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
186set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
187
188install(TARGETS ${BINARY_NAME}-qt
189	RUNTIME DESTINATION bin COMPONENT ${BINARY_NAME}-qt
190	BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
191if(UNIX AND NOT APPLE)
192	find_program(DESKTOP_FILE_INSTALL desktop-file-install)
193	if(DESKTOP_FILE_INSTALL)
194		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/\")")
195	endif()
196endif()
197if(UNIX)
198	install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
199endif()
200if(APPLE OR WIN32)
201	set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
202endif()
203if(APPLE)
204	set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib)
205	if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
206		set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I ${CMAKE_INSTALL_NAME_TOOL})
207	endif()
208	if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
209		set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O ${CMAKE_OTOOL})
210	endif()
211	if(DEFINED CROSS_ROOT)
212		set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R ${CROSS_ROOT})
213	endif()
214	add_custom_command(TARGET ${BINARY_NAME}-qt POST_BUILD COMMAND ${CMAKE_SOURCE_DIR}/tools/deploy-mac.py ${DEPLOY_OPTIONS} ${PROJECT_NAME}.app)
215endif()