cmake: add SDL2 support to cmake build script
This commit is contained in:
parent
4e13e65b1c
commit
f713d5d2d7
@ -1,7 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
|
||||
project(librw C CXX)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
||||
|
||||
if(PS2DEV AND EE)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/cmake/ee.cmake")
|
||||
endif()
|
||||
@ -19,6 +20,16 @@ if(NOT LIBRW_PLATFORM IN_LIST LIBRW_PLATFORMS)
|
||||
message(FATAL_ERROR "Illegal LIBRW_PLATFORM=${LIBRW_PLATFORM}")
|
||||
endif()
|
||||
|
||||
set(LIBRW_GL3_GFXLIBS "GLFW" "SDL2")
|
||||
set(LIBRW_GL3_GFXLIB "GLFW" CACHE STRING "gfxlib for gl3")
|
||||
set_property(CACHE LIBRW_GL3_GFXLIB PROPERTY STRINGS ${LIBRW_GL3_GFXLIBS})
|
||||
if(LIBRW_PLATFORM_GL3)
|
||||
message(STATUS "LIBRW_GL3_GFXLIB = ${LIBRW_GL3_GFXLIB} (choices=${LIBRW_GL3_GFXLIBS})")
|
||||
endif()
|
||||
if(NOT LIBRW_GL3_GFXLIB IN_LIST LIBRW_GL3_GFXLIBS)
|
||||
message(FATAL_ERROR "Illegal LIBRW_GL3_GFXLIB=${LIBRW_GL3_GFXLIB}")
|
||||
endif()
|
||||
|
||||
if(LIBRW_PLATFORM_PS2)
|
||||
enable_language(DSM)
|
||||
endif()
|
||||
@ -41,7 +52,7 @@ endif()
|
||||
|
||||
if(LIBRW_INSTALL)
|
||||
include(CMakePackageConfigHelpers)
|
||||
configure_package_config_file(librw-config.cmake.in librw-config.cmake
|
||||
configure_package_config_file(cmake/librw-config.cmake.in librw-config.cmake
|
||||
INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}"
|
||||
)
|
||||
install(
|
||||
|
27
cmake/FindSDL2.cmake
Normal file
27
cmake/FindSDL2.cmake
Normal file
@ -0,0 +1,27 @@
|
||||
find_package(PkgConfig QUIET)
|
||||
if(PKG_CONFIG_FOUND)
|
||||
pkg_check_modules(SDL2 IMPORTED_TARGET "sdl2")
|
||||
if(TARGET PkgConfig::SDL2 AND NOT TARGET sdl2::sdl2)
|
||||
add_library(_sdl2 INTERFACE)
|
||||
target_link_libraries(_sdl2 INTERFACE PkgConfig::SDL2)
|
||||
add_library(SDL2::SDL2 ALIAS _sdl2)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT SDL2_FOUND)
|
||||
find_path(SDL2_INCLUDE_DIR sdl2.h)
|
||||
find_library(SDL2_LIBRARY sdl2)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(libuv
|
||||
REQUIRED_VARS SDL2_INCLUDE_DIR SDL2_LIBRARY
|
||||
)
|
||||
|
||||
if(NOT TARGET SDL2::SDL2)
|
||||
add_library(SDL2::SDL2 UNKNOWN IMPORTED)
|
||||
set_target_properties(SDL2::SDL2 PROPERTIES
|
||||
IMPORTED_LOCATION "${SDL2_LIBRARY}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
|
||||
)
|
||||
endif()
|
||||
endif()
|
19
cmake/librw-config.cmake.in
Normal file
19
cmake/librw-config.cmake.in
Normal file
@ -0,0 +1,19 @@
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/librw-targets.cmake")
|
||||
|
||||
set(LIBRW_PLATFORM "@LIBRW_PLATFORM@")
|
||||
set(LIBRW_PLATFORMS "@LIBRW_PLATFORMS@")
|
||||
set(LIBRW_PLATFORM_@LIBRW_PLATFORM@ ON)
|
||||
|
||||
if(LIBRW_PLATFORM_GL3)
|
||||
set(LIBRW_GL3_GFXLIB "@LIBRW_GL3_GFXLIB@")
|
||||
set(LIBRW_GL3_GFXLIBS "@LIBRW_GL3_GFXLIBS@")
|
||||
|
||||
set(OpenGL_GL_PREFERENCE GLVND)
|
||||
find_package(OpenGL REQUIRED)
|
||||
if(LIBRW_GL3_GFXLIB STREQUAL "GLFW")
|
||||
find_package(GLEW REQUIRED)
|
||||
find_package(glfw3 REQUIRED)
|
||||
elseif(LIBRW_GL3_GFXLIB STREQUAL "GLFW")
|
||||
find_package(SDL2 REQUIRED)
|
||||
endif()
|
||||
endif()
|
@ -1,12 +0,0 @@
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/librw-targets.cmake")
|
||||
|
||||
set(LIBRW_PLATFORM "@LIBRW_PLATFORM@")
|
||||
set(LIBRW_PLATFORMS "@LIBRW_PLATFORMS@")
|
||||
set(LIBRW_PLATFORM_@LIBRW_PLATFORM@ ON)
|
||||
|
||||
if(LIBRW_PLATFORM_GL3)
|
||||
set(OpenGL_GL_PREFERENCE GLVND)
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(GLEW REQUIRED)
|
||||
find_package(glfw3 REQUIRED)
|
||||
endif()
|
@ -1,5 +1,6 @@
|
||||
add_library(librw_skeleton
|
||||
glfw.cpp
|
||||
sdl2.cpp
|
||||
skeleton.cpp
|
||||
skeleton.h
|
||||
win.cpp
|
||||
|
@ -1,10 +1,3 @@
|
||||
if(LIBRW_PLATFORM_GL3)
|
||||
set(OpenGL_GL_PREFERENCE GLVND)
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(GLEW REQUIRED)
|
||||
find_package(glfw3 REQUIRED)
|
||||
endif()
|
||||
|
||||
add_library(librw
|
||||
"${PROJECT_SOURCE_DIR}/args.h"
|
||||
"${PROJECT_SOURCE_DIR}/rw.h"
|
||||
@ -145,12 +138,33 @@ set_target_properties(librw
|
||||
)
|
||||
|
||||
if(LIBRW_PLATFORM_GL3)
|
||||
|
||||
|
||||
if(LIBRW_PLATFORM_GL3)
|
||||
set(OpenGL_GL_PREFERENCE GLVND)
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(GLEW REQUIRED)
|
||||
|
||||
target_link_libraries(librw
|
||||
PUBLIC
|
||||
glfw
|
||||
GLEW::GLEW
|
||||
OpenGL::GL
|
||||
GLEW::GLEW
|
||||
)
|
||||
if (LIBRW_GL3_GFXLIB STREQUAL "GLFW")
|
||||
find_package(glfw3 REQUIRED)
|
||||
target_link_libraries(librw
|
||||
PUBLIC
|
||||
glfw
|
||||
)
|
||||
elseif (LIBRW_GL3_GFXLIB STREQUAL "SDL2")
|
||||
find_package(SDL2 REQUIRED)
|
||||
target_compile_definitions(librw PUBLIC LIBRW_SDL2)
|
||||
target_link_libraries(librw
|
||||
PUBLIC
|
||||
SDL2::SDL2
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
elseif(LIBRW_PLATFORM_D3D9)
|
||||
target_link_libraries(librw
|
||||
PUBLIC
|
||||
|
Loading…
Reference in New Issue
Block a user