mirror of
https://github.com/BlackMATov/flat.hpp.git
synced 2025-12-13 01:36:27 +07:00
add ability to use the library as cmake subdirectory #9
This commit is contained in:
11
.travis.yml
11
.travis.yml
@@ -66,5 +66,16 @@ matrix:
|
||||
after_success: ./scripts/upload_coverage.sh
|
||||
before_install:
|
||||
- eval "${MATRIX_EVAL}"
|
||||
- if [ "$TRAVIS_OS_NAME" == 'osx' ]; then
|
||||
brew update;
|
||||
brew upgrade cmake;
|
||||
brew install git-lfs;
|
||||
fi
|
||||
- if [ "$TRAVIS_OS_NAME" == 'linux' ]; then
|
||||
mkdir $HOME/cmake;
|
||||
export PATH="$HOME/cmake/bin:$PATH";
|
||||
travis_retry wget -q https://cmake.org/files/v3.11/cmake-3.11.4-Linux-x86_64.sh;
|
||||
sh cmake-3.11.4-Linux-x86_64.sh --prefix=$HOME/cmake --exclude-subdir --skip-license;
|
||||
fi
|
||||
script:
|
||||
- ./scripts/build_all.sh
|
||||
|
||||
@@ -1,43 +1,29 @@
|
||||
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
|
||||
project(flat)
|
||||
# 3.8 version is required for `cxx_std_14`
|
||||
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
|
||||
|
||||
#
|
||||
# coverage mode
|
||||
#
|
||||
|
||||
option(FLAT_BUILD_WITH_COVERAGE "Build with coverage" OFF)
|
||||
if(FLAT_BUILD_WITH_COVERAGE AND (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang"))
|
||||
add_definitions(-DFLAT_BUILD_WITH_COVERAGE)
|
||||
set(FLAT_COVERAGE_FLAGS "--coverage")
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAT_COVERAGE_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAT_COVERAGE_FLAGS}")
|
||||
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} ${FLAT_COVERAGE_FLAGS}")
|
||||
if(NOT DEFINED PROJECT_NAME)
|
||||
set(BUILD_AS_STANDALONE ON)
|
||||
endif()
|
||||
|
||||
#
|
||||
# sanitizer mode
|
||||
#
|
||||
project(flat.hpp)
|
||||
|
||||
option(FLAT_BUILD_WITH_SANITIZER "Build with sanitizer" OFF)
|
||||
if(FLAT_BUILD_WITH_SANITIZER AND (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang"))
|
||||
add_definitions(-DFLAT_BUILD_WITH_SANITIZER)
|
||||
set(FLAT_SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address")
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAT_SANITIZER_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAT_SANITIZER_FLAGS}")
|
||||
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} ${FLAT_SANITIZER_FLAGS}")
|
||||
add_library(${PROJECT_NAME} INTERFACE)
|
||||
target_include_directories(${PROJECT_NAME} INTERFACE headers)
|
||||
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_14)
|
||||
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
|
||||
|
||||
if(BUILD_AS_STANDALONE)
|
||||
option(BUILD_WITH_UNTESTS "Build with unit tests" ON)
|
||||
if(BUILD_WITH_UNTESTS)
|
||||
enable_testing()
|
||||
add_subdirectory(untests)
|
||||
endif()
|
||||
|
||||
option(BUILD_WITH_COVERAGE "Build with coverage" OFF)
|
||||
if(BUILD_WITH_COVERAGE AND (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang"))
|
||||
set(COVERAGE_FLAGS "--coverage")
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COVERAGE_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COVERAGE_FLAGS}")
|
||||
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} ${COVERAGE_FLAGS}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#
|
||||
# tests executable
|
||||
#
|
||||
|
||||
file(GLOB test_sources "*.cpp" "*.hpp")
|
||||
add_executable(${PROJECT_NAME} ${test_sources})
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
CXX_STANDARD 14
|
||||
CXX_STANDARD_REQUIRED YES
|
||||
CXX_EXTENSIONS NO)
|
||||
|
||||
enable_testing()
|
||||
add_test(${PROJECT_NAME} ${PROJECT_NAME})
|
||||
|
||||
20
README.md
20
README.md
@@ -25,7 +25,25 @@
|
||||
|
||||
## Installation
|
||||
|
||||
[flat.hpp][flat] is a header only library. All you need to do is copy the header files (`flat_set.hpp` and `flat_map.hpp`) into your project and include them.
|
||||
[flat.hpp][flat] is a header-only library. All you need to do is copy the headers files from `headers` directory into your project and include them:
|
||||
|
||||
```cpp
|
||||
#include "flat_hpp/flat_set.hpp"
|
||||
using namespace flat_hpp;
|
||||
|
||||
int main() {
|
||||
flat_set<int> s;
|
||||
s.insert(42);
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
Also, you can add the root repository directory to your [cmake](https://cmake.org) project:
|
||||
|
||||
```cmake
|
||||
add_subdirectory(external/flat.hpp)
|
||||
target_link_libraries(your_project_target flat.hpp)
|
||||
```
|
||||
|
||||
## API
|
||||
- [Flat Set](#flat-set)
|
||||
|
||||
22
untests/CMakeLists.txt
Normal file
22
untests/CMakeLists.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
# 3.11 version is required for `FetchContent`
|
||||
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
|
||||
|
||||
project(flat.hpp.untests)
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
catch2
|
||||
GIT_REPOSITORY https://github.com/catchorg/catch2)
|
||||
|
||||
FetchContent_GetProperties(catch2)
|
||||
if(NOT catch2_POPULATED)
|
||||
FetchContent_Populate(catch2)
|
||||
add_subdirectory(${catch2_SOURCE_DIR} ${catch2_BINARY_DIR})
|
||||
endif()
|
||||
|
||||
file(GLOB UNTESTS_SOURCES "*.cpp" "*.hpp")
|
||||
add_executable(${PROJECT_NAME} ${UNTESTS_SOURCES})
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
Catch2::Catch2
|
||||
flat.hpp::flat.hpp)
|
||||
add_test(${PROJECT_NAME} ${PROJECT_NAME})
|
||||
@@ -6,4 +6,4 @@
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#define CATCH_CONFIG_FAST_COMPILE
|
||||
#include "catch.hpp"
|
||||
#include <catch2/catch.hpp>
|
||||
@@ -5,11 +5,11 @@
|
||||
******************************************************************************/
|
||||
|
||||
#define CATCH_CONFIG_FAST_COMPILE
|
||||
#include "catch.hpp"
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
#include <deque>
|
||||
|
||||
#include "flat_map.hpp"
|
||||
#include <flat_hpp/flat_map.hpp>
|
||||
using namespace flat_hpp;
|
||||
|
||||
namespace
|
||||
@@ -5,11 +5,11 @@
|
||||
******************************************************************************/
|
||||
|
||||
#define CATCH_CONFIG_FAST_COMPILE
|
||||
#include "catch.hpp"
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
#include <deque>
|
||||
|
||||
#include "flat_set.hpp"
|
||||
#include <flat_hpp/flat_set.hpp>
|
||||
using namespace flat_hpp;
|
||||
|
||||
namespace
|
||||
Reference in New Issue
Block a user