diff --git a/.tipi/env b/.tipi/env new file mode 100644 index 0000000..0e53b00 --- /dev/null +++ b/.tipi/env @@ -0,0 +1 @@ +CMAKE_TIPI_PROVIDER_ENABLE=ON \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d888f8..a89cb01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,44 +14,36 @@ if ("${COMPILER_IN_USE}" STREQUAL "GNU" OR "${COMPILER_IN_USE}" MATCHES "CLANG") ) endif() -find_package(Threads) - include (FetchContent) FetchContent_Declare( Boost - GIT_REPOSITORY https://github.com/boostorg/boost.git - # boost 1.80 - GIT_TAG 32da69a36f84c5255af8a994951918c258bac601 + GIT_REPOSITORY https://github.com/nxxm/boost.git + # boost-1.89.0 with updates + GIT_TAG 23090bb21676cb22f1d4ceed21d59fda8b420cc9 + EXCLUDE_FROM_ALL ) FetchContent_MakeAvailable(Boost) -find_package(boost_filesystem CONFIG REQUIRED) -find_package(boost_system CONFIG REQUIRED) -find_package(boost_uuid CONFIG REQUIRED) +find_package(boost_filesystem CONFIG) +find_package(boost_system CONFIG) +find_package(boost_uuid CONFIG) # Define library -add_library(file INTERFACE ) +add_library(file INTERFACE) add_library(cpp-pre_file::file ALIAS file) - -set(include_install_dir "include") - -target_include_directories(file BEFORE INTERFACE - $ - $) - -target_link_libraries(file INTERFACE - Boost::system Boost::filesystem Boost::uuid - ${CMAKE_THREAD_LIBS_INIT} +target_sources(file + PUBLIC + FILE_SET HEADERS + FILES + pre/file/hash.hpp + pre/file/string.hpp + pre/file/home.hpp ) +target_compile_features(file INTERFACE cxx_std_17) - -# Targets: -install( - TARGETS - EXPORT "${targets_export_name}" - LIBRARY DESTINATION "lib" - ARCHIVE DESTINATION "lib" - RUNTIME DESTINATION "bin" - INCLUDES DESTINATION "${include_install_dir}" +target_link_libraries(file INTERFACE + Boost::filesystem + Boost::system + Boost::uuid ) add_subdirectory(tests) @@ -100,7 +92,7 @@ install( LIBRARY DESTINATION "lib" ARCHIVE DESTINATION "lib" RUNTIME DESTINATION "bin" - INCLUDES DESTINATION "${include_install_dir}" + FILE_SET HEADERS DESTINATION "include" ) # Headers: diff --git a/pre/file/hash.hpp b/pre/file/hash.hpp index fab57a7..922826b 100644 --- a/pre/file/hash.hpp +++ b/pre/file/hash.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -10,6 +11,13 @@ namespace pre::file { + namespace { + constexpr char int_to_hex[16] = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', + '9', 'a', 'b', 'c', 'd', 'e', 'f' + }; + } + using namespace std::string_literals; //! Calculate the SHA1 sum for a file on disk @@ -41,13 +49,31 @@ namespace pre::file { } // compute the hash - uint32_t hash[5] = {0}; + boost::uuids::detail::sha1::digest_type hash = {0}; char hash_buf[41] = {0}; sha1.get_digest(hash); - for (int i = 0; i < 5; i++) { - std::sprintf(hash_buf + (i << 3), "%08x", hash[i]); + if constexpr (std::size(hash) == 20) { + // Newer Boost has digest_type of type "unsigned char[20]" + for (size_t i = 0; i < std::size(hash); i++) { + hash_buf[i * 2 + 0] = int_to_hex[(hash[i] >> 4) & 0xF]; + hash_buf[i * 2 + 1] = int_to_hex[(hash[i] ) & 0xF]; + } + } else if constexpr (std::size(hash) == 5) { + // Older Boost has digest_type of type "unsigned int[5]" + for (size_t i = 0; i < std::size(hash); i++) { + hash_buf[i * 2 + 0] = int_to_hex[(hash[i] >> 28) & 0xF]; + hash_buf[i * 2 + 1] = int_to_hex[(hash[i] >> 24) & 0xF]; + hash_buf[i * 2 + 2] = int_to_hex[(hash[i] >> 20) & 0xF]; + hash_buf[i * 2 + 3] = int_to_hex[(hash[i] >> 16) & 0xF]; + hash_buf[i * 2 + 4] = int_to_hex[(hash[i] >> 12) & 0xF]; + hash_buf[i * 2 + 5] = int_to_hex[(hash[i] >> 8) & 0xF]; + hash_buf[i * 2 + 6] = int_to_hex[(hash[i] >> 4) & 0xF]; + hash_buf[i * 2 + 7] = int_to_hex[(hash[i] ) & 0xF]; + } + } else { + throw std::runtime_error("Unsupported boost::uuids::detail::sha1::digest_type size"); } return std::string(hash_buf);