mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-16 14:11:28 +07:00
return single-header version
This commit is contained in:
112
.ci/build_singles.py
Executable file
112
.ci/build_singles.py
Executable file
@@ -0,0 +1,112 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
EMPTY_MATCHER = re.compile(r'^\s*$')
|
||||||
|
C_COMMENT_MATCHER = re.compile(r'^/\*.*\*/', re.S)
|
||||||
|
|
||||||
|
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:
|
||||||
|
headerContent = headerStream.read().strip()
|
||||||
|
if result := re.match(C_COMMENT_MATCHER, headerContent):
|
||||||
|
return result.group()
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def CollectSystemIncludes(headerPath, parsedHeaders = set()):
|
||||||
|
with open(headerPath, "r") as headerStream:
|
||||||
|
headerContent = headerStream.read().strip()
|
||||||
|
|
||||||
|
if PRAGMA_ONCE_MATCHER.search(headerContent) and headerPath in parsedHeaders:
|
||||||
|
return set()
|
||||||
|
|
||||||
|
headerIncludes = set()
|
||||||
|
|
||||||
|
parsedHeaders.add(headerPath)
|
||||||
|
headerLines = headerContent.split('\n')
|
||||||
|
|
||||||
|
for headerLine in headerLines:
|
||||||
|
if result := USER_INCLUDE_MATCHER.findall(headerLine):
|
||||||
|
internalHeaderPath = os.path.abspath(os.path.join(os.path.dirname(headerPath), result[0]))
|
||||||
|
headerIncludes = headerIncludes.union(CollectSystemIncludes(internalHeaderPath, parsedHeaders))
|
||||||
|
if result := SYSTEM_INCLUDE_MATCHER.findall(headerLine):
|
||||||
|
headerIncludes.add(result[0])
|
||||||
|
|
||||||
|
return headerIncludes
|
||||||
|
|
||||||
|
def ParseHeader(headerPath, parsedHeaders = set()):
|
||||||
|
with open(headerPath, "r") as headerStream:
|
||||||
|
headerContent = headerStream.read().strip()
|
||||||
|
headerContent = re.sub(C_COMMENT_MATCHER, '', headerContent)
|
||||||
|
|
||||||
|
if PRAGMA_ONCE_MATCHER.search(headerContent) and headerPath in parsedHeaders:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
parsedHeaders.add(headerPath)
|
||||||
|
headerLines = headerContent.split('\n')
|
||||||
|
|
||||||
|
outputContent = ""
|
||||||
|
shouldSkipNextEmptyLines = True
|
||||||
|
|
||||||
|
for headerLine in headerLines:
|
||||||
|
if EMPTY_MATCHER.match(headerLine) and shouldSkipNextEmptyLines:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if PRAGMA_ONCE_MATCHER.match(headerLine):
|
||||||
|
shouldSkipNextEmptyLines = True
|
||||||
|
continue
|
||||||
|
|
||||||
|
if result := USER_INCLUDE_MATCHER.findall(headerLine):
|
||||||
|
internalHeaderPath = os.path.abspath(os.path.join(os.path.dirname(headerPath), result[0]))
|
||||||
|
internalHeaderContent = ParseHeader(internalHeaderPath, parsedHeaders)
|
||||||
|
|
||||||
|
outputContent += internalHeaderContent
|
||||||
|
shouldSkipNextEmptyLines = True
|
||||||
|
continue
|
||||||
|
|
||||||
|
if result := SYSTEM_INCLUDE_MATCHER.findall(headerLine):
|
||||||
|
shouldSkipNextEmptyLines = True
|
||||||
|
continue
|
||||||
|
|
||||||
|
shouldSkipNextEmptyLines = False
|
||||||
|
outputContent += "{}\n".format(headerLine)
|
||||||
|
|
||||||
|
return "{}\n".format(outputContent)
|
||||||
|
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
inputHeaderPath = os.path.abspath(sys.argv[1])
|
||||||
|
outputHeaderPath = os.path.abspath(sys.argv[2])
|
||||||
|
|
||||||
|
os.makedirs(os.path.dirname(outputHeaderPath), exist_ok=True)
|
||||||
|
|
||||||
|
with open(outputHeaderPath, "w") as outputHeaderStream:
|
||||||
|
licenseComment = CollectLicenseComment(inputHeaderPath)
|
||||||
|
systemIncludes = CollectSystemIncludes(inputHeaderPath)
|
||||||
|
|
||||||
|
outputHeaderStream.write("{}\n".format(licenseComment))
|
||||||
|
outputHeaderStream.write("\n")
|
||||||
|
|
||||||
|
for systemInclude in sorted(systemIncludes):
|
||||||
|
outputHeaderStream.write("#include <{}>\n".format(systemInclude))
|
||||||
|
outputHeaderStream.write("\n")
|
||||||
|
|
||||||
|
outputHeaderStream.write(ParseHeader(inputHeaderPath).strip())
|
||||||
|
outputHeaderStream.write("\n")
|
||||||
@@ -13,15 +13,9 @@ add_library(${PROJECT_NAME} INTERFACE)
|
|||||||
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
|
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
|
||||||
target_include_directories(${PROJECT_NAME} INTERFACE headers)
|
target_include_directories(${PROJECT_NAME} INTERFACE headers)
|
||||||
|
|
||||||
target_compile_options(${PROJECT_NAME}
|
add_library(${PROJECT_NAME}.singles INTERFACE)
|
||||||
INTERFACE
|
target_compile_features(${PROJECT_NAME}.singles INTERFACE cxx_std_17)
|
||||||
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
|
target_include_directories(${PROJECT_NAME}.singles INTERFACE singles)
|
||||||
-Wno-c++98-compat-pedantic
|
|
||||||
-Wno-ctad-maybe-unsupported
|
|
||||||
-Wno-double-promotion
|
|
||||||
-Wno-float-equal
|
|
||||||
-Wno-shadow
|
|
||||||
-Wno-unknown-warning-option>)
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# BUILD_AS_STANDALONE
|
# BUILD_AS_STANDALONE
|
||||||
@@ -43,5 +37,6 @@ include(EnableASan)
|
|||||||
include(EnableGCov)
|
include(EnableGCov)
|
||||||
include(EnableUBSan)
|
include(EnableUBSan)
|
||||||
|
|
||||||
|
add_subdirectory(singles)
|
||||||
add_subdirectory(vendors)
|
add_subdirectory(vendors)
|
||||||
add_subdirectory(untests)
|
add_subdirectory(untests)
|
||||||
|
|||||||
17
singles/CMakeLists.txt
Normal file
17
singles/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
project(vmath.hpp.singles)
|
||||||
|
|
||||||
|
find_package(PythonInterp REQUIRED)
|
||||||
|
|
||||||
|
set(VMATH_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||||
|
set(VMATH_SINGLES_BUILD_SCRIPT "${VMATH_ROOT_DIR}/.ci/build_singles.py")
|
||||||
|
set(VMATH_SINGLES_INPUT_HEADER "${VMATH_ROOT_DIR}/headers/vmath.hpp/vmath.hpp")
|
||||||
|
set(VMATH_SINGLES_OUTPUT_HEADER "${VMATH_ROOT_DIR}/singles/vmath.hpp/vmath.hpp")
|
||||||
|
|
||||||
|
add_custom_command(OUTPUT ${VMATH_SINGLES_OUTPUT_HEADER}
|
||||||
|
COMMAND "${PYTHON_EXECUTABLE}"
|
||||||
|
"${VMATH_SINGLES_BUILD_SCRIPT}"
|
||||||
|
"${VMATH_SINGLES_INPUT_HEADER}"
|
||||||
|
"${VMATH_SINGLES_OUTPUT_HEADER}")
|
||||||
|
|
||||||
|
add_custom_target(vmath.hpp.singles.generate
|
||||||
|
DEPENDS "${VMATH_SINGLES_OUTPUT_HEADER}")
|
||||||
4556
singles/vmath.hpp/vmath.hpp
Normal file
4556
singles/vmath.hpp/vmath.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,26 +1,40 @@
|
|||||||
project(vmath.hpp.untests)
|
project(vmath.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")
|
file(GLOB_RECURSE UNTESTS_SOURCES "*.cpp" "*.hpp")
|
||||||
add_executable(${PROJECT_NAME} ${UNTESTS_SOURCES})
|
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${UNTESTS_SOURCES})
|
||||||
target_link_libraries(${PROJECT_NAME} vmath.hpp doctest_with_main)
|
|
||||||
|
|
||||||
target_compile_options(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME} ${UNTESTS_SOURCES})
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE vmath.hpp)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME}.singles ${UNTESTS_SOURCES})
|
||||||
|
add_dependencies(${PROJECT_NAME}.singles vmath.hpp.singles.generate)
|
||||||
|
target_link_libraries(${PROJECT_NAME}.singles PRIVATE vmath.hpp.singles)
|
||||||
|
|
||||||
|
#
|
||||||
|
# setup libraries
|
||||||
|
#
|
||||||
|
|
||||||
|
function(setup_libraries_for_target TARGET)
|
||||||
|
target_link_libraries(${TARGET} PRIVATE doctest_with_main)
|
||||||
|
|
||||||
|
if(${BUILD_WITH_COVERAGE})
|
||||||
|
target_link_libraries(${TARGET} PRIVATE enable_gcov)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(${BUILD_WITH_SANITIZERS})
|
||||||
|
target_link_libraries(${TARGET} PRIVATE enable_asan enable_ubsan)
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
setup_libraries_for_target(${PROJECT_NAME})
|
||||||
|
setup_libraries_for_target(${PROJECT_NAME}.singles)
|
||||||
|
|
||||||
|
#
|
||||||
|
# setup warnings
|
||||||
|
#
|
||||||
|
|
||||||
|
function(setup_warnings_for_target TARGET)
|
||||||
|
target_compile_options(${TARGET}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
$<$<CXX_COMPILER_ID:MSVC>:
|
$<$<CXX_COMPILER_ID:MSVC>:
|
||||||
/WX /W4>
|
/WX /W4>
|
||||||
@@ -29,6 +43,23 @@ target_compile_options(${PROJECT_NAME}
|
|||||||
-Werror -Wall -Wextra -Wpedantic>
|
-Werror -Wall -Wextra -Wpedantic>
|
||||||
PRIVATE
|
PRIVATE
|
||||||
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
|
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
|
||||||
-Werror -Weverything -Wconversion>)
|
-Werror -Weverything -Wconversion
|
||||||
|
-Wno-c++98-compat
|
||||||
|
-Wno-c++98-compat-pedantic
|
||||||
|
-Wno-ctad-maybe-unsupported
|
||||||
|
-Wno-double-promotion
|
||||||
|
-Wno-float-equal
|
||||||
|
-Wno-shadow-field-in-constructor
|
||||||
|
-Wno-unknown-warning-option
|
||||||
|
>)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
setup_warnings_for_target(${PROJECT_NAME})
|
||||||
|
setup_warnings_for_target(${PROJECT_NAME}.singles)
|
||||||
|
|
||||||
|
#
|
||||||
|
# add tests
|
||||||
|
#
|
||||||
|
|
||||||
add_test(${PROJECT_NAME} ${PROJECT_NAME})
|
add_test(${PROJECT_NAME} ${PROJECT_NAME})
|
||||||
|
add_test(${PROJECT_NAME} ${PROJECT_NAME}.singles)
|
||||||
|
|||||||
Reference in New Issue
Block a user