all repos — mgba @ 5966f46355d18ba472404a7f7ed3cbeebf846635

mGBA Game Boy Advance Emulator

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

  1cmake_minimum_required(VERSION 2.8.11)
  2enable_language(CXX)
  3
  4set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11")
  5
  6if(APPLE)
  7	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.7")
  8	if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  9		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
 10	endif()
 11endif()
 12
 13set(PLATFORM_SRC)
 14set(QT_STATIC OFF)
 15
 16if(BUILD_SDL)
 17	if(NOT SDL_FOUND AND NOT SDL2_FOUND)
 18		find_package(SDL 1.2 REQUIRED)
 19	endif()
 20	if(SDL2_FOUND)
 21		link_directories(${SDL2_LIBDIR})
 22	endif()
 23	list(APPEND PLATFORM_LIBRARY ${SDL_LIBRARY} ${SDLMAIN_LIBRARY})
 24	list(APPEND PLATFORM_SRC ${PLATFORM_SRC} ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-events.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-audio.c)
 25	include_directories(${SDL_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src/platform/sdl)
 26endif()
 27
 28set(CMAKE_AUTOMOC ON)
 29set(CMAKE_INCLUDE_CURRENT_DIR ON)
 30
 31if(NOT WIN32 OR NOT BUILD_SDL)
 32	find_package(Qt5Multimedia)
 33endif()
 34find_package(Qt5OpenGL)
 35find_package(Qt5Widgets)
 36
 37if(NOT BUILD_GL AND NOT BUILD_GLES2)
 38	message(WARNING "OpenGL is required to build the Qt port")
 39	set(BUILD_QT OFF PARENT_SCOPE)
 40	return()
 41endif()
 42
 43if(NOT Qt5OpenGL_FOUND OR NOT Qt5Widgets_FOUND)
 44	message(WARNING "Cannot find Qt modules")
 45	set(BUILD_QT OFF PARENT_SCOPE)
 46	return()
 47endif()
 48
 49if(BUILD_GL)
 50list(APPEND PLATFORM_SRC ${PLATFORM_SRC} ${CMAKE_SOURCE_DIR}/src/platform/opengl/gl.c)
 51endif()
 52
 53if(BUILD_GLES2)
 54list(APPEND PLATFORM_SRC ${PLATFORM_SRC} ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c)
 55endif()
 56
 57get_target_property(QT_TYPE Qt5::Core TYPE)
 58if(QT_TYPE STREQUAL STATIC_LIBRARY)
 59	set(QT_STATIC ON)
 60	add_definitions(-DQT_STATIC)
 61endif()
 62
 63set(SOURCE_FILES
 64	AboutScreen.cpp
 65	AudioProcessor.cpp
 66	CheatsModel.cpp
 67	CheatsView.cpp
 68	ConfigController.cpp
 69	Display.cpp
 70	DisplayGL.cpp
 71	DisplayQt.cpp
 72	GBAApp.cpp
 73	GBAKeyEditor.cpp
 74	GIFView.cpp
 75	GameController.cpp
 76	GamepadAxisEvent.cpp
 77	GamepadButtonEvent.cpp
 78	InputController.cpp
 79	InputProfile.cpp
 80	KeyEditor.cpp
 81	LoadSaveState.cpp
 82	LogController.cpp
 83	LogView.cpp
 84	MemoryModel.cpp
 85	MemoryView.cpp
 86	MessagePainter.cpp
 87	MultiplayerController.cpp
 88	OverrideView.cpp
 89	PaletteView.cpp
 90	SavestateButton.cpp
 91	SensorView.cpp
 92	SettingsView.cpp
 93	ShortcutController.cpp
 94	ShortcutView.cpp
 95	Swatch.cpp
 96	Window.cpp
 97	VFileDevice.cpp
 98	VideoView.cpp)
 99
100qt5_wrap_ui(UI_FILES
101	AboutScreen.ui
102	CheatsView.ui
103	GIFView.ui
104	LoadSaveState.ui
105	LogView.ui
106	MemoryView.ui
107	OverrideView.ui
108	PaletteView.ui
109	SensorView.ui
110	SettingsView.ui
111	ShortcutView.ui
112	VideoView.ui)
113
114set(QT_LIBRARIES)
115set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5,libqt5opengl5")
116
117set(AUDIO_SRC)
118if(BUILD_SDL)
119	list(APPEND AUDIO_SRC AudioProcessorSDL.cpp)
120endif()
121
122if(Qt5Multimedia_FOUND)
123	list(APPEND AUDIO_SRC
124		AudioProcessorQt.cpp
125		AudioDevice.cpp)
126	if (WIN32 AND QT_STATIC)
127		list(APPEND QT_LIBRARIES qtaudio_windows strmiids winmm)
128	endif()
129	list(APPEND QT_LIBRARIES Qt5::Multimedia)
130	add_definitions(-DBUILD_QT_MULTIMEDIA)
131	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5multimedia5")
132endif()
133
134if(NOT AUDIO_SRC)
135	message(WARNING "No supported audio modules found")
136	set(BUILD_QT OFF PARENT_SCOPE)
137	return()
138endif()
139
140if(USE_GDB_STUB)
141	list(APPEND PLATFORM_SRC GDBController.cpp GDBWindow.cpp)
142endif()
143set(MACOSX_BUNDLE_ICON_FILE mgba.icns)
144set(MACOSX_BUNDLE_BUNDLE_VERSION ${LIB_VERSION_STRING})
145set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
146set(MACOSX_BUNDLE_GUI_IDENTIFIER com.endrift.${BINARY_NAME}-qt)
147set_source_files_properties(${CMAKE_SOURCE_DIR}/res/mgba.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
148
149qt5_add_resources(RESOURCES resources.qrc)
150if(WIN32)
151	configure_file(${CMAKE_SOURCE_DIR}/res/mgba.rc.in ${CMAKE_BINARY_DIR}/res/mgba.rc)
152	list(APPEND RESOURCES ${CMAKE_BINARY_DIR}/res/mgba.rc)
153	if(QT_STATIC)
154		list(APPEND QT_LIBRARIES qwindows imm32)
155	endif()
156endif()
157add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_FILES} ${AUDIO_SRC} ${RESOURCES})
158set_target_properties(${BINARY_NAME}-qt PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/res/info.plist.in COMPILE_DEFINITIONS "${FEATURE_DEFINES}")
159
160list(APPEND QT_LIBRARIES Qt5::Widgets Qt5::OpenGL)
161target_link_libraries(${BINARY_NAME}-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
162set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
163
164install(TARGETS ${BINARY_NAME}-qt
165	RUNTIME DESTINATION bin COMPONENT ${BINARY_NAME}-qt
166	BUNDLE DESTINATION Applications COMPONENT ${BINARY_NAME}-qt)
167if(UNIX AND NOT APPLE)
168	find_program(DESKTOP_FILE_INSTALL desktop-file-install)
169	if(DESKTOP_FILE_INSTALL)
170		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/\")")
171	endif()
172endif()
173if(UNIX)
174	install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt)
175endif()
176if(APPLE OR WIN32)
177	set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
178endif()
179if(APPLE)
180	set(DEPLOY_OPTIONS -p platforms/libqcocoa.dylib,audio/libqtaudio_coreaudio.dylib)
181	if(NOT CMAKE_INSTALL_NAME_TOOL EQUAL "install_name_tool")
182		set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -I ${CMAKE_INSTALL_NAME_TOOL})
183	endif()
184	if(DEFINED CMAKE_OTOOL AND NOT CMAKE_OTOOL EQUAL "otool")
185		set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -O ${CMAKE_OTOOL})
186	endif()
187	if(DEFINED CROSS_ROOT)
188		set(DEPLOY_OPTIONS ${DEPLOY_OPTIONS} -R ${CROSS_ROOT})
189	endif()
190	add_custom_command(TARGET ${BINARY_NAME}-qt POST_BUILD COMMAND ${CMAKE_SOURCE_DIR}/tools/deploy-mac.py ${DEPLOY_OPTIONS} ${PROJECT_NAME}.app)
191endif()