Skip to content

Commit

Permalink
Modernize project and add MSVC support (#10)
Browse files Browse the repository at this point in the history
* add .gitignore

* update tests to use doctest

* apply clang-format

* update benchmark and version

* add /permissive- flag

* replace standalone with benchmark test

* add codecov.yaml

* update google benchmark

* update google benchmark

* compile with cross-compilation flags

* test with other flags

* try installing libc++

* try another answer

* also install libc++abi-dev

* build benchmark as release

* remove deprecated std::iterator base class

* why does release build of the benchmark target add the "-Werror" flag?

* require C++17

* add find utility function

* swap argument order

* add instructions to run benchmark
  • Loading branch information
TheLartians committed Apr 15, 2020
1 parent 5b3672a commit aab0c0d
Show file tree
Hide file tree
Showing 26 changed files with 926 additions and 693 deletions.
16 changes: 16 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
BasedOnStyle: Google
AccessModifierOffset: '-2'
AlignTrailingComments: 'true'
AllowAllParametersOfDeclarationOnNextLine: 'false'
AlwaysBreakTemplateDeclarations: 'No'
BreakBeforeBraces: Attach
ColumnLimit: '100'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
IncludeBlocks: Regroup
IndentPPDirectives: AfterHash
IndentWidth: '2'
NamespaceIndentation: All
BreakBeforeBinaryOperators: All
BreakBeforeTernaryOperators: 'true'
...
24 changes: 24 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Benchmark

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

# https://stackoverflow.com/questions/39332406/install-libc-on-ubuntu
- name: install dependencies
run: |
sudo apt-get update
sudo apt-get install libc++-dev libc++abi-dev
- name: configure
# flags set to avoid strange regular expression backend error: https://github.com/google/benchmark/issues/773
run: cmake -Hbenchmark -Bbuild -DRUN_HAVE_STD_REGEX=0 -DRUN_HAVE_POSIX_REGEX=0

- name: build
run: cmake --build build -j4
31 changes: 31 additions & 0 deletions .github/workflows/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Install

on: [push]

env:
CTEST_OUTPUT_ON_FAILURE: 1

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: build and install library
run: |
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Release
sudo cmake --build build --target install
rm -rf build
- name: configure
run: cmake -Htest -Bbuild -DTEST_INSTALLED_VERSION=1

- name: build
run: cmake --build build --config Debug -j4

- name: test
run: |
cd build
ctest --build-config Debug
25 changes: 25 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: MacOS

on: [push]

env:
CTEST_OUTPUT_ON_FAILURE: 1

jobs:
build:

runs-on: macos-latest

steps:
- uses: actions/checkout@v1

- name: configure
run: cmake -Htest -Bbuild

- name: build
run: cmake --build build --config Debug -j4

- name: test
run: |
cd build
ctest --build-config Debug
20 changes: 20 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Style

on: [push]

jobs:
build:

runs-on: macos-latest

steps:
- uses: actions/checkout@v1

- name: Install clang-format
run: brew install clang-format

- name: configure
run: cmake -Htest -Bbuild

- name: check style
run: cmake --build build --target check-format
29 changes: 29 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Ubuntu

on: [push]

env:
CTEST_OUTPUT_ON_FAILURE: 1
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: configure
run: cmake -Htest -Bbuild -DENABLE_TEST_COVERAGE=1

- name: build
run: cmake --build build --config Debug -j4

- name: test
run: |
cd build
ctest --build-config Debug
- name: collect code coverage
run: bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"
25 changes: 25 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Windows

on: [push]

env:
CTEST_OUTPUT_ON_FAILURE: 1

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v1

- name: configure
run: cmake -Htest -Bbuild

- name: build
run: cmake --build build --config Debug -j4

- name: test
run: |
cd build
ctest --build-config Debug
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
.vscode
/build*
70 changes: 0 additions & 70 deletions .travis.yml

This file was deleted.

101 changes: 25 additions & 76 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,104 +3,53 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
# ---- Project ----

project(EasyIterator
VERSION 1.1
VERSION 1.4
LANGUAGES CXX
)

# ---- Configuration variables ----

option(EASY_ITERATOR_ENABLE_TESTS "Build tests" OFF)
option(EASY_ITERATOR_BUILD_EXAMPLES "Enable examples" OFF)
option(EASY_ITERATOR_BUILD_BENCHMARK "Enable benchmark" OFF)

# ---- Include guards ----

if(TARGET EasyIterator)
return()
endif()

if(${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR})
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.")
endif()

# ---- Add dependencies via CPM ----
# see https://github.com/TheLartians/CPM.cmake for more info

include(cmake/CPM.cmake)

# PackageProject.cmake will be used to make our target installable
CPMAddPackage(
NAME PackageProject.cmake
GITHUB_REPOSITORY TheLartians/PackageProject.cmake
VERSION 1.0
)

# ---- Header target ----

FILE(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
FILE(GLOB_RECURSE headers CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
add_library(EasyIterator-headers EXCLUDE_FROM_ALL ${headers})
SET_TARGET_PROPERTIES(EasyIterator-headers PROPERTIES LINKER_LANGUAGE CXX)

# ---- Create library ----

add_library(EasyIterator INTERFACE)

target_compile_options(EasyIterator INTERFACE "$<$<BOOL:${MSVC}>:/permissive->")
set_target_properties(EasyIterator PROPERTIES INTERFACE_COMPILE_FEATURES cxx_std_17)

target_include_directories(EasyIterator
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)

include(CMakePackageConfigHelpers)
# ---- Create an installable target ----

write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/EasyIteratorConfigVersion.cmake"
packageProject(
NAME ${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

# ---- Install ----

install(
TARGETS EasyIterator
EXPORT EasyIteratorTargets
LIBRARY DESTINATION lib COMPONENT Runtime
ARCHIVE DESTINATION lib COMPONENT Development
RUNTIME DESTINATION bin COMPONENT Runtime
PUBLIC_HEADER DESTINATION include COMPONENT Development
BUNDLE DESTINATION bin COMPONENT Runtime
BINARY_DIR ${PROJECT_BINARY_DIR}
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
)

include(CMakePackageConfigHelpers)

configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/EasyIteratorConfig.cmake.in"
"${PROJECT_BINARY_DIR}/EasyIteratorConfig.cmake"
INSTALL_DESTINATION lib/cmake/EasyIterator
)

install(
EXPORT EasyIteratorTargets
DESTINATION lib/cmake/EasyIterator
)

install(
FILES
"${PROJECT_BINARY_DIR}/EasyIteratorConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/EasyIteratorConfig.cmake"
DESTINATION
lib/cmake/EasyIterator
)

install(
DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION include
)

# ---- Test ----

if(${EASY_ITERATOR_ENABLE_TESTS})
ENABLE_TESTING()
add_subdirectory(tests)
endif()

# ---- Examples ----

if(${EASY_ITERATOR_BUILD_EXAMPLES})
add_subdirectory(examples)
endif()

# ---- Benchmark ----

if(${EASY_ITERATOR_BUILD_BENCHMARK})
add_subdirectory(benchmark)
endif()

Loading

0 comments on commit aab0c0d

Please sign in to comment.