Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
[submodule "extern/strtype"]
path = extern/strtype
url = https://github.com/JessyDL/strtype.git
[submodule "extern/cppfront"]
path = extern/cppfront
url = https://github.com/hsutter/cppfront.git
16 changes: 13 additions & 3 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,20 @@ add_custom_command(TARGET core_generator
BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/gen/core/paradigm.hpp
COMMENT "Generating headers for Paradigm")

add_library(core STATIC ${FWD} ${SRC} ${INC} ${GEN} ${INC_GLES} ${SRC_GLES} ${INC_VULKAN} ${SRC_VULKAN} ${NATVIS})
add_custom_target(core_cppfront)
list(TRANSFORM SRC_GEN_CPP2 PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/)
add_custom_command(TARGET core_cppfront
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../tools/cppfront.py -c $<TARGET_FILE:cppfront_compiler> -i ${SRC_CPP2} --generate
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
BYPRODUCTS ${SRC_GEN_CPP2}
COMMENT "Transpile cpp2 to cpp")

add_dependencies(core_cppfront cppfront_compiler)

add_library(core STATIC ${FWD} ${SRC} ${INC} ${GEN} ${INC_GLES} ${SRC_GLES} ${INC_VULKAN} ${SRC_VULKAN} ${NATVIS} ${SRC_GEN_CPP2})
add_library(paradigm::core ALIAS core)

add_dependencies(core core_generator)
add_dependencies(core core_generator core_cppfront)

if(${PE_PCH})
target_precompile_headers(core PUBLIC ${INC_PCH})
Expand All @@ -119,7 +129,7 @@ if(VK_STATIC AND PE_VULKAN)
list(APPEND PE_DL_LIBS ${vk_lib_name})
endif()

target_link_libraries(core PUBLIC paradigm::psl ${CMAKE_DL_LIBS} ${PE_DL_LIBS} ${TEST_LIBS})
target_link_libraries(core PUBLIC paradigm::psl ${CMAKE_DL_LIBS} ${PE_DL_LIBS} ${TEST_LIBS} cppfront_interface)
set_target_output_directory(core)
target_include_directories(core
PUBLIC
Expand Down
9 changes: 9 additions & 0 deletions core/src.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,12 @@ if(${PE_GLES})
list(TRANSFORM SRC_GLES PREPEND src/gles/)
list(TRANSFORM SRC_GLES APPEND .cpp)
endif()

set(SRC_CPP2
)

list(TRANSFORM SRC_CPP2 PREPEND src/)
set(SRC_GEN_CPP2 ${SRC_CPP2})
list(TRANSFORM SRC_GEN_CPP2 APPEND .gen.cpp)
list(TRANSFORM SRC_CPP2 APPEND .cpp2)
set_source_files_properties(${SRC_GEN_CPP2} PROPERTIES GENERATED 1)
9 changes: 9 additions & 0 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ if(NOT TARGET strtype)
add_subdirectory(strtype)
endif()
set_property(TARGET strtype PROPERTY FOLDER "extern")

# setup cppfront which lacks a cmake integration
add_executable(cppfront_compiler "${CMAKE_CURRENT_SOURCE_DIR}/cppfront/source/cppfront.cpp")
target_include_directories(cppfront_compiler PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/cppfront/source")
set_target_properties(cppfront_compiler PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED TRUE OUTPUT_NAME cppfront EXPORT_NAME cppfront)

add_library(cppfront_interface INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/cppfront/include/cpp2util.h")
set_target_properties(cppfront_interface PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED TRUE)
target_include_directories(cppfront_interface SYSTEM INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cppfront/include>")
1 change: 1 addition & 0 deletions extern/cppfront
Submodule cppfront added at d4647e
37 changes: 37 additions & 0 deletions tools/cppfront.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from typing import List
from argparse import ArgumentParser
import subprocess
import os

def get_path(file: str):
filename, extension = os.path.splitext(file)
return (file, f"{filename}.gen{extension[:-1]}") if extension in [".cpp2", ".hpp2"] else (None, None)


def clean(files : List[str]):
for file in files:
source, destination = get_path(file)
if source and destination and os.path.exists(destination):
os.remove(destination)

def generate(compiler : str, files : List[str]):
for file in files:
source, destination = get_path(file)
if source and destination:
process = subprocess.run([compiler, source, "-o", destination])
assert(process.returncode == 0)

if __name__ == "__main__":
argParse = ArgumentParser(description='Generate cppfront files for the current project.')
argParse.add_argument("-i", "--input", default=[], nargs='?')
argParse.add_argument("-c", "--compiler")
argParse.add_argument("--clean", action='store_true')
argParse.add_argument("--generate", action='store_true')

args = argParse.parse_args()

if args.input is not None and len(args.input) > 0:
if(args.clean):
clean(args.input)
if(args.generate):
generate(args.compiler, args.input)