diff --git a/.gitignore b/.gitignore index c57c218..94e5b13 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ build/* +install/* .clangd/* -.vscode/* CMakeLists.txt.user diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..f432300 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,11 @@ +{ + "version": "0.2.0", + "configurations": [{ + "name": "LLDB Debug", + "type": "lldb", + "request": "launch", + "program": "${command:cmake.launchTargetPath}", + "args": [], + "cwd": "${workspaceFolder}" + }] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..966d80c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,29 @@ +{ + "[cpp]": { + "files.encoding": "utf8", + "files.insertFinalNewline": true, + "files.trimFinalNewlines": true, + "files.trimTrailingWhitespace": true + }, + "[cmake]": { + "files.encoding": "utf8", + "files.insertFinalNewline": true, + "files.trimFinalNewlines": true, + "files.trimTrailingWhitespace": true + }, + "[python]": { + "files.encoding": "utf8", + "files.insertFinalNewline": true, + "files.trimFinalNewlines": true, + "files.trimTrailingWhitespace": true + }, + "clangd.arguments": [ + "--all-scopes-completion", + "--background-index", + "--clang-tidy", + "--compile-commands-dir=${workspaceFolder}/.clangd", + "--completion-style=detailed", + "--header-insertion=never" + ], + "cmake.copyCompileCommands": "${workspaceFolder}/.clangd/compile_commands.json" +} diff --git a/CMakeLists.txt b/CMakeLists.txt index 525c68d..ee88fc7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,36 +1,95 @@ -cmake_minimum_required(VERSION 3.15 FATAL_ERROR) +cmake_minimum_required(VERSION 3.21 FATAL_ERROR) -if(NOT DEFINED PROJECT_NAME) - set(BUILD_AS_STANDALONE ON) -else() - set(BUILD_AS_STANDALONE OFF) -endif() +project(flat.hpp + VERSION "0.0.1" + DESCRIPTION "Library of flat vector-like based associative containers" + HOMEPAGE_URL "https://github.com/blackmatov/flat.hpp") -project(flat.hpp) +# +# LIBRARY +# add_library(${PROJECT_NAME} INTERFACE) -target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17) -target_include_directories(${PROJECT_NAME} INTERFACE headers) +add_library(flat.hpp::flat.hpp ALIAS ${PROJECT_NAME}) + +target_compile_features(${PROJECT_NAME} INTERFACE + cxx_std_17) + +target_include_directories(${PROJECT_NAME} INTERFACE + $ + $) # -# BUILD_AS_STANDALONE +# INSTALL # -if(NOT ${BUILD_AS_STANDALONE}) - return() +if(PROJECT_IS_TOP_LEVEL) + include(CMakePackageConfigHelpers) + include(GNUInstallDirs) + + set(FLAT_HPP_INSTALL_CONFIG_DIR + "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + + set(FLAT_HPP_INSTALL_CONFIG_INPUT + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in") + + set(FLAT_HPP_INSTALL_GENERATED_CONFIG_CMAKE + "${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}-config.cmake") + + set(FLAT_HPP_INSTALL_GENERATED_CONFIG_VERSION_CMAKE + "${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}-config-version.cmake") + + configure_package_config_file( + "${FLAT_HPP_INSTALL_CONFIG_INPUT}" + "${FLAT_HPP_INSTALL_GENERATED_CONFIG_CMAKE}" + INSTALL_DESTINATION "${FLAT_HPP_INSTALL_CONFIG_DIR}" + NO_SET_AND_CHECK_MACRO + NO_CHECK_REQUIRED_COMPONENTS_MACRO) + + write_basic_package_version_file( + "${FLAT_HPP_INSTALL_GENERATED_CONFIG_VERSION_CMAKE}" + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion + ARCH_INDEPENDENT) + + install( + TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}-targets + INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") + + install( + DIRECTORY headers/${PROJECT_NAME} + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") + + install( + EXPORT ${PROJECT_NAME}-targets + FILE ${PROJECT_NAME}-targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION "${FLAT_HPP_INSTALL_CONFIG_DIR}") + + install( + FILES "${FLAT_HPP_INSTALL_GENERATED_CONFIG_CMAKE}" + "${FLAT_HPP_INSTALL_GENERATED_CONFIG_VERSION_CMAKE}" + DESTINATION "${FLAT_HPP_INSTALL_CONFIG_DIR}") endif() -option(BUILD_WITH_COVERAGE "Build with coverage" OFF) -option(BUILD_WITH_SANITIZERS "Build with sanitizers" OFF) +# +# DEVELOPER +# -enable_testing() -set_property(GLOBAL PROPERTY USE_FOLDERS ON) -set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake") -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +if(PROJECT_IS_TOP_LEVEL) + option(BUILD_WITH_COVERAGE "Build with coverage" OFF) + option(BUILD_WITH_SANITIZERS "Build with sanitizers" OFF) -include(EnableASan) -include(EnableGCov) -include(EnableUBSan) + enable_testing() + set_property(GLOBAL PROPERTY USE_FOLDERS ON) + set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake") + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -add_subdirectory(vendors) -add_subdirectory(untests) + include(EnableASan) + include(EnableGCov) + include(EnableUBSan) + + add_subdirectory(vendors) + add_subdirectory(untests) +endif() diff --git a/LICENSE.md b/LICENSE.md index 33252ab..80d0414 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) +Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index ec3ca7e..1f98eba 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Also, you can add the root repository directory to your [cmake](https://cmake.or ```cmake add_subdirectory(external/flat.hpp) -target_link_libraries(your_project_target PUBLIC flat.hpp) +target_link_libraries(your_project_target PUBLIC flat.hpp::flat.hpp) ``` ## API diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in new file mode 100644 index 0000000..d66aef9 --- /dev/null +++ b/cmake/Config.cmake.in @@ -0,0 +1,3 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/flat.hpp-targets.cmake") diff --git a/cmake/EnableASan.cmake b/cmake/EnableASan.cmake index 83a9be5..1af49c9 100644 --- a/cmake/EnableASan.cmake +++ b/cmake/EnableASan.cmake @@ -1,14 +1,15 @@ # https://clang.llvm.org/docs/AddressSanitizer.html -add_library(enable_asan INTERFACE) +add_library(${PROJECT_NAME}.enable_asan INTERFACE) +add_library(${PROJECT_NAME}::enable_asan ALIAS ${PROJECT_NAME}.enable_asan) -target_compile_options(enable_asan INTERFACE +target_compile_options(${PROJECT_NAME}.enable_asan INTERFACE -fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-scope -fsanitize-address-use-after-return=always) -target_link_options(enable_asan INTERFACE +target_link_options(${PROJECT_NAME}.enable_asan INTERFACE -fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-scope diff --git a/cmake/EnableGCov.cmake b/cmake/EnableGCov.cmake index f390dd4..e98ea88 100644 --- a/cmake/EnableGCov.cmake +++ b/cmake/EnableGCov.cmake @@ -1,9 +1,10 @@ # https://clang.llvm.org/docs/SourceBasedCodeCoverage.html -add_library(enable_gcov INTERFACE) +add_library(${PROJECT_NAME}.enable_gcov INTERFACE) +add_library(${PROJECT_NAME}::enable_gcov ALIAS ${PROJECT_NAME}.enable_gcov) -target_compile_options(enable_gcov INTERFACE +target_compile_options(${PROJECT_NAME}.enable_gcov INTERFACE --coverage) -target_link_options(enable_gcov INTERFACE +target_link_options(${PROJECT_NAME}.enable_gcov INTERFACE --coverage) diff --git a/cmake/EnableUBSan.cmake b/cmake/EnableUBSan.cmake index ee954ff..358b14d 100644 --- a/cmake/EnableUBSan.cmake +++ b/cmake/EnableUBSan.cmake @@ -1,11 +1,12 @@ # https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html -add_library(enable_ubsan INTERFACE) +add_library(${PROJECT_NAME}.enable_ubsan INTERFACE) +add_library(${PROJECT_NAME}::enable_ubsan ALIAS ${PROJECT_NAME}.enable_ubsan) -target_compile_options(enable_ubsan INTERFACE +target_compile_options(${PROJECT_NAME}.enable_ubsan INTERFACE -fsanitize=undefined -fno-omit-frame-pointer) -target_link_options(enable_ubsan INTERFACE +target_link_options(${PROJECT_NAME}.enable_ubsan INTERFACE -fsanitize=undefined -fno-omit-frame-pointer) diff --git a/headers/flat.hpp/detail/eq_compare.hpp b/headers/flat.hpp/detail/eq_compare.hpp index bf7ddde..ada00c6 100644 --- a/headers/flat.hpp/detail/eq_compare.hpp +++ b/headers/flat.hpp/detail/eq_compare.hpp @@ -1,7 +1,7 @@ /******************************************************************************* * This file is part of the "https://github.com/blackmatov/flat.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) + * Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #pragma once diff --git a/headers/flat.hpp/detail/is_allocator.hpp b/headers/flat.hpp/detail/is_allocator.hpp index 4ce4a7a..13e0c34 100644 --- a/headers/flat.hpp/detail/is_allocator.hpp +++ b/headers/flat.hpp/detail/is_allocator.hpp @@ -1,7 +1,7 @@ /******************************************************************************* * This file is part of the "https://github.com/blackmatov/flat.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) + * Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #pragma once diff --git a/headers/flat.hpp/detail/is_sorted.hpp b/headers/flat.hpp/detail/is_sorted.hpp index 7b9cda3..e207d66 100644 --- a/headers/flat.hpp/detail/is_sorted.hpp +++ b/headers/flat.hpp/detail/is_sorted.hpp @@ -1,7 +1,7 @@ /******************************************************************************* * This file is part of the "https://github.com/blackmatov/flat.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) + * Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #pragma once diff --git a/headers/flat.hpp/detail/is_transparent.hpp b/headers/flat.hpp/detail/is_transparent.hpp index ac835d7..8dfc56e 100644 --- a/headers/flat.hpp/detail/is_transparent.hpp +++ b/headers/flat.hpp/detail/is_transparent.hpp @@ -1,7 +1,7 @@ /******************************************************************************* * This file is part of the "https://github.com/blackmatov/flat.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) + * Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #pragma once diff --git a/headers/flat.hpp/detail/iter_traits.hpp b/headers/flat.hpp/detail/iter_traits.hpp index c44723f..5cfc5c4 100644 --- a/headers/flat.hpp/detail/iter_traits.hpp +++ b/headers/flat.hpp/detail/iter_traits.hpp @@ -1,7 +1,7 @@ /******************************************************************************* * This file is part of the "https://github.com/blackmatov/flat.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) + * Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #pragma once diff --git a/headers/flat.hpp/detail/pair_compare.hpp b/headers/flat.hpp/detail/pair_compare.hpp index bb39b92..8f758bd 100644 --- a/headers/flat.hpp/detail/pair_compare.hpp +++ b/headers/flat.hpp/detail/pair_compare.hpp @@ -1,7 +1,7 @@ /******************************************************************************* * This file is part of the "https://github.com/blackmatov/flat.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) + * Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #pragma once diff --git a/headers/flat.hpp/flat.hpp b/headers/flat.hpp/flat.hpp index 8a9f623..5d95e74 100644 --- a/headers/flat.hpp/flat.hpp +++ b/headers/flat.hpp/flat.hpp @@ -1,7 +1,7 @@ /******************************************************************************* * This file is part of the "https://github.com/blackmatov/flat.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) + * Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #include "flat_map.hpp" diff --git a/headers/flat.hpp/flat_fwd.hpp b/headers/flat.hpp/flat_fwd.hpp index da8d4fe..7f2e733 100644 --- a/headers/flat.hpp/flat_fwd.hpp +++ b/headers/flat.hpp/flat_fwd.hpp @@ -1,7 +1,7 @@ /******************************************************************************* * This file is part of the "https://github.com/blackmatov/flat.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) + * Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #pragma once diff --git a/headers/flat.hpp/flat_map.hpp b/headers/flat.hpp/flat_map.hpp index fda25da..e1b155e 100644 --- a/headers/flat.hpp/flat_map.hpp +++ b/headers/flat.hpp/flat_map.hpp @@ -1,7 +1,7 @@ /******************************************************************************* * This file is part of the "https://github.com/blackmatov/flat.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) + * Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #pragma once diff --git a/headers/flat.hpp/flat_multimap.hpp b/headers/flat.hpp/flat_multimap.hpp index fbe23a8..763a7ea 100644 --- a/headers/flat.hpp/flat_multimap.hpp +++ b/headers/flat.hpp/flat_multimap.hpp @@ -1,7 +1,7 @@ /******************************************************************************* * This file is part of the "https://github.com/blackmatov/flat.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) + * Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #pragma once diff --git a/headers/flat.hpp/flat_multiset.hpp b/headers/flat.hpp/flat_multiset.hpp index 4bac8ce..c5fe652 100644 --- a/headers/flat.hpp/flat_multiset.hpp +++ b/headers/flat.hpp/flat_multiset.hpp @@ -1,7 +1,7 @@ /******************************************************************************* * This file is part of the "https://github.com/blackmatov/flat.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) + * Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #pragma once diff --git a/headers/flat.hpp/flat_set.hpp b/headers/flat.hpp/flat_set.hpp index 1bcdd9b..194112a 100644 --- a/headers/flat.hpp/flat_set.hpp +++ b/headers/flat.hpp/flat_set.hpp @@ -1,7 +1,7 @@ /******************************************************************************* * This file is part of the "https://github.com/blackmatov/flat.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) + * Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #pragma once diff --git a/untests/CMakeLists.txt b/untests/CMakeLists.txt index 2e3ef97..35e6196 100644 --- a/untests/CMakeLists.txt +++ b/untests/CMakeLists.txt @@ -4,7 +4,7 @@ file(GLOB_RECURSE UNTESTS_SOURCES "*.cpp" "*.hpp") source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${UNTESTS_SOURCES}) add_executable(${PROJECT_NAME} ${UNTESTS_SOURCES}) -target_link_libraries(${PROJECT_NAME} PRIVATE flat.hpp) +target_link_libraries(${PROJECT_NAME} PRIVATE flat.hpp::flat.hpp) # # setup defines @@ -23,14 +23,14 @@ setup_defines_for_target(${PROJECT_NAME}) # function(setup_libraries_for_target TARGET) - target_link_libraries(${TARGET} PRIVATE doctest_with_main) + target_link_libraries(${TARGET} PRIVATE doctest::doctest_with_main) if(${BUILD_WITH_COVERAGE}) - target_link_libraries(${TARGET} PRIVATE enable_gcov) + target_link_libraries(${TARGET} PRIVATE flat.hpp::enable_gcov) endif() if(${BUILD_WITH_SANITIZERS}) - target_link_libraries(${TARGET} PRIVATE enable_asan enable_ubsan) + target_link_libraries(${TARGET} PRIVATE flat.hpp::enable_asan flat.hpp::enable_ubsan) endif() endfunction() diff --git a/untests/flat_detail_tests.cpp b/untests/flat_detail_tests.cpp index 0eaf9c6..daada0e 100644 --- a/untests/flat_detail_tests.cpp +++ b/untests/flat_detail_tests.cpp @@ -1,7 +1,7 @@ /******************************************************************************* * This file is part of the "https://github.com/blackmatov/flat.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) + * Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #include diff --git a/untests/flat_map_tests.cpp b/untests/flat_map_tests.cpp index 64e717c..891e3f0 100644 --- a/untests/flat_map_tests.cpp +++ b/untests/flat_map_tests.cpp @@ -1,7 +1,7 @@ /******************************************************************************* * This file is part of the "https://github.com/blackmatov/flat.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) + * Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #include diff --git a/untests/flat_multimap_tests.cpp b/untests/flat_multimap_tests.cpp index 5cb48bf..d70dbea 100644 --- a/untests/flat_multimap_tests.cpp +++ b/untests/flat_multimap_tests.cpp @@ -1,7 +1,7 @@ /******************************************************************************* * This file is part of the "https://github.com/blackmatov/flat.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) + * Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #include diff --git a/untests/flat_multiset_tests.cpp b/untests/flat_multiset_tests.cpp index 27d9e84..7704586 100644 --- a/untests/flat_multiset_tests.cpp +++ b/untests/flat_multiset_tests.cpp @@ -1,7 +1,7 @@ /******************************************************************************* * This file is part of the "https://github.com/blackmatov/flat.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) + * Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #include diff --git a/untests/flat_set_tests.cpp b/untests/flat_set_tests.cpp index 24f445f..b96867c 100644 --- a/untests/flat_set_tests.cpp +++ b/untests/flat_set_tests.cpp @@ -1,7 +1,7 @@ /******************************************************************************* * This file is part of the "https://github.com/blackmatov/flat.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) + * Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #include diff --git a/untests/flat_tests.hpp b/untests/flat_tests.hpp index c874564..d0c1f20 100644 --- a/untests/flat_tests.hpp +++ b/untests/flat_tests.hpp @@ -1,7 +1,7 @@ /******************************************************************************* * This file is part of the "https://github.com/blackmatov/flat.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com) + * Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #include