mirror of
https://github.com/red0124/ssp.git
synced 2025-01-23 04:55:20 +01:00
Merge pull request #1 from friendlyanon/cmake-support
CMake project structure
This commit is contained in:
commit
7166e1ebad
99
.github/workflows/ci.yml
vendored
Normal file
99
.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
name: Continuous Integration
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
clang_tests:
|
||||
if: >-
|
||||
! contains(toJSON(github.event.commits.*.message), '[skip ci]') &&
|
||||
! contains(toJSON(github.event.commits.*.message), '[skip github]')
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
version: [12, 11, 10, 9, 8, 7]
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
name: Clang ${{ matrix.version }}
|
||||
|
||||
container:
|
||||
image: teeks99/clang-ubuntu:${{ matrix.version }}
|
||||
|
||||
options: -v /usr/local:/host_usr_local
|
||||
|
||||
env:
|
||||
CC: clang-${{ matrix.version }}
|
||||
CXX: clang++-${{ matrix.version }}
|
||||
CXXFLAGS: -stdlib=libc++
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- uses: friendlyanon/fetch-core-count@v1
|
||||
id: cores
|
||||
|
||||
- name: CMake
|
||||
run: echo "/host_usr_local/bin" >> $GITHUB_PATH
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install -y git
|
||||
script/ci_install_deps.sh
|
||||
|
||||
- name: Configure
|
||||
run: cmake -S test -B build -D CMAKE_BUILD_TYPE=Debug
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build -j ${{ steps.cores.outputs.count }}
|
||||
|
||||
- name: Run
|
||||
working-directory: build
|
||||
run: ctest --output-on-failure -j ${{ steps.cores.outputs.count }}
|
||||
|
||||
gcc_tests:
|
||||
if: >-
|
||||
! contains(toJSON(github.event.commits.*.message), '[skip ci]') &&
|
||||
! contains(toJSON(github.event.commits.*.message), '[skip github]')
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
version: [10, 9, 8]
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
name: GCC ${{ matrix.version }}
|
||||
|
||||
container:
|
||||
image: gcc:${{ matrix.version }}
|
||||
|
||||
options: -v /usr/local:/host_usr_local
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- uses: friendlyanon/fetch-core-count@v1
|
||||
id: cores
|
||||
|
||||
- name: CMake
|
||||
run: echo "/host_usr_local/bin" >> $GITHUB_PATH
|
||||
|
||||
- name: Install dependencies
|
||||
run: script/ci_install_deps.sh
|
||||
|
||||
- name: Configure
|
||||
run: cmake -S test -B build -D CMAKE_BUILD_TYPE=Debug
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build -j ${{ steps.cores.outputs.count }}
|
||||
|
||||
- name: Run
|
||||
working-directory: build
|
||||
run: ctest --output-on-failure -j ${{ steps.cores.outputs.count }}
|
84
CMakeLists.txt
Normal file
84
CMakeLists.txt
Normal file
@ -0,0 +1,84 @@
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
project(
|
||||
ssp
|
||||
VERSION 0.0.1
|
||||
DESCRIPTION "Static split parser"
|
||||
HOMEPAGE_URL "https://github.com/red0124/ssp"
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
# ---- Warning guard ----
|
||||
|
||||
# Protect dependents from this project's warnings if the guard isn't disabled
|
||||
set(ssp_warning_guard SYSTEM)
|
||||
if(ssp_INCLUDE_WITHOUT_SYSTEM)
|
||||
set(ssp_warning_guard "")
|
||||
endif()
|
||||
|
||||
# ---- Declare library ----
|
||||
|
||||
add_library(ssp INTERFACE)
|
||||
add_library(ssp::ssp ALIAS ssp)
|
||||
|
||||
target_include_directories(
|
||||
ssp
|
||||
${ssp_warning_guard}
|
||||
INTERFACE
|
||||
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
|
||||
)
|
||||
|
||||
target_compile_features(ssp INTERFACE cxx_std_17)
|
||||
|
||||
target_link_libraries(
|
||||
ssp
|
||||
INTERFACE
|
||||
"$<$<AND:$<CXX_COMPILER_ID:AppleClang,Clang>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.0>>:c++fs>"
|
||||
"$<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.1>>:stdc++fs>"
|
||||
)
|
||||
|
||||
# ---- Install ----
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
set(ssp_directory "ssp-${PROJECT_VERSION}")
|
||||
set(ssp_include_directory "${CMAKE_INSTALL_INCLUDEDIR}/${ssp_directory}")
|
||||
|
||||
install(
|
||||
DIRECTORY "${PROJECT_SOURCE_DIR}/include/"
|
||||
DESTINATION "${ssp_include_directory}"
|
||||
COMPONENT ssp_Development
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS ssp
|
||||
EXPORT sspTargets
|
||||
INCLUDES DESTINATION "${ssp_include_directory}"
|
||||
)
|
||||
|
||||
write_basic_package_version_file(
|
||||
ssp-config-version.cmake
|
||||
COMPATIBILITY SameMajorVersion
|
||||
ARCH_INDEPENDENT
|
||||
)
|
||||
|
||||
set(ssp_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/${ssp_directory}")
|
||||
|
||||
install(
|
||||
FILES "${PROJECT_BINARY_DIR}/ssp-config-version.cmake"
|
||||
DESTINATION "${ssp_install_cmakedir}"
|
||||
COMPONENT ssp_Development
|
||||
)
|
||||
|
||||
install(
|
||||
EXPORT sspTargets
|
||||
FILE ssp-config.cmake
|
||||
NAMESPACE ssp::
|
||||
DESTINATION "${ssp_install_cmakedir}"
|
||||
COMPONENT ssp_Development
|
||||
)
|
||||
|
||||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
include(CPack)
|
||||
endif()
|
10
makefile
10
makefile
@ -1,10 +0,0 @@
|
||||
install:
|
||||
cp -r ./include/ss/ /usr/local/include/
|
||||
|
||||
uninstall:
|
||||
rm -rf /usr/local/include/ss/*.hpp
|
||||
|
||||
test:
|
||||
cd test && $(MAKE) -j4 && $(MAKE) test && $(MAKE) clean
|
||||
|
||||
.PHONY: install test
|
17
script/ci_install_deps.sh
Executable file
17
script/ci_install_deps.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
JOBS=4
|
||||
BUILD_TYPE=Debug
|
||||
|
||||
set -eux
|
||||
|
||||
git clone https://github.com/onqtam/doctest -b 2.4.4 --depth 1
|
||||
|
||||
cmake -S doctest -B doctest/build \
|
||||
-D CMAKE_BUILD_TYPE=${BUILD_TYPE} \
|
||||
-D DOCTEST_WITH_MAIN_IN_STATIC_LIB=NO \
|
||||
-D DOCTEST_WITH_TESTS=NO
|
||||
|
||||
cmake --build doctest/build --config ${BUILD_TYPE} --target install -j ${JOBS}
|
||||
|
||||
rm -rf doctest
|
36
test/CMakeLists.txt
Normal file
36
test/CMakeLists.txt
Normal file
@ -0,0 +1,36 @@
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
project(ssp_tests CXX)
|
||||
|
||||
# ---- Dependencies ----
|
||||
|
||||
set(
|
||||
ssp_INCLUDE_WITHOUT_SYSTEM
|
||||
YES
|
||||
CACHE
|
||||
INTERNAL
|
||||
"Turn the warning guard off to have errors appear in test builds"
|
||||
)
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(ssp SOURCE_DIR "${PROJECT_SOURCE_DIR}/..")
|
||||
FetchContent_MakeAvailable(ssp)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
target_compile_options(ssp INTERFACE -Wall -Wextra)
|
||||
endif()
|
||||
|
||||
find_package(doctest 2.4.4 CONFIG REQUIRED)
|
||||
# for doctest_discover_tests
|
||||
include(doctest)
|
||||
|
||||
# ---- Test ----
|
||||
|
||||
enable_testing()
|
||||
|
||||
foreach(name IN ITEMS test_parser test_converter test_extractions)
|
||||
add_executable("${name}" "${name}.cpp")
|
||||
target_link_libraries("${name}" PRIVATE ssp::ssp doctest::doctest)
|
||||
target_compile_definitions("${name}" PRIVATE DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN)
|
||||
doctest_discover_tests("${name}")
|
||||
endforeach()
|
6205
test/doctest.h
6205
test/doctest.h
File diff suppressed because it is too large
Load Diff
@ -1,26 +0,0 @@
|
||||
CXX=clang++
|
||||
CXXFLAGS=-Wall -Wextra -std=c++17 -lstdc++fs
|
||||
TESTS=test_parser test_converter test_extractions
|
||||
|
||||
all: $(TESTS)
|
||||
|
||||
# pattern rule, replacing built-in implicit .cpp-suffix rule
|
||||
%: %.cpp
|
||||
$(CXX) $(CXXFLAGS) $< -o $@
|
||||
|
||||
debug: CXXFLAGS += -g
|
||||
debug: all
|
||||
|
||||
clean:
|
||||
@$(RM) -fv $(TESTS)
|
||||
@$(RM) *.csv
|
||||
|
||||
test:
|
||||
@for i in $(TESTS); do \
|
||||
./$$i; \
|
||||
done
|
||||
|
||||
# don't use any implicit rules
|
||||
.SUFFIXES:
|
||||
# these rules won't actually build the targets they're named after
|
||||
.PHONY: all clean run debug
|
@ -1,6 +1,5 @@
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "../include/ss/converter.hpp"
|
||||
#include "doctest.h"
|
||||
#include <ss/converter.hpp>
|
||||
#include <doctest/doctest.h>
|
||||
#include <algorithm>
|
||||
|
||||
TEST_CASE("testing split") {
|
||||
|
@ -1,6 +1,5 @@
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "../include/ss/extract.hpp"
|
||||
#include "doctest.h"
|
||||
#include <ss/extract.hpp>
|
||||
#include <doctest/doctest.h>
|
||||
#include <algorithm>
|
||||
|
||||
constexpr auto eps = 0.000001;
|
||||
|
@ -1,6 +1,5 @@
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "../include/ss/parser.hpp"
|
||||
#include "doctest.h"
|
||||
#include <ss/parser.hpp>
|
||||
#include <doctest/doctest.h>
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user