mirror of
https://github.com/BlackMATov/ecs.hpp.git
synced 2025-12-13 02:26:27 +07:00
new build scripts and cmake install targets
This commit is contained in:
@@ -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})
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "doctest.h"
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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__))
|
||||
@@ -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>(
|
||||
|
||||
Reference in New Issue
Block a user