Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions attachments/template/CMake/FindKTX.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# FindKTX.cmake
#
# Finds the KTX library
#
# This will define the following variables
#
# KTX_FOUND
# KTX_INCLUDE_DIRS
# KTX_LIBRARIES
#
# and the following imported targets
#
# KTX::ktx
#

# Check if we're on Linux - if so, we'll skip the search and directly use FetchContent
if(UNIX AND NOT APPLE)
# On Linux, we assume KTX is not installed and proceed directly to fetching it
set(KTX_FOUND FALSE)
else()
# On non-Linux platforms, try to find KTX using pkg-config first
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_KTX QUIET ktx libktx ktx2 libktx2)
endif()

# Try to find KTX using standard find_package
find_path(KTX_INCLUDE_DIR
NAMES ktx.h
PATH_SUFFIXES include ktx KTX ktx2 KTX2
HINTS
${PC_KTX_INCLUDEDIR}
/usr/include
/usr/local/include
$ENV{KTX_DIR}/include
$ENV{VULKAN_SDK}/include
${CMAKE_SOURCE_DIR}/external/ktx/include
)

find_library(KTX_LIBRARY
NAMES ktx ktx2 libktx libktx2
PATH_SUFFIXES lib lib64
HINTS
${PC_KTX_LIBDIR}
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
$ENV{KTX_DIR}/lib
$ENV{VULKAN_SDK}/lib
${CMAKE_SOURCE_DIR}/external/ktx/lib
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(KTX
REQUIRED_VARS KTX_INCLUDE_DIR KTX_LIBRARY
FAIL_MESSAGE "" # Suppress the error message to allow our fallback
)

# Debug output if KTX is not found (only on non-Linux platforms)
if(NOT KTX_FOUND)
message(STATUS "KTX include directory search paths: ${PC_KTX_INCLUDEDIR}, /usr/include, /usr/local/include, $ENV{KTX_DIR}/include, $ENV{VULKAN_SDK}/include, ${CMAKE_SOURCE_DIR}/external/ktx/include")
message(STATUS "KTX library search paths: ${PC_KTX_LIBDIR}, /usr/lib, /usr/lib64, /usr/local/lib, /usr/local/lib64, $ENV{KTX_DIR}/lib, $ENV{VULKAN_SDK}/lib, ${CMAKE_SOURCE_DIR}/external/ktx/lib")
endif()
endif()

if(KTX_FOUND)
set(KTX_INCLUDE_DIRS ${KTX_INCLUDE_DIR})
set(KTX_LIBRARIES ${KTX_LIBRARY})

if(NOT TARGET KTX::ktx)
add_library(KTX::ktx UNKNOWN IMPORTED)
set_target_properties(KTX::ktx PROPERTIES
IMPORTED_LOCATION "${KTX_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${KTX_INCLUDE_DIRS}"
)
endif()
else()
# If not found, use FetchContent to download and build
include(FetchContent)

# Only show the message on non-Linux platforms
if(NOT (UNIX AND NOT APPLE))
message(STATUS "KTX not found, fetching from GitHub...")
endif()

FetchContent_Declare(
ktx
GIT_REPOSITORY https://github.com/KhronosGroup/KTX-Software.git
GIT_TAG v4.4.2 # Use a specific tag for stability
)

# Set options to minimize build time and dependencies
set(KTX_FEATURE_TOOLS OFF CACHE BOOL "Build KTX tools" FORCE)
set(KTX_FEATURE_DOC OFF CACHE BOOL "Build KTX documentation" FORCE)
set(KTX_FEATURE_TESTS OFF CACHE BOOL "Build KTX tests" FORCE)

FetchContent_MakeAvailable(ktx)

# Create an alias to match the expected target name
if(NOT TARGET KTX::ktx)
add_library(KTX::ktx ALIAS ktx)
endif()

set(KTX_FOUND TRUE)
endif()
86 changes: 86 additions & 0 deletions attachments/template/CMake/Findstb.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Findstb.cmake
#
# Finds the stb library (specifically stb_image.h)
#
# This will define the following variables
#
# stb_FOUND
# stb_INCLUDE_DIRS
#
# and the following imported targets
#
# stb::stb
#

# Try to find the package using pkg-config first
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_stb QUIET stb)
endif()

