all repos — mgba @ e12db1e9d8db34cc6cc070a5d4b2f00d1c42fb78

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	endif()
 12endif()
 13
 14if(SDL_VERSION EQUAL "1.2" OR NOT SDL2_FOUND)
 15	find_package(SDL 1.2)
 16	if(SDL_FOUND)
 17		set(SDL_VERSION "1.2" PARENT_SCOPE)
 18		set(SDL_VERSION_DEBIAN "1.2debian")
 19		set(USE_PIXMAN ON)
 20	endif()
 21endif()
 22
 23if (NOT SDL2_FOUND AND NOT SDL_FOUND)
 24	set(SDL_FOUND OFF PARENT_SCOPE)
 25	return()
 26endif()
 27
 28add_definitions(-DBUILD_SDL)
 29
 30find_feature(USE_PIXMAN "pixman-1")
 31if(USE_PIXMAN)
 32	add_definitions(-DUSE_PIXMAN)
 33	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libpixman-1.0" PARENT_SCOPE)
 34endif()
 35
 36if(WIN32)
 37	list(APPEND SDL_LIBRARY imm32 version winmm)
 38elseif(APPLE)
 39	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework AppKit -framework AudioUnit -framework Carbon -framework CoreAudio -framework AudioToolbox -framework ForceFeedback -framework IOKit")
 40	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" PARENT_SCOPE)
 41endif()
 42
 43if(NOT SDLMAIN_LIBRARY)
 44	set(SDLMAIN_LIBRARY "")
 45endif()
 46
 47set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libsdl${SDL_VERSION_DEBIAN}" PARENT_SCOPE)
 48
 49file(GLOB PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-*.c)
 50set(PLATFORM_LIBRARY ${SDL_LIBRARY} ${SDLMAIN_LIBRARY} ${PIXMAN-1_LIBRARIES})
 51include_directories(${CMAKE_SOURCE_DIR}/src/platform/sdl ${PIXMAN-1_INCLUDE_DIRS} ${SDL_INCLUDE_DIR})
 52
 53set(SDL_INCLUDE_DIR "${SDL_INCLUDE_DIR}" PARENT_SCOPE)
 54set(SDL_LIBRARY "${SDL_LIBRARY}" PARENT_SCOPE)
 55set(SDLMAIN_LIBRARY "${SDLMAIN_LIBRARY}" PARENT_SCOPE)
 56
 57set(MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/main.c)
 58
 59if(BUILD_RASPI)
 60	add_definitions(-DBUILD_RASPI)
 61	list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-common.c)
 62	list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/gles2-sdl.c)
 63	set(OPENGLES2_LIBRARY "-lEGL -lGLESv2 -lbcm_host")
 64	set(BUILD_GLES2 ON CACHE BOOL "Using OpenGL|ES 2" FORCE)
 65	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fgnu89-inline")
 66	add_executable(${BINARY_NAME}-rpi ${PLATFORM_SRC} ${MAIN_SRC})
 67	set_target_properties(${BINARY_NAME}-rpi PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES};${FUNCTION_DEFINES}")
 68	target_link_libraries(${BINARY_NAME}-rpi ${BINARY_NAME} ${PLATFORM_LIBRARY} ${OPENGLES2_LIBRARY})
 69	install(TARGETS ${BINARY_NAME}-rpi DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-rpi)
 70	unset(OPENGLES2_INCLUDE_DIR CACHE) # Clear NOTFOUND
 71endif()
 72
 73if(BUILD_PANDORA)
 74	list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/pandora-sdl.c)
 75else()
 76	if(BUILD_GL)
 77		list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-sdl.c)
 78		list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gl.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-common.c)
 79		include_directories(${OPENGL_INCLUDE_DIR})
 80	endif()
 81	if(BUILD_GLES2)
 82		list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/gles2-sdl.c)
 83		list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-common.c)
 84		include_directories(${OPENGLES2_INCLUDE_DIR})
 85	endif()
 86	if(NOT BUILD_GL AND NOT BUILD_GLES2)
 87		list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sw-sdl.c)
 88	endif()
 89endif()
 90
 91if(ENABLE_SCRIPTING)
 92	if(BUILD_PYTHON)
 93		list(APPEND PLATFORM_LIBRARY ${BINARY_NAME}-pylib)
 94	endif()
 95endif()
 96
 97add_executable(${BINARY_NAME}-sdl WIN32 ${PLATFORM_SRC} ${MAIN_SRC})
 98set_target_properties(${BINARY_NAME}-sdl PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES};${FUNCTION_DEFINES}")
 99target_link_libraries(${BINARY_NAME}-sdl ${BINARY_NAME} ${PLATFORM_LIBRARY} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
100if(NOT WIN32)
101	set_target_properties(${BINARY_NAME}-sdl PROPERTIES OUTPUT_NAME ${BINARY_NAME})
102endif()
103install(TARGETS ${BINARY_NAME}-sdl DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-sdl)
104if(UNIX)
105	install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-sdl)
106endif()