all repos — mgba @ 72fa184bac4f7eee1a07b6deba3147f1fa976c92

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