|
| 1 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# This source code is licensed under the BSD-style license found in the |
| 5 | +# LICENSE file in the root directory of this source tree. |
| 6 | + |
| 7 | +# Please this file formatted by running: |
| 8 | +# ~~~ |
| 9 | +# cmake-format --first-comment-is-literal=True CMakeLists.txt |
| 10 | +# ~~~ |
| 11 | + |
| 12 | +cmake_minimum_required(VERSION 3.19) |
| 13 | + |
| 14 | +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 15 | +if(NOT CMAKE_CXX_STANDARD) |
| 16 | + set(CMAKE_CXX_STANDARD 17) |
| 17 | +endif() |
| 18 | + |
| 19 | +if(NOT PYTHON_EXECUTABLE) |
| 20 | + set(PYTHON_EXECUTABLE python3) |
| 21 | +endif() |
| 22 | +# Source root directory for executorch. |
| 23 | +if(NOT EXECUTORCH_ROOT) |
| 24 | + set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) |
| 25 | +endif() |
| 26 | + |
| 27 | +include(${EXECUTORCH_ROOT}/build/Utils.cmake) |
| 28 | + |
| 29 | +set(_common_include_directories ${EXECUTORCH_ROOT}/..) |
| 30 | +set(_common_compile_options -Wno-deprecated-declarations) |
| 31 | + |
| 32 | +set(_xnnpack_schema__include_dir "${CMAKE_BINARY_DIR}/schema/include") |
| 33 | +# Paths to headers generated from the .fbs files. |
| 34 | +set(_xnnpack_schema__outputs) |
| 35 | +foreach(fbs_file ${_xnnpack_schema__srcs}) |
| 36 | + string(REGEX REPLACE "serialization/([^/]+)[.]fbs$" "\\1_generated.h" |
| 37 | + generated "${fbs_file}") |
| 38 | + list(APPEND _xnnpack_schema__outputs |
| 39 | + "${_xnnpack_schema__include_dir}/executorch/${generated}") |
| 40 | +endforeach() |
| 41 | + |
| 42 | +# Generate the headers from the .fbs files. |
| 43 | +add_custom_command( |
| 44 | + OUTPUT ${_xnnpack_schema__outputs} |
| 45 | + COMMAND |
| 46 | + flatc --cpp --cpp-std c++11 --scoped-enums -o |
| 47 | + "${_xnnpack_schema__include_dir}/executorch/backends/xnnpack" |
| 48 | + ${_xnnpack_schema__srcs} |
| 49 | + WORKING_DIRECTORY ${EXECUTORCH_ROOT} |
| 50 | + COMMENT "Generating xnnpack_schema headers" |
| 51 | + VERBATIM) |
| 52 | + |
| 53 | +add_library(xnnpack_schema INTERFACE ${_xnnpack_schema__outputs}) |
| 54 | +set_target_properties(xnnpack_schema PROPERTIES LINKER_LANGUAGE CXX) |
| 55 | +target_include_directories( |
| 56 | + xnnpack_schema INTERFACE ${_xnnpack_schema__include_dir} |
| 57 | + ${EXECUTORCH_ROOT}/third-party/flatbuffers/include) |
| 58 | + |
| 59 | +set(xnn_executor_runner_libs ${_libs} xnnpack_schema) |
| 60 | + |
| 61 | +list(TRANSFORM _dynamic_quant_utils__srcs PREPEND "${EXECUTORCH_ROOT}/") |
| 62 | +add_library(dynamic_quant_utils ${_dynamic_quant_utils__srcs}) |
| 63 | +set_target_properties(dynamic_quant_utils PROPERTIES LINKER_LANGUAGE CXX) |
| 64 | +target_include_directories(dynamic_quant_utils |
| 65 | + PUBLIC ${_common_include_directories}) |
| 66 | +target_compile_options(dynamic_quant_utils PUBLIC ${_common_compile_options}) |
| 67 | + |
| 68 | +if(ENABLE_DYNAMIC_QUANTIZATION) |
| 69 | + list(APPEND xnn_executor_runner_libs dynamic_quant_utils) |
| 70 | +endif() |
| 71 | + |
| 72 | +include(cmake/Dependencies.cmake) |
| 73 | + |
| 74 | +list(TRANSFORM _xnnpack_backend__srcs PREPEND "${EXECUTORCH_ROOT}/") |
| 75 | +add_library(xnnpack_backend ${_xnnpack_backend__srcs}) |
| 76 | +target_link_libraries(xnnpack_backend PRIVATE ${xnn_executor_runner_libs}) |
| 77 | +target_include_directories(xnnpack_backend |
| 78 | + PUBLIC ${_common_include_directories}) |
| 79 | +target_include_directories(xnnpack_backend PUBLIC ${XNNPACK_INCLUDE_DIR}) |
| 80 | +target_compile_options(xnnpack_backend PUBLIC ${_common_compile_options}) |
| 81 | +target_link_options_shared_lib(xnnpack_backend) |
| 82 | + |
| 83 | +list(APPEND xnn_executor_runner_libs xnnpack_backend) |
| 84 | + |
| 85 | +# ios can only build library but not binary |
| 86 | +if(NOT CMAKE_TOOLCHAIN_FILE MATCHES ".*ios\.toolchain\.cmake$") |
| 87 | + # |
| 88 | + # xnn_executor_runner: Like executor_runner but with XNNPACK, the binary will |
| 89 | + # be at ${CMAKE_BINARY_DIR}/backends/xnnpack |
| 90 | + # |
| 91 | + list(TRANSFORM _xnn_executor_runner__srcs PREPEND "${EXECUTORCH_ROOT}/") |
| 92 | + add_executable(xnn_executor_runner ${_xnn_executor_runner__srcs}) |
| 93 | + target_link_libraries(xnn_executor_runner ${xnn_executor_runner_libs}) |
| 94 | + target_compile_options(xnn_executor_runner PUBLIC ${_common_compile_options}) |
| 95 | +endif() |
0 commit comments