diff options
author | Blaine Bublitz <blaine.bublitz@gmail.com> | 2022-05-05 17:35:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-06 00:35:38 +0000 |
commit | 8554428d4b26865c03bafa3dbe61ee4fb2957fe1 (patch) | |
tree | a787c6db8ee62c998dcf0511e2f0fbd95d4bbab9 /CMakeLists.txt | |
parent | fb24b53ffc91030829fddb1140bb0a79507a25e7 (diff) | |
download | binaryen-8554428d4b26865c03bafa3dbe61ee4fb2957fe1.tar.gz binaryen-8554428d4b26865c03bafa3dbe61ee4fb2957fe1.tar.bz2 binaryen-8554428d4b26865c03bafa3dbe61ee4fb2957fe1.zip |
Add CMake flag JS_OF_OCAML for js_of_ocaml (#4637)
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c0699ba24..820e78366 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,9 @@ option(BYN_ENABLE_ASSERTIONS "Enable assertions" ON) # Turn this off to avoid the dependency on gtest. option(BUILD_TESTS "Build GTest-based tests" ON) +# Turn this on to build binaryen.js as ES5, with additional compatibility configuration for js_of_ocaml. +option(JS_OF_OCAML "Build binaryen.js for js_of_ocaml" OFF) + # For git users, attempt to generate a more useful version string if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git) find_package(Git QUIET REQUIRED) @@ -403,14 +406,36 @@ if(EMSCRIPTEN) # only valid with fastcomp and WASM=0 target_link_libraries(binaryen_js "-s ELIMINATE_DUPLICATE_FUNCTIONS=1") endif() - target_link_libraries(binaryen_js "-s NO_FILESYSTEM=0") + # Disabling filesystem and setting web environment for js_of_ocaml + # so it doesn't try to detect the "node" environment + if(JS_OF_OCAML) + target_link_libraries(binaryen_js "-s NO_FILESYSTEM=1") + target_link_libraries(binaryen_js "-s ENVIRONMENT=web,worker") + else() + target_link_libraries(binaryen_js "-s NO_FILESYSTEM=0") + endif() target_link_libraries(binaryen_js "-s NODERAWFS=0") target_link_libraries(binaryen_js "-s EXPORT_NAME=Binaryen") - target_link_libraries(binaryen_js "-s EXPORT_ES6=1") + # Currently, js_of_ocaml can only process ES5 code + if(JS_OF_OCAML) + target_link_libraries(binaryen_js "-s EXPORT_ES6=0") + else() + target_link_libraries(binaryen_js "-s EXPORT_ES6=1") + endif() target_link_libraries(binaryen_js "--post-js ${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-post.js") - target_link_libraries(binaryen_js "--extern-pre-js ${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-extern-pre.js") + # js_of_ocaml needs a specified variable with special comment to provide the library to consumers + if(JS_OF_OCAML) + target_link_libraries(binaryen_js "--extern-pre-js ${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.jsoo-extern-pre.js") + else() + target_link_libraries(binaryen_js "--extern-pre-js ${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-extern-pre.js") + endif() target_link_libraries(binaryen_js optimized "--closure 1") - target_link_libraries(binaryen_js optimized "--closure-args \"--language_in=ECMASCRIPT6 --language_out=ECMASCRIPT6\"") + # Currently, js_of_ocaml can only process ES5 code + if(JS_OF_OCAML) + target_link_libraries(binaryen_js optimized "--closure-args \"--language_in=ECMASCRIPT6 --language_out=ECMASCRIPT5\"") + else() + target_link_libraries(binaryen_js optimized "--closure-args \"--language_in=ECMASCRIPT6 --language_out=ECMASCRIPT6\"") + endif() target_link_libraries(binaryen_js optimized "-flto") target_link_libraries(binaryen_js debug "--profiling") target_link_libraries(binaryen_js debug "-s ASSERTIONS") |