Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: CMakeLists.txt

Issue 29556820: Working Draft: CMake build for Emscripten
Patch Set: Created Oct. 17, 2017, 6:28 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « .hgignore ('k') | README.CMAKE.md » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: CMakeLists.txt
===================================================================
new file mode 100644
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,183 @@
+# 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)
+
+#
+# Configurations
+# - Release. The default with no special compile or link flags.
+# - ReleaseTrace. Enables tracing.
+# - Debug. Turns on debugging.
+# - DebugTrace. Turns on debugging and enables tracing.
+#
+set(AVAILABLE_CONFIGURATIONS "Release;ReleaseTrace;Debug;DebugTrace")
+if(CMAKE_CONFIGURATION_TYPES)
+ # We are using a multiconfiguration generator.
+ set(CMAKE_CONFIGURATION_TYPES ${AVAILABLE_CONFIGURATIONS}
+ CACHE STRING "" FORCE)
+else()
+ # We are using a single-configuration generator.
+ if(NOT CMAKE_BUILD_TYPE)
+ message("Build type not specified explicitly. Defaulting to 'Release'.")
+ set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
+ endif()
+ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
+ HELPSTRING "Available build types")
+ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
+ STRINGS ${AVAILABLE_CONFIGURATIONS})
+endif()
+
+#
+# Remove variables for the default configurations
+# This is a workaround for a poorly documented feature in CMake. Setting
+# these toolchain variables is *not* destructive assignment but rather
+# an append operation. Removing the variable has an effect equivalent to
+# setting its value to empty.
+#
+foreach(FLAG_TYPE IN ITEMS C CXX EXE_LINKER MODULE_LINKER SHARED_LINKER STATIC_LINKER)
+ foreach(BUILTIN_CONFIG IN ITEMS RELEASE DEBUG MINSIZEREL RELWITHDEBINFO)
+ unset(CMAKE_${FLAG_TYPE}_FLAGS_${BUILTIN_CONFIG})
+ unset(CMAKE_${FLAG_TYPE}_FLAGS_${BUILTIN_CONFIG} CACHE)
+ endforeach()
+endforeach()
+#
+# Set up the flags for our own configurations.
+#
+set(CONFIG_DOC_STRING "Overridden by adblockpluscore")
+# Release
+set(CMAKE_C_FLAGS_RELEASE "" CACHE STRING ${CONFIG_DOC_STRING} FORCE)
+set(CMAKE_CXX_FLAGS_RELEASE "" CACHE STRING ${CONFIG_DOC_STRING} FORCE)
+set(CMAKE_EXE_LINKER_FLAGS_RELEASE "" CACHE STRING ${CONFIG_DOC_STRING} FORCE)
+# ReleaseTrace
+set(CMAKE_C_FLAGS_RELEASETRACE "--tracing" CACHE STRING ${CONFIG_DOC_STRING} FORCE)
+set(CMAKE_CXX_FLAGS_RELEASETRACE "--tracing" CACHE STRING ${CONFIG_DOC_STRING} FORCE)
+set(CMAKE_EXE_LINKER_FLAGS_RELEASETRACE "--tracing" CACHE STRING ${CONFIG_DOC_STRING} FORCE)
+# Debug
+set(CMAKE_C_FLAGS_DEBUG "-g3" CACHE STRING ${CONFIG_DOC_STRING} FORCE)
+set(CMAKE_CXX_FLAGS_DEBUG "-g3" CACHE STRING ${CONFIG_DOC_STRING} FORCE)
+set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-g3" CACHE STRING ${CONFIG_DOC_STRING} FORCE)
+# DebugTrace
+set(CMAKE_C_FLAGS_DEBUGTRACE "-g3 --tracing" CACHE STRING ${CONFIG_DOC_STRING} FORCE)
+set(CMAKE_CXX_FLAGS_DEBUGTRACE "-g3 --tracing" CACHE STRING ${CONFIG_DOC_STRING} FORCE)
+set(CMAKE_EXE_LINKER_FLAGS_DEBUGTRACE "-g3 --tracing" CACHE STRING ${CONFIG_DOC_STRING} FORCE)
+
+#
+# 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()
+
+#
+# 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 named) and
+# for linker flags (very much not as named). 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 ${PROJECT_SOURCE_DIR}/compiled/library.js"
+ "--js-library ${PROJECT_SOURCE_DIR}/compiled/bindings/library.js"
+ )
+
+#
+# File: bindings.js
+#
+# CMake does not consider bindings.js to be a "top-level target". Rather it's
+# considered a "file-level" entity. Thus it's added to a source list instead
+# of using it to declare a dependency.
+#
+add_custom_command(OUTPUT bindings.js
+ COMMAND ${NODE_JS_EXECUTABLE} bindings-generator >bindings.js
+ DEPENDS bindings-generator
+ BYPRODUCTS bindings.js)
+
+#
+# Target: Core
+#
+add_executable(compiled ${CORE_SOURCES} bindings.js)
+target_compile_options(compiled PRIVATE
+ -O3 -m32 -Wall -Werror -fno-rtti -fno-exceptions)
+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 ${PROJECT_SOURCE_DIR}/compiled/library.js"
+ )
+# Use an absolute, native path for the SHELL_FILE argument
+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}'\"")
+
« no previous file with comments | « .hgignore ('k') | README.CMAKE.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld