]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
build: Add support for using system nonstd-span
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 22 Mar 2024 20:40:58 +0000 (21:40 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 27 Apr 2024 08:14:29 +0000 (10:14 +0200)
15 files changed:
.clang-format
LICENSE.adoc
cmake/Dependencies.cmake
cmake/FindNonstdSpan.cmake [new file with mode: 0644]
doc/INSTALL.md
src/ccache/CMakeLists.txt
src/ccache/Hash.hpp
src/ccache/storage/remote/RemoteStorage.hpp
src/ccache/util/file.hpp
src/ccache/util/string.hpp
src/ccache/util/zstd.hpp
src/third_party/CMakeLists.txt
src/third_party/nonstd-span/CMakeLists.txt [new file with mode: 0644]
src/third_party/nonstd-span/nonstd/span.hpp [moved from src/third_party/nonstd/span.hpp with 100% similarity]
unittest/test_util_Bytes.cpp

index e35a0140cdde88a7dd1fd87e8840bd93b1aa353b..ce4d58691fdb961ef8fcc5d4b5d3e3983b9ec1d9 100644 (file)
@@ -31,7 +31,7 @@ IncludeCategories:
   - Regex: '^<ccache/'
     Priority: 2
   # Dependency headers:
-  - Regex: '^<(doctest/.*|fmt/.*|hiredis/.*|httplib\.h|zstd\.h)>$'
+  - Regex: '^<(doctest/.*|fmt/.*|hiredis/.*|httplib\.h|nonstd/.*|zstd\.h)>$'
     Priority: 3
   # System headers:
   - Regex: '\.h.*>$'
index 98b8e18cd04985b5531b66de2538f3220b4828fd..a366cbd939212a74f9cb5432adb47fef1866a247 100644 (file)
@@ -418,7 +418,7 @@ SOFTWARE.
 ----
 
 
-=== src/third_party/nonstd/span.hpp
+=== src/third_party/nonstd-span/nonstd/span.hpp
 
 This is the single header version of
 https://github.com/martinmoene/span-lite[span-lite] 0.10.3 with the
index 9d47567a26f27ae0ef2b940843fd238768cc65d4..d381a494c7e1e136d2ca0a5c3fe39bc5c6b4b48c 100644 (file)
@@ -21,6 +21,7 @@ set_property(CACHE DEPS PROPERTY STRINGS AUTO DOWNLOAD LOCAL)
 
 find_package(CppHttplib 0.10.6 MODULE REQUIRED)
 find_package(Fmt 8.0.0 MODULE REQUIRED)
+find_package(NonstdSpan 0.10.3 MODULE REQUIRED)
 find_package(Zstd 1.3.4 MODULE REQUIRED)
 
 if(ENABLE_TESTING)
diff --git a/cmake/FindNonstdSpan.cmake b/cmake/FindNonstdSpan.cmake
new file mode 100644 (file)
index 0000000..c15bb85
--- /dev/null
@@ -0,0 +1,21 @@
+mark_as_advanced(NONSTDSPAN_INCLUDE_DIR)
+
+if(DEP_NONSTDSPAN STREQUAL "BUNDLED")
+  message(STATUS "Using bundled NonstdSpan as requested")
+else()
+  find_path(NONSTDSPAN_INCLUDE_DIR nonstd/span.hpp)
+  if(NONSTDSPAN_INCLUDE_DIR)
+    file(READ "${NONSTDSPAN_INCLUDE_DIR}/nonstd/span.hpp" _nonstdspan_h)
+    string(REGEX MATCH "#define span_lite_MAJOR ([0-9]+).*#define span_lite_MINOR ([0-9]+).*#define span_lite_PATCH ([0-9]+)" _ "${_nonstdspan_h}")
+    set(_nonstdspan_version_string "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
+    if(NOT "${CMAKE_MATCH_0}" STREQUAL "" AND "${_nonstdspan_version_string}" VERSION_GREATER_EQUAL "${NonstdSpan_FIND_VERSION}")
+      message(STATUS "Using system NonstdSpan (${NONSTDSPAN_INCLUDE_DIR}/nonstd/span.hpp)")
+      add_library(dep_nonstdspan INTERFACE IMPORTED)
+      target_include_directories(dep_nonstdspan INTERFACE "${NONSTDSPAN_INCLUDE_DIR}")
+      register_dependency(NonstdSpan "SYSTEM (${NONSTDSPAN_INCLUDE_DIR}/nonstd/span.hpp)" ${_nonstdspan_version_string})
+    endif()
+  endif()
+  if(NOT TARGET dep_nonstdspan)
+    message(STATUS "Using bundled NonstdSpan since NonstdSpan>=${NonstdSpan_FIND_VERSION} was not found locally")
+  endif()
+endif()
index 45032dae04a687b85e4eb47a717f7927e030c083..c61ea667eac37d7a5f11664066adc6ff18330fd7 100644 (file)
@@ -45,6 +45,7 @@ should be located or retrieved:
 - [fmt](https://fmt.dev)[^2]
 - [hiredis](https://github.com/redis/hiredis)[^2] (optional, disable with `-D
   REDIS_STORAGE_BACKEND=OFF`)
+- [span-lite](https://github.com/martinmoene/span-lite)[^1]
 - [Zstandard](https://github.com/facebook/zstd)[^2]
 
 [^1]: A bundled version will be used if missing locally.
index b175405398d58c2000a171a34f9261140a91cde5..4e78521466f2f0d1db9d0d0ec27fe0c13c69f6c7 100644 (file)
@@ -46,6 +46,7 @@ target_link_libraries(
   ccache_framework
   PUBLIC
     dep_fmt
+    dep_nonstdspan
     third_party
   PRIVATE
     dep_cpphttplib
index df95b66c2014dbaa525cda90a882fbac37e5aa55..4ece77f566e668bcdf75ab5101c039c2e28461b5 100644 (file)
@@ -18,8 +18,9 @@
 
 #pragma once
 
-#include <blake3/blake3.h>
 #include <nonstd/span.hpp>
+
+#include <blake3/blake3.h>
 #include <tl/expected.hpp>
 
 #include <array>
index 5551bd1d2db3b678d5b970955800123db318a687..b8db6b8a5add2919f94d5a0d845d793402949ea7 100644 (file)
@@ -22,6 +22,7 @@
 #include <ccache/util/Bytes.hpp>
 
 #include <nonstd/span.hpp>
+
 #include <tl/expected.hpp>
 #include <url.hpp>
 
index 4707f4f5857a0f8501f0125d570cf9977c42669b..72af091017026a2e962fc78023569fd5e2c6ce21 100644 (file)
@@ -24,6 +24,7 @@
 #include <ccache/util/types.hpp>
 
 #include <nonstd/span.hpp>
+
 #include <tl/expected.hpp>
 
 #include <cstddef>
index ca8029fad0c15dbbf3b9027a2f62151ad1b57cc6..c0209f89e3485c4b028e917fb8723168edf48ab8 100644 (file)
@@ -22,6 +22,7 @@
 #include <ccache/util/conversion.hpp>
 
 #include <nonstd/span.hpp>
+
 #include <sys/stat.h> // for mode_t
 #include <tl/expected.hpp>
 
index 557d9cbc6fbea01406b45b3efeeba2cc87431041..01ab43bb2db54b19302a19e42a7000e6f8314a7a 100644 (file)
@@ -21,6 +21,7 @@
 #include <ccache/util/Bytes.hpp>
 
 #include <nonstd/span.hpp>
+
 #include <tl/expected.hpp>
 
 #include <cstddef>
index baea1d76ca7b634c515bc5b5b5e3ea240d193790..9e7d9dc972cd1e6dcee9e899a74137c356faded4 100644 (file)
@@ -59,3 +59,6 @@ add_subdirectory(blake3)
 if(NOT TARGET dep_cpphttplib)
   add_subdirectory(cpp-httplib)
 endif()
+if(NOT TARGET dep_nonstdspan)
+  add_subdirectory(nonstd-span)
+endif()
diff --git a/src/third_party/nonstd-span/CMakeLists.txt b/src/third_party/nonstd-span/CMakeLists.txt
new file mode 100644 (file)
index 0000000..9e42e6a
--- /dev/null
@@ -0,0 +1,2 @@
+register_dependency(NonstdSpan BUNDLED 0.10.3)
+add_header_only_library(nonstdspan DIR "${CMAKE_CURRENT_SOURCE_DIR}")
index 87c914a73c38dc19df75b89f4fcc38ec2f84ab99..e1eefb77c31fe13b441cf4d557771ea996efe5ed 100644 (file)
@@ -19,7 +19,6 @@
 #include <ccache/util/Bytes.hpp>
 
 #include <doctest/doctest.h>
-
 #include <nonstd/span.hpp>
 
 #include <vector>