all repos — mgba @ af35438aaab9307f0451f358a678644d4d9336ba

mGBA Game Boy Advance Emulator

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

  1set(SDL_VERSION "2" CACHE STRING "Version of SDL to use (1.2 or 2)")
  2
  3if (SDL_VERSION EQUAL "2")
  4	include(FindPkgConfig)
  5	pkg_search_module(SDL2 sdl2)
  6	if (SDL2_FOUND)
  7		set(SDL_INCLUDE_DIR ${SDL2_INCLUDE_DIRS})
  8		set(SDL_LIBRARY ${SDL2_LIBRARIES})
  9		link_directories(${SDL2_LIBDIR})
 10		set(SDL_VERSION_DEBIAN "2-2.0-0")
 11		set(SDL_FOUND ON PARENT_SCOPE)
 12	endif()
 13endif()
 14
 15if(SDL_VERSION EQUAL "1.2" OR NOT SDL2_FOUND)
 16	find_package(SDL 1.2)
 17	if(SDL_FOUND)
 18		set(SDL_VERSION "1.2")
 19		set(SDL_VERSION_DEBIAN "1.2debian")
 20		set(USE_PIXMAN ON)
 21	endif()
 22endif()
 23
 24if (NOT SDL2_FOUND AND NOT SDL_FOUND)
 25	set(SDL_FOUND OFF PARENT_SCOPE)
 26	return()
 27endif()
 28
 29set(SDL_VERSION "${SDL_VERSION}" PARENT_SCOPE)
 30add_definitions(-DBUILD_SDL)
 31
 32find_feature(USE_PIXMAN "pixman-1")
 33if(USE_PIXMAN)
 34	add_definitions(-DUSE_PIXMAN)
 35	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libpixman-1.0" PARENT_SCOPE)
 36endif()
 37
 38if(WIN32)
 39	list(APPEND SDL_LIBRARY imm32 version winmm)
 40elseif(APPLE)
 41	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework AppKit -framework AudioUnit -framework Carbon -framework CoreAudio -framework AudioToolbox -framework ForceFeedback -framework IOKit")
 42	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" PARENT_SCOPE)
 43endif()
 44
 45if(NOT SDLMAIN_LIBRARY)
 46	set(SDLMAIN_LIBRARY "")
 47endif()
 48
 49set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libsdl${SDL_VERSION_DEBIAN}" PARENT_SCOPE)
 50
 51file(GLOB PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-*.c)
 52set(PLATFORM_LIBRARY ${SDL_LIBRARY} ${SDLMAIN_LIBRARY} ${PIXMAN-1_LIBRARIES})
 53include_directories(${CMAKE_SOURCE_DIR}/src/platform/sdl ${PIXMAN-1_INCLUDE_DIRS} ${SDL_INCLUDE_DIR})
 54
 55set(SDL_INCLUDE_DIR "${SDL_INCLUDE_DIR}" PARENT_SCOPE)
 56set(SDL_LIBRARY "${SDL_LIBRARY}" PARENT_SCOPE)
 57set(SDLMAIN_LIBRARY "${SDLMAIN_LIBRARY}" PARENT_SCOPE)
 58
 59set(MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/main.c)
 60
 61if(BUILD_RASPI)
 62	add_definitions(-DBUILD_RASPI)
 63	list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-common.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/rpi-common.c)
 64	list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/gles2-sdl.c)
 65	set(OPENGLES2_LIBRARY "-lEGL -lGLESv2 -lbcm_host")
 66	set(BUILD_GLES2 ON CACHE BOOL "Using OpenGL|ES 2" FORCE)
 67	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fgnu89-inline")
 68	add_executable(${BINARY_NAME}-rpi ${PLATFORM_SRC} ${MAIN_SRC})
 69	set_target_properties(${BINARY_NAME}-rpi PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES};${FUNCTION_DEFINES}")
 70	target_link_libraries(${BINARY_NAME}-rpi ${BINARY_NAME} ${PLATFORM_LIBRARY} ${OPENGLES2_LIBRARY})
 71	install(TARGETS ${BINARY_NAME}-rpi DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-rpi)
 72	unset(OPENGLES2_INCLUDE_DIR CACHE) # Clear NOTFOUND
 73endif()
 74
 75if(BUILD_PANDORA)
 76	list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/pandora-sdl.c)
 77else()
 78	if(BUILD_GL)
 79		list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-sdl.c)
 80		list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gl.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-common.c)
 81		include_directories(${OPENGL_INCLUDE_DIR})
 82	endif()
 83	if(BUILD_GLES2)
 84		list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/gles2-sdl.c)
 85		list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-common.c)
 86		include_directories(${OPENGLES2_INCLUDE_DIR})
 87	endif()
 88	if(NOT BUILD_GL AND NOT BUILD_GLES2)
 89		if(SDL_VERSION EQUAL "2")
 90			list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sw-sdl2.c)
 91		else()
 92			list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sw-sdl1.c)
 93		endif()
 94	endif()
 95endif()
 96
 97if(ENABLE_SCRIPTING)
 98	if(BUILD_PYTHON)
 99		list(APPEND PLATFORM_LIBRARY ${BINARY_NAME}-pylib)
100	endif()
101endif()
102
103add_executable(${BINARY_NAME}-sdl WIN32 ${PLATFORM_SRC} ${MAIN_SRC})
104set_target_properties(${BINARY_NAME}-sdl PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES};${FUNCTION_DEFINES}")
105target_link_libraries(${BINARY_NAME}-sdl ${BINARY_NAME} ${PLATFORM_LIBRARY} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
106if(NOT WIN32)
107	set_target_properties(${BINARY_NAME}-sdl PROPERTIES OUTPUT_NAME ${BINARY_NAME})
108endif()
109install(TARGETS ${BINARY_NAME}-sdl DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-sdl)
110if(UNIX)
111	install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-sdl)
112endif()
113
114if(DISTBUILD AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
115	if(NOT APPLE)
116		add_custom_command(TARGET ${BINARY_NAME}-sdl POST_BUILD COMMAND "${OBJCOPY}" --only-keep-debug "$<TARGET_FILE:${BINARY_NAME}-sdl>" "$<TARGET_FILE:${BINARY_NAME}-sdl>.dSYM")
117		add_custom_command(TARGET ${BINARY_NAME}-sdl POST_BUILD COMMAND "${STRIP}" -S "$<TARGET_FILE:${BINARY_NAME}-sdl>")
118		install(FILES "$<TARGET_FILE:${BINARY_NAME}-sdl>.dSYM" DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-sdl-dbg)
119	endif()
120endif()