src/platform/sdl/CMakeLists.txt (view raw)
1set(SDL_VERSION "2" CACHE STRING "Version of SDL to use (1.2 or 2)")
2set(BUILD_GL ON CACHE STRING "Build with OpenGL")
3
4if (SDL_VERSION EQUAL "2")
5 include(FindPkgConfig)
6 pkg_search_module(SDL2 sdl2)
7 if (SDL2_FOUND)
8 set(SDL_INCLUDE_DIR ${SDL2_INCLUDE_DIRS} CACHE INTERNAL "")
9 set(SDL_LIBRARY ${SDL2_LIBRARIES} CACHE INTERNAL "")
10 set(SDLMAIN_LIBRARY "" CACHE INTERNAL "")
11 link_directories(${SDL2_LIBDIR})
12 set(SDL_VERSION_DEBIAN "2-2.0-0")
13 endif()
14endif()
15
16if(SDL_VERSION EQUAL "1.2" OR NOT SDL2_FOUND)
17 find_package(SDL 1.2)
18 set(SDL_VERSION "1.2" PARENT_SCOPE)
19 set(SDL_VERSION_DEBIAN "1.2debian")
20endif()
21
22if (NOT SDL2_FOUND AND NOT SDL_FOUND)
23 set(BUILD_SDL OFF PARENT_SCOPE)
24 return()
25endif()
26
27set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libsdl${SDL_VERSION_DEBIAN}" PARENT_SCOPE)
28
29file(GLOB PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-*.c)
30set(PLATFORM_LIBRARY ${SDL_LIBRARY} ${SDLMAIN_LIBRARY})
31include_directories(${CMAKE_SOURCE_DIR}/src/platform/sdl ${SDL_INCLUDE_DIR})
32
33set(MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/main.c)
34
35if(BUILD_RASPI)
36 add_definitions(-DBUILD_RASPI)
37 set(EGL_MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/egl-sdl.c)
38 set(EGL_LIBRARY "-lEGL -lGLESv2 -lbcm_host")
39 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fgnu89-inline")
40 add_executable(${BINARY_NAME}-rpi ${PLATFORM_SRC} ${MAIN_SRC} ${EGL_MAIN_SRC})
41 target_link_libraries(${BINARY_NAME}-rpi ${BINARY_NAME} ${PLATFORM_LIBRARY} ${EGL_LIBRARY})
42 install(TARGETS ${BINARY_NAME}-rpi DESTINATION bin COMPONENT ${BINARY_NAME}-rpi)
43endif()
44
45if(BUILD_BBB OR BUILD_RASPI OR NOT BUILD_GL)
46 list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sw-sdl.c)
47else()
48 list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-sdl.c)
49 add_definitions(-DBUILD_GL)
50 find_package(OpenGL REQUIRED)
51 include_directories(${OPENGL_INCLUDE_DIR})
52endif()
53
54add_executable(${BINARY_NAME}-sdl WIN32 ${PLATFORM_SRC} ${MAIN_SRC})
55target_link_libraries(${BINARY_NAME}-sdl ${BINARY_NAME} ${PLATFORM_LIBRARY} ${OPENGL_LIBRARY})
56set_target_properties(${BINARY_NAME}-sdl PROPERTIES OUTPUT_NAME ${BINARY_NAME})
57install(TARGETS ${BINARY_NAME}-sdl DESTINATION bin COMPONENT ${BINARY_NAME}-sdl)