Skip to content

Commit

Permalink
Merge pull request #14860 from ethereum/improve_solidity_embeddability
Browse files Browse the repository at this point in the history
[buildsystem] Improve solidity embeddability.
  • Loading branch information
nikola-matic authored Apr 3, 2024
2 parents ab1f2b8 + 780018a commit a26691e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
33 changes: 23 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,21 @@ option(SOLC_STATIC_STDLIBS "Link solc against static versions of libgcc and libs
option(STRICT_Z3_VERSION "Use the latest version of Z3" ON)
option(PEDANTIC "Enable extra warnings and pedantic build flags. Treat all warnings as errors." ON)
option(PROFILE_OPTIMIZER_STEPS "Output performance metrics for the optimiser steps." OFF)
option(USE_SYSTEM_LIBRARIES "Use system libraries" OFF)
option(ONLY_BUILD_SOLIDITY_LIBRARIES "Only build solidity libraries" OFF)
option(STRICT_JSONCPP_VERSION "Strictly check installed jsoncpp version" ON)

# Setup cccache.
include(EthCcache)

# Let's find our dependencies
include(EthDependencies)
include(fmtlib)
include(jsoncpp)
include(range-v3)
include_directories(SYSTEM ${JSONCPP_INCLUDE_DIR})
if (NOT USE_SYSTEM_LIBRARIES)
include(fmtlib)
include(jsoncpp)
include(range-v3)
include_directories(SYSTEM ${JSONCPP_INCLUDE_DIR})
endif()

find_package(Threads)

Expand All @@ -58,6 +63,10 @@ if (PROFILE_OPTIMIZER_STEPS)
add_definitions(-DPROFILE_OPTIMIZER_STEPS)
endif()

if (STRICT_JSONCPP_VERSION)
add_definitions(-DSTRICT_JSONCPP_VERSION_CHECK)
endif()

# Figure out what compiler and system are we using
include(EthCompilerSettings)

Expand Down Expand Up @@ -141,12 +150,16 @@ add_subdirectory(libyul)
add_subdirectory(libsolidity)
add_subdirectory(libsolc)
add_subdirectory(libstdlib)
add_subdirectory(tools)

if (NOT EMSCRIPTEN)
add_subdirectory(solc)
endif()
if (NOT ONLY_BUILD_SOLIDITY_LIBRARIES)
add_subdirectory(tools)

if (TESTS AND NOT EMSCRIPTEN)
add_subdirectory(test)
if (NOT EMSCRIPTEN)
add_subdirectory(solc)
endif()

if (TESTS AND NOT EMSCRIPTEN)
add_subdirectory(test)
endif()
endif()

2 changes: 2 additions & 0 deletions libsolutil/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
#include <map>
#include <memory>

#ifdef STRICT_JSONCPP_VERSION_CHECK
static_assert(
(JSONCPP_VERSION_MAJOR == 1) && (JSONCPP_VERSION_MINOR == 9) && (JSONCPP_VERSION_PATCH == 3),
"Unexpected jsoncpp version: " JSONCPP_VERSION_STRING ". Expecting 1.9.3."
);
#endif

namespace solidity::util
{
Expand Down
8 changes: 4 additions & 4 deletions libstdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# This will re-generate the headers if any file within src was modified.
set_directory_properties(PROPERTY CMAKE_CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/stdlib/src/)
set_directory_properties(PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/)

set(STDLIB stub)
set(GENERATED_STDLIB_HEADERS)
foreach(src IN LISTS STDLIB)
set(STDLIB_FILE ${PROJECT_SOURCE_DIR}/libstdlib/src/${src}.sol)
set(STDLIB_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/${src}.sol)
file(READ ${STDLIB_FILE} STDLIB_FILE_CONTENT HEX)
string(REGEX MATCHALL ".." STDLIB_FILE_CONTENT "${STDLIB_FILE_CONTENT}")
list(REMOVE_ITEM STDLIB_FILE_CONTENT "0d")
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("${PROJECT_SOURCE_DIR}/libstdlib/stdlib.src.h.in" ${PROJECT_BINARY_DIR}/include/libstdlib/${src}.h NEWLINE_STYLE LF @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/stdlib.src.h.in" ${PROJECT_BINARY_DIR}/include/libstdlib/${src}.h NEWLINE_STYLE LF @ONLY)
list(APPEND GENERATED_STDLIB_HEADERS ${PROJECT_BINARY_DIR}/include/libstdlib/${src}.h)
endforeach()

configure_file("${PROJECT_SOURCE_DIR}/libstdlib/stdlib.h.in" ${PROJECT_BINARY_DIR}/include/libstdlib/stdlib.h NEWLINE_STYLE LF @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/stdlib.h.in" ${PROJECT_BINARY_DIR}/include/libstdlib/stdlib.h NEWLINE_STYLE LF @ONLY)

0 comments on commit a26691e

Please sign in to comment.