Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 # Set the minimum we require to the minimum that Emscripten requires. | 1 # Set the minimum we require to the minimum that Emscripten requires. |
2 # See the Emscripten toolchain file for details. | 2 # See the Emscripten toolchain file for details. |
3 cmake_minimum_required(VERSION 3.4.3) | 3 cmake_minimum_required(VERSION 3.4.3) |
4 project (adblockpluscore) | |
4 | 5 |
5 project (adblockpluscore) | 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) | |
6 | 63 |
7 # | 64 # |
8 # Sanity check that the tool chain is set up correctly. | 65 # Sanity check that the tool chain is set up correctly. |
9 # | 66 # |
10 if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten") | 67 if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten") |
11 message(FATAL_ERROR | 68 message(FATAL_ERROR |
12 "The Emscripten toolchain does not appear is not installed in the" | 69 "The Emscripten toolchain does not appear is not installed in the" |
13 "CMake cache. Please follow the instructions in README.CMAKE.") | 70 "CMake cache. Please follow the instructions in README.CMAKE.") |
14 endif() | 71 endif() |
15 | 72 |
16 # | 73 # |
17 # Node.js is required to generate the bindings file. | 74 # Node.js is required to generate the bindings file. |
18 # | 75 # |
19 if (${NODE_JS_EXECUTABLE} MATCHES "NOTFOUND") | 76 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
| |
20 message(FATAL_ERROR | 77 message(FATAL_ERROR |
21 "The Node interpreter was not found while setting up the Emscripten" | 78 "The Node interpreter was not found while setting up the Emscripten" |
22 "toolchain.") | 79 "toolchain.") |
23 endif() | 80 endif() |
24 | 81 |
25 # | 82 # |
26 # Source file lists | 83 # Source file lists |
27 # We don't use globbing. CMakes expands a globbing expression at the time it | 84 # We don't use globbing. CMakes expands a globbing expression at the time it |
28 # runs, not at the time the build runs. Thus if we were to use globbing, we | 85 # runs, not at the time the build runs. Thus if we were to use globbing, we |
29 # would generate build files with fixed lists of sources found at the time | 86 # would generate build files with fixed lists of sources found at the time |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 # | 124 # |
68 # Options for all targets | 125 # Options for all targets |
69 # | 126 # |
70 add_compile_options(-std=c++1z) | 127 add_compile_options(-std=c++1z) |
71 | 128 |
72 # | 129 # |
73 # Target: bindings-generator | 130 # Target: bindings-generator |
74 # | 131 # |
75 add_executable(bindings-generator ${BINDINGS_GENERATOR_SOURCES}) | 132 add_executable(bindings-generator ${BINDINGS_GENERATOR_SOURCES}) |
76 # | 133 # |
77 # CMake overloads `target_link_libraries` for both libraries (as stated) and | 134 # CMake overloads `target_link_libraries` for both libraries (as named) and |
78 # for linker flags (very much not as a stated). In order for CMake to | 135 # for linker flags (very much not as named). In order for CMake to recognize |
79 # recognize an option with parameter, that is, with an embedded space, it | 136 # an option with parameter, that is, with an embedded space, it requires that |
80 # requires that it be quoted. This oddity is not well-documented in CMake. | 137 # it be quoted. This oddity is not well-documented in CMake. |
81 # | 138 # |
82 target_link_libraries(bindings-generator | 139 target_link_libraries(bindings-generator |
83 "--js-library compiled/library.js" | 140 "--js-library ${PROJECT_SOURCE_DIR}/compiled/library.js" |
84 "--js-library compiled/bindings/library.js" | 141 "--js-library ${PROJECT_SOURCE_DIR}/compiled/bindings/libr ary.js" |
85 ) | 142 ) |
86 | 143 |
87 # | 144 # |
88 # Target: bindings | 145 # File: bindings.js |
89 # | 146 # |
90 add_custom_target(bindings | 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 | |
91 COMMAND ${NODE_JS_EXECUTABLE} bindings-generator >bindings.js | 152 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
| |
92 BYPRODUCTS bindings) | 153 DEPENDS bindings-generator |
93 add_dependencies(bindings bindings-generator) | 154 BYPRODUCTS bindings.js) |
94 | 155 |
95 # | 156 # |
96 # Target: Core | 157 # Target: Core |
97 # | 158 # |
98 add_executable(compiled ${CORE_SOURCES}) | 159 add_executable(compiled ${CORE_SOURCES} bindings.js) |
99 add_dependencies(compiled bindings) | |
100 | |
101 target_compile_options(compiled PRIVATE | 160 target_compile_options(compiled PRIVATE |
102 -O3 -m32 -Wall -Werror -fno-rtti -fno-exceptions) | 161 -O3 -m32 -Wall -Werror -fno-rtti -fno-exceptions) |
103 | |
104 # Debugging | |
105 target_compile_options(compiled PRIVATE -g3) | |
106 | |
107 target_link_libraries(compiled PRIVATE | 162 target_link_libraries(compiled PRIVATE |
108 "--post-js bindings.js" | 163 "--post-js bindings.js" |
109 -O3 | 164 -O3 |
110 --emit-symbol-map | 165 --emit-symbol-map |
111 "--memory-init-file 0" | 166 "--memory-init-file 0" |
112 "-s ASM_JS=2" | 167 "-s ASM_JS=2" |
113 "-s TOTAL_MEMORY=16*1024*1024" | 168 "-s TOTAL_MEMORY=16*1024*1024" |
114 "-s TOTAL_STACK=1*1024*1024" | 169 "-s TOTAL_STACK=1*1024*1024" |
115 "-s ALLOW_MEMORY_GROWTH=1" | 170 "-s ALLOW_MEMORY_GROWTH=1" |
116 "-s NO_EXIT_RUNTIME=1" | 171 "-s NO_EXIT_RUNTIME=1" |
117 "-s NO_DYNAMIC_EXECUTION=1" | 172 "-s NO_DYNAMIC_EXECUTION=1" |
118 "-s NO_FILESYSTEM=1" | 173 "-s NO_FILESYSTEM=1" |
119 "-s INVOKE_RUN=0" | 174 "-s INVOKE_RUN=0" |
120 "-s TEXTDECODER=0" | 175 "-s TEXTDECODER=0" |
121 "-s EXPORTED_RUNTIME_METHODS=\"['cwrap','ccall','stringToA scii']\"" | 176 "-s EXPORTED_RUNTIME_METHODS=\"['cwrap','ccall','stringToA scii']\"" |
122 "--js-library compiled/library.js" | 177 "--js-library ${PROJECT_SOURCE_DIR}/compiled/library.js" |
123 ) | 178 ) |
124 # | 179 # Use an absolute, native path for the SHELL_FILE argument |
125 # The interaction between command line parsing of "-s SHELL_FILE=" and Windows | |
126 # path names with backslashes is, frankly, insane. It's left as an exercise, | |
127 # that is, waste of time, for the reader to divine all the levels of quoting | |
128 # required to make it work. | |
129 # | |
130 file(GLOB SHELL_FILE compiled/shell.js) | 180 file(GLOB SHELL_FILE compiled/shell.js) |
131 file(TO_NATIVE_PATH ${SHELL_FILE} SHELL_FILE) | 181 file(TO_NATIVE_PATH ${SHELL_FILE} SHELL_FILE) |
132 target_link_libraries(compiled PRIVATE "-s SHELL_FILE=\"\\\"${SHELL_FILE}\\\"\"" ) | 182 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.
| |
133 | 183 |
134 # Debugging | |
135 target_link_libraries(compiled PRIVATE -g3) | |
LEFT | RIGHT |