2022-03-31 20:01:08 +00:00
|
|
|
################################################################################
|
|
|
|
## Author: Shaun Reed ##
|
|
|
|
## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
|
|
|
|
## ##
|
|
|
|
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
|
|
|
################################################################################
|
2019-10-15 01:51:50 +00:00
|
|
|
|
|
|
|
# Define CMake version
|
|
|
|
cmake_minimum_required(VERSION 3.15)
|
|
|
|
|
2021-05-24 20:20:54 +00:00
|
|
|
project(
|
|
|
|
#[[NAME]] SDL-Cmake
|
|
|
|
DESCRIPTION "Example project for building SDL projects with CMake"
|
|
|
|
LANGUAGES CXX
|
2019-10-15 01:51:50 +00:00
|
|
|
)
|
|
|
|
|
2021-05-24 20:20:54 +00:00
|
|
|
# Add Library
|
|
|
|
add_library(
|
2022-03-31 20:01:08 +00:00
|
|
|
graphics-lib-sdl # Library Name
|
|
|
|
src/lib-sdl-test.cpp src/lib-sdl-test.h # Sources..
|
2019-10-15 01:51:50 +00:00
|
|
|
)
|
|
|
|
|
2021-05-24 20:20:54 +00:00
|
|
|
target_include_directories( # When calling library, include a directory
|
2022-03-31 20:01:08 +00:00
|
|
|
graphics-lib-sdl # Library name
|
2021-05-24 20:20:54 +00:00
|
|
|
PUBLIC # Visibility
|
2022-03-31 20:01:08 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src # Source directory for library
|
|
|
|
)
|
2021-05-24 20:20:54 +00:00
|
|
|
|
|
|
|
# Search for SDL2 package
|
|
|
|
find_package(SDL2 REQUIRED sdl2)
|
|
|
|
|
|
|
|
# If SDL2 was found successfully, link to lib-sdl-test
|
|
|
|
if (SDL2_FOUND)
|
|
|
|
# Any target that links with this library will also link to SDL2
|
|
|
|
# + Because we choose PUBLIC visibility
|
2022-03-31 20:01:08 +00:00
|
|
|
target_include_directories(graphics-lib-sdl PUBLIC ${SDL2_INCLUDE_DIRS})
|
|
|
|
target_link_libraries(graphics-lib-sdl PUBLIC "${SDL2_LIBRARIES}")
|
2021-05-24 20:20:54 +00:00
|
|
|
|
|
|
|
# Creating executable
|
|
|
|
add_executable(
|
2022-03-31 20:01:08 +00:00
|
|
|
graphics-cmake-sdl # Exe name
|
|
|
|
apps/sdl-test.cpp # Exe Source(s)
|
2019-10-15 01:51:50 +00:00
|
|
|
)
|
|
|
|
|
2021-05-24 20:20:54 +00:00
|
|
|
# Linking the exe to library
|
|
|
|
target_link_libraries(
|
2022-03-31 20:01:08 +00:00
|
|
|
graphics-cmake-sdl # Executable to link
|
2021-05-24 20:20:54 +00:00
|
|
|
PRIVATE # Visibility
|
2022-03-31 20:01:08 +00:00
|
|
|
graphics-lib-sdl # Library to link
|
2021-05-24 20:20:54 +00:00
|
|
|
)
|
2019-10-15 01:51:50 +00:00
|
|
|
|
2021-05-24 20:20:54 +00:00
|
|
|
else()
|
|
|
|
message(
|
|
|
|
"Error: CMake was unable to find SDL2 package.\n"
|
|
|
|
"Please install the libsdl2-dev package and try again.\n"
|
|
|
|
)
|
2019-10-15 01:51:50 +00:00
|
|
|
endif()
|