114 lines
3.5 KiB
CMake
114 lines
3.5 KiB
CMake
cmake_minimum_required(VERSION 4.0)
|
|
project(sdl_project)
|
|
set(CMAKE_C_STANDARD 23)
|
|
|
|
# Include the command that downloads libraries
|
|
include(FetchContent)
|
|
|
|
# define a function for adding git dependencies
|
|
function(include_dependency libName gitURL gitTag)
|
|
FetchContent_Declare(${libName}
|
|
GIT_REPOSITORY ${gitURL}
|
|
GIT_TAG ${gitTag}
|
|
GIT_SHALLOW TRUE
|
|
GIT_PROGRESS TRUE
|
|
)
|
|
FetchContent_MakeAvailable(${libName})
|
|
endfunction()
|
|
|
|
# add SDL2 support
|
|
find_package(SDL2 QUIET)
|
|
if (NOT SDL2_FOUND)
|
|
message(STATUS "Getting SDL2 from Github")
|
|
include_dependency(SDL2 https://github.com/libsdl-org/SDL.git release-2.30.8)
|
|
else()
|
|
message(STATUS "Using local SDL2")
|
|
endif()
|
|
|
|
# add SDL2_image support
|
|
find_package(SDL2_image QUIET)
|
|
if (NOT SDL2_image_FOUND)
|
|
message(STATUS "Getting SDL2_image from Github")
|
|
include_dependency(SDL2_image https://github.com/libsdl-org/SDL_image.git release-2.8.2)
|
|
else()
|
|
message(STATUS "Using local SDL2_image")
|
|
endif()
|
|
|
|
## add SDL2_gfx support (NO find_package, fetch and add it manually)
|
|
#find_package(SDL2_gfx QUIET)
|
|
#if (NOT SDL2_gfx)
|
|
# message(STATUS "Getting SDL2_gfx from Github")
|
|
# include_dependency(SDL2_gfx https://github.com/giroletm/SDL2_gfx.git release-1.0.4)
|
|
#else()
|
|
# message(STATUS "Using local SDL2_gfx")
|
|
#endif()
|
|
|
|
# SDL2_gfx (DO NOT use the function for this one)
|
|
FetchContent_Declare(
|
|
SDL2_gfx
|
|
GIT_REPOSITORY https://github.com/giroletm/SDL2_gfx.git
|
|
GIT_TAG master
|
|
)
|
|
FetchContent_MakeAvailable(SDL2_gfx)
|
|
message(STATUS "sdl2_gfx_SOURCE_DIR is: ${sdl2_gfx_SOURCE_DIR}")
|
|
add_library(SDL2_gfx STATIC
|
|
${sdl2_gfx_SOURCE_DIR}/SDL2_gfxPrimitives.c
|
|
${sdl2_gfx_SOURCE_DIR}/SDL2_rotozoom.c
|
|
)
|
|
|
|
target_include_directories(SDL2_gfx PUBLIC ${sdl2_gfx_SOURCE_DIR}/sdl2_gfx-src)
|
|
target_link_libraries(SDL2_gfx PUBLIC SDL2::SDL2)
|
|
|
|
# add SDL2_ttf support
|
|
#set(SDL2TTF_VENDORED ON)
|
|
#find_package(SDL2_ttf QUIET)
|
|
#if (NOT SDL2_ttf_FOUND)
|
|
# message(STATUS "Getting SDL2_ttf from Github")
|
|
# include_dependency(SDL2_ttf https://github.com/libsdl-org/SDL_ttf.git release-2.22.0)
|
|
#else()
|
|
# message(STATUS "Using local SDL2_ttf")
|
|
#endif()
|
|
|
|
add_executable(${PROJECT_NAME} scripts/main.c
|
|
scripts/array.c
|
|
scripts/vector.c
|
|
scripts/matrix.c
|
|
scripts/mesh.c
|
|
scripts/triangle.c
|
|
scripts/light.c
|
|
scripts/texture.c
|
|
scripts/swap.c
|
|
scripts/upng.c
|
|
scripts/display.c
|
|
)
|
|
|
|
# Target include directories for non-gfx libs
|
|
target_include_directories(
|
|
${PROJECT_NAME}
|
|
PUBLIC
|
|
${SDL2_INCLUDE_DIRS}
|
|
${SDL2_IMAGE_INCLUDE_DIRS}
|
|
# ${SDL2_TTF_INCLUDE_DIRS}
|
|
${sdl2_gfx_SOURCE_DIR} # Add SDL2_gfx headers directory
|
|
)
|
|
|
|
# link all libraries to the project
|
|
target_link_libraries(
|
|
${PROJECT_NAME}
|
|
PRIVATE
|
|
SDL2::SDL2
|
|
SDL2::SDL2main
|
|
SDL2_image::SDL2_image
|
|
# SDL2_ttf::SDL2_ttf
|
|
SDL2_gfx # Link in the SDL2_gfx library we added
|
|
)
|
|
|
|
if (WIN32)
|
|
add_custom_command(
|
|
TARGET ${PROJECT_NAME} POST_BUILD
|
|
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:SDL2::SDL2>" "$<TARGET_FILE_DIR:sdl_project>"
|
|
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:SDL2_image::SDL2_image>" "$<TARGET_FILE_DIR:sdl_project>"
|
|
#COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:SDL2_ttf::SDL2_ttf>" "$<TARGET_FILE_DIR:sdl_project>"
|
|
VERBATIM
|
|
)
|
|
endif() |