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