-
Notifications
You must be signed in to change notification settings - Fork 191
/
Copy pathfetchcontent_dependency.cmake
38 lines (29 loc) · 1.07 KB
/
fetchcontent_dependency.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
include(${CPM_PATH}/testing.cmake)
include(CMakePackageConfigHelpers)
set(CPM_SOURCE_CACHE_DIR "${CMAKE_CURRENT_BINARY_DIR}/CPM")
set(TEST_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/fetchcontent_dependency)
function(clear_cache)
message(STATUS "clearing CPM cache")
file(REMOVE_RECURSE ${CPM_SOURCE_CACHE_DIR})
assert_not_exists("${CPM_SOURCE_CACHE_DIR}")
endfunction()
function(update_cmake_lists)
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/fetchcontent_dependency/CMakeLists.txt.in"
"${CMAKE_CURRENT_LIST_DIR}/fetchcontent_dependency/CMakeLists.txt"
INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/junk
)
endfunction()
function(reset_test)
clear_cache()
file(REMOVE_RECURSE ${TEST_BUILD_DIR})
update_cmake_lists()
endfunction()
# Read CPM_SOURCE_CACHE from arguments
reset_test()
execute_process(
COMMAND ${CMAKE_COMMAND} "-S${CMAKE_CURRENT_LIST_DIR}/fetchcontent_dependency"
"-B${TEST_BUILD_DIR}" "-DCPM_SOURCE_CACHE=${CPM_SOURCE_CACHE_DIR}" RESULT_VARIABLE ret
)
assert_equal(${ret} "0")