Skip to content

Commit b3daef7

Browse files
[CMake] Refactor libsolc linker flag for EXPORTED_FUNCTIONS and make it more readable.
1 parent 145186f commit b3daef7

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

cmake/EthUtils.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,11 @@ function(detect_stray_source_files FILELIST DIRECTORY)
4848
message(SEND_ERROR "The following source files are present but are not compiled: ${sources}")
4949
endif()
5050
endfunction(detect_stray_source_files)
51+
52+
# CreateExportedFunctionsForEMSDK(OUTPUT_VARIABLE Symbol1 Symbol2 ... SymbolN)
53+
function(CreateExportedFunctionsForEMSDK OUTPUT_VARIABLE)
54+
list(TRANSFORM ARGN PREPEND "\"_")
55+
list(TRANSFORM ARGN APPEND "\"")
56+
list(JOIN ARGN "," ARGN)
57+
set(${OUTPUT_VARIABLE} "[${ARGN}]" PARENT_SCOPE)
58+
endfunction()

libsolc/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
if (EMSCRIPTEN)
2+
CreateExportedFunctionsForEMSDK(
3+
ExportedFunctions
4+
solidity_license
5+
solidity_version
6+
solidity_compile
7+
solidity_alloc
8+
solidity_free
9+
solidity_reset
10+
)
211
# Specify which functions to export in soljson.js.
312
# Note that additional Emscripten-generated methods needed by solc-js are
413
# defined to be exported in cmake/EthCompilerSettings.cmake.
5-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s EXPORTED_FUNCTIONS='[\"_solidity_license\",\"_solidity_version\",\"_solidity_compile\",\"_solidity_alloc\",\"_solidity_free\",\"_solidity_reset\"]'")
14+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s EXPORTED_FUNCTIONS='${ExportedFunctions}'")
615
add_executable(soljson libsolc.cpp libsolc.h)
716
target_link_libraries(soljson PRIVATE solidity)
817
else()

0 commit comments

Comments
 (0)