Skip to content

Commit

Permalink
[CMake] Refactor libsolc linker flag for EXPORTED_FUNCTIONS and make …
Browse files Browse the repository at this point in the history
…it more readable.
  • Loading branch information
christianparpart committed Mar 9, 2022
1 parent 145186f commit b3daef7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions cmake/EthUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,11 @@ function(detect_stray_source_files FILELIST DIRECTORY)
message(SEND_ERROR "The following source files are present but are not compiled: ${sources}")
endif()
endfunction(detect_stray_source_files)

# CreateExportedFunctionsForEMSDK(OUTPUT_VARIABLE Symbol1 Symbol2 ... SymbolN)
function(CreateExportedFunctionsForEMSDK OUTPUT_VARIABLE)
list(TRANSFORM ARGN PREPEND "\"_")
list(TRANSFORM ARGN APPEND "\"")
list(JOIN ARGN "," ARGN)
set(${OUTPUT_VARIABLE} "[${ARGN}]" PARENT_SCOPE)
endfunction()
11 changes: 10 additions & 1 deletion libsolc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
if (EMSCRIPTEN)
CreateExportedFunctionsForEMSDK(
ExportedFunctions
solidity_license
solidity_version
solidity_compile
solidity_alloc
solidity_free
solidity_reset
)
# Specify which functions to export in soljson.js.
# Note that additional Emscripten-generated methods needed by solc-js are
# defined to be exported in cmake/EthCompilerSettings.cmake.
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s EXPORTED_FUNCTIONS='[\"_solidity_license\",\"_solidity_version\",\"_solidity_compile\",\"_solidity_alloc\",\"_solidity_free\",\"_solidity_reset\"]'")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s EXPORTED_FUNCTIONS='${ExportedFunctions}'")
add_executable(soljson libsolc.cpp libsolc.h)
target_link_libraries(soljson PRIVATE solidity)
else()
Expand Down

0 comments on commit b3daef7

Please sign in to comment.