Index: CMakeLists.txt |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/CMakeLists.txt |
@@ -0,0 +1,135 @@ |
+# 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") |
Wladimir Palant
2017/10/04 12:05:50
Could it be that Emscripten configures an external
Eric
2017/10/05 13:06:13
If you do it right, then the Emscripten toolchain
sergei
2017/10/17 10:58:42
Which node is found actually depends on the order
Eric
2017/10/17 19:07:22
Yes, exactly. What you are observing is what I've
|
+ message(FATAL_ERROR |
+ "The Node interpreter was not found while setting up the Emscripten" |
+ "toolchain.") |
+endif() |
+ |
+# |
+# Source file lists |
+# We don't use globbing. CMakes expands a globbing expression at the time it |
+# runs, not at the time the build runs. Thus if we were to use globbing, we |
+# would generate build files with fixed lists of sources found at the time |
+# CMake runs. Afterwards, such a build would not discover new files created |
+# in the interim. |
+# |
+set(COMMON_SOURCES |
+ compiled/bindings/runtime_utils.cpp |
+ compiled/filter/ActiveFilter.cpp |
+ compiled/filter/BlockingFilter.cpp |
+ compiled/filter/CommentFilter.cpp |
+ compiled/filter/ElemHideBase.cpp |
+ compiled/filter/ElemHideEmulationFilter.cpp |
+ compiled/filter/ElemHideException.cpp |
+ compiled/filter/ElemHideFilter.cpp |
+ compiled/filter/Filter.cpp |
+ compiled/filter/InvalidFilter.cpp |
+ compiled/filter/RegExpFilter.cpp |
+ compiled/filter/WhitelistFilter.cpp |
+ compiled/storage/FilterStorage.cpp |
+ compiled/subscription/DownloadableSubscription.cpp |
+ compiled/subscription/Subscription.cpp |
+ compiled/subscription/UserDefinedSubscription.cpp |
+ ) |
+set(CORE_SPECIFIC_SOURCES |
+ compiled/traceInit.cpp |
+ ) |
+set(BINDINGS_SPECIFIC_SOURCES |
+ compiled/bindings/generator.cpp |
+ compiled/bindings/main.cpp |
+ ) |
+ |
+set(BINDINGS_GENERATOR_SOURCES ${COMMON_SOURCES}) |
+list(APPEND BINDINGS_GENERATOR_SOURCES ${BINDINGS_SPECIFIC_SOURCES}) |
+list(SORT BINDINGS_GENERATOR_SOURCES) |
+ |
+set(CORE_SOURCES ${COMMON_SOURCES}) |
+list(APPEND CORE_SOURCES ${CORE_SPECIFIC_SOURCES}) |
+list(SORT CORE_SOURCES) |
+ |
+# |
+# Options for all targets |
+# |
+add_compile_options(-std=c++1z) |
+ |
+# |
+# Target: bindings-generator |
+# |
+add_executable(bindings-generator ${BINDINGS_GENERATOR_SOURCES}) |
+# |
+# 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. This oddity is not well-documented in CMake. |
+# |
+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 |
sergei
2017/10/17 10:58:42
Is there a way to store both an intermediate and t
Eric
2017/10/17 19:07:22
CMake has a way of exporting projects and importin
|
+ BYPRODUCTS bindings) |
+add_dependencies(bindings bindings-generator) |
+ |
+# |
+# Target: Core |
+# |
+add_executable(compiled ${CORE_SOURCES}) |
+add_dependencies(compiled bindings) |
+ |
+target_compile_options(compiled PRIVATE |
+ -O3 -m32 -Wall -Werror -fno-rtti -fno-exceptions) |
+ |
+# Debugging |
+target_compile_options(compiled PRIVATE -g3) |
+ |
+target_link_libraries(compiled PRIVATE |
+ "--post-js bindings.js" |
+ -O3 |
+ --emit-symbol-map |
+ "--memory-init-file 0" |
+ "-s ASM_JS=2" |
+ "-s TOTAL_MEMORY=16*1024*1024" |
+ "-s TOTAL_STACK=1*1024*1024" |
+ "-s ALLOW_MEMORY_GROWTH=1" |
+ "-s NO_EXIT_RUNTIME=1" |
+ "-s NO_DYNAMIC_EXECUTION=1" |
+ "-s NO_FILESYSTEM=1" |
+ "-s INVOKE_RUN=0" |
+ "-s TEXTDECODER=0" |
+ "-s EXPORTED_RUNTIME_METHODS=\"['cwrap','ccall','stringToAscii']\"" |
+ "--js-library compiled/library.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}\\\"\"") |
Wladimir Palant
2017/10/04 12:05:50
What about using single quotation marks? SHELL_FIL
Eric
2017/10/05 13:06:13
I'll try that. CMake has some capability to do pla
Wladimir Palant
2017/10/09 08:49:12
It seems that you don't have any escaping issues w
Eric
2017/10/17 19:07:22
Done. It works fine.
|
+ |
+# Debugging |
+target_link_libraries(compiled PRIVATE -g3) |