all repos — mgba @ 1d5f8817a5980ba90556d3679fd3dc7aa18a8fe1

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 (NOT SDL2_FOUND)
  7		find_package(SDL2)
  8	endif()
  9	
 10	if (SDL2_FOUND)
 11		set(SDL_INCLUDE_DIR ${SDL2_INCLUDE_DIRS})
 12		set(SDL_LIBRARY ${SDL2_LIBRARIES})
 13		link_directories(${SDL2_LIBDIR})
 14		set(SDL_VERSION_DEBIAN "2-2.0-0")
 15		set(SDL_FOUND ON PARENT_SCOPE)
 16
 17		if (NOT SDL2MAIN_LIBRARY)
 18			set(SDL2MAIN_LIBRARY "")
 19		endif()
 20
 21		set(SDLMAIN_LIBRARY ${SDL2MAIN_LIBRARY})
 22	endif()
 23endif()
 24
 25if(SDL_VERSION EQUAL "1.2" OR NOT SDL2_FOUND)
 26	find_package(SDL 1.2)
 27	if(SDL_FOUND)
 28		set(SDL_VERSION "1.2")
 29		set(SDL_VERSION_DEBIAN "1.2debian")
 30		set(USE_PIXMAN ON)
 31	endif()
 32endif()
 33
 34if (NOT SDL2_FOUND AND NOT SDL_FOUND)
 35	set(SDL_FOUND OFF PARENT_SCOPE)
 36	return()
 37endif()
 38
 39set(SDL_VERSION "${SDL_VERSION}" PARENT_SCOPE)
 40add_definitions(-DBUILD_SDL)
 41
 42find_feature(USE_PIXMAN "pixman-1")
 43if(USE_PIXMAN)
 44	add_definitions(-DUSE_PIXMAN)
 45	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libpixman-1.0" PARENT_SCOPE)
 46endif()
 47
 48if(WIN32)
 49	list(APPEND SDL_LIBRARY imm32 version winmm)
 50elseif(APPLE)
 51	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework AppKit -framework AudioUnit -framework Carbon -framework CoreAudio -framework AudioToolbox -framework ForceFeedback -framework IOKit")
 52	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" PARENT_SCOPE)
 53endif()
 54
 55if(NOT SDLMAIN_LIBRARY)
 56	set(SDLMAIN_LIBRARY "")
 57endif()
 58
 59set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libsdl${SDL_VERSION_DEBIAN}" PARENT_SCOPE)
 60
 61file(GLOB PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sdl-*.c)
 62set(PLATFORM_LIBRARY ${SDL_LIBRARY} ${SDLMAIN_LIBRARY} ${PIXMAN-1_LIBRARIES})
 63include_directories(${CMAKE_SOURCE_DIR}/src/platform/sdl ${PIXMAN-1_INCLUDE_DIRS} ${SDL_INCLUDE_DIR})
 64
 65set(SDL_INCLUDE_DIR "${SDL_INCLUDE_DIR}" PARENT_SCOPE)
 66set(SDL_LIBRARY "${SDL_LIBRARY}" PARENT_SCOPE)
 67set(SDLMAIN_LIBRARY "${SDLMAIN_LIBRARY}" PARENT_SCOPE)
 68
 69set(MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/main.c)
 70
 71if(BUILD_RASPI)
 72	add_definitions(-DBUILD_RASPI)
 73	list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/opengl/gles2.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-common.c ${CMAKE_SOURCE_DIR}/src/platform/sdl/rpi-common.c)
 74	list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/gles2-sdl.c)
 75	set(OPENGLES2_LIBRARY "-lEGL -lGLESv2 -lbcm_host")
 76	set(BUILD_GLES2 ON CACHE BOOL "Using OpenGL|ES 2" FORCE)
 77	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fgnu89-inline")
 78	add_executable(${BINARY_NAME}-rpi ${PLATFORM_SRC} ${MAIN_SRC})
 79	set_target_properties(${BINARY_NAME}-rpi PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES};${FUNCTION_DEFINES}")
 80	target_link_libraries(${BINARY_NAME}-rpi ${BINARY_NAME} ${PLATFORM_LIBRARY} ${OPENGLES2_LIBRARY})
 81	install(TARGETS ${BINARY_NAME}-rpi DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-rpi)
 82	unset(OPENGLES2_INCLUDE_DIR CACHE) # Clear NOTFOUND
 83endif()
 84
 85if(BUILD_PANDORA)
 86	list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/pandora-sdl.c)
 87else()
 88	if(BUILD_GL)
 89		list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-sdl.c)
 90		list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-common.c)
 91	endif()
 92	if(BUILD_GLES2)
 93		list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/gles2-sdl.c)
 94		list(APPEND PLATFORM_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/gl-common.c)
 95		include_directories(${OPENGLES2_INCLUDE_DIR})
 96	endif()
 97	if(NOT BUILD_GL AND NOT BUILD_GLES2)
 98		if(SDL_VERSION EQUAL "2")
 99			list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sw-sdl2.c)
100		else()
101			list(APPEND MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/sw-sdl1.c)
102		endif()
103	endif()
104endif()
105
106if(ENABLE_SCRIPTING)
107	if(BUILD_PYTHON)
108		list(APPEND PLATFORM_LIBRARY ${BINARY_NAME}-pylib)
109	endif()
110endif()
111
112add_executable(${BINARY_NAME}-sdl WIN32 ${PLATFORM_SRC} ${MAIN_SRC})
113set_target_properties(${BINARY_NAME}-sdl PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES};${FUNCTION_DEFINES}")
114target_link_libraries(${BINARY_NAME}-sdl ${BINARY_NAME} ${PLATFORM_LIBRARY} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
115if(NOT WIN32)
116	set_target_properties(${BINARY_NAME}-sdl PROPERTIES OUTPUT_NAME ${BINARY_NAME})
117endif()
118if (WIN32 AND MSVC)
119	set_target_properties(${BINARY_NAME}-sdl PROPERTIES LINK_FLAGS "/SUBSYSTEM:CONSOLE")
120endif()
121install(TARGETS ${BINARY_NAME}-sdl DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-sdl)
122if(UNIX)
123	install(FILES ${CMAKE_SOURCE_DIR}/doc/mgba.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-sdl)
124endif()
125
126if(DISTBUILD AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
127	if(NOT APPLE)
128		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")
129		add_custom_command(TARGET ${BINARY_NAME}-sdl POST_BUILD COMMAND "${STRIP}" -S "$<TARGET_FILE:${BINARY_NAME}-sdl>")
130		install(FILES "$<TARGET_FILE:${BINARY_NAME}-sdl>.dSYM" DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-sdl-dbg)
131	endif()
132endif()