]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
build: Add support for using system tl-expected
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 23 Mar 2024 20:00:03 +0000 (21:00 +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/FindTlExpected.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/tl-expected/CMakeLists.txt [new file with mode: 0644]
src/third_party/tl-expected/tl/expected.hpp [moved from src/third_party/tl/expected.hpp with 100% similarity]
unittest/test_util_expected.cpp

index ce4d58691fdb961ef8fcc5d4b5d3e3983b9ec1d9..3910db4d905489ca0c67d5be7c789db14b22f9ba 100644 (file)
@@ -31,7 +31,7 @@ IncludeCategories:
   - Regex: '^<ccache/'
     Priority: 2
   # Dependency headers:
-  - Regex: '^<(doctest/.*|fmt/.*|hiredis/.*|httplib\.h|nonstd/.*|zstd\.h)>$'
+  - Regex: '^<(doctest/.*|fmt/.*|hiredis/.*|httplib\.h|nonstd/.*|tl/expected\.hpp|zstd\.h)>$'
     Priority: 3
   # System headers:
   - Regex: '\.h.*>$'
index a366cbd939212a74f9cb5432adb47fef1866a247..c8e824a2d2a0e1c7804ce018e6e76907e9d3ec3c 100644 (file)
@@ -453,7 +453,7 @@ DEALINGS IN THE SOFTWARE.
 ----
 
 
-=== src/third_party/tl/expected.hpp
+=== src/third_party/tl-expected/tl/expected.hpp
 
 This is https://github.com/TartanLlama/expected[TartanLlama expected] 1.1.0 with
 the following license:
index d381a494c7e1e136d2ca0a5c3fe39bc5c6b4b48c..ae50429b57824dec5cb6a2f3f2303a02f4129f0b 100644 (file)
@@ -22,6 +22,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(TlExpected 1.1.0 MODULE REQUIRED)
 find_package(Zstd 1.3.4 MODULE REQUIRED)
 
 if(ENABLE_TESTING)
diff --git a/cmake/FindTlExpected.cmake b/cmake/FindTlExpected.cmake
new file mode 100644 (file)
index 0000000..93a6267
--- /dev/null
@@ -0,0 +1,21 @@
+mark_as_advanced(TLEXPECTED_INCLUDE_DIR)
+
+if(DEP_TLEXPECTED STREQUAL "BUNDLED")
+  message(STATUS "Using bundled TlExpected as requested")
+else()
+  find_path(TLEXPECTED_INCLUDE_DIR tl/expected.hpp)
+  if(TLEXPECTED_INCLUDE_DIR)
+    file(READ "${TLEXPECTED_INCLUDE_DIR}/tl/expected.hpp" _tlexpected_h)
+    string(REGEX MATCH "#define TL_EXPECTED_VERSION_MAJOR ([0-9]+).*#define TL_EXPECTED_VERSION_MINOR ([0-9]+).*#define TL_EXPECTED_VERSION_PATCH ([0-9]+)" _ "${_tlexpected_h}")
+    set(_tlexpected_version_string "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
+    if(NOT "${CMAKE_MATCH_0}" STREQUAL "" AND "${_tlexpected_version_string}" VERSION_GREATER_EQUAL "${TlExpected_FIND_VERSION}")
+      message(STATUS "Using system TlExpected (${TLEXPECTED_INCLUDE_DIR}/tl/expected.hpp)")
+      add_library(dep_tlexpected INTERFACE IMPORTED)
+      target_include_directories(dep_tlexpected INTERFACE "${TLEXPECTED_INCLUDE_DIR}")
+      register_dependency(TlExpected "SYSTEM (${TLEXPECTED_INCLUDE_DIR}/tl/expected.hpp)" "${_tlexpected_version_string}")
+    endif()
+  endif()
+  if(NOT TARGET dep_tlexpected)
+    message(STATUS "Using bundled TlExpected since TlExpected>=${TlExpected_FIND_VERSION} was not found locally")
+  endif()
+endif()
index c61ea667eac37d7a5f11664066adc6ff18330fd7..0a283f23f5fcea651d2ff49e42c86f05a565a036 100644 (file)
@@ -46,6 +46,7 @@ should be located or retrieved:
 - [hiredis](https://github.com/redis/hiredis)[^2] (optional, disable with `-D
   REDIS_STORAGE_BACKEND=OFF`)
 - [span-lite](https://github.com/martinmoene/span-lite)[^1]
+- [tl-expected](https://github.com/TartanLlama/expected)[^1]
 - [Zstandard](https://github.com/facebook/zstd)[^2]
 
 [^1]: A bundled version will be used if missing locally.
index 4e78521466f2f0d1db9d0d0ec27fe0c13c69f6c7..5952e8801f3bfd8aa1754c32b9f089119c606395 100644 (file)
@@ -47,6 +47,7 @@ target_link_libraries(
   PUBLIC
     dep_fmt
     dep_nonstdspan
+    dep_tlexpected
     third_party
   PRIVATE
     dep_cpphttplib
index 4ece77f566e668bcdf75ab5101c039c2e28461b5..4e97b042712f8f7f88d2f1625f400113e685dc8b 100644 (file)
@@ -19,9 +19,9 @@
 #pragma once
 
 #include <nonstd/span.hpp>
+#include <tl/expected.hpp>
 
 #include <blake3/blake3.h>
-#include <tl/expected.hpp>
 
 #include <array>
 #include <cstdint>
index b8db6b8a5add2919f94d5a0d845d793402949ea7..341b47bdc1fdf428340d28fee405d978afb1dd90 100644 (file)
@@ -22,8 +22,8 @@
 #include <ccache/util/Bytes.hpp>
 
 #include <nonstd/span.hpp>
-
 #include <tl/expected.hpp>
+
 #include <url.hpp>
 
 #include <chrono>
index 72af091017026a2e962fc78023569fd5e2c6ce21..4707f4f5857a0f8501f0125d570cf9977c42669b 100644 (file)
@@ -24,7 +24,6 @@
 #include <ccache/util/types.hpp>
 
 #include <nonstd/span.hpp>
-
 #include <tl/expected.hpp>
 
 #include <cstddef>
index c0209f89e3485c4b028e917fb8723168edf48ab8..07f791f2b5d3fb70fb3b28558b2f99e306293361 100644 (file)
@@ -22,9 +22,9 @@
 #include <ccache/util/conversion.hpp>
 
 #include <nonstd/span.hpp>
+#include <tl/expected.hpp>
 
 #include <sys/stat.h> // for mode_t
-#include <tl/expected.hpp>
 
 #include <cstdint>
 #include <cstring>
index 01ab43bb2db54b19302a19e42a7000e6f8314a7a..557d9cbc6fbea01406b45b3efeeba2cc87431041 100644 (file)
@@ -21,7 +21,6 @@
 #include <ccache/util/Bytes.hpp>
 
 #include <nonstd/span.hpp>
-
 #include <tl/expected.hpp>
 
 #include <cstddef>
index 9e7d9dc972cd1e6dcee9e899a74137c356faded4..2f28156b4403a808f31551dbdc0be13914470dc0 100644 (file)
@@ -62,3 +62,6 @@ endif()
 if(NOT TARGET dep_nonstdspan)
   add_subdirectory(nonstd-span)
 endif()
+if(NOT TARGET dep_tlexpected)
+  add_subdirectory(tl-expected)
+endif()
diff --git a/src/third_party/tl-expected/CMakeLists.txt b/src/third_party/tl-expected/CMakeLists.txt
new file mode 100644 (file)
index 0000000..fa215e6
--- /dev/null
@@ -0,0 +1,2 @@
+register_dependency(TlExpected BUNDLED 1.1.0)
+add_header_only_library(tlexpected DIR "${CMAKE_CURRENT_SOURCE_DIR}")
index b0875750c0d8b09e982547c35e56d0f5728f58b1..bd84ac61214246e15d753e6d34631b6d1e2c04d2 100644 (file)
@@ -19,7 +19,6 @@
 #include <ccache/util/expected.hpp>
 
 #include <doctest/doctest.h>
-
 #include <tl/expected.hpp>
 
 #include <iostream> // macOS bug: https://github.com/onqtam/doctest/issues/126