From 67e82d80657dd72496ebce3135474b76ac24bca6 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 27 Jun 2022 00:42:09 +0200 Subject: [PATCH] Add cmake-based header generation --- stdlib/CMakeLists.txt | 21 +++++++++++++++++++++ stdlib/stdlib.h.in | 15 +++++++++++++++ stdlib/stdlib.src.h.in | 13 +++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 stdlib/CMakeLists.txt create mode 100644 stdlib/stdlib.h.in create mode 100644 stdlib/stdlib.src.h.in diff --git a/stdlib/CMakeLists.txt b/stdlib/CMakeLists.txt new file mode 100644 index 000000000..742755f85 --- /dev/null +++ b/stdlib/CMakeLists.txt @@ -0,0 +1,21 @@ +# This will re-generate the headers if any file within src was modified. +set_directory_properties(PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/stdlib/src/) + +set(STDLIB precompiles) +set(GENERATED_STDLIB_HEADERS) +foreach(src IN LISTS STDLIB) + set(STDLIB_FILE ${CMAKE_SOURCE_DIR}/stdlib/src/${src}.sol) + file(READ ${STDLIB_FILE} STDLIB_FILE_CONTENT HEX) + string(REGEX MATCHALL ".." STDLIB_FILE_CONTENT "${STDLIB_FILE_CONTENT}") + string(REGEX REPLACE ";" ",\n\t0x" STDLIB_FILE_CONTENT "${STDLIB_FILE_CONTENT}") + set(STDLIB_FILE_CONTENT "0x${STDLIB_FILE_CONTENT}") + set(STDLIB_FILE_NAME ${src}) + configure_file("${CMAKE_SOURCE_DIR}/stdlib/stdlib.src.h.in" ${CMAKE_BINARY_DIR}/include/stdlib/${src}.h @ONLY) + list(APPEND GENERATED_STDLIB_HEADERS ${CMAKE_BINARY_DIR}/include/stdlib/${src}.h) +endforeach() + +configure_file("${CMAKE_SOURCE_DIR}/stdlib/stdlib.h.in" ${CMAKE_BINARY_DIR}/include/stdlib.h @ONLY) + +#add_library(stdlib +# ${GENERATED_STDLIB_HEADERS} +#) diff --git a/stdlib/stdlib.h.in b/stdlib/stdlib.h.in new file mode 100644 index 000000000..b1d243270 --- /dev/null +++ b/stdlib/stdlib.h.in @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +#include "stdlib/precompiles.h" + +namespace solidity::stdlib +{ + +static std::map sources = { + { "std/precompiles.sol", precompiles }, +}; + +} // namespace solidity::stdlib diff --git a/stdlib/stdlib.src.h.in b/stdlib/stdlib.src.h.in new file mode 100644 index 000000000..0407663d6 --- /dev/null +++ b/stdlib/stdlib.src.h.in @@ -0,0 +1,13 @@ +// The generation of this file is defined in stdlib/CMakeLists.txt. +// This file was generated by using the content of stdlib/src/@STDLIB_FILE_NAME@.sol. + +#pragma once + +namespace solidity::stdlib +{ + +static char const @STDLIB_FILE_NAME@[] = { + @STDLIB_FILE_CONTENT@, 0 +}; + +} // namespace solidity::stdlib