@@ -54,22 +54,33 @@ function(libenvpp_set_compiler_parameters TARGET)
54
54
endfunction ()
55
55
56
56
# External dependencies.
57
+ include (FetchContent )
58
+
57
59
if (LIBENVPP_INSTALL )
58
60
set (FMT_INSTALL ON CACHE BOOL "" FORCE )
59
61
endif ()
60
- include (FetchContent )
61
- FetchContent_Declare (fmt
62
- GIT_REPOSITORY https://github.com/fmtlib/fmt.git
63
- GIT_TAG 11.0.2
64
- )
65
- FetchContent_MakeAvailable (fmt )
62
+
63
+ macro (fetch_content_from_submodule DEPNAME RELPATH )
64
+ # Dependencies may have already been satisfied by the parent project, in this case the already provided dependency will be used.
65
+ # The parent project is responsible for ensuring that the provided dependency version is compatible.
66
+ if (${DEPNAME} _FOUND OR TARGET ${DEPNAME} )
67
+ message (STATUS "Depndency ${DEPNAME} already provided, reusing it" )
68
+ else ()
69
+ message (STATUS "Fetching ${DEPNAME} from submodule" )
70
+ if (NOT EXISTS "${PROJECT_SOURCE_DIR} /${RELPATH} /CMakeLists.txt" )
71
+ message (FATAL_ERROR "The git submodule ${RELPATH} is missing.\n Try running `git submodule update --init`" )
72
+ endif ()
73
+ FetchContent_Declare (${DEPNAME}
74
+ URL "${PROJECT_SOURCE_DIR} /${RELPATH} "
75
+ )
76
+ FetchContent_MakeAvailable (${DEPNAME} )
77
+ endif ()
78
+ endmacro ()
79
+
80
+ fetch_content_from_submodule (fmt external/fmt )
66
81
67
82
if (LIBENVPP_TESTS )
68
- FetchContent_Declare (Catch2
69
- GIT_REPOSITORY https://github.com/catchorg/Catch2.git
70
- GIT_TAG v3.7.1
71
- )
72
- FetchContent_MakeAvailable (Catch2 )
83
+ fetch_content_from_submodule (Catch2 external/Catch2 )
73
84
list (APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR} /extras )
74
85
endif ()
75
86
0 commit comments