diff --git a/README.md b/README.md index 73ac1752..c1b7db15 100644 --- a/README.md +++ b/README.md @@ -165,12 +165,12 @@ add_executable(foo main.cpp) target_link_libraries(foo PRIVATE etl::etl) ``` +Alternatively you can use [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html). -Alternatively you can use [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html), -replacing `` with the version to install based on a git tag: +By Git, replacing `` with the version to install based on a git tag: -```sh -Include(FetchContent) +```cmake +include(FetchContent) FetchContent_Declare( etl @@ -184,6 +184,25 @@ add_executable(foo main.cpp) target_link_libraries(foo PRIVATE etl::etl) ``` +Or by URL, fetching a release tarball directly, again replacing `` with the desired version: + +```cmake +include(FetchContent) + +FetchContent_Declare( + etl + URL https://github.com/ETLCPP/etl/archive/refs/tags/.tar.gz +) + +FetchContent_MakeAvailable(etl) + +add_executable(foo main.cpp) +target_link_libraries(foo PRIVATE etl::etl) +``` + +A tarball fetched this way has no `.git` directory of its own. ETL detects this and falls back to +reading its version from `version.txt` instead of `git describe`, so no extra configuration is needed. + ## Profile definition When using ETL in a project, there is typically an `etl_profile.h` defined to diff --git a/cmake/GetGitRevisionDescription.cmake b/cmake/GetGitRevisionDescription.cmake index d0966da1..d45b2101 100644 --- a/cmake/GetGitRevisionDescription.cmake +++ b/cmake/GetGitRevisionDescription.cmake @@ -82,6 +82,19 @@ function(etl_get_git_head_revision _refspecvar _hashvar) set(GIT_DIR "") endif() endif() + if(NOT "${GIT_DIR}" STREQUAL "") + # Reject a .git dir that belongs to a parent project (e.g. when fetched + # as a URL tarball with no .git of its own and _etl_git_find_closest_git_dir + # walked up into the consuming project's repository). Gated by the same + # flag as above, since CMAKE_CURRENT_SOURCE_DIR is always at or below + # CMAKE_SOURCE_DIR, so this check is strictly tighter than the one above + # and must honor the same opt-out. + file(RELATIVE_PATH _relative_etl_to_git "${CMAKE_CURRENT_SOURCE_DIR}" + "${GIT_DIR}") + if("${_relative_etl_to_git}" MATCHES "^[.][.]" AND NOT ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR) + set(GIT_DIR "") + endif() + endif() if("${GIT_DIR}" STREQUAL "") set(${_refspecvar} "GITDIR-NOTFOUND"