forked from pytorch/executorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
129 lines (106 loc) · 3.78 KB
/
CMakeLists.txt
File metadata and controls
129 lines (106 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
#
# Simple CMake build system for selective build demo.
#
# ### Editing this file ###
#
# This file should be formatted with
# ~~~
# cmake-format --first-comment-is-literal=True CMakeLists.txt
# ~~~
# It should also be cmake-lint clean.
#
cmake_minimum_required(VERSION 3.19)
project(selective_build_example)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
set(TORCH_ROOT ${EXECUTORCH_ROOT}/third-party/pytorch)
include(${EXECUTORCH_ROOT}/build/Utils.cmake)
include(${EXECUTORCH_ROOT}/build/Codegen.cmake)
if(NOT PYTHON_EXECUTABLE)
resolve_python_executable()
endif()
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
# Can't set to 11 due to executor_runner.cpp make_unique
endif()
set(_common_compile_options -Wno-deprecated-declarations -fPIC)
# Let files say "include <executorch/path/to/header.h>".
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
find_package(executorch CONFIG REQUIRED)
find_package(
gflags REQUIRED PATHS ${CMAKE_CURRENT_BINARY_DIR}/../../third-party
)
target_include_directories(executorch INTERFACE ${_common_include_directories})
# ------------------------------ OPTIONS BEGIN -------------------------------
# Option to register ops from yaml file
option(EXECUTORCH_SELECT_OPS_YAML "Register all the ops from a given yaml file"
OFF)
# Option to register op list
option(EXECUTORCH_SELECT_OPS_LIST "Register a list of ops, separated by comma"
OFF)
# Selective build options.
option(EXECUTORCH_SELECT_ALL_OPS
"Whether to register all ops defined in portable kernel library." OFF)
# ------------------------------- OPTIONS END --------------------------------
#
# The `_<target>_srcs` lists are defined by including ${EXECUTORCH_SRCS_FILE}.
#
set(
EXECUTORCH_SRCS_FILE
"${CMAKE_CURRENT_BINARY_DIR}/../../executorch_srcs.cmake"
)
extract_sources(${EXECUTORCH_SRCS_FILE})
include(${EXECUTORCH_SRCS_FILE})
#
# select_build_lib: C++ library to register selected ops in custom kernel
# library
#
set(_kernel_lib)
if(EXECUTORCH_SELECT_OPS_YAML)
set(_custom_ops_yaml
${EXECUTORCH_ROOT}/examples/portable/custom_ops/custom_ops.yaml)
set(kernel_sources
${EXECUTORCH_ROOT}/examples/portable/custom_ops/custom_ops_1_out.cpp
${EXECUTORCH_ROOT}/examples/portable/custom_ops/custom_ops_2_out.cpp)
#
# custom_kernels: C++ kernel implementations of custom ops
#
add_library(custom_kernels ${kernel_sources})
target_link_libraries(custom_kernels PRIVATE executorch)
target_compile_options(custom_kernels PUBLIC ${_common_compile_options})
list(APPEND _kernel_lib custom_kernels)
else()
list(APPEND _kernel_lib portable_kernels)
endif()
gen_selected_ops(
"${_custom_ops_yaml}"
"${EXECUTORCH_SELECT_OPS_LIST}"
"${EXECUTORCH_SELECT_ALL_OPS}")
generate_bindings_for_kernels(
FUNCTIONS_YAML ${EXECUTORCH_ROOT}/kernels/portable/functions.yaml
CUSTOM_OPS_YAML "${_custom_ops_yaml}")
gen_operators_lib(
"select_build_lib"
KERNEL_LIBS ${_kernel_lib}
DEPS executorch)
list(TRANSFORM _executor_runner__srcs PREPEND "${EXECUTORCH_ROOT}/")
#
# selective_build_test: test binary to allow different operator libraries to
# link to
#
add_executable(selective_build_test ${_executor_runner__srcs})
if(CMAKE_BUILD_TYPE EQUAL "RELEASE")
target_link_options(selective_build_test PRIVATE "LINKER:--gc-sections")
endif()
target_link_libraries(
selective_build_test PRIVATE executorch gflags select_build_lib
)
target_link_options_shared_lib(select_build_lib)
target_link_options_shared_lib(executorch)
target_compile_options(selective_build_test PUBLIC ${_common_compile_options})
# Print all summary
executorch_print_configuration_summary()