new build scripts and cmake install targets

This commit is contained in:
BlackMATov
2023-01-07 16:00:19 +07:00
parent dcaad6f3dc
commit c30d744784
28 changed files with 653 additions and 6469 deletions

View File

@@ -1,19 +0,0 @@
#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE}" )" && pwd )"
ROOT_DIR="${DIR}/.."
BUILD_DIR="${ROOT_DIR}/build/coverage"
mkdir -p "${BUILD_DIR}"
(cd "${BUILD_DIR}" && cmake "${ROOT_DIR}" -DCMAKE_BUILD_TYPE=Debug -DBUILD_WITH_COVERAGE=ON)
(cd "${BUILD_DIR}" && cmake --build .)
(cd "${BUILD_DIR}" && lcov -d . -z)
(cd "${BUILD_DIR}" && ctest --verbose)
(cd "${BUILD_DIR}" && lcov -d . -c -o "coverage.info")
(cd "${BUILD_DIR}" && lcov -r "coverage.info" "*/usr/*" "*/untests/*" -o "coverage.info")
(cd "${BUILD_DIR}" && lcov -l "coverage.info")
bash <(curl -s https://codecov.io/bash) -f "${BUILD_DIR}/coverage.info" || echo "Codecov did not collect coverage reports"

View File

@@ -1,11 +0,0 @@
#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE}" )" && pwd )"
ROOT_DIR="${DIR}/.."
BUILD_DIR="${ROOT_DIR}/build/darwin_release"
mkdir -p "${BUILD_DIR}"
(cd "${BUILD_DIR}" && cmake "${ROOT_DIR}" -DCMAKE_BUILD_TYPE=Release)
(cd "${BUILD_DIR}" && cmake --build .)
(cd "${BUILD_DIR}" && ctest --verbose)

View File

@@ -1,11 +0,0 @@
#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE}" )" && pwd )"
ROOT_DIR="${DIR}/.."
BUILD_DIR="${ROOT_DIR}/build/linux_release"
mkdir -p "${BUILD_DIR}"
(cd "${BUILD_DIR}" && cmake "${ROOT_DIR}" -DCMAKE_BUILD_TYPE=Release)
(cd "${BUILD_DIR}" && cmake --build .)
(cd "${BUILD_DIR}" && ctest --verbose)

View File

@@ -1,19 +0,0 @@
@echo off
set DIR=%~dp0
set ROOT_DIR=%DIR%..\
set BUILD_DIR=%ROOT_DIR%build\windows_release_x64\
if not exist %BUILD_DIR% mkdir %BUILD_DIR% || goto :error
pushd %BUILD_DIR% || goto :error
cmake %ROOT_DIR% -A x64 || goto :error
cmake --build . --config Release || goto :error
ctest --verbose || goto :error
popd || goto :error
goto :EOF
:error
echo Failed with error #%errorlevel%.
exit /b %errorlevel%

View File

@@ -1,19 +0,0 @@
@echo off
set DIR=%~dp0
set ROOT_DIR=%DIR%..\
set BUILD_DIR=%ROOT_DIR%build\windows_release_x86\
if not exist %BUILD_DIR% mkdir %BUILD_DIR% || goto :error
pushd %BUILD_DIR% || goto :error
cmake %ROOT_DIR% -A Win32 || goto :error
cmake --build . --config Release || goto :error
ctest --verbose || goto :error
popd || goto :error
goto :EOF
:error
echo Failed with error #%errorlevel%.
exit /b %errorlevel%

View File

@@ -1,16 +0,0 @@
name: coverage
on: [push, pull_request]
jobs:
build:
runs-on: macos-10.15
name: "coverage"
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Install lcov by Homebrew
run: brew install lcov
- name: Build && Test && Upload
run: .ci/build_coverage.sh

View File

@@ -10,15 +10,22 @@ jobs:
matrix:
config:
# https://github.com/actions/virtual-environments/tree/main/images/macos
- { os: "macos-10.15", xcode: "10.3" }
- { os: "macos-10.15", xcode: "11.7" }
- { os: "macos-10.15", xcode: "12.4" }
- { os: "macos-10.15", xcode: "10.3", arch: "x64" }
- { os: "macos-12", xcode: "14.2", arch: "x64" }
name: "xcode-${{matrix.config.xcode}}"
steps:
- uses: actions/checkout@v2
- name: Setup
run: brew install cmake ninja
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
submodules: true
- name: Select Xcode
run: sudo xcode-select --switch "/Applications/Xcode_${{matrix.config.xcode}}.app"
- name: Build && Test
run: .ci/build_darwin.sh
- name: Build
run: |
cmake --preset macos-${{matrix.config.arch}}
cmake --build --preset macos-${{matrix.config.arch}}-release
- name: Test
run: |
ctest --preset macos-${{matrix.config.arch}}-release

View File

@@ -11,21 +11,21 @@ jobs:
config:
# https://github.com/actions/virtual-environments/tree/main/images/linux
- { os: "ubuntu-20.04", cc: "gcc-7", cxx: "g++-7" }
- { os: "ubuntu-20.04", cc: "gcc-8", cxx: "g++-8" }
- { os: "ubuntu-20.04", cc: "gcc-9", cxx: "g++-9" }
- { os: "ubuntu-20.04", cc: "gcc-10", cxx: "g++-10" }
- { os: "ubuntu-20.04", cc: "clang-7", cxx: "clang++-7" }
- { os: "ubuntu-20.04", cc: "clang-8", cxx: "clang++-8" }
- { os: "ubuntu-20.04", cc: "clang-9", cxx: "clang++-9" }
- { os: "ubuntu-20.04", cc: "clang-10", cxx: "clang++-10" }
- { os: "ubuntu-22.04", cc: "gcc-12", cxx: "g++-12" }
- { os: "ubuntu-22.04", cc: "clang-14", cxx: "clang++-14" }
name: "${{matrix.config.cxx}}"
steps:
- name: Setup
run: sudo apt-get -y install "${{matrix.config.cc}}" "${{matrix.config.cxx}}"
run: sudo apt-get -y install cmake ninja-build ${{matrix.config.cc}} ${{matrix.config.cxx}}
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: recursive
- name: Build && Test
run: .ci/build_linux.sh
env: { CC: "${{matrix.config.cc}}", CXX: "${{matrix.config.cxx}}" }
submodules: true
- name: Build
run: |
cmake --preset linux-${{matrix.config.cc}}
cmake --build --preset linux-${{matrix.config.cc}}-release
- name: Test
run: |
ctest --preset linux-${{matrix.config.cc}}-release

View File

@@ -10,14 +10,24 @@ jobs:
matrix:
config:
# https://github.com/actions/virtual-environments/tree/main/images/win
- { os: "windows-2016", vs: "Visual Studio 2017", arch: "x86" }
- { os: "windows-2016", vs: "Visual Studio 2017", arch: "x64" }
- { os: "windows-2019", vs: "Visual Studio 2019", arch: "x86" }
- { os: "windows-2019", vs: "Visual Studio 2019", arch: "x64" }
name: "${{matrix.config.vs}} ${{matrix.config.arch}}"
- { os: "windows-2019", vc: "msvc2019", arch: "x86" }
- { os: "windows-2019", vc: "msvc2019", arch: "x64" }
- { os: "windows-2022", vc: "msvc2022", arch: "x86" }
- { os: "windows-2022", vc: "msvc2022", arch: "x64" }
name: "${{matrix.config.vc}} ${{matrix.config.arch}}"
steps:
- uses: actions/checkout@v2
- name: Setup
run: choco install cmake ninja
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Build && Test
run: .ci\build_windows_${{matrix.config.arch}}.bat
submodules: true
- name: Select MSVC
uses: ilammy/msvc-dev-cmd@v1
- name: Build
run: |
cmake --preset windows-${{matrix.config.arch}}-${{matrix.config.vc}}
cmake --build --preset windows-${{matrix.config.arch}}-${{matrix.config.vc}}-release
- name: Test
run: |
ctest --preset windows-${{matrix.config.arch}}-${{matrix.config.vc}}-release

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
build/*
.vscode/*
install/*
.clangd/*
CMakeLists.txt.user

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "vendors/doctest"]
path = vendors/doctest
url = https://github.com/doctest/doctest/

11
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [{
"name": "LLDB Debug",
"type": "lldb",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": [],
"cwd": "${workspaceFolder}"
}]
}

29
.vscode/settings.json vendored Normal file
View File

@@ -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"
}

View File

@@ -1,31 +1,95 @@
# 3.8 version is required for `cxx_std_17`
cmake_minimum_required(VERSION 3.8 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(ecs.hpp
VERSION "0.0.1"
DESCRIPTION "C++17 Entity Component System"
HOMEPAGE_URL "https://github.com/blackmatov/ecs.hpp")
project(ecs.hpp)
#
# LIBRARY
#
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE headers)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
add_library(ecs.hpp::ecs.hpp ALIAS ${PROJECT_NAME})
target_compile_options(${PROJECT_NAME}
INTERFACE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
-Wno-c++98-compat-pedantic
-Wno-padded
-Wno-shadow
-Wno-unknown-warning-option
-Wno-weak-vtables>)
target_compile_features(${PROJECT_NAME} INTERFACE
cxx_std_17)
if(BUILD_AS_STANDALONE)
option(BUILD_WITH_UNTESTS "Build with unit tests" ON)
if(BUILD_WITH_UNTESTS)
enable_testing()
add_subdirectory(untests)
endif()
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/headers>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
#
# INSTALL
#
if(PROJECT_IS_TOP_LEVEL)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
set(ECS_HPP_INSTALL_CONFIG_DIR
"${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
set(ECS_HPP_INSTALL_CONFIG_INPUT
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in")
set(ECS_HPP_INSTALL_GENERATED_CONFIG_CMAKE
"${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}-config.cmake")
set(ECS_HPP_INSTALL_GENERATED_CONFIG_VERSION_CMAKE
"${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}-config-version.cmake")
configure_package_config_file(
"${ECS_HPP_INSTALL_CONFIG_INPUT}"
"${ECS_HPP_INSTALL_GENERATED_CONFIG_CMAKE}"
INSTALL_DESTINATION "${ECS_HPP_INSTALL_CONFIG_DIR}"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
write_basic_package_version_file(
"${ECS_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 "${ECS_HPP_INSTALL_CONFIG_DIR}")
install(
FILES "${ECS_HPP_INSTALL_GENERATED_CONFIG_CMAKE}"
"${ECS_HPP_INSTALL_GENERATED_CONFIG_VERSION_CMAKE}"
DESTINATION "${ECS_HPP_INSTALL_CONFIG_DIR}")
endif()
#
# DEVELOPER
#
if(PROJECT_IS_TOP_LEVEL)
option(BUILD_WITH_COVERAGE "Build with coverage" OFF)
option(BUILD_WITH_SANITIZERS "Build with sanitizers" OFF)
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")
include(EnableASan)
include(EnableGCov)
include(EnableUBSan)
add_subdirectory(vendors)
add_subdirectory(untests)
endif()

342
CMakePresets.json Normal file
View File

@@ -0,0 +1,342 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 0
},
"configurePresets": [
{
"name": "ninja-base",
"hidden": true,
"generator": "Ninja Multi-Config",
"binaryDir": "${sourceDir}/build/${presetName}",
"installDir": "${sourceDir}/install/${presetName}",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": true
}
},
{
"name": "linux-base",
"hidden": true,
"inherits": "ninja-base",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
}
},
{
"name": "linux-clang-7",
"inherits": "linux-base",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang-7",
"CMAKE_CXX_COMPILER": "clang++-7"
}
},
{
"name": "linux-clang-14",
"inherits": "linux-base",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang-14",
"CMAKE_CXX_COMPILER": "clang++-14"
}
},
{
"name": "linux-gcc-7",
"inherits": "linux-base",
"cacheVariables": {
"CMAKE_C_COMPILER": "gcc-7",
"CMAKE_CXX_COMPILER": "g++-7"
}
},
{
"name": "linux-gcc-12",
"inherits": "linux-base",
"cacheVariables": {
"CMAKE_C_COMPILER": "gcc-12",
"CMAKE_CXX_COMPILER": "g++-12"
}
},
{
"name": "macos-base",
"hidden": true,
"inherits": "ninja-base",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
}
},
{
"name": "macos-arm64",
"inherits": "macos-base",
"architecture": {
"value": "arm64",
"strategy": "external"
}
},
{
"name": "macos-arm64-san",
"inherits": "macos-arm64",
"cacheVariables": {
"BUILD_WITH_SANITIZERS": true
}
},
{
"name": "macos-x64",
"inherits": "macos-base",
"architecture": {
"value": "x64",
"strategy": "external"
}
},
{
"name": "macos-x64-san",
"inherits": "macos-x64",
"cacheVariables": {
"BUILD_WITH_SANITIZERS": true
}
},
{
"name": "windows-base",
"hidden": true,
"inherits": "ninja-base",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "windows-x86-msvc2019",
"inherits": "windows-base",
"architecture": {
"value": "x86",
"strategy": "external"
},
"toolset": {
"value": "v142,host=x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl"
}
},
{
"name": "windows-x64-msvc2019",
"inherits": "windows-base",
"architecture": {
"value": "x64",
"strategy": "external"
},
"toolset": {
"value": "v142,host=x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl"
}
},
{
"name": "windows-x86-msvc2022",
"inherits": "windows-base",
"architecture": {
"value": "x86",
"strategy": "external"
},
"toolset": {
"value": "v143,host=x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl"
}
},
{
"name": "windows-x64-msvc2022",
"inherits": "windows-base",
"architecture": {
"value": "x64",
"strategy": "external"
},
"toolset": {
"value": "v143,host=x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl"
}
}
],
"buildPresets": [
{
"name": "linux-clang-7-debug",
"configuration": "Debug",
"configurePreset": "linux-clang-7"
},
{
"name": "linux-clang-7-release",
"configuration": "Release",
"configurePreset": "linux-clang-7"
},
{
"name": "linux-clang-14-debug",
"configuration": "Debug",
"configurePreset": "linux-clang-14"
},
{
"name": "linux-clang-14-release",
"configuration": "Release",
"configurePreset": "linux-clang-14"
},
{
"name": "linux-gcc-7-debug",
"configuration": "Debug",
"configurePreset": "linux-gcc-7"
},
{
"name": "linux-gcc-7-release",
"configuration": "Release",
"configurePreset": "linux-gcc-7"
},
{
"name": "linux-gcc-12-debug",
"configuration": "Debug",
"configurePreset": "linux-gcc-12"
},
{
"name": "linux-gcc-12-release",
"configuration": "Release",
"configurePreset": "linux-gcc-12"
},
{
"name": "macos-arm64-debug",
"configuration": "Debug",
"configurePreset": "macos-arm64-san"
},
{
"name": "macos-arm64-release",
"configuration": "Release",
"configurePreset": "macos-arm64"
},
{
"name": "macos-x64-debug",
"configuration": "Debug",
"configurePreset": "macos-x64-san"
},
{
"name": "macos-x64-release",
"configuration": "Release",
"configurePreset": "macos-x64"
},
{
"name": "windows-x86-msvc2019-debug",
"configuration": "Debug",
"configurePreset": "windows-x86-msvc2019"
},
{
"name": "windows-x86-msvc2019-release",
"configuration": "Release",
"configurePreset": "windows-x86-msvc2019"
},
{
"name": "windows-x64-msvc2019-debug",
"configuration": "Debug",
"configurePreset": "windows-x64-msvc2019"
},
{
"name": "windows-x64-msvc2019-release",
"configuration": "Release",
"configurePreset": "windows-x64-msvc2019"
},
{
"name": "windows-x86-msvc2022-debug",
"configuration": "Debug",
"configurePreset": "windows-x86-msvc2022"
},
{
"name": "windows-x86-msvc2022-release",
"configuration": "Release",
"configurePreset": "windows-x86-msvc2022"
},
{
"name": "windows-x64-msvc2022-debug",
"configuration": "Debug",
"configurePreset": "windows-x64-msvc2022"
},
{
"name": "windows-x64-msvc2022-release",
"configuration": "Release",
"configurePreset": "windows-x64-msvc2022"
}
],
"testPresets": [
{
"name": "test-base",
"hidden": true,
"output": {
"verbosity": "verbose"
},
"configuration": "Release"
},
{
"name": "linux-clang-7-release",
"inherits": "test-base",
"configurePreset": "linux-clang-7"
},
{
"name": "linux-clang-14-release",
"inherits": "test-base",
"configurePreset": "linux-clang-14"
},
{
"name": "linux-gcc-7-release",
"inherits": "test-base",
"configurePreset": "linux-gcc-7"
},
{
"name": "linux-gcc-12-release",
"inherits": "test-base",
"configurePreset": "linux-gcc-12"
},
{
"name": "macos-arm64-release",
"inherits": "test-base",
"configurePreset": "macos-arm64"
},
{
"name": "macos-x64-release",
"inherits": "test-base",
"configurePreset": "macos-x64"
},
{
"name": "windows-x86-msvc2019-release",
"inherits": "test-base",
"configurePreset": "windows-x86-msvc2019"
},
{
"name": "windows-x64-msvc2019-release",
"inherits": "test-base",
"configurePreset": "windows-x64-msvc2019"
},
{
"name": "windows-x86-msvc2022-release",
"inherits": "test-base",
"configurePreset": "windows-x86-msvc2022"
},
{
"name": "windows-x64-msvc2022-release",
"inherits": "test-base",
"configurePreset": "windows-x64-msvc2022"
}
]
}

View File

@@ -5,21 +5,18 @@
[![linux][badge.linux]][linux]
[![darwin][badge.darwin]][darwin]
[![windows][badge.windows]][windows]
[![codecov][badge.codecov]][codecov]
[![language][badge.language]][language]
[![license][badge.license]][license]
[badge.darwin]: https://img.shields.io/github/workflow/status/BlackMATov/ecs.hpp/darwin/main?label=Xcode&logo=xcode
[badge.linux]: https://img.shields.io/github/workflow/status/BlackMATov/ecs.hpp/linux/main?label=GCC%2FClang&logo=linux
[badge.windows]: https://img.shields.io/github/workflow/status/BlackMATov/ecs.hpp/windows/main?label=Visual%20Studio&logo=visual-studio
[badge.codecov]: https://img.shields.io/codecov/c/github/BlackMATov/ecs.hpp/main?logo=codecov
[badge.darwin]: https://img.shields.io/github/actions/workflow/status/BlackMATov/ecs.hpp/.github/workflows/darwin.yml?label=Xcode&logo=xcode
[badge.linux]: https://img.shields.io/github/actions/workflow/status/BlackMATov/ecs.hpp/.github/workflows/linux.yml?label=GCC%2FClang&logo=linux
[badge.windows]: https://img.shields.io/github/actions/workflow/status/BlackMATov/ecs.hpp/.github/workflows/windows.yml?label=Visual%20Studio&logo=visual-studio
[badge.language]: https://img.shields.io/badge/language-C%2B%2B17-yellow
[badge.license]: https://img.shields.io/badge/license-MIT-blue
[darwin]: https://github.com/BlackMATov/ecs.hpp/actions?query=workflow%3Adarwin
[linux]: https://github.com/BlackMATov/ecs.hpp/actions?query=workflow%3Alinux
[windows]: https://github.com/BlackMATov/ecs.hpp/actions?query=workflow%3Awindows
[codecov]: https://codecov.io/gh/BlackMATov/ecs.hpp
[language]: https://en.wikipedia.org/wiki/C%2B%2B17
[license]: https://en.wikipedia.org/wiki/MIT_License
@@ -27,9 +24,10 @@
## Requirements
- [gcc](https://www.gnu.org/software/gcc/) **>= 7**
- [clang](https://clang.llvm.org/) **>= 7**
- [msvc](https://visualstudio.microsoft.com/) **>= 2017**
- [gcc](https://www.gnu.org/software/gcc/) **>= 7**
- [msvc](https://visualstudio.microsoft.com/) **>= 2019**
- [xcode](https://developer.apple.com/xcode/) **>= 10.3**
## Installation
@@ -43,7 +41,7 @@ Also, you can add the root repository directory to your [cmake](https://cmake.or
```cmake
add_subdirectory(external/ecs.hpp)
target_link_libraries(your_project_target ecs.hpp)
target_link_libraries(your_project_target PUBLIC ecs.hpp::ecs.hpp)
```
## Basic usage

3
cmake/Config.cmake.in Normal file
View File

@@ -0,0 +1,3 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/ecs.hpp-targets.cmake")

16
cmake/EnableASan.cmake Normal file
View File

@@ -0,0 +1,16 @@
# https://clang.llvm.org/docs/AddressSanitizer.html
add_library(${PROJECT_NAME}.enable_asan INTERFACE)
add_library(${PROJECT_NAME}::enable_asan ALIAS ${PROJECT_NAME}.enable_asan)
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(${PROJECT_NAME}.enable_asan INTERFACE
-fsanitize=address
-fno-omit-frame-pointer
-fsanitize-address-use-after-scope
-fsanitize-address-use-after-return=always)

10
cmake/EnableGCov.cmake Normal file
View File

@@ -0,0 +1,10 @@
# https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
add_library(${PROJECT_NAME}.enable_gcov INTERFACE)
add_library(${PROJECT_NAME}::enable_gcov ALIAS ${PROJECT_NAME}.enable_gcov)
target_compile_options(${PROJECT_NAME}.enable_gcov INTERFACE
--coverage)
target_link_options(${PROJECT_NAME}.enable_gcov INTERFACE
--coverage)

12
cmake/EnableUBSan.cmake Normal file
View File

@@ -0,0 +1,12 @@
# https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
add_library(${PROJECT_NAME}.enable_ubsan INTERFACE)
add_library(${PROJECT_NAME}::enable_ubsan ALIAS ${PROJECT_NAME}.enable_ubsan)
target_compile_options(${PROJECT_NAME}.enable_ubsan INTERFACE
-fsanitize=undefined
-fno-omit-frame-pointer)
target_link_options(${PROJECT_NAME}.enable_ubsan INTERFACE
-fsanitize=undefined
-fno-omit-frame-pointer)

View File

@@ -2422,11 +2422,11 @@ namespace ecs_hpp
feature& feature::process_event(registry& owner, const Event& event) {
detail::incremental_lock_guard lock(systems_locker_);
const auto fire_event = [this, &owner](const auto& event){
const auto fire_event = [this, &owner](const auto& wrapped_event){
for ( const auto& base_system : systems_ ) {
using system_type = system<std::decay_t<decltype(event)>>;
using system_type = system<std::decay_t<decltype(wrapped_event)>>;
if ( auto event_system = dynamic_cast<system_type*>(base_system.get()) ) {
event_system->process(owner, event);
event_system->process(owner, wrapped_event);
}
}
};

View File

@@ -1,34 +1,68 @@
project(ecs.hpp.untests)
#
# coverage
#
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()
#
# executable
#
file(GLOB_RECURSE UNTESTS_SOURCES "*.cpp" "*.hpp")
add_executable(${PROJECT_NAME} ${UNTESTS_SOURCES})
target_link_libraries(${PROJECT_NAME} ecs.hpp)
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${UNTESTS_SOURCES})
target_compile_options(${PROJECT_NAME}
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:
/WX /W4>
PRIVATE
$<$<CXX_COMPILER_ID:GNU>:
-Werror -Wall -Wextra -Wpedantic>
PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
-Werror -Weverything -Wconversion>)
add_executable(${PROJECT_NAME} ${UNTESTS_SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE ecs.hpp::ecs.hpp)
#
# setup defines
#
function(setup_defines_for_target TARGET)
target_compile_definitions(${TARGET} PRIVATE
DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
DOCTEST_CONFIG_USE_STD_HEADERS)
endfunction()
setup_defines_for_target(${PROJECT_NAME})
#
# setup libraries
#
function(setup_libraries_for_target TARGET)
target_link_libraries(${TARGET} PRIVATE doctest::doctest_with_main)
if(${BUILD_WITH_COVERAGE})
target_link_libraries(${TARGET} PRIVATE ecs.hpp::enable_gcov)
endif()
if(${BUILD_WITH_SANITIZERS})
target_link_libraries(${TARGET} PRIVATE ecs.hpp::enable_asan ecs.hpp::enable_ubsan)
endif()
endfunction()
setup_libraries_for_target(${PROJECT_NAME})
#
# setup warnings
#
function(setup_warnings_for_target TARGET)
target_compile_options(${TARGET}
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:
/WX /W4>
PRIVATE
$<$<CXX_COMPILER_ID:GNU>:
-Werror -Wall -Wextra -Wpedantic>
PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
-Werror -Weverything -Wconversion
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-padded
-Wno-unknown-warning-option
-Wno-weak-vtables
>)
endfunction()
setup_warnings_for_target(${PROJECT_NAME})
#
# add tests
#
add_test(${PROJECT_NAME} ${PROJECT_NAME})

View File

@@ -1,2 +0,0 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +0,0 @@
#pragma once
#include "doctest.h"
#define STATIC_REQUIRE(...)\
static_assert(__VA_ARGS__, #__VA_ARGS__);\
REQUIRE(__VA_ARGS__)
#define STATIC_REQUIRE_FALSE(...)\
static_assert(!(__VA_ARGS__), "!(" #__VA_ARGS__ ")");\
REQUIRE(!(__VA_ARGS__))

View File

@@ -33,11 +33,13 @@ namespace
static_assert(std::is_empty_v<movable_c>, "!!!");
static_assert(std::is_empty_v<disabled_c>, "!!!");
[[maybe_unused]]
bool operator==(const position_c& l, const position_c& r) noexcept {
return l.x == r.x
&& l.y == r.y;
}
[[maybe_unused]]
bool operator==(const velocity_c& l, const velocity_c& r) noexcept {
return l.x == r.x
&& l.y == r.y;
@@ -45,13 +47,13 @@ namespace
struct mult_indexer {
template < typename T >
std::size_t operator()(const T& v) const noexcept {
[[maybe_unused]] std::size_t operator()(const T& v) const noexcept {
return static_cast<std::size_t>(v * 2);
}
};
struct position_c_indexer {
std::size_t operator()(const position_c& v) const noexcept {
[[maybe_unused]] std::size_t operator()(const position_c& v) const noexcept {
return static_cast<std::size_t>(v.x);
}
};
@@ -1265,16 +1267,16 @@ TEST_CASE("registry") {
const_cast<position_c&>(p).y += v.y;
});
w.for_each_entity([](ecs::entity e){
auto& p = e.get_component<position_c>();
const auto& v = e.get_component<velocity_c>();
w.for_each_entity([](ecs::entity ne){
auto& p = ne.get_component<position_c>();
const auto& v = ne.get_component<velocity_c>();
p.x += v.x;
p.y += v.y;
}, movable::to_option());
std::as_const(w).for_each_entity([](const ecs::const_entity& e){
const auto& p = e.get_component<position_c>();
const auto& v = e.get_component<velocity_c>();
std::as_const(w).for_each_entity([](const ecs::const_entity& ne){
const auto& p = ne.get_component<position_c>();
const auto& v = ne.get_component<velocity_c>();
const_cast<position_c&>(p).x += v.x;
const_cast<position_c&>(p).y += v.y;
}, movable::to_option());
@@ -1474,6 +1476,7 @@ TEST_CASE("registry") {
class gravity_system : public ecs::system<update_evt> {
public:
[[maybe_unused]]
gravity_system(int g)
: g_(g) {}
@@ -1544,6 +1547,7 @@ TEST_CASE("registry") {
class gravity_system : public ecs::system<ecs::before<physics_evt>> {
public:
[[maybe_unused]]
gravity_system(int g)
: g_(g) {}
@@ -1607,6 +1611,7 @@ TEST_CASE("registry") {
SUBCASE("fillers") {
struct component_n {
int i = 0;
[[maybe_unused]]
component_n(int ni) : i(ni) {}
};
@@ -1614,6 +1619,7 @@ TEST_CASE("registry") {
class system_n : public ecs::system<update_evt> {
public:
[[maybe_unused]]
system_n(int n) : n_(n) {}
void process(ecs::registry& owner, const update_evt&) override {
owner.for_each_component<component_n>(

5
vendors/CMakeLists.txt vendored Normal file
View File

@@ -0,0 +1,5 @@
project(ecs.hpp.vendors)
set(DOCTEST_NO_INSTALL ON CACHE INTERNAL "")
add_subdirectory(doctest)
set_target_properties(doctest_with_main PROPERTIES FOLDER ecs.hpp.vendors)

1
vendors/doctest vendored Submodule

Submodule vendors/doctest added at b7c21ec5ce