mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-13 19:18:01 +07:00
enable pch for meta cmake interfaces
This commit is contained in:
@@ -22,6 +22,9 @@ add_library(meta.hpp::meta.hpp ALIAS ${PROJECT_NAME})
|
||||
target_compile_features(${PROJECT_NAME} INTERFACE
|
||||
cxx_std_20)
|
||||
|
||||
target_precompile_headers(${PROJECT_NAME} INTERFACE
|
||||
"headers/meta.hpp/meta_all.hpp")
|
||||
|
||||
target_include_directories(${PROJECT_NAME} INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/headers>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
|
||||
@@ -13,10 +13,13 @@ set(META_HPP_SINGLES_SCRIPT "${META_HPP_ROOT_DIR}/develop/singles/scripts/build_
|
||||
file(GLOB_RECURSE META_SINGLES_DEPENDS CONFIGURE_DEPENDS "${META_HPP_ROOT_DIR}/headers/*.hpp")
|
||||
|
||||
add_custom_command(OUTPUT "${META_HPP_SINGLES_OUTPUT}"
|
||||
COMMAND "${Python3_EXECUTABLE}" "${META_HPP_SINGLES_SCRIPT}"
|
||||
"${META_HPP_SINGLES_INPUT}" "${META_HPP_SINGLES_OUTPUT}"
|
||||
DEPENDS ${META_SINGLES_DEPENDS}
|
||||
WORKING_DIRECTORY "${META_HPP_ROOT_DIR}")
|
||||
COMMAND
|
||||
"${Python3_EXECUTABLE}" "${META_HPP_SINGLES_SCRIPT}"
|
||||
"${META_HPP_SINGLES_INPUT}" "${META_HPP_SINGLES_OUTPUT}"
|
||||
DEPENDS
|
||||
"${META_HPP_SINGLES_SCRIPT}" ${META_SINGLES_DEPENDS}
|
||||
WORKING_DIRECTORY
|
||||
"${META_HPP_ROOT_DIR}")
|
||||
|
||||
add_custom_target(${PROJECT_NAME}.generate
|
||||
DEPENDS "${META_HPP_SINGLES_OUTPUT}")
|
||||
@@ -34,6 +37,9 @@ add_dependencies(${PROJECT_NAME}
|
||||
target_compile_features(${PROJECT_NAME} INTERFACE
|
||||
cxx_std_20)
|
||||
|
||||
target_precompile_headers(${PROJECT_NAME} INTERFACE
|
||||
"headers/meta.hpp/meta_all.hpp")
|
||||
|
||||
target_include_directories(${PROJECT_NAME} INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/headers>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
* Copyright (C) 2021-2023, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user