|
4 | 4 | # This source code is licensed under the BSD-style license found in the |
5 | 5 | # LICENSE file in the root directory of this source tree. |
6 | 6 |
|
7 | | -# Please this file formatted by running: |
8 | | -# ~~~ |
9 | | -# cmake-format -i CMakeLists.txt |
10 | | -# ~~~ |
11 | | - |
12 | | -cmake_minimum_required(VERSION 3.19) |
13 | | - |
14 | | -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
15 | | - |
16 | | -set(_flatcc_source_dir ${CMAKE_CURRENT_SOURCE_DIR}/../third-party/flatcc) |
17 | | - |
18 | | -if(NOT CMAKE_CXX_STANDARD) |
19 | | - set(CMAKE_CXX_STANDARD 17) |
20 | | -endif() |
21 | | - |
22 | | -if(NOT FLATCC_EXECUTABLE) |
23 | | - if(WIN32) |
24 | | - set(FLATCC_EXECUTABLE ${_flatcc_source_dir}/bin/${CMAKE_BUILD_TYPE}/flatcc) |
25 | | - else() |
26 | | - set(FLATCC_EXECUTABLE ${_flatcc_source_dir}/bin/flatcc) |
27 | | - endif() |
28 | | -endif() |
29 | | - |
30 | | -# Source root directory for executorch. |
31 | | -if(NOT EXECUTORCH_ROOT) |
32 | | - set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) |
33 | | -endif() |
34 | | - |
35 | | -include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) |
36 | | - |
37 | | -if(NOT PYTHON_EXECUTABLE) |
38 | | - resolve_python_executable() |
39 | | -endif() |
40 | | - |
41 | | -# Paths to headers generated from the .fbs files. set(_etdump_schemas |
42 | | -# etdump_schema_flatcc.fbs scalar_type.fbs) |
43 | | - |
44 | | -set(_etdump_schema_names "etdump_schema_flatcc.fbs" "scalar_type.fbs") |
45 | | -set(_bundled_input_schema_names "bundled_program_schema.fbs" "scalar_type.fbs") |
46 | | - |
47 | | -foreach(schema_file ${_etdump_schema_names}) |
48 | | - list(APPEND _etdump_schema__srcs |
49 | | - "${CMAKE_CURRENT_SOURCE_DIR}/etdump/${schema_file}" |
50 | | - ) |
51 | | -endforeach() |
52 | | - |
53 | | -foreach(schema_file ${_bundled_input_schema_names}) |
54 | | - list(APPEND _bundled_program_schema__srcs |
55 | | - "${CMAKE_CURRENT_SOURCE_DIR}/bundled_program/schema/${schema_file}" |
56 | | - ) |
57 | | -endforeach() |
58 | | - |
59 | | -set(FLATCC_TEST |
60 | | - OFF |
61 | | - CACHE BOOL "" |
62 | | -) |
63 | | -set(FLATCC_REFLECTION |
64 | | - OFF |
65 | | - CACHE BOOL "" |
66 | | -) |
67 | | -set(FLATCC_DEBUG_CLANG_SANITIZE |
68 | | - OFF |
69 | | - CACHE BOOL "" |
70 | | -) |
71 | | - |
72 | | -add_subdirectory(${_flatcc_source_dir} ${CMAKE_BINARY_DIR}/third-party/flatcc) |
73 | | - |
74 | | -# Fix for "relocation R_X86_64_32 against `.rodata' can not be used when making |
75 | | -# a shared object; recompile with -fPIC" when building on some x86 linux |
76 | | -# systems. |
77 | | -set_property(TARGET flatccrt PROPERTY POSITION_INDEPENDENT_CODE ON) |
78 | | - |
79 | | -# Assume we are cross-compiling and the CMAKE_TOOLCHAIN_FILE is set |
80 | | -include(ExternalProject) |
81 | | - |
82 | 7 | # The include directory that will contain the generated schema headers. |
83 | | -set(_program_schema__include_dir "${CMAKE_BINARY_DIR}/devtools/include") |
84 | | -set(_bundled_schema__include_dir "${CMAKE_BINARY_DIR}/devtools/bundled_program") |
85 | | - |
86 | | -# TODO(dbort): Only enable this when cross-compiling. It can cause build race |
87 | | -# conditions (libflatcc.a errors) when enabled. |
88 | | -option(EXECUTORCH_SEPARATE_FLATCC_HOST_PROJECT |
89 | | - "Whether to build the flatcc commandline tool as a separate project" ON |
90 | | -) |
91 | | - |
92 | | -if(EXECUTORCH_SEPARATE_FLATCC_HOST_PROJECT) |
93 | | - # Add the host project. We build this separately so that we can generate |
94 | | - # headers on the host during the build, even if we're cross-compiling the |
95 | | - # flatcc runtime to a different architecture. |
96 | | - execute_process( |
97 | | - COMMAND |
98 | | - ${CMAKE_COMMAND} ${_flatcc_source_dir} -DFLATCC_TEST=OFF |
99 | | - -DFLATCC_REFLECTION=OFF |
100 | | - # See above comment about POSITION_INDEPENDENT_CODE. |
101 | | - -DCMAKE_POSITION_INDEPENDENT_CODE=ON -B${CMAKE_BINARY_DIR}/_host_build |
102 | | - ) |
103 | | - execute_process( |
104 | | - COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/_host_build |
105 | | - ) |
106 | | - set(_etdump_schema_gen_dep) |
107 | | - # TODO(dbort): flatcc installs its files directly in its source directory |
108 | | - # instead of under CMAKE_BINARY_DIR, and it has no options to avoid doing |
109 | | - # this. We build flatcc twice in the executorch build: once to get the |
110 | | - # `flatcc` host commandline tool, and once to get the (potentially |
111 | | - # cross-compiled) target runtime library. The host build will put its outputs |
112 | | - # in the source tree, making the cross-compiling target build think that the |
113 | | - # outputs have already been built. It will then try to link against the |
114 | | - # host-architecture libraries, failing when cross-compiling. To work around |
115 | | - # this, delete the host outputs after running this command (which only runs |
116 | | - # when setting up the cmake files, not when actually building). This leaves |
117 | | - # room for the target build to put its own files in the source tree. We should |
118 | | - # try to remove this hack, ideally by submitting an upstream PR that adds an |
119 | | - # option to change the installation location. |
120 | | - set(_etdump_schema_cleanup_paths ${_flatcc_source_dir}/bin/* |
121 | | - ${_flatcc_source_dir}/lib/* |
122 | | - ) |
123 | | -else() |
124 | | - # If we're not cross-compiling, we can just use the plain commandline target. |
125 | | - set(_etdump_schema_gen_dep flatcc_cli) |
126 | | - set(_etdump_schema_cleanup_paths "") |
127 | | -endif() |
128 | | - |
129 | | -set(_etdump_schema__outputs) |
130 | | -foreach(fbs_file ${_etdump_schema_names}) |
131 | | - string(REGEX REPLACE "[.]fbs$" "_reader.h" generated "${fbs_file}") |
132 | | - list(APPEND _etdump_schema__outputs |
133 | | - "${_program_schema__include_dir}/executorch/devtools/etdump/${generated}" |
134 | | - ) |
135 | | - string(REGEX REPLACE "[.]fbs$" "_builder.h" generated "${fbs_file}") |
136 | | - list(APPEND _etdump_schema__outputs |
137 | | - "${_program_schema__include_dir}/executorch/devtools/etdump/${generated}" |
138 | | - ) |
139 | | -endforeach() |
140 | | - |
141 | | -# lint_cmake: -linelength |
142 | | -set(_bundled_program_schema__outputs) |
143 | | -foreach(fbs_file ${_bundled_input_schema_names}) |
144 | | - string(REGEX REPLACE "[.]fbs$" "_generated.h" generated "${fbs_file}") |
145 | | - list( |
146 | | - APPEND |
147 | | - _bundled_program_schema__outputs |
148 | | - "${_bundled_schema__include_dir}/executorch/devtools/bundled_program/schema/${generated}" |
149 | | - ) |
150 | | -endforeach() |
151 | | - |
152 | | -add_library(etdump_schema INTERFACE ${_etdump_schema__outputs}) |
153 | | -add_library( |
154 | | - bundled_program_schema INTERFACE ${_bundled_program_schema__outputs} |
155 | | -) |
156 | | - |
157 | | -file(MAKE_DIRECTORY ${_program_schema__include_dir}/executorch/devtools/etdump) |
158 | | -file(MAKE_DIRECTORY |
159 | | - ${_program_schema__include_dir}/executorch/devtools/bundled_program |
160 | | -) |
161 | | - |
162 | | -if(WIN32) |
163 | | - set(RM_COMMAND rmdir /s /q) |
164 | | -else() |
165 | | - set(RM_COMMAND rm -rf) |
166 | | -endif() |
167 | | - |
168 | | -add_custom_command( |
169 | | - OUTPUT ${_etdump_schema__outputs} |
170 | | - COMMAND |
171 | | - # Note that the flatcc project actually writes its outputs into the source |
172 | | - # tree instead of under the binary directory, and there's no way to change |
173 | | - # that behavior. |
174 | | - ${FLATCC_EXECUTABLE} -cwr -o |
175 | | - ${_program_schema__include_dir}/executorch/devtools/etdump |
176 | | - ${_etdump_schema__srcs} |
177 | | - COMMAND ${RM_COMMAND} ${_etdump_schema_cleanup_paths} |
178 | | - DEPENDS ${_etdump_schema_gen_dep} |
179 | | - COMMENT "Generating etdump headers" |
180 | | -) |
181 | | - |
182 | | -unset(RM_COMMAND) |
183 | | - |
184 | | -add_library( |
185 | | - etdump ${CMAKE_CURRENT_SOURCE_DIR}/etdump/etdump_flatcc.cpp |
186 | | - ${CMAKE_CURRENT_SOURCE_DIR}/etdump/emitter.cpp |
187 | | - ${CMAKE_CURRENT_SOURCE_DIR}/etdump/data_sinks/buffer_data_sink.cpp |
188 | | - ${CMAKE_CURRENT_SOURCE_DIR}/etdump/data_sinks/buffer_data_sink.h |
189 | | - ${CMAKE_CURRENT_SOURCE_DIR}/etdump/data_sinks/file_data_sink.cpp |
190 | | - ${CMAKE_CURRENT_SOURCE_DIR}/etdump/data_sinks/file_data_sink.h |
191 | | -) |
192 | | - |
193 | | -target_link_libraries( |
194 | | - etdump |
195 | | - PUBLIC etdump_schema flatccrt |
196 | | - PRIVATE executorch |
197 | | -) |
198 | | - |
199 | | -add_custom_command( |
200 | | - OUTPUT ${_bundled_program_schema__outputs} |
201 | | - COMMAND |
202 | | - flatc --cpp --cpp-std c++11 --gen-mutable --scoped-enums -o |
203 | | - "${_bundled_schema__include_dir}/executorch/devtools/bundled_program/schema" |
204 | | - ${_bundled_program_schema__srcs} |
205 | | - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/devtools |
206 | | - DEPENDS flatc ${_bundled_program_schema__srcs} |
207 | | - COMMENT "Generating bundled_program headers" |
208 | | - VERBATIM |
209 | | -) |
210 | | - |
211 | | -# add_library(bundled_program INTERFACE ${_bundled_program_schema__outputs}) |
212 | | -add_library( |
213 | | - bundled_program |
214 | | - ${CMAKE_CURRENT_SOURCE_DIR}/bundled_program/bundled_program.cpp |
215 | | -) |
216 | | -target_link_libraries(bundled_program executorch bundled_program_schema) |
217 | | - |
218 | | -set_target_properties(bundled_program PROPERTIES LINKER_LANGUAGE CXX) |
219 | | -target_include_directories( |
220 | | - bundled_program PUBLIC ${_bundled_schema__include_dir} |
221 | | - ${EXECUTORCH_ROOT}/third-party/flatbuffers/include |
222 | | -) |
223 | | - |
224 | | -target_include_directories( |
225 | | - etdump PUBLIC ${_program_schema__include_dir} ${_flatcc_source_dir}/include |
226 | | -) |
227 | | - |
228 | | -# Install libraries |
229 | | -install( |
230 | | - TARGETS bundled_program etdump flatccrt |
231 | | - DESTINATION ${CMAKE_BINARY_DIR}/lib |
232 | | - INCLUDES |
233 | | - DESTINATION ${_common_include_directories} |
234 | | -) |
| 8 | +set(DEVTOOLS_INCLUDE_DIR "${CMAKE_BINARY_DIR}/devtools/include") |
235 | 9 |
|
236 | | -if(BUILD_TESTING) |
237 | | - # TODO: This is currently not working! |
238 | | - # add_subdirectory(etdump/tests) |
239 | | -endif() |
| 10 | +add_subdirectory(etdump) |
| 11 | +add_subdirectory(bundled_program) |
0 commit comments