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 project (adblockpluscore) |
| 5 |
| 6 # |
| 7 # Configurations |
| 8 # - Release. The default with no special compile or link flags. |
| 9 # - ReleaseTrace. Enables tracing. |
| 10 # - Debug. Turns on debugging. |
| 11 # - DebugTrace. Turns on debugging and enables tracing. |
| 12 # |
| 13 set(AVAILABLE_CONFIGURATIONS "Release;ReleaseTrace;Debug;DebugTrace") |
| 14 if(CMAKE_CONFIGURATION_TYPES) |
| 15 # We are using a multiconfiguration generator. |
| 16 set(CMAKE_CONFIGURATION_TYPES ${AVAILABLE_CONFIGURATIONS} |
| 17 CACHE STRING "" FORCE) |
| 18 else() |
| 19 # We are using a single-configuration generator. |
| 20 if(NOT CMAKE_BUILD_TYPE) |
| 21 message("Build type not specified explicitly. Defaulting to 'Release'.") |
| 22 set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE) |
| 23 endif() |
| 24 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY |
| 25 HELPSTRING "Available build types") |
| 26 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY |
| 27 STRINGS ${AVAILABLE_CONFIGURATIONS}) |
| 28 endif() |
| 29 |
| 30 # |
| 31 # Remove variables for the default configurations |
| 32 # This is a workaround for a poorly documented feature in CMake. Setting |
| 33 # these toolchain variables is *not* destructive assignment but rather |
| 34 # an append operation. Removing the variable has an effect equivalent to |
| 35 # setting its value to empty. |
| 36 # |
| 37 foreach(FLAG_TYPE IN ITEMS C CXX EXE_LINKER MODULE_LINKER SHARED_LINKER STATIC_L
INKER) |
| 38 foreach(BUILTIN_CONFIG IN ITEMS RELEASE DEBUG MINSIZEREL RELWITHDEBINFO) |
| 39 unset(CMAKE_${FLAG_TYPE}_FLAGS_${BUILTIN_CONFIG}) |
| 40 unset(CMAKE_${FLAG_TYPE}_FLAGS_${BUILTIN_CONFIG} CACHE) |
| 41 endforeach() |
| 42 endforeach() |
| 43 # |
| 44 # Set up the flags for our own configurations. |
| 45 # |
| 46 set(CONFIG_DOC_STRING "Overridden by adblockpluscore") |
| 47 # Release |
| 48 set(CMAKE_C_FLAGS_RELEASE "" CACHE STRING ${CONFIG_DOC_STRING} FORCE) |
| 49 set(CMAKE_CXX_FLAGS_RELEASE "" CACHE STRING ${CONFIG_DOC_STRING} FORCE) |
| 50 set(CMAKE_EXE_LINKER_FLAGS_RELEASE "" CACHE STRING ${CONFIG_DOC_STRING} FORCE) |
| 51 # ReleaseTrace |
| 52 set(CMAKE_C_FLAGS_RELEASETRACE "--tracing" CACHE STRING ${CONFIG_DOC_STRING} FOR
CE) |
| 53 set(CMAKE_CXX_FLAGS_RELEASETRACE "--tracing" CACHE STRING ${CONFIG_DOC_STRING} F
ORCE) |
| 54 set(CMAKE_EXE_LINKER_FLAGS_RELEASETRACE "--tracing" CACHE STRING ${CONFIG_DOC_ST
RING} FORCE) |
| 55 # Debug |
| 56 set(CMAKE_C_FLAGS_DEBUG "-g3" CACHE STRING ${CONFIG_DOC_STRING} FORCE) |
| 57 set(CMAKE_CXX_FLAGS_DEBUG "-g3" CACHE STRING ${CONFIG_DOC_STRING} FORCE) |
| 58 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-g3" CACHE STRING ${CONFIG_DOC_STRING} FORCE) |
| 59 # DebugTrace |
| 60 set(CMAKE_C_FLAGS_DEBUGTRACE "-g3 --tracing" CACHE STRING ${CONFIG_DOC_STRING} F
ORCE) |
| 61 set(CMAKE_CXX_FLAGS_DEBUGTRACE "-g3 --tracing" CACHE STRING ${CONFIG_DOC_STRING}
FORCE) |
| 62 set(CMAKE_EXE_LINKER_FLAGS_DEBUGTRACE "-g3 --tracing" CACHE STRING ${CONFIG_DOC_
STRING} FORCE) |
| 63 |
| 64 # |
| 65 # Sanity check that the tool chain is set up correctly. |
| 66 # |
| 67 if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten") |
| 68 message(FATAL_ERROR |
| 69 "The Emscripten toolchain does not appear is not installed in the" |
| 70 "CMake cache. Please follow the instructions in README.CMAKE.") |
| 71 endif() |
| 72 |
| 73 # |
| 74 # Node.js is required to generate the bindings file. |
| 75 # |
| 76 if(${NODE_JS_EXECUTABLE} MATCHES "NOTFOUND") |
| 77 message(FATAL_ERROR |
| 78 "The Node interpreter was not found while setting up the Emscripten" |
| 79 "toolchain.") |
| 80 endif() |
| 81 |
| 82 # |
| 83 # Source file lists |
| 84 # We don't use globbing. CMakes expands a globbing expression at the time it |
| 85 # runs, not at the time the build runs. Thus if we were to use globbing, we |
| 86 # would generate build files with fixed lists of sources found at the time |
| 87 # CMake runs. Afterwards, such a build would not discover new files created |
| 88 # in the interim. |
| 89 # |
| 90 set(COMMON_SOURCES |
| 91 compiled/bindings/runtime_utils.cpp |
| 92 compiled/filter/ActiveFilter.cpp |
| 93 compiled/filter/BlockingFilter.cpp |
| 94 compiled/filter/CommentFilter.cpp |
| 95 compiled/filter/ElemHideBase.cpp |
| 96 compiled/filter/ElemHideEmulationFilter.cpp |
| 97 compiled/filter/ElemHideException.cpp |
| 98 compiled/filter/ElemHideFilter.cpp |
| 99 compiled/filter/Filter.cpp |
| 100 compiled/filter/InvalidFilter.cpp |
| 101 compiled/filter/RegExpFilter.cpp |
| 102 compiled/filter/WhitelistFilter.cpp |
| 103 compiled/storage/FilterStorage.cpp |
| 104 compiled/subscription/DownloadableSubscription.cpp |
| 105 compiled/subscription/Subscription.cpp |
| 106 compiled/subscription/UserDefinedSubscription.cpp |
| 107 ) |
| 108 set(CORE_SPECIFIC_SOURCES |
| 109 compiled/traceInit.cpp |
| 110 ) |
| 111 set(BINDINGS_SPECIFIC_SOURCES |
| 112 compiled/bindings/generator.cpp |
| 113 compiled/bindings/main.cpp |
| 114 ) |
| 115 |
| 116 set(BINDINGS_GENERATOR_SOURCES ${COMMON_SOURCES}) |
| 117 list(APPEND BINDINGS_GENERATOR_SOURCES ${BINDINGS_SPECIFIC_SOURCES}) |
| 118 list(SORT BINDINGS_GENERATOR_SOURCES) |
| 119 |
| 120 set(CORE_SOURCES ${COMMON_SOURCES}) |
| 121 list(APPEND CORE_SOURCES ${CORE_SPECIFIC_SOURCES}) |
| 122 list(SORT CORE_SOURCES) |
| 123 |
| 124 # |
| 125 # Options for all targets |
| 126 # |
| 127 add_compile_options(-std=c++1z) |
| 128 |
| 129 # |
| 130 # Target: bindings-generator |
| 131 # |
| 132 add_executable(bindings-generator ${BINDINGS_GENERATOR_SOURCES}) |
| 133 # |
| 134 # CMake overloads `target_link_libraries` for both libraries (as named) and |
| 135 # for linker flags (very much not as named). In order for CMake to recognize |
| 136 # an option with parameter, that is, with an embedded space, it requires that |
| 137 # it be quoted. This oddity is not well-documented in CMake. |
| 138 # |
| 139 target_link_libraries(bindings-generator |
| 140 "--js-library ${PROJECT_SOURCE_DIR}/compiled/library.js" |
| 141 "--js-library ${PROJECT_SOURCE_DIR}/compiled/bindings/libr
ary.js" |
| 142 ) |
| 143 |
| 144 # |
| 145 # File: bindings.js |
| 146 # |
| 147 # CMake does not consider bindings.js to be a "top-level target". Rather it's |
| 148 # considered a "file-level" entity. Thus it's added to a source list instead |
| 149 # of using it to declare a dependency. |
| 150 # |
| 151 add_custom_command(OUTPUT bindings.js |
| 152 COMMAND ${NODE_JS_EXECUTABLE} bindings-generator >bindings.js |
| 153 DEPENDS bindings-generator |
| 154 BYPRODUCTS bindings.js) |
| 155 |
| 156 # |
| 157 # Target: Core |
| 158 # |
| 159 add_executable(compiled ${CORE_SOURCES} bindings.js) |
| 160 target_compile_options(compiled PRIVATE |
| 161 -O3 -m32 -Wall -Werror -fno-rtti -fno-exceptions) |
| 162 target_link_libraries(compiled PRIVATE |
| 163 "--post-js bindings.js" |
| 164 -O3 |
| 165 --emit-symbol-map |
| 166 "--memory-init-file 0" |
| 167 "-s ASM_JS=2" |
| 168 "-s TOTAL_MEMORY=16*1024*1024" |
| 169 "-s TOTAL_STACK=1*1024*1024" |
| 170 "-s ALLOW_MEMORY_GROWTH=1" |
| 171 "-s NO_EXIT_RUNTIME=1" |
| 172 "-s NO_DYNAMIC_EXECUTION=1" |
| 173 "-s NO_FILESYSTEM=1" |
| 174 "-s INVOKE_RUN=0" |
| 175 "-s TEXTDECODER=0" |
| 176 "-s EXPORTED_RUNTIME_METHODS=\"['cwrap','ccall','stringToA
scii']\"" |
| 177 "--js-library ${PROJECT_SOURCE_DIR}/compiled/library.js" |
| 178 ) |
| 179 # Use an absolute, native path for the SHELL_FILE argument |
| 180 file(GLOB SHELL_FILE compiled/shell.js) |
| 181 file(TO_NATIVE_PATH ${SHELL_FILE} SHELL_FILE) |
| 182 target_link_libraries(compiled PRIVATE "-s SHELL_FILE=\"'${SHELL_FILE}'\"") |
| 183 |
OLD | NEW |