From 26b16023dc639ae354e246458719e4b569bc1d97 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 3 Dec 2024 22:26:40 +0200 Subject: [PATCH] Add CMake main project support --- .gitignore | 1 + CMakeLists.txt | 69 ++++++++++++++++++++++++++++++++++++++++ benchmark/CMakeLists.txt | 10 ++++++ example/CMakeLists.txt | 16 ++++++++++ 4 files changed, 96 insertions(+) create mode 100644 .gitignore create mode 100644 benchmark/CMakeLists.txt create mode 100644 example/CMakeLists.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..67ec9ac --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/__build__/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e60c29..1ba98f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,8 +23,77 @@ target_link_libraries(boost_hash2 target_compile_features(boost_hash2 INTERFACE cxx_std_11) +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + + include(CTest) # defines BUILD_TESTING + include(FetchContent) + + FetchContent_Declare(boostorg_cmake GIT_REPOSITORY https://github.com/boostorg/cmake GIT_TAG master) + FetchContent_MakeAvailable(boostorg_cmake) + FetchContent_GetProperties(boostorg_cmake) + list(APPEND CMAKE_MODULE_PATH ${boostorg_cmake_SOURCE_DIR}/include) + +endif() + if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") add_subdirectory(test) endif() + +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + + set(deps + + # hash2 + + assert + config + container_hash + describe + mp11 + + # tests + + array + core + utility + + # benchmark + + unordered + + # example + + endian + + # secondaries + + static_assert + throw_exception + io + preprocessor + type_traits + predef + ) + + set(BUILD_TESTING OFF) # Hide cache variable + + list(LENGTH deps n) + set(i 0) + + foreach(dep IN LISTS deps) + + math(EXPR i "${i}+1") + message(STATUS "Fetching boostorg/${dep} [${i}/${n}]") + FetchContent_Declare(boostorg_${dep} GIT_REPOSITORY https://github.com/boostorg/${dep} GIT_TAG master EXCLUDE_FROM_ALL) + FetchContent_MakeAvailable(boostorg_${dep}) + + endforeach() + + unset(BUILD_TESTING) + + add_subdirectory(benchmark) + add_subdirectory(example) + +endif() diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt new file mode 100644 index 0000000..93368c3 --- /dev/null +++ b/benchmark/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright 2024 Peter Dimov +# Distributed under the Boost Software License, Version 1.0. +# https://www.boost.org/LICENSE_1_0.txt + +link_libraries(Boost::hash2 Boost::core Boost::unordered) + +add_executable(buffer buffer.cpp) +add_executable(unordered unordered.cpp) +add_executable(average average.cpp) +add_executable(keys keys.cpp) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt new file mode 100644 index 0000000..b2efeb7 --- /dev/null +++ b/example/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright 2024 Peter Dimov +# Distributed under the Boost Software License, Version 1.0. +# https://www.boost.org/LICENSE_1_0.txt + +link_libraries(Boost::hash2 Boost::unordered Boost::endian) + +add_executable(md5sum md5sum.cpp) +add_executable(hash2sum hash2sum.cpp) +add_executable(compile_time compile_time.cpp) +add_executable(compile_time_2 compile_time_2.cpp) +add_executable(hash_without_seed hash_without_seed.cpp) +add_executable(hash_with_uint64_seed hash_with_uint64_seed.cpp) +add_executable(hash_with_byte_seed hash_with_byte_seed.cpp) +add_executable(hash_with_any_seed hash_with_any_seed.cpp) +add_executable(hash_32_64 hash_32_64.cpp) +add_executable(xxh128_from_xxh64 xxh128_from_xxh64.cpp)