From b3daef766525459a7f624b0a66d667a76044194c Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Mon, 7 Mar 2022 13:31:55 +0100 Subject: [PATCH] [CMake] Refactor libsolc linker flag for EXPORTED_FUNCTIONS and make it more readable. --- cmake/EthUtils.cmake | 8 ++++++++ libsolc/CMakeLists.txt | 11 ++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cmake/EthUtils.cmake b/cmake/EthUtils.cmake index fca41107e..44b92f4a0 100644 --- a/cmake/EthUtils.cmake +++ b/cmake/EthUtils.cmake @@ -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() diff --git a/libsolc/CMakeLists.txt b/libsolc/CMakeLists.txt index 776b97ca5..fce54dd24 100644 --- a/libsolc/CMakeLists.txt +++ b/libsolc/CMakeLists.txt @@ -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()