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 set(SDL_VERSION "1.2" PARENT_SCOPE)
17 set(SDL_VERSION_DEBIAN "1.2debian")
18 set(USE_PIXMAN ON)
19endif()
20
21if (NOT SDL2_FOUND AND NOT SDL_FOUND)
22 set(BUILD_SDL OFF PARENT_SCOPE)
23 return()
24endif()
25
26add_definitions(-DBUILD_SDL)
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
41if(NOT SDLMAIN_LIBRARY)
42 set(SDLMAIN_LIBRARY "")
43endif()
44
45set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libsdl${SDL_VERSION_DEBIAN}" PARENT_SCOPE)
46
47file(GLOB PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-*.c)
48set(PLATFORM_LIBRARY ${SDL_LIBRARY} ${SDLMAIN_LIBRARY} ${PIXMAN-1_LIBRARIES})
49include_directories(${CMAKE_SOURCE_DIR}/src/platform/sdl ${PIXMAN-1_INCLUDE_DIRS} ${SDL_INCLUDE_DIR})
50
51set(SDL_INCLUDE_DIR "${SDL_INCLUDE_DIR}" PARENT_SCOPE)
52set(SDL_LIBRARY "${SDL_LIBRARY}" PARENT_SCOPE)
53set(SDLMAIN_LIBRARY "${SDLMAIN_LIBRARY}" PARENT_SCOPE)
54
55set(MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/main.c)
56
57if(BUILD_RASPI)
58 add_definitions(-DBUILD_RASPI)
59 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-common.c)
60 list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/gles2-sdl.c)
61 set(OPENGLES2_LIBRARY "-lEGL -lGLESv2 -lbcm_host")
62 set(BUILD_GLES2 ON CACHE BOOL "Using OpenGL|ES 2" FORCE)
63 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fgnu89-inline")
64 add_executable(${BINARY_NAME}-rpi ${PLATFORM_SRC} ${MAIN_SRC})
65 set_target_properties(${BINARY_NAME}-rpi PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES};${FUNCTION_DEFINES}")
66 target_link_libraries(${BINARY_NAME}-rpi ${BINARY_NAME} ${PLATFORM_LIBRARY} ${OPENGLES2_LIBRARY})
67 install(TARGETS ${BINARY_NAME}-rpi DESTINATION bin COMPONENT ${BINARY_NAME}-rpi)
68 unset(OPENGLES2_INCLUDE_DIR} CACHE) # Clear NOTFOUND
69endif()
70
71if(BUILD_PANDORA)
72 list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/pandora-sdl.c)
73else()
74 if(BUILD_GL)
75 list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-sdl.c)
76 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gl.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-common.c)
77 include_directories(${OPENGL_INCLUDE_DIR})
78 endif()
79 if(BUILD_GLES2)
80 list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/gles2-sdl.c)
81 list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-common.c)
82 include_directories(${OPENGLES2_INCLUDE_DIR})
83 endif()
84 if(NOT BUILD_GL AND NOT BUILD_GLES2)
85 list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sw-sdl.c)
86 endif()
87endif()
88
89if(ENABLE_SCRIPTING)
90 if(BUILD_PYTHON)
91 list(APPEND PLATFORM_LIBRARY "${PYTHON_LIBRARY}")
92 endif()
93endif()
94
95add_executable(${BINARY_NAME}-sdl WIN32 ${PLATFORM_SRC} ${MAIN_SRC})
96set_target_properties(${BINARY_NAME}-sdl PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES};${FUNCTION_DEFINES}")
97target_link_libraries(${BINARY_NAME}-sdl ${BINARY_NAME} ${PLATFORM_LIBRARY} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
98set_target_properties(${BINARY_NAME}-sdl PROPERTIES OUTPUT_NAME ${BINARY_NAME})
99install(TARGETS ${BINARY_NAME}-sdl DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-sdl)
100if(UNIX)
101 install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-sdl)
102endif()