all repos — mgba @ 0cd28060e07c587ab10901ce815563a9e998f297

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