| Index: CMakeLists.txt |
| =================================================================== |
| new file mode 100644 |
| --- /dev/null |
| +++ b/CMakeLists.txt |
| @@ -0,0 +1,113 @@ |
| +# Set the minimum we require to the minimum that Emscripten requires. |
| +# See the Emscripten toolchain file for details. |
| +cmake_minimum_required(VERSION 3.4.3) |
| + |
| +project (adblockpluscore) |
| + |
| +# |
| +# Sanity check that the tool chain is set up correctly. |
| +# |
| +if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten") |
| + message(FATAL_ERROR |
| + "The Emscripten toolchain does not appear is not installed in the" |
| + "CMake cache. Please follow the instructions in README.CMAKE.") |
| +endif() |
| + |
| +# |
| +# Node.js is required to generate the bindings file. |
| +# |
| +if (${NODE_JS_EXECUTABLE} MATCHES "NOTFOUND") |
| + message(FATAL_ERROR |
| + "The Node interpreter was not found while setting up the Emscripten" |
| + "toolchain.") |
| +endif() |
| + |
| +# |
| +# Legacy options from `compile` script |
| +# TODO: convert these to configurations |
| +# |
| +option(debug "Disable code minification") |
| +option(tracing "Enable memory tracing") |
| + |
| +# |
| +# Source file lists |
| +# |
| +file(GLOB_RECURSE ALL_SOURCES compiled/*.cpp) |
| +# Sort, so that the same source code always yields identical results. |
| +list(SORT ALL_SOURCES) |
| +set(BINDINGS_GENERATOR_SOURCES ${ALL_SOURCES}) |
| +set(CORE_SOURCES ${ALL_SOURCES}) |
| +list(FILTER CORE_SOURCES EXCLUDE REGEX compiled/bindings/runtime_) |
| + |
| +# |
| +# Options for all targets |
| +# |
| +add_compile_options(-std=c++1z) |
| + |
| +# |
| +# Target: bindings-generator |
| +# |
| +add_executable(bindings-generator ${BINDINGS_GENERATOR_SOURCES}) |
| +target_link_libraries(bindings-generator |
| + "--js-library compiled/library.js" |
| + "--js-library compiled/bindings/library.js") |
| + |
| +# |
| +# Target: bindings |
| +# |
| +add_custom_target(bindings |
| + COMMAND ${NODE_JS_EXECUTABLE} bindings-generator >bindings.js |
| + BYPRODUCTS bindings.js) |
| +add_dependencies(bindings bindings-generator) |
| + |
| + |
| +# |
| +# Target: Core |
| +# |
| +add_executable(compiled ${CORE_SOURCES}) |
| +add_dependencies(compiled bindings) |
| + |
| +target_compile_options(compiled PRIVATE |
| + -O3 -m32 |
| + --memory-init-file 0 --emit-symbol-map |
| + -Wall -Werror -fno-rtti) |
| +# Disabled. This option is present in the compile script (see its script |
| +# variable ADDITIONAL_PARAMS). When present as a proper compile option, |
| +# however, it yields an error "cannot use 'throw' with exceptions disabled" |
| +# when added as a proper compile option. |
| +#target_compile_options(compiled PRIVATE -fno-exceptions) |
| + |
| + |
| +# |
| +# CMake overloads `target_link_libraries` for both libraries (as stated) and |
| +# for linker flags (very much not as a stated). In order for CMake to |
| +# recognize an option with parameter, that is, with an embedded space, it |
| +# requires that it be quoted. |
| +# |
| +target_link_libraries(compiled PRIVATE "--post-js bindings.js") |
| +# |
| +# The interaction between command line parsing of "-s SHELL_FILE=" and Windows |
| +# path names with backslashes is, frankly, insane. It's left as an exercise, |
| +# that is, waste of time, for the reader to divine all the levels of quoting |
| +# required to make it work. |
| +# |
| +file(GLOB SHELL_FILE compiled/shell.js) |
| +file(TO_NATIVE_PATH ${SHELL_FILE} SHELL_FILE) |
| +target_link_libraries(compiled PRIVATE "-s SHELL_FILE=\"\\\"${SHELL_FILE}\\\"\"") |
| +target_link_libraries(compiled PRIVATE "-s ASM_JS=2") |
| +target_link_libraries(compiled PRIVATE "-s TOTAL_MEMORY=16*1024*1024") |
| +target_link_libraries(compiled PRIVATE "-s TOTAL_STACK=1*1024*1024") |
| +target_link_libraries(compiled PRIVATE "-s ALLOW_MEMORY_GROWTH=1") |
| +target_link_libraries(compiled PRIVATE "-s NO_EXIT_RUNTIME=1") |
| +target_link_libraries(compiled PRIVATE "-s NO_DYNAMIC_EXECUTION=1") |
| +target_link_libraries(compiled PRIVATE "-s NO_FILESYSTEM=1") |
| +target_link_libraries(compiled PRIVATE "-s INVOKE_RUN=0") |
| +target_link_libraries(compiled PRIVATE "-s TEXTDECODER=0") |
| +target_link_libraries(compiled PRIVATE "-s EXPORTED_RUNTIME_METHODS=\"['cwrap','ccall','stringToAscii']\"") |
| + |
| + |
| +# |
| +# GENERAL TODO |
| +# |
| +# - Bindings and generator are in the root, unlike "compiled/" in the script. |
| +# - "compiled.js" is in the root, unlike "lib/" in the script. |