Skip to content

Commit

Permalink
Fetch dependencies from submodules potentially reusing already provid…
Browse files Browse the repository at this point in the history
…ed ones
  • Loading branch information
BlackMark29A committed Oct 7, 2024
1 parent 6f73292 commit cfacbb8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "external/fmt"]
path = external/fmt
url = [email protected]:fmtlib/fmt.git
[submodule "external/Catch2"]
path = external/Catch2
url = [email protected]:catchorg/Catch2.git
33 changes: 22 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,33 @@ function(libenvpp_set_compiler_parameters TARGET)
endfunction()

# External dependencies.
include(FetchContent)

if(LIBENVPP_INSTALL)
set(FMT_INSTALL ON CACHE BOOL "" FORCE)
endif()
include(FetchContent)
FetchContent_Declare(fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 11.0.2
)
FetchContent_MakeAvailable(fmt)

macro(fetch_content_from_submodule DEPNAME RELPATH)
# Dependencies may have already been satisfied by the parent project, in this case the already provided dependency will be used.
# The parent project is responsible for ensuring that the provided dependency version is compatible.
if(${DEPNAME}_FOUND)
message(STATUS "Using system ${DEPNAME} in ${${DEPNAME}_DIR}")
else()
message(STATUS "Fetching ${DEPNAME} from submodule")
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/${RELPATH}/CMakeLists.txt")
message(FATAL_ERROR "The git submodule ${RELPATH} is missing.\nTry running `git submodule update --init`.")
endif()
FetchContent_Declare(${DEPNAME}
URL "${PROJECT_SOURCE_DIR}/${RELPATH}"
)
FetchContent_MakeAvailable(${DEPNAME})
endif()
endmacro()

fetch_content_from_submodule(fmt external/fmt)

if(LIBENVPP_TESTS)
FetchContent_Declare(Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.7.1
)
FetchContent_MakeAvailable(Catch2)
fetch_content_from_submodule(Catch2 external/Catch2)
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
endif()

Expand Down
1 change: 1 addition & 0 deletions external/Catch2
Submodule Catch2 added at fa43b7
1 change: 1 addition & 0 deletions external/fmt
Submodule fmt added at 0c9fce

0 comments on commit cfacbb8

Please sign in to comment.