Skip to content

Commit

Permalink
Change: Use FetchContent to fetch test/example deps
Browse files Browse the repository at this point in the history
This replaces the Python script and makes the tests and examples a lot simpler to setup.
  • Loading branch information
spnda committed Aug 20, 2024
1 parent c462eaf commit 890c1dd
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 103 deletions.
141 changes: 99 additions & 42 deletions deps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
set(FASTGLTF_DEPS_DIR "${CMAKE_CURRENT_SOURCE_DIR}")

include(FetchContent)

# glm
if((FASTGLTF_ENABLE_TESTS OR FASTGLTF_ENABLE_EXAMPLES) AND EXISTS "${FASTGLTF_DEPS_DIR}/glm")
message(STATUS "fastgltf: Found glm")
if(FASTGLTF_ENABLE_TESTS OR FASTGLTF_ENABLE_EXAMPLES)
message(STATUS "fastgltf: Fetching glm")
FetchContent_Declare(
glm
GIT_REPOSITORY https://github.com/g-truc/glm
GIT_TAG 0.9.9.8
GIT_SHALLOW TRUE
)

# glm breaks because it apparently can't properly detect constexpr/C++ version and
# sets -Weverything which enables C++98 compatibility on Clang??
option(GLM_ENABLE_CXX_17 "" ON)

add_subdirectory("${FASTGLTF_DEPS_DIR}/glm")
FetchContent_MakeAvailable(glm)

add_library(glm::glm ALIAS glm)

if (TARGET glm_static)
Expand All @@ -22,8 +31,15 @@ if((FASTGLTF_ENABLE_TESTS OR FASTGLTF_ENABLE_EXAMPLES) AND EXISTS "${FASTGLTF_DE
endif()

# Catch2
if (FASTGLTF_ENABLE_TESTS AND EXISTS "${FASTGLTF_DEPS_DIR}/catch2")
message(STATUS "fastgltf: Found catch2")
if (FASTGLTF_ENABLE_TESTS)
message(STATUS "fastgltf: Fetching catch2")
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2
GIT_TAG v3.7.0
GIT_SHALLOW TRUE
)

# We can set Catch2 config options like this. We want all the C++17 features.
option(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS "" ON)
option(CATCH_CONFIG_CPP17_STRING_VIEW "" ON)
Expand All @@ -38,25 +54,40 @@ if (FASTGLTF_ENABLE_TESTS AND EXISTS "${FASTGLTF_DEPS_DIR}/catch2")
if (MSVC)
option(CATCH_CONFIG_WINDOWS_CRTDBG "" ON)
endif()
add_subdirectory(${FASTGLTF_DEPS_DIR}/catch2)

FetchContent_MakeAvailable(catch2)
endif()

# corrosion
if (FASTGLTF_ENABLE_GLTF_RS AND EXISTS "${FASTGLTF_DEPS_DIR}/corrosion")
message(STATUS "fastgltf: Found corrosion")
add_subdirectory(${FASTGLTF_DEPS_DIR}/corrosion)
if (FASTGLTF_ENABLE_GLTF_RS)
message(STATUS "fastgltf: Fetching corrosion")
FetchContent_Declare(
corrosion
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion
GIT_TAG v0.5
GIT_SHALLOW TRUE
)

FetchContent_MakeAvailable(corrosion)
endif()

# glfw. We emulate parts of glfw's CMakeLists but don't want to include any examples or tests.
if(FASTGLTF_ENABLE_EXAMPLES AND EXISTS "${FASTGLTF_DEPS_DIR}/glfw")
message(STATUS "fastgltf: Found glfw")
if(FASTGLTF_ENABLE_EXAMPLES)
message(STATUS "fastgltf: Fetching glfw")
FetchContent_Declare(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw
GIT_TAG 3.4
GIT_SHALLOW TRUE
)

# copied from glfw's CMakeLists. We seriously don't want any examples/tests/docs.
option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" OFF)
option(GLFW_BUILD_TESTS "Build the GLFW test programs" OFF)
option(GLFW_BUILD_DOCS "Build the GLFW documentation" OFF)
option(GLFW_INSTALL "Generate installation target" OFF)

add_subdirectory("${FASTGLTF_DEPS_DIR}/glfw")
FetchContent_MakeAvailable(glfw)

set_target_properties(glfw PROPERTIES EXCLUDE_FROM_ALL 1)
set_target_properties(update_mappings PROPERTIES EXCLUDE_FROM_ALL 1)
Expand All @@ -65,44 +96,70 @@ if(FASTGLTF_ENABLE_EXAMPLES AND EXISTS "${FASTGLTF_DEPS_DIR}/glfw")
endif()

