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

Side by Side Diff: CMakeLists.txt

Issue 29556820: Working Draft: CMake build for Emscripten
Patch Set: Created Oct. 2, 2017, 6:25 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « .hgignore ('k') | README.CMAKE.md » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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")
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
21 "The Node interpreter was not found while setting up the Emscripten"
22 "toolchain.")
23 endif()
24
25 #
26 # Source file lists
27 # 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
29 # would generate build files with fixed lists of sources found at the time
30 # CMake runs. Afterwards, such a build would not discover new files created
31 # in the interim.
32 #
33 set(COMMON_SOURCES
34 compiled/bindings/runtime_utils.cpp
35 compiled/filter/ActiveFilter.cpp
36 compiled/filter/BlockingFilter.cpp
37 compiled/filter/CommentFilter.cpp
38 compiled/filter/ElemHideBase.cpp
39 compiled/filter/ElemHideEmulationFilter.cpp
40 compiled/filter/ElemHideException.cpp
41 compiled/filter/ElemHideFilter.cpp
42 compiled/filter/Filter.cpp
43 compiled/filter/InvalidFilter.cpp
44 compiled/filter/RegExpFilter.cpp
45 compiled/filter/WhitelistFilter.cpp
46 compiled/storage/FilterStorage.cpp
47 compiled/subscription/DownloadableSubscription.cpp
48 compiled/subscription/Subscription.cpp
49 compiled/subscription/UserDefinedSubscription.cpp
50 )
51 set(CORE_SPECIFIC_SOURCES
52 compiled/traceInit.cpp
53 )
54 set(BINDINGS_SPECIFIC_SOURCES
55 compiled/bindings/generator.cpp
56 compiled/bindings/main.cpp
57 )
58
59 set(BINDINGS_GENERATOR_SOURCES ${COMMON_SOURCES})
60 list(APPEND BINDINGS_GENERATOR_SOURCES ${BINDINGS_SPECIFIC_SOURCES})
61 list(SORT BINDINGS_GENERATOR_SOURCES)
62
63 set(CORE_SOURCES ${COMMON_SOURCES})
64 list(APPEND CORE_SOURCES ${CORE_SPECIFIC_SOURCES})
65 list(SORT CORE_SOURCES)
66
67 #
68 # Options for all targets
69 #
70 add_compile_options(-std=c++1z)
71
72 #
73 # Target: bindings-generator
74 #
75 add_executable(bindings-generator ${BINDINGS_GENERATOR_SOURCES})
76 #
77 # CMake overloads `target_link_libraries` for both libraries (as stated) and
78 # for linker flags (very much not as a stated). In order for CMake to
79 # recognize an option with parameter, that is, with an embedded space, it
80 # requires that it be quoted. This oddity is not well-documented in CMake.
81 #
82 target_link_libraries(bindings-generator
83 "--js-library compiled/library.js"
84 "--js-library compiled/bindings/library.js"
85 )
86
87 #
88 # Target: bindings
89 #
90 add_custom_target(bindings
91 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)
93 add_dependencies(bindings bindings-generator)
94
95 #
96 # Target: Core
97 #
98 add_executable(compiled ${CORE_SOURCES})
99 add_dependencies(compiled bindings)
100
101 target_compile_options(compiled PRIVATE
102 -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
108 "--post-js bindings.js"
109 -O3
110 --emit-symbol-map
111 "--memory-init-file 0"
112 "-s ASM_JS=2"
113 "-s TOTAL_MEMORY=16*1024*1024"
114 "-s TOTAL_STACK=1*1024*1024"
115 "-s ALLOW_MEMORY_GROWTH=1"
116 "-s NO_EXIT_RUNTIME=1"
117 "-s NO_DYNAMIC_EXECUTION=1"
118 "-s NO_FILESYSTEM=1"
119 "-s INVOKE_RUN=0"
120 "-s TEXTDECODER=0"
121 "-s EXPORTED_RUNTIME_METHODS=\"['cwrap','ccall','stringToA scii']\""
122 "--js-library compiled/library.js"
123 )
124 #
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)
131 file(TO_NATIVE_PATH ${SHELL_FILE} SHELL_FILE)
132 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
134 # Debugging
135 target_link_libraries(compiled PRIVATE -g3)
OLDNEW
« no previous file with comments | « .hgignore ('k') | README.CMAKE.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld