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# Example CMakeLists.txt for building executor_runner with Developer Tools 8# support. In this example we link devtools and bundled_program libraries into 9# executor_runner binary 10cmake_minimum_required(VERSION 3.19) 11project(devtools_example) 12 13option(EXECUTORCH_BUILD_COREML "Build the Core ML backend" OFF) 14 15set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 16if(NOT CMAKE_CXX_STANDARD) 17 set(CMAKE_CXX_STANDARD 17) 18endif() 19 20# Source root directory for executorch. 21if(NOT EXECUTORCH_ROOT) 22 set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) 23endif() 24 25include(${EXECUTORCH_ROOT}/build/Utils.cmake) 26include(${EXECUTORCH_ROOT}/build/Codegen.cmake) 27 28if(NOT PYTHON_EXECUTABLE) 29 resolve_python_executable() 30endif() 31 32set(_common_compile_options -Wno-deprecated-declarations -fPIC) 33 34# Let files say "include <executorch/path/to/header.h>". 35set(_common_include_directories ${EXECUTORCH_ROOT}/..) 36 37# Find prebuilt libraries. executorch package should contain portable_ops_lib, 38# etdump, bundled_program. 39find_package(executorch CONFIG REQUIRED) 40target_link_options_shared_lib(executorch) 41target_link_options_shared_lib(portable_ops_lib) 42 43target_include_directories(executorch INTERFACE ${_common_include_directories}) 44 45find_package( 46 gflags REQUIRED PATHS ${CMAKE_CURRENT_BINARY_DIR}/../../third-party 47) 48 49add_executable(example_runner example_runner/example_runner.cpp) 50target_compile_options(executorch INTERFACE -DET_EVENT_TRACER_ENABLED) 51 52target_include_directories( 53 etdump INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/../../devtools/include 54 ${EXECUTORCH_ROOT}/third-party/flatcc/include 55) 56target_link_libraries( 57 example_runner 58 executorch 59 gflags 60 etdump 61 extension_data_loader 62 bundled_program 63 flatccrt 64 portable_ops_lib 65 portable_kernels 66) 67 68if(EXECUTORCH_BUILD_COREML) 69 find_library(ACCELERATE_FRAMEWORK Accelerate) 70 find_library(COREML_FRAMEWORK CoreML) 71 find_library(FOUNDATION_FRAMEWORK Foundation) 72 find_library(SQLITE_LIBRARY sqlite3) 73 74 set(PROTOBUF_LIB_DIR 75 ${CMAKE_CURRENT_BINARY_DIR}/../../backends/apple/coreml/third-party/coremltools/deps/protobuf/cmake 76 ) 77 find_library( 78 PROTOBUF_LITE REQUIRED 79 NAMES libprotobuf-lite.a 80 PATHS ${PROTOBUF_LIB_DIR} 81 NO_DEFAULT_PATH 82 ) 83 84 target_link_libraries( 85 example_runner "-Wl,-force_load" coremldelegate 86 ) 87 88 target_link_libraries( 89 example_runner ${PROTOBUF_LITE} ${ACCELERATE_FRAMEWORK} 90 ${COREML_FRAMEWORK} ${FOUNDATION_FRAMEWORK} ${SQLITE_LIBRARY} 91 ) 92endif() 93