FindSDL2
This commit is contained in:
@@ -57,7 +57,7 @@ if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
|||||||
find_package(SDL2 REQUIRED)
|
find_package(SDL2 REQUIRED)
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
target_link_libraries(${DUSK_TARGET_NAME} PRIVATE
|
target_link_libraries(${DUSK_TARGET_NAME} PRIVATE
|
||||||
SDL2::SDL2
|
SDL2
|
||||||
OpenGL::GL
|
OpenGL::GL
|
||||||
GL
|
GL
|
||||||
)
|
)
|
||||||
|
42
cmake/modules/FindSDL2.cmake
Normal file
42
cmake/modules/FindSDL2.cmake
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# Try to find SDL2 in common locations
|
||||||
|
find_path(SDL2_INCLUDE_DIR SDL.h
|
||||||
|
PATHS
|
||||||
|
/usr/include/SDL2
|
||||||
|
/usr/local/include/SDL2
|
||||||
|
$ENV{SDL2_DIR}/include
|
||||||
|
PATH_SUFFIXES SDL2
|
||||||
|
)
|
||||||
|
|
||||||
|
find_library(SDL2_LIBRARY
|
||||||
|
NAMES SDL2
|
||||||
|
PATHS
|
||||||
|
/usr/lib
|
||||||
|
/usr/local/lib
|
||||||
|
$ENV{SDL2_DIR}/lib
|
||||||
|
)
|
||||||
|
|
||||||
|
if(SDL2_INCLUDE_DIR AND SDL2_LIBRARY)
|
||||||
|
set(SDL2_FOUND TRUE)
|
||||||
|
set(SDL2_LIBRARIES ${SDL2_LIBRARY})
|
||||||
|
set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIR})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# If not found, use FetchContent to acquire SDL2
|
||||||
|
if(NOT SDL2_FOUND)
|
||||||
|
include(FetchContent)
|
||||||
|
FetchContent_Declare(
|
||||||
|
SDL2
|
||||||
|
GIT_REPOSITORY https://github.com/libsdl-org/SDL.git
|
||||||
|
GIT_TAG release-2.28.5 # Change to desired version
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(SDL2)
|
||||||
|
set(SDL2_FOUND TRUE)
|
||||||
|
set(SDL2_LIBRARIES SDL2)
|
||||||
|
set(SDL2_INCLUDE_DIRS ${sdl2_SOURCE_DIR}/include)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Provide variables for downstream usage
|
||||||
|
if(SDL2_FOUND)
|
||||||
|
set(SDL2_INCLUDE_DIR ${SDL2_INCLUDE_DIRS} CACHE PATH "SDL2 include directory")
|
||||||
|
set(SDL2_LIBRARY ${SDL2_LIBRARIES} CACHE FILEPATH "SDL2 library")
|
||||||
|
endif()
|
Reference in New Issue
Block a user