From e624cf1488559866eebefcb32198c6570d3793a8 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 21 Sep 2022 17:01:24 +0700 Subject: [PATCH] fix singles generation --- .ci/build_singles.py | 24 +++++++++-------- CMakeLists.txt | 4 --- singles/CMakeLists.txt | 32 ++++++++++++++++------- singles/{ => headers}/vmath.hpp/vmath.hpp | 0 untests/CMakeLists.txt | 1 - 5 files changed, 35 insertions(+), 26 deletions(-) rename singles/{ => headers}/vmath.hpp/vmath.hpp (100%) diff --git a/.ci/build_singles.py b/.ci/build_singles.py index 93ab292..e37d34a 100755 --- a/.ci/build_singles.py +++ b/.ci/build_singles.py @@ -23,10 +23,8 @@ 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 "" + commentMatch = re.match(C_COMMENT_MATCHER, headerContent) + return commentMatch.group() if commentMatch else "" def CollectSystemIncludes(headerPath, parsedHeaders = set()): with open(headerPath, "r") as headerStream: @@ -41,11 +39,13 @@ def CollectSystemIncludes(headerPath, parsedHeaders = set()): 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])) + includeMatch = USER_INCLUDE_MATCHER.findall(headerLine) + if includeMatch: + internalHeaderPath = os.path.abspath(os.path.join(os.path.dirname(headerPath), includeMatch[0])) headerIncludes = headerIncludes.union(CollectSystemIncludes(internalHeaderPath, parsedHeaders)) - if result := SYSTEM_INCLUDE_MATCHER.findall(headerLine): - headerIncludes.add(result[0]) + includeMatch = SYSTEM_INCLUDE_MATCHER.findall(headerLine) + if includeMatch: + headerIncludes.add(includeMatch[0]) return headerIncludes @@ -71,15 +71,17 @@ def ParseHeader(headerPath, parsedHeaders = set()): shouldSkipNextEmptyLines = True continue - if result := USER_INCLUDE_MATCHER.findall(headerLine): - internalHeaderPath = os.path.abspath(os.path.join(os.path.dirname(headerPath), result[0])) + includeMatch = USER_INCLUDE_MATCHER.findall(headerLine) + if includeMatch: + internalHeaderPath = os.path.abspath(os.path.join(os.path.dirname(headerPath), includeMatch[0])) internalHeaderContent = ParseHeader(internalHeaderPath, parsedHeaders) outputContent += internalHeaderContent shouldSkipNextEmptyLines = True continue - if result := SYSTEM_INCLUDE_MATCHER.findall(headerLine): + includeMatch = SYSTEM_INCLUDE_MATCHER.findall(headerLine) + if includeMatch: shouldSkipNextEmptyLines = True continue diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a325e6..3e3827e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,10 +13,6 @@ add_library(${PROJECT_NAME} INTERFACE) target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17) target_include_directories(${PROJECT_NAME} INTERFACE headers) -add_library(${PROJECT_NAME}.singles INTERFACE) -target_compile_features(${PROJECT_NAME}.singles INTERFACE cxx_std_17) -target_include_directories(${PROJECT_NAME}.singles INTERFACE singles) - # # BUILD_AS_STANDALONE # diff --git a/singles/CMakeLists.txt b/singles/CMakeLists.txt index 6927caf..9347453 100644 --- a/singles/CMakeLists.txt +++ b/singles/CMakeLists.txt @@ -1,17 +1,29 @@ project(vmath.hpp.singles) +# +# generate +# + 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") +set(VMATH_SINGLES_INPUT "${VMATH_ROOT_DIR}/headers/vmath.hpp/vmath.hpp") +set(VMATH_SINGLES_OUTPUT "${VMATH_ROOT_DIR}/singles/headers/vmath.hpp/vmath.hpp") +file(GLOB_RECURSE VMATH_SINGLES_DEPENDS "${VMATH_ROOT_DIR}/headers/*.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_command(OUTPUT "${VMATH_SINGLES_OUTPUT}" + COMMAND "${PYTHON_EXECUTABLE}" ".ci/build_singles.py" "${VMATH_SINGLES_INPUT}" "${VMATH_SINGLES_OUTPUT}" + DEPENDS ${VMATH_SINGLES_DEPENDS} + WORKING_DIRECTORY "${VMATH_ROOT_DIR}") -add_custom_target(vmath.hpp.singles.generate - DEPENDS "${VMATH_SINGLES_OUTPUT_HEADER}") +add_custom_target(${PROJECT_NAME}.generate + DEPENDS "${VMATH_SINGLES_OUTPUT}") + +# +# library +# + +add_library(${PROJECT_NAME} INTERFACE) +add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}.generate) +target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17) +target_include_directories(${PROJECT_NAME} INTERFACE headers) diff --git a/singles/vmath.hpp/vmath.hpp b/singles/headers/vmath.hpp/vmath.hpp similarity index 100% rename from singles/vmath.hpp/vmath.hpp rename to singles/headers/vmath.hpp/vmath.hpp diff --git a/untests/CMakeLists.txt b/untests/CMakeLists.txt index f3e55f5..343a66a 100644 --- a/untests/CMakeLists.txt +++ b/untests/CMakeLists.txt @@ -7,7 +7,6 @@ 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) #