#=============================================================================
# Copyright (c) 2021, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================

function(setup_cpm_cache )
  set(CPM_SOURCE_CACHE "${CMAKE_BINARY_DIR}")
  cmake_path(APPEND_STRING CPM_SOURCE_CACHE "/cache")

  set(src_dir "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/fill_cache/")
  set(build_dir "${CPM_SOURCE_CACHE}")

  #download all pre-configured rapids-cmake packages
  execute_process(COMMAND ${CMAKE_COMMAND}
      -Drapids-cmake-dir=${PROJECT_SOURCE_DIR}/../rapids-cmake
      -S ${src_dir} -B ${build_dir}
      WORKING_DIRECTORY ${src_dir}
      )

  set(CPM_SOURCE_CACHE "${CPM_SOURCE_CACHE}" PARENT_SCOPE)
endfunction()