# Find the include directory
find_path(stb_INCLUDE_DIR
NAMES stb_image.h
PATHS
${PC_stb_INCLUDE_DIRS}
/usr/include
/usr/local/include
$ENV{VULKAN_SDK}/include
${ANDROID_NDK}/sources/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/include
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../include
PATH_SUFFIXES stb
)

# If the include directory wasn't found, use FetchContent to download and build
if(NOT stb_INCLUDE_DIR)
# If not found, use FetchContent to download and build
include(FetchContent)

message(STATUS "stb_image.h not found, fetching from GitHub...")
FetchContent_Declare(
stb
GIT_REPOSITORY https://github.com/nothings/stb.git
GIT_TAG master # stb doesn't use version tags, so we use master
)

# Set policy to suppress the deprecation warning
if(POLICY CMP0169)
cmake_policy(SET CMP0169 OLD)
endif()

# Populate the content
FetchContent_GetProperties(stb)
if(NOT stb_POPULATED)
FetchContent_Populate(stb)
endif()

# stb is a header-only library with no CMakeLists.txt, so we just need to set the include directory
set(stb_INCLUDE_DIR ${stb_SOURCE_DIR})
endif()

# Set the variables
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(stb
REQUIRED_VARS stb_INCLUDE_DIR
)

if(stb_FOUND)
set(stb_INCLUDE_DIRS ${stb_INCLUDE_DIR})

# Create an imported target
if(NOT TARGET stb::stb)
add_library(stb::stb INTERFACE IMPORTED)
set_target_properties(stb::stb PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${stb_INCLUDE_DIRS}"
)
endif()
endif()

mark_as_advanced(stb_INCLUDE_DIR)
162 changes: 162 additions & 0 deletions attachments/template/CMake/Findtinygltf.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Findtinygltf.cmake
#
# Finds the tinygltf library
#
# This will define the following variables
#
# tinygltf_FOUND
# tinygltf_INCLUDE_DIRS
#
# and the following imported targets
#
# tinygltf::tinygltf
#

# First, try to find nlohmann_json
find_package(nlohmann_json QUIET)
if(NOT nlohmann_json_FOUND)
include(FetchContent)
message(STATUS "nlohmann_json not found, fetching v3.12.0 from GitHub...")
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.12.0 # Use a specific tag for stability
)
FetchContent_MakeAvailable(nlohmann_json)
endif()

# Try to find tinygltf using standard find_package
find_path(tinygltf_INCLUDE_DIR
NAMES tiny_gltf.h
PATHS
${PC_tinygltf_INCLUDE_DIRS}
/usr/include
/usr/local/include
$ENV{VULKAN_SDK}/include
${ANDROID_NDK}/sources/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../attachments/include
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../external
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../include
PATH_SUFFIXES tinygltf include
)

# If not found, use FetchContent to download and build
if(NOT tinygltf_INCLUDE_DIR)
# If not found, use FetchContent to download and build
include(FetchContent)

message(STATUS "tinygltf not found, fetching from GitHub...")
FetchContent_Declare(
tinygltf
GIT_REPOSITORY https://github.com/syoyo/tinygltf.git
GIT_TAG v2.8.18 # Use a specific tag for stability
)

# Set policy to suppress the deprecation warning
if(POLICY CMP0169)
cmake_policy(SET CMP0169 OLD)
endif()

# Populate the content but don't configure it yet
FetchContent_GetProperties(tinygltf)
if(NOT tinygltf_POPULATED)
FetchContent_Populate(tinygltf)

# Update the minimum required CMake version to avoid deprecation warning
file(READ "${tinygltf_SOURCE_DIR}/CMakeLists.txt" TINYGLTF_CMAKE_CONTENT)
string(REPLACE "cmake_minimum_required(VERSION 3.6)"
"cmake_minimum_required(VERSION 3.10)"
TINYGLTF_CMAKE_CONTENT "${TINYGLTF_CMAKE_CONTENT}")
file(WRITE "${tinygltf_SOURCE_DIR}/CMakeLists.txt" "${TINYGLTF_CMAKE_CONTENT}")

# Create a symbolic link to make nlohmann/json.hpp available
if(EXISTS "${tinygltf_SOURCE_DIR}/json.hpp")
file(MAKE_DIRECTORY "${tinygltf_SOURCE_DIR}/nlohmann")
file(CREATE_LINK "${tinygltf_SOURCE_DIR}/json.hpp" "${tinygltf_SOURCE_DIR}/nlohmann/json.hpp" SYMBOLIC)
endif()

# Set tinygltf to header-only mode
set(TINYGLTF_HEADER_ONLY ON CACHE BOOL "Use header only version" FORCE)
set(TINYGLTF_INSTALL OFF CACHE BOOL "Do not install tinygltf" FORCE)

# Add the subdirectory after modifying the CMakeLists.txt
add_subdirectory(${tinygltf_SOURCE_DIR} ${tinygltf_BINARY_DIR})
else()
# If already populated, just make it available
FetchContent_MakeAvailable(tinygltf)
endif()

# Get the include directory from the target
get_target_property(tinygltf_INCLUDE_DIR tinygltf INTERFACE_INCLUDE_DIRECTORIES)
if(NOT tinygltf_INCLUDE_DIR)
# If we can't get the include directory from the target, use the source directory
FetchContent_GetProperties(tinygltf SOURCE_DIR tinygltf_SOURCE_DIR)
set(tinygltf_INCLUDE_DIR ${tinygltf_SOURCE_DIR})
endif()
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(tinygltf
REQUIRED_VARS tinygltf_INCLUDE_DIR
)

if(tinygltf_FOUND)
set(tinygltf_INCLUDE_DIRS ${tinygltf_INCLUDE_DIR})

if(NOT TARGET tinygltf::tinygltf)
add_library(tinygltf::tinygltf INTERFACE IMPORTED)
set_target_properties(tinygltf::tinygltf PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${tinygltf_INCLUDE_DIRS}"
INTERFACE_COMPILE_DEFINITIONS "TINYGLTF_IMPLEMENTATION;TINYGLTF_NO_EXTERNAL_IMAGE;TINYGLTF_NO_STB_IMAGE;TINYGLTF_NO_STB_IMAGE_WRITE"
)
if(TARGET nlohmann_json::nlohmann_json)
target_link_libraries(tinygltf::tinygltf INTERFACE nlohmann_json::nlohmann_json)
endif()
endif()
elseif(TARGET tinygltf)
# If find_package_handle_standard_args failed but we have a tinygltf target from FetchContent
# Create an alias for the tinygltf target
if(NOT TARGET tinygltf::tinygltf)
add_library(tinygltf_wrapper INTERFACE)
target_link_libraries(tinygltf_wrapper INTERFACE tinygltf)
target_compile_definitions(tinygltf_wrapper INTERFACE
TINYGLTF_IMPLEMENTATION
TINYGLTF_NO_EXTERNAL_IMAGE
TINYGLTF_NO_STB_IMAGE
TINYGLTF_NO_STB_IMAGE_WRITE
)
if(TARGET nlohmann_json::nlohmann_json)
target_link_libraries(tinygltf_wrapper INTERFACE nlohmann_json::nlohmann_json)
endif()
add_library(tinygltf::tinygltf ALIAS tinygltf_wrapper)
endif()

# Set variables to indicate that tinygltf was found
set(tinygltf_FOUND TRUE)
set(TINYGLTF_FOUND TRUE)

# Set include directories
get_target_property(tinygltf_INCLUDE_DIR tinygltf INTERFACE_INCLUDE_DIRECTORIES)
if(tinygltf_INCLUDE_DIR)
set(tinygltf_INCLUDE_DIRS ${tinygltf_INCLUDE_DIR})
else()
# If we can't get the include directory from the target, use the source directory
FetchContent_GetProperties(tinygltf SOURCE_DIR tinygltf_SOURCE_DIR)
set(tinygltf_INCLUDE_DIR ${tinygltf_SOURCE_DIR})
set(tinygltf_INCLUDE_DIRS ${tinygltf_INCLUDE_DIR})

# Explicitly set the include directory on the target
if(TARGET tinygltf)
set_target_properties(tinygltf PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${tinygltf_INCLUDE_DIR}"
)
endif()
endif()
endif()

mark_as_advanced(tinygltf_INCLUDE_DIR)
Loading
Loading