From ed8b09e125093d6e69a91f45b8d7cd385941324a Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Mon, 27 Feb 2023 16:12:54 +0700 Subject: [PATCH] little fix build scripts --- develop/cmake/SetupTargets.cmake | 34 ++++---------- develop/singles/CMakeLists.txt | 11 +++-- .../singles/headers/vmath.hpp/vmath_all.hpp | 6 ++- develop/singles/scripts/build_singles.py | 47 ++++++++++--------- develop/untests/CMakeLists.txt | 6 ++- headers/vmath.hpp/vmath_ext.hpp | 4 +- 6 files changed, 51 insertions(+), 57 deletions(-) diff --git a/develop/cmake/SetupTargets.cmake b/develop/cmake/SetupTargets.cmake index fd5eac3..c1aa6e8 100644 --- a/develop/cmake/SetupTargets.cmake +++ b/develop/cmake/SetupTargets.cmake @@ -1,9 +1,6 @@ add_library(${PROJECT_NAME}.setup_targets INTERFACE) add_library(${PROJECT_NAME}::setup_targets ALIAS ${PROJECT_NAME}.setup_targets) -target_link_libraries(${PROJECT_NAME}.setup_targets INTERFACE - vmath.hpp.vendors::doctest) - target_compile_options(${PROJECT_NAME}.setup_targets INTERFACE $<$: /WX /W4> @@ -20,26 +17,13 @@ target_compile_options(${PROJECT_NAME}.setup_targets INTERFACE -Wno-unknown-warning-option >) -if(BUILD_WITH_COVERAGE) - target_link_libraries(${PROJECT_NAME}.setup_targets INTERFACE - vmath.hpp::enable_gcov) -endif() - -if(BUILD_WITH_SANITIZERS) - target_link_libraries(${PROJECT_NAME}.setup_targets INTERFACE +target_link_libraries(${PROJECT_NAME}.setup_targets INTERFACE + $<$: + vmath.hpp::enable_gcov> + $<$: vmath.hpp::enable_asan - vmath.hpp::enable_ubsan) -endif() - -if(BUILD_WITH_NO_EXCEPTIONS) - target_link_libraries(${PROJECT_NAME}.setup_targets INTERFACE - vmath.hpp::disable_exceptions) - - target_compile_definitions(${PROJECT_NAME}.setup_targets INTERFACE - DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS) -endif() - -if(BUILD_WITH_NO_RTTI) - target_link_libraries(${PROJECT_NAME}.setup_targets INTERFACE - vmath.hpp::disable_rtti) -endif() + vmath.hpp::enable_ubsan> + $<$: + vmath.hpp::disable_exceptions> + $<$: + vmath.hpp::disable_rtti>) diff --git a/develop/singles/CMakeLists.txt b/develop/singles/CMakeLists.txt index 930b461..ea1551e 100644 --- a/develop/singles/CMakeLists.txt +++ b/develop/singles/CMakeLists.txt @@ -13,10 +13,13 @@ set(VMATH_HPP_SINGLES_SCRIPT "${VMATH_HPP_ROOT_DIR}/develop/singles/scripts/buil file(GLOB_RECURSE VMATH_SINGLES_DEPENDS CONFIGURE_DEPENDS "${VMATH_HPP_ROOT_DIR}/headers/*.hpp") add_custom_command(OUTPUT "${VMATH_HPP_SINGLES_OUTPUT}" - COMMAND "${Python3_EXECUTABLE}" "${VMATH_HPP_SINGLES_SCRIPT}" - "${VMATH_HPP_SINGLES_INPUT}" "${VMATH_HPP_SINGLES_OUTPUT}" - DEPENDS ${VMATH_SINGLES_DEPENDS} - WORKING_DIRECTORY "${VMATH_HPP_ROOT_DIR}") + COMMAND + "${Python3_EXECUTABLE}" "${VMATH_HPP_SINGLES_SCRIPT}" + "${VMATH_HPP_SINGLES_INPUT}" "${VMATH_HPP_SINGLES_OUTPUT}" + DEPENDS + "${VMATH_HPP_SINGLES_SCRIPT}" ${VMATH_SINGLES_DEPENDS} + WORKING_DIRECTORY + "${VMATH_HPP_ROOT_DIR}") add_custom_target(${PROJECT_NAME}.generate DEPENDS "${VMATH_HPP_SINGLES_OUTPUT}") diff --git a/develop/singles/headers/vmath.hpp/vmath_all.hpp b/develop/singles/headers/vmath.hpp/vmath_all.hpp index f9265d1..8bd60a7 100644 --- a/develop/singles/headers/vmath.hpp/vmath_all.hpp +++ b/develop/singles/headers/vmath.hpp/vmath_all.hpp @@ -4,6 +4,8 @@ * Copyright (C) 2020-2023, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ +#pragma once + #include #include #include @@ -3661,12 +3663,12 @@ namespace vmath_hpp::detail } }; - template < typename T, size_t Size > + template < typename T, std::size_t Size > [[nodiscard]] std::size_t hash(const vec& v) noexcept { return fold_join(hash_combiner{}, std::size_t{}, v); } - template < typename T, size_t Size > + template < typename T, std::size_t Size > [[nodiscard]] std::size_t hash(const mat& m) noexcept { return fold_join(hash_combiner{}, std::size_t{}, m); } diff --git a/develop/singles/scripts/build_singles.py b/develop/singles/scripts/build_singles.py index b3af5f8..a4bff29 100755 --- a/develop/singles/scripts/build_singles.py +++ b/develop/singles/scripts/build_singles.py @@ -5,10 +5,6 @@ import os import re import sys -# -# -# - EMPTY_MATCHER = re.compile(r'^\s*$') C_COMMENT_MATCHER = re.compile(r'^/\*.*\*/', re.S) @@ -19,9 +15,6 @@ USER_INCLUDE_MATCHER = re.compile(r'#\s*include\s*\"(.*)\"') SYSTEM_INCLUDE_MATCHER = re.compile(r'#\s*include\s*<(.*)>') PRAGMA_ONCE_MATCHER = re.compile(r'#\s*pragma\s+once') -# -# -# def CollectLicenseComment(headerPath): with open(headerPath, "r") as headerStream: @@ -29,7 +22,8 @@ def CollectLicenseComment(headerPath): commentMatch = re.match(C_COMMENT_MATCHER, headerContent) return commentMatch.group() if commentMatch else "" -def CollectSystemIncludes(headerPath, parsedHeaders = set()): + +def CollectSystemIncludes(headerPath, parsedHeaders=set()): with open(headerPath, "r") as headerStream: headerContent = headerStream.read().strip() @@ -50,8 +44,10 @@ def CollectSystemIncludes(headerPath, parsedHeaders = set()): includeMatch = USER_INCLUDE_MATCHER.findall(headerLine) if includeMatch and ifdefScopeLevel == 0: - internalHeaderPath = os.path.abspath(os.path.join(os.path.dirname(headerPath), includeMatch[0])) - headerIncludes = headerIncludes.union(CollectSystemIncludes(internalHeaderPath, parsedHeaders)) + internalHeaderPath = os.path.abspath(os.path.join( + os.path.dirname(headerPath), includeMatch[0])) + headerIncludes = headerIncludes.union( + CollectSystemIncludes(internalHeaderPath, parsedHeaders)) includeMatch = SYSTEM_INCLUDE_MATCHER.findall(headerLine) if includeMatch and ifdefScopeLevel == 0: @@ -59,7 +55,8 @@ def CollectSystemIncludes(headerPath, parsedHeaders = set()): return headerIncludes -def ParseHeader(headerPath, parsedHeaders = set()): + +def ParseHeader(headerPath, parsedHeaders=set()): with open(headerPath, "r") as headerStream: headerContent = headerStream.read().strip() headerContent = re.sub(C_COMMENT_MATCHER, '', headerContent) @@ -89,8 +86,10 @@ def ParseHeader(headerPath, parsedHeaders = set()): includeMatch = USER_INCLUDE_MATCHER.findall(headerLine) if includeMatch and ifdefScopeLevel == 0: - internalHeaderPath = os.path.abspath(os.path.join(os.path.dirname(headerPath), includeMatch[0])) - internalHeaderContent = ParseHeader(internalHeaderPath, parsedHeaders) + internalHeaderPath = os.path.abspath(os.path.join( + os.path.dirname(headerPath), includeMatch[0])) + internalHeaderContent = ParseHeader( + internalHeaderPath, parsedHeaders) outputContent += internalHeaderContent shouldSkipNextEmptyLines = True @@ -106,9 +105,6 @@ def ParseHeader(headerPath, parsedHeaders = set()): return "{}\n".format(outputContent) -# -# -# inputHeaderPath = os.path.abspath(sys.argv[1]) outputHeaderPath = os.path.abspath(sys.argv[2]) @@ -118,13 +114,20 @@ os.makedirs(os.path.dirname(outputHeaderPath), exist_ok=True) with open(outputHeaderPath, "w") as outputHeaderStream: licenseComment = CollectLicenseComment(inputHeaderPath) systemIncludes = CollectSystemIncludes(inputHeaderPath) + headersContent = ParseHeader(inputHeaderPath) - outputHeaderStream.write("{}\n".format(licenseComment)) + if licenseComment: + outputHeaderStream.write("{}\n".format(licenseComment)) + outputHeaderStream.write("\n") + + outputHeaderStream.write("#pragma once\n") outputHeaderStream.write("\n") - for systemInclude in sorted(systemIncludes): - outputHeaderStream.write("#include <{}>\n".format(systemInclude)) - outputHeaderStream.write("\n") + if systemIncludes: + for systemInclude in sorted(systemIncludes): + outputHeaderStream.write("#include <{}>\n".format(systemInclude)) + outputHeaderStream.write("\n") - outputHeaderStream.write(ParseHeader(inputHeaderPath).strip()) - outputHeaderStream.write("\n") + if headersContent: + outputHeaderStream.write(headersContent.strip()) + outputHeaderStream.write("\n") diff --git a/develop/untests/CMakeLists.txt b/develop/untests/CMakeLists.txt index af6f006..1cb65c8 100644 --- a/develop/untests/CMakeLists.txt +++ b/develop/untests/CMakeLists.txt @@ -8,11 +8,13 @@ add_executable(${PROJECT_NAME}.singles ${UNTESTS_SOURCES}) target_link_libraries(${PROJECT_NAME} PRIVATE vmath.hpp::vmath.hpp - vmath.hpp::setup_targets) + vmath.hpp::setup_targets + vmath.hpp.vendors::doctest) target_link_libraries(${PROJECT_NAME}.singles PRIVATE vmath.hpp::singles - vmath.hpp::setup_targets) + vmath.hpp::setup_targets + vmath.hpp.vendors::doctest) add_test(${PROJECT_NAME} ${PROJECT_NAME}) add_test(${PROJECT_NAME} ${PROJECT_NAME}.singles) diff --git a/headers/vmath.hpp/vmath_ext.hpp b/headers/vmath.hpp/vmath_ext.hpp index f85e8a1..6a41393 100644 --- a/headers/vmath.hpp/vmath_ext.hpp +++ b/headers/vmath.hpp/vmath_ext.hpp @@ -68,12 +68,12 @@ namespace vmath_hpp::detail } }; - template < typename T, size_t Size > + template < typename T, std::size_t Size > [[nodiscard]] std::size_t hash(const vec& v) noexcept { return fold_join(hash_combiner{}, std::size_t{}, v); } - template < typename T, size_t Size > + template < typename T, std::size_t Size > [[nodiscard]] std::size_t hash(const mat& m) noexcept { return fold_join(hash_combiner{}, std::size_t{}, m); }