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})
9 set(SDL_LIBRARY ${SDL2_LIBRARIES})
10 set(SDLMAIN_LIBRARY "")
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")
20 set(USE_PIXMAN ON)
21endif()
22
23if (NOT SDL2_FOUND AND NOT SDL_FOUND)
24 set(BUILD_SDL OFF PARENT_SCOPE)
25 return()
26endif()
27
28find_feature(USE_PIXMAN "pixman-1")
29if(USE_PIXMAN)
30 add_definitions(-DUSE_PIXMAN)
31 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libpixman-1.0" PARENT_SCOPE)
32endif()
33
34if(WIN32)
35 list(APPEND SDL_LIBRARY imm32 version winmm)
36elseif(APPLE)
37 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework AppKit -framework AudioUnit -framework Carbon -framework CoreAudio -framework ForceFeedback -framework IOKit")
38 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" PARENT_SCOPE)
39endif()
40
41set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libsdl${SDL_VERSION_DEBIAN}" PARENT_SCOPE)
42
43file(GLOB PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-*.c)
44set(PLATFORM_LIBRARY ${SDL_LIBRARY} ${SDLMAIN_LIBRARY} ${PIXMAN-1_LIBRARIES})
45include_directories(${CMAKE_SOURCE_DIR}/src/platform/sdl ${PIXMAN-1_INCLUDE_DIR} ${SDL_INCLUDE_DIR})
46
47set(SDL_INCLUDE_DIR "${SDL_INCLUDE_DIR}" PARENT_SCOPE)
48set(SDL_LIBRARY "${SDL_LIBRARY}" PARENT_SCOPE)
49set(SDLMAIN_LIBRARY "${SDLMAIN_LIBRARY}" PARENT_SCOPE)
50
51set(MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/main.c)
52
53if(BUILD_RASPI)
54 add_definitions(-DBUILD_RASPI)
55 set(EGL_MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/egl-sdl.c)
56 set(EGL_LIBRARY "-lEGL -lGLESv2 -lbcm_host")
57 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fgnu89-inline")
58 add_executable(${BINARY_NAME}-rpi ${PLATFORM_SRC} ${MAIN_SRC} ${EGL_MAIN_SRC})
59 set_target_properties(${BINARY_NAME}-rpi PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES}")
60 target_link_libraries(${BINARY_NAME}-rpi ${BINARY_NAME} ${PLATFORM_LIBRARY} ${EGL_LIBRARY})
61 install(TARGETS ${BINARY_NAME}-rpi DESTINATION bin COMPONENT ${BINARY_NAME}-rpi)
62endif()
63
64if(BUILD_PANDORA)
65 list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/pandora-sdl.c)
66else()
67 list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sw-sdl.c)
68 if(BUILD_GL)
69 list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-sdl.c)
70 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gl.c)
71 add_definitions(-DBUILD_GL)
72 find_package(OpenGL REQUIRED)
73 include_directories(${OPENGL_INCLUDE_DIR})
74 endif()
75endif()
76
77add_executable(${BINARY_NAME}-sdl WIN32 ${PLATFORM_SRC} ${MAIN_SRC})
78set_target_properties(${BINARY_NAME}-sdl PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES}")
79target_link_libraries(${BINARY_NAME}-sdl ${BINARY_NAME} ${PLATFORM_LIBRARY} ${OPENGL_LIBRARY})
80set_target_properties(${BINARY_NAME}-sdl PROPERTIES OUTPUT_NAME ${BINARY_NAME})
81install(TARGETS ${BINARY_NAME}-sdl DESTINATION bin COMPONENT ${BINARY_NAME}-sdl)