OLD | NEW |
(Empty) | |
| 1 # Set the minimum we require to the minimum that Emscripten requires. |
| 2 # See the Emscripten toolchain file for details. |
| 3 cmake_minimum_required(VERSION 3.4.3) |
| 4 |
| 5 project (adblockpluscore) |
| 6 |
| 7 # |
| 8 # Sanity check that the tool chain is set up correctly. |
| 9 # |
| 10 if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten") |
| 11 message(FATAL_ERROR |
| 12 "The Emscripten toolchain does not appear is not installed in the" |
| 13 "CMake cache. Please follow the instructions in README.CMAKE.") |
| 14 endif() |
| 15 |
| 16 # |
| 17 # Node.js is required to generate the bindings file. |
| 18 # |
| 19 if (${NODE_JS_EXECUTABLE} MATCHES "NOTFOUND") |
| 20 message(FATAL_ERROR |
| 21 "The Node interpreter was not found while setting up the Emscripten" |
| 22 "toolchain.") |
| 23 endif() |
| 24 |
| 25 # |
| 26 # Legacy options from `compile` script |
| 27 # TODO: convert these to configurations |
| 28 # |
| 29 option(debug "Disable code minification") |
| 30 option(tracing "Enable memory tracing") |
| 31 |
| 32 # |
| 33 # Source file lists |
| 34 # |
| 35 file(GLOB_RECURSE ALL_SOURCES compiled/*.cpp) |
| 36 # Sort, so that the same source code always yields identical results. |
| 37 list(SORT ALL_SOURCES) |
| 38 set(BINDINGS_GENERATOR_SOURCES ${ALL_SOURCES}) |
| 39 set(CORE_SOURCES ${ALL_SOURCES}) |
| 40 list(FILTER CORE_SOURCES EXCLUDE REGEX compiled/bindings/runtime_) |
| 41 |
| 42 # |
| 43 # Options for all targets |
| 44 # |
| 45 add_compile_options(-std=c++1z) |
| 46 |
| 47 # |
| 48 # Target: bindings-generator |
| 49 # |
| 50 add_executable(bindings-generator ${BINDINGS_GENERATOR_SOURCES}) |
| 51 target_link_libraries(bindings-generator |
| 52 "--js-library compiled/library.js" |
| 53 "--js-library compiled/bindings/library.js") |
| 54 |
| 55 # |
| 56 # Target: bindings |
| 57 # |
| 58 add_custom_target(bindings |
| 59 COMMAND ${NODE_JS_EXECUTABLE} bindings-generator >bindings.js |
| 60 BYPRODUCTS bindings.js) |
| 61 add_dependencies(bindings bindings-generator) |
| 62 |
| 63 |
| 64 # |
| 65 # Target: Core |
| 66 # |
| 67 add_executable(compiled ${CORE_SOURCES}) |
| 68 add_dependencies(compiled bindings) |
| 69 |
| 70 target_compile_options(compiled PRIVATE |
| 71 -O3 -m32 |
| 72 --memory-init-file 0 --emit-symbol-map |
| 73 -Wall -Werror -fno-rtti) |
| 74 # Disabled. This option is present in the compile script (see its script |
| 75 # variable ADDITIONAL_PARAMS). When present as a proper compile option, |
| 76 # however, it yields an error "cannot use 'throw' with exceptions disabled" |
| 77 # when added as a proper compile option. |
| 78 #target_compile_options(compiled PRIVATE -fno-exceptions) |
| 79 |
| 80 |
| 81 # |
| 82 # CMake overloads `target_link_libraries` for both libraries (as stated) and |
| 83 # for linker flags (very much not as a stated). In order for CMake to |
| 84 # recognize an option with parameter, that is, with an embedded space, it |
| 85 # requires that it be quoted. |
| 86 # |
| 87 target_link_libraries(compiled PRIVATE "--post-js bindings.js") |
| 88 # |
| 89 # The interaction between command line parsing of "-s SHELL_FILE=" and Windows |
| 90 # path names with backslashes is, frankly, insane. It's left as an exercise, |
| 91 # that is, waste of time, for the reader to divine all the levels of quoting |
| 92 # required to make it work. |
| 93 # |
| 94 file(GLOB SHELL_FILE compiled/shell.js) |
| 95 file(TO_NATIVE_PATH ${SHELL_FILE} SHELL_FILE) |
| 96 target_link_libraries(compiled PRIVATE "-s SHELL_FILE=\"\\\"${SHELL_FILE}\\\"\""
) |
| 97 target_link_libraries(compiled PRIVATE "-s ASM_JS=2") |
| 98 target_link_libraries(compiled PRIVATE "-s TOTAL_MEMORY=16*1024*1024") |
| 99 target_link_libraries(compiled PRIVATE "-s TOTAL_STACK=1*1024*1024") |
| 100 target_link_libraries(compiled PRIVATE "-s ALLOW_MEMORY_GROWTH=1") |
| 101 target_link_libraries(compiled PRIVATE "-s NO_EXIT_RUNTIME=1") |
| 102 target_link_libraries(compiled PRIVATE "-s NO_DYNAMIC_EXECUTION=1") |
| 103 target_link_libraries(compiled PRIVATE "-s NO_FILESYSTEM=1") |
| 104 target_link_libraries(compiled PRIVATE "-s INVOKE_RUN=0") |
| 105 target_link_libraries(compiled PRIVATE "-s TEXTDECODER=0") |
| 106 target_link_libraries(compiled PRIVATE "-s EXPORTED_RUNTIME_METHODS=\"['cwrap','
ccall','stringToAscii']\"") |
| 107 |
| 108 |
| 109 # |
| 110 # GENERAL TODO |
| 111 # |
| 112 # - Bindings and generator are in the root, unlike "compiled/" in the script. |
| 113 # - "compiled.js" is in the root, unlike "lib/" in the script. |
OLD | NEW |