# glad
if (FASTGLTF_ENABLE_EXAMPLES AND EXISTS "${FASTGLTF_DEPS_DIR}/glad")
message(STATUS "fastgltf: Found glad")
add_subdirectory(${FASTGLTF_DEPS_DIR}/glad/cmake glad_cmake)
if (FASTGLTF_ENABLE_EXAMPLES)
message(STATUS "fastgltf: Fetching glad")
FetchContent_Declare(
glad
GIT_REPOSITORY https://github.com/Dav1dde/glad
GIT_TAG glad2
GIT_SHALLOW TRUE
SOURCE_SUBDIR cmake
)

FetchContent_MakeAvailable(glad)

# Let the glad script generate the glad headers
glad_add_library(fg_glad_gl46 REPRODUCIBLE EXCLUDE_FROM_ALL LOADER API gl:core=4.6)
endif()

# imgui
if (FASTGLTF_ENABLE_EXAMPLES AND EXISTS "${FASTGLTF_DEPS_DIR}/imgui")
message(STATUS "fastgltf: Found imgui")

set(IMGUI_DIRECTORY "${FASTGLTF_DEPS_DIR}/imgui")
if(NOT EXISTS "${IMGUI_DIRECTORY}")
message(FATAL_ERROR "The imgui submodule does not exist.")
if (FASTGLTF_ENABLE_EXAMPLES)
message(STATUS "fastgltf: Fetching imgui")
FetchContent_Declare(
imgui
GIT_REPOSITORY https://github.com/ocornut/imgui
GIT_TAG v1.90.9
GIT_SHALLOW TRUE
)

FetchContent_GetProperties(imgui)
if(NOT imgui_POPULATED)
FetchContent_Populate(imgui)

add_library(imgui)
add_library(imgui::imgui ALIAS imgui)
fastgltf_add_source_directory(TARGET imgui FOLDER "${imgui_SOURCE_DIR}")
fastgltf_add_source_directory(TARGET imgui FOLDER "${imgui_SOURCE_DIR}/misc/cpp/")

target_include_directories(imgui SYSTEM PUBLIC "${imgui_SOURCE_DIR}")
target_include_directories(imgui SYSTEM PUBLIC "${imgui_SOURCE_DIR}/backends")
target_include_directories(imgui SYSTEM PUBLIC "${imgui_SOURCE_DIR}/misc/cpp")

target_compile_definitions(imgui PUBLIC IMGUI_DISABLE_OBSOLETE_FUNCTIONS=1)

# We only need the GLFW implementation
target_sources(imgui PUBLIC "${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.h" "${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp")
target_sources(imgui PUBLIC "${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.h" "${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp")

target_link_libraries(imgui PUBLIC glfw::glfw)
endif()

add_library(imgui)
add_library(imgui::imgui ALIAS imgui)
fastgltf_add_source_directory(TARGET imgui FOLDER "${IMGUI_DIRECTORY}")
fastgltf_add_source_directory(TARGET imgui FOLDER "${IMGUI_DIRECTORY}/misc/cpp/")

target_include_directories(imgui SYSTEM PUBLIC "${IMGUI_DIRECTORY}")
target_include_directories(imgui SYSTEM PUBLIC "${IMGUI_DIRECTORY}/backends")
target_include_directories(imgui SYSTEM PUBLIC "${IMGUI_DIRECTORY}/misc/cpp")

target_compile_definitions(imgui PUBLIC IMGUI_DISABLE_OBSOLETE_FUNCTIONS=1)

# We only need the GLFW implementation
target_sources(imgui PUBLIC "${IMGUI_DIRECTORY}/backends/imgui_impl_glfw.h" "${IMGUI_DIRECTORY}/backends/imgui_impl_glfw.cpp")
target_sources(imgui PUBLIC "${IMGUI_DIRECTORY}/backends/imgui_impl_opengl3.h" "${IMGUI_DIRECTORY}/backends/imgui_impl_opengl3.cpp")

target_link_libraries(imgui PUBLIC glfw::glfw)
endif()

# stb
if(FASTGLTF_ENABLE_EXAMPLES AND EXISTS "${FASTGLTF_DEPS_DIR}/stb")
message(STATUS "fastgltf: Found stb")
add_library(stb INTERFACE)
target_include_directories(stb INTERFACE "${FASTGLTF_DEPS_DIR}/stb")
if(FASTGLTF_ENABLE_EXAMPLES)
message(STATUS "fastgltf: Fetching stb")
FetchContent_Declare(
stb
GIT_REPOSITORY https://github.com/nothings/stb
GIT_TAG master
GIT_SHALLOW TRUE
)

FetchContent_GetProperties(stb)
if(NOT stb_POPULATED)
FetchContent_Populate(stb)

add_library(stb INTERFACE)
target_include_directories(stb INTERFACE ${stb_SOURCE_DIR})
endif()
endif()
61 changes: 0 additions & 61 deletions fetch_test_deps.py

This file was deleted.

0 comments on commit 890c1dd

Please sign in to comment.