73 lines
2.6 KiB
CMake
73 lines
2.6 KiB
CMake
include(CMakeParseArguments)
|
|
include(FetchContent)
|
|
|
|
# Resolve hdk-assets for examples only.
|
|
function(hdk_resolve_example_assets)
|
|
set(_opts "")
|
|
set(_one_value OUT_VAR FETCH_OPTION MIN_VERSION GIT_REPOSITORY GIT_TAG CONTEXT)
|
|
cmake_parse_arguments(HDK_ASSETS "${_opts}" "${_one_value}" "" ${ARGN})
|
|
|
|
if(NOT HDK_ASSETS_OUT_VAR)
|
|
message(FATAL_ERROR "hdk_resolve_example_assets requires OUT_VAR")
|
|
endif()
|
|
|
|
set(_resolved_assets_dir "")
|
|
set(_repo_assets_dir "${CMAKE_CURRENT_SOURCE_DIR}/../../assets")
|
|
if(EXISTS "${_repo_assets_dir}/textures")
|
|
set(_resolved_assets_dir "${_repo_assets_dir}")
|
|
endif()
|
|
|
|
if(NOT _resolved_assets_dir)
|
|
if(HDK_ASSETS_MIN_VERSION)
|
|
find_package(hdk_assets ${HDK_ASSETS_MIN_VERSION} QUIET CONFIG NAMES hdk-assets hdk_assets)
|
|
else()
|
|
find_package(hdk_assets QUIET CONFIG NAMES hdk-assets hdk_assets)
|
|
endif()
|
|
|
|
foreach(_candidate_var IN ITEMS HDK_ASSETS_SOURCE_DIR HDK_ASSETS_DIR hdk_assets_SOURCE_DIR hdk_assets_DIR)
|
|
if(NOT _resolved_assets_dir AND DEFINED ${_candidate_var})
|
|
set(_candidate_dir "${${_candidate_var}}")
|
|
if(EXISTS "${_candidate_dir}/textures")
|
|
set(_resolved_assets_dir "${_candidate_dir}")
|
|
endif()
|
|
endif()
|
|
endforeach()
|
|
|
|
if(NOT _resolved_assets_dir AND DEFINED hdk_assets_DIR)
|
|
get_filename_component(_hdk_assets_prefix "${hdk_assets_DIR}" DIRECTORY)
|
|
get_filename_component(_hdk_assets_prefix "${_hdk_assets_prefix}" DIRECTORY)
|
|
get_filename_component(_hdk_assets_prefix "${_hdk_assets_prefix}" DIRECTORY)
|
|
if(EXISTS "${_hdk_assets_prefix}/assets/textures")
|
|
set(_resolved_assets_dir "${_hdk_assets_prefix}/assets")
|
|
endif()
|
|
endif()
|
|
endif()
|
|
|
|
if(NOT _resolved_assets_dir)
|
|
if(NOT HDK_ASSETS_FETCH_OPTION)
|
|
if(HDK_ASSETS_CONTEXT)
|
|
message(FATAL_ERROR "No suitable hdk-assets source found for ${HDK_ASSETS_CONTEXT} and fetch fallback is disabled")
|
|
else()
|
|
message(FATAL_ERROR "No suitable hdk-assets source found and fetch fallback is disabled")
|
|
endif()
|
|
endif()
|
|
|
|
if(NOT HDK_ASSETS_GIT_REPOSITORY)
|
|
message(FATAL_ERROR "hdk_resolve_example_assets fallback requires GIT_REPOSITORY")
|
|
endif()
|
|
if(NOT HDK_ASSETS_GIT_TAG)
|
|
message(FATAL_ERROR "hdk_resolve_example_assets fallback requires GIT_TAG")
|
|
endif()
|
|
|
|
FetchContent_Declare(
|
|
hdk_assets
|
|
GIT_REPOSITORY ${HDK_ASSETS_GIT_REPOSITORY}
|
|
GIT_TAG ${HDK_ASSETS_GIT_TAG}
|
|
)
|
|
FetchContent_MakeAvailable(hdk_assets)
|
|
set(_resolved_assets_dir "${hdk_assets_SOURCE_DIR}")
|
|
endif()
|
|
|
|
set(${HDK_ASSETS_OUT_VAR} "${_resolved_assets_dir}" PARENT_SCOPE)
|
|
endfunction()
|