From 7a690f8cf8aec5a170d677ffebda28ba49c479c9 Mon Sep 17 00:00:00 2001 From: RJ Ascani Date: Fri, 28 Aug 2026 11:43:12 -0700 Subject: [PATCH] Make CMake builds independent of checkout name Remove the requirement that the repository directory itself be named executorch. Generate a checkout-local include root in the build tree, route build-time include paths through it, and retain the public executorch/... include namespace and installed layout. Review this commit by starting with tools/cmake/Utils.cmake and the top-level CMakeLists.txt, then checking the standalone backend and example entrypoints, and finally test/test_worktree_build.sh. Authored with assistance from Codex. --- .ci/scripts/unittest-linux.sh | 4 + .ci/scripts/utils.sh | 7 +- CMakeLists.txt | 20 ++--- backends/aoti/CMakeLists.txt | 7 +- backends/apple/coreml/CMakeLists.txt | 4 +- backends/arm/CMakeLists.txt | 6 +- backends/cadence/CMakeLists.txt | 8 +- .../fusion_g3/operators/CMakeLists.txt | 8 +- .../cadence/generic/kernels/CMakeLists.txt | 3 +- .../cadence/generic/operators/CMakeLists.txt | 10 ++- backends/cadence/hifi/kernels/CMakeLists.txt | 3 +- .../cadence/hifi/operators/CMakeLists.txt | 10 ++- .../hifi/operators/tests/CMakeLists.txt | 3 +- .../cadence/vision/kernels/CMakeLists.txt | 3 +- .../cadence/vision/operators/CMakeLists.txt | 11 ++- backends/cortex_m/CMakeLists.txt | 5 +- backends/cuda/CMakeLists.txt | 5 +- .../cuda/runtime/shims/tests/CMakeLists.txt | 23 +++-- backends/mediatek/CMakeLists.txt | 2 +- backends/mlx/examples/llm/CMakeLists.txt | 5 +- backends/nxp/CMakeLists.txt | 2 +- backends/openvino/CMakeLists.txt | 9 +- backends/qualcomm/CMakeLists.txt | 4 +- backends/samsung/CMakeLists.txt | 2 +- backends/vulkan/CMakeLists.txt | 5 +- backends/vulkan/cmake/ShaderLibrary.cmake | 4 +- backends/vulkan/test/CMakeLists.txt | 8 +- .../vulkan/test/custom_ops/CMakeLists.txt | 7 +- backends/vulkan/test/op_tests/CMakeLists.txt | 5 +- backends/webgpu/CMakeLists.txt | 11 ++- codegen/tools/CMakeLists.txt | 2 +- examples/arm/executor_runner/CMakeLists.txt | 20 ++--- .../runtime/CMakeLists.txt | 4 +- .../runtime/CMakeLists.txt | 4 +- .../runtime/CMakeLists.txt | 4 +- examples/cadence/CMakeLists.txt | 10 ++- examples/devtools/CMakeLists.txt | 5 +- .../espressif/executor_runner/CMakeLists.txt | 12 ++- examples/llm_server/cpp/CMakeLists.txt | 5 +- examples/mediatek/CMakeLists.txt | 6 +- .../llama_runner/CMakeLists.txt | 6 +- examples/models/dinov2/CMakeLists.txt | 5 +- examples/models/gemma3/CMakeLists.txt | 5 +- examples/models/gemma4/CMakeLists.txt | 5 +- examples/models/gemma4_31b/CMakeLists.txt | 5 +- examples/models/llama/CMakeLists.txt | 5 +- examples/models/llama/runner/CMakeLists.txt | 5 +- examples/models/llava/CMakeLists.txt | 5 +- examples/models/muse-glimmer/CMakeLists.txt | 5 +- examples/models/parakeet/CMakeLists.txt | 5 +- examples/models/phi-3-mini/CMakeLists.txt | 7 +- examples/models/qwen3_5_moe/CMakeLists.txt | 5 +- examples/models/silero_vad/CMakeLists.txt | 5 +- examples/models/sortformer/CMakeLists.txt | 5 +- examples/models/supertonic/CMakeLists.txt | 5 +- examples/models/voxtral/CMakeLists.txt | 5 +- .../models/voxtral_realtime/CMakeLists.txt | 5 +- examples/models/voxtral_tts/CMakeLists.txt | 5 +- examples/models/whisper/CMakeLists.txt | 5 +- examples/models/yolo26/CMakeLists.txt | 5 +- examples/portable/custom_ops/CMakeLists.txt | 5 +- examples/qualcomm/CMakeLists.txt | 5 +- exir/backend/test/demos/rpc/CMakeLists.txt | 5 +- extension/wasm/CMakeLists.txt | 5 +- extension/wasm/tokenizers/CMakeLists.txt | 5 +- runtime/kernel/test/CMakeLists.txt | 6 +- test/CMakeLists.txt | 5 +- test/run_oss_cpp_tests.sh | 6 +- test/test_worktree_build.sh | 52 +++++++++++ tools/cmake/Utils.cmake | 87 +++++++++++++++++++ 70 files changed, 437 insertions(+), 123 deletions(-) create mode 100755 test/test_worktree_build.sh diff --git a/.ci/scripts/unittest-linux.sh b/.ci/scripts/unittest-linux.sh index a2ca9f5134e..8808f4e6cf1 100755 --- a/.ci/scripts/unittest-linux.sh +++ b/.ci/scripts/unittest-linux.sh @@ -11,6 +11,10 @@ source "$(dirname "${BASH_SOURCE[0]}")/utils.sh" read -r BUILD_TOOL BUILD_MODE EDITABLE < <(parse_args "$@") +if [[ "$BUILD_TOOL" == "cmake" && -z "${EXECUTORCH_CMAKE_SOURCE_DIR:-}" ]]; then + exec bash test/test_worktree_build.sh "$0" "$@" +fi + # The generic Linux job chooses to use base env, not the one setup by the image eval "$(conda shell.bash hook)" CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]") diff --git a/.ci/scripts/utils.sh b/.ci/scripts/utils.sh index 234e162e48e..9b997a3436a 100644 --- a/.ci/scripts/utils.sh +++ b/.ci/scripts/utils.sh @@ -211,7 +211,12 @@ build_executorch_runner_cmake() { -DCMAKE_BUILD_TYPE="${build_type}" \ ${sanitizer_flag} \ ${CMAKE_ARGS:-} \ - -B${CMAKE_OUTPUT_DIR} . + -B${CMAKE_OUTPUT_DIR} "${EXECUTORCH_CMAKE_SOURCE_DIR:-.}" + + if [[ -n "${EXECUTORCH_CMAKE_SOURCE_DIR:-}" ]]; then + test "${CMAKE_OUTPUT_DIR}/executorch_source_include/executorch" \ + -ef "${EXECUTORCH_CMAKE_SOURCE_DIR}" + fi if [ "$(uname)" == "Darwin" ]; then CMAKE_JOBS=$(( $(sysctl -n hw.ncpu) - 1 )) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40cbef38abe..707a24ee5b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,6 +113,10 @@ include(CMakeDependentOption) include(ExternalProject) include(GNUInstallDirs) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) + if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) endif() @@ -523,22 +527,8 @@ if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE list(APPEND _common_compile_options $<$>:-fPIC>) endif() -# Let files say "include ". -# TODO(#6475): This requires/assumes that the repo lives in a directory named -# exactly `executorch`. Check the assumption first. Remove this check once we -# stop relying on the assumption. -cmake_path(GET CMAKE_CURRENT_SOURCE_DIR FILENAME _repo_dir_name) -if(NOT "${_repo_dir_name}" STREQUAL "executorch") - message( - FATAL_ERROR - "The ExecuTorch repo must be cloned into a directory named exactly " - "`executorch`; found `${_repo_dir_name}`. See " - "https://github.com/pytorch/executorch/issues/6475 for progress on a " - "fix for this restriction." - ) -endif() set(_common_include_directories - $ + $ $ $ $ diff --git a/backends/aoti/CMakeLists.txt b/backends/aoti/CMakeLists.txt index 5ba98c67f20..09af0c9551f 100644 --- a/backends/aoti/CMakeLists.txt +++ b/backends/aoti/CMakeLists.txt @@ -23,6 +23,9 @@ endif() # Use ExecuTorch's standard way to find PyTorch libraries for AOTI include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) find_package_torch() # ============================================================================== @@ -34,7 +37,7 @@ add_library(aoti_common STATIC ${_aoti_common_sources}) target_include_directories( aoti_common PUBLIC $ $ - $ + $ ) target_compile_options( aoti_common @@ -73,7 +76,7 @@ add_library(slimtensor INTERFACE) target_include_directories( slimtensor INTERFACE $ - $ + $ $ $ ) diff --git a/backends/apple/coreml/CMakeLists.txt b/backends/apple/coreml/CMakeLists.txt index 4b7b4e70c13..1c79910947c 100644 --- a/backends/apple/coreml/CMakeLists.txt +++ b/backends/apple/coreml/CMakeLists.txt @@ -217,7 +217,9 @@ if(APPLE) target_include_directories( coremldelegate PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/runtime/delegate ) - target_include_directories(coremldelegate PRIVATE ${PROJECT_SOURCE_DIR}/..) + target_include_directories( + coremldelegate PRIVATE ${EXECUTORCH_SOURCE_INCLUDE_DIR} + ) target_include_directories( coremldelegate PRIVATE ${PROJECT_SOURCE_DIR}/runtime/core/portable_type/c10 ) diff --git a/backends/arm/CMakeLists.txt b/backends/arm/CMakeLists.txt index 45640e8f3dd..364f63f501b 100644 --- a/backends/arm/CMakeLists.txt +++ b/backends/arm/CMakeLists.txt @@ -15,9 +15,13 @@ endif() include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) include(${EXECUTORCH_ROOT}/backends/arm/scripts/corstone_utils.cmake) include(${EXECUTORCH_ROOT}/backends/arm/cmake/ArmEthosUSDK.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) set(_common_include_directories - ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 + ${EXECUTORCH_SOURCE_INCLUDE_DIR} + ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 ) add_compile_definitions(C10_USING_CUSTOM_GENERATED_MACROS) diff --git a/backends/cadence/CMakeLists.txt b/backends/cadence/CMakeLists.txt index c4bcd47f343..b8825ba7ba1 100644 --- a/backends/cadence/CMakeLists.txt +++ b/backends/cadence/CMakeLists.txt @@ -20,10 +20,14 @@ if(NOT EXECUTORCH_ROOT) endif() include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) # Let files say "include ". set(_common_include_directories - ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 + ${EXECUTORCH_SOURCE_INCLUDE_DIR} + ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 ) add_compile_definitions(C10_USING_CUSTOM_GENERATED_MACROS) @@ -59,7 +63,7 @@ if(EXECUTORCH_CADENCE_CPU_RUNNER) ) target_include_directories( - cadence_runner PUBLIC ${ROOT_DIR}/.. ${CMAKE_BINARY_DIR} + cadence_runner PUBLIC ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${CMAKE_BINARY_DIR} ${_common_include_directories} ) diff --git a/backends/cadence/fusion_g3/operators/CMakeLists.txt b/backends/cadence/fusion_g3/operators/CMakeLists.txt index a9501c687bb..ce5e11053ac 100644 --- a/backends/cadence/fusion_g3/operators/CMakeLists.txt +++ b/backends/cadence/fusion_g3/operators/CMakeLists.txt @@ -13,6 +13,9 @@ endif() include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) # ATen compliant ops that are needed to run this model. set(_aten_ops__srcs @@ -70,13 +73,14 @@ target_link_libraries(aten_ops_cadence PRIVATE xa_nnlib) # Let files say "include ". set(_common_include_directories - ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 + ${EXECUTORCH_SOURCE_INCLUDE_DIR} + ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 ) target_include_directories( aten_ops_cadence PUBLIC - ${ROOT_DIR}/.. + ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${CMAKE_BINARY_DIR} ${_common_include_directories} ${EXECUTORCH_ROOT}/backends/cadence/fusion_g3/third-party/nnlib/nnlib-FusionG3/xa_nnlib/algo/common/include/ diff --git a/backends/cadence/generic/kernels/CMakeLists.txt b/backends/cadence/generic/kernels/CMakeLists.txt index 5af049418ce..adcaf91af91 100644 --- a/backends/cadence/generic/kernels/CMakeLists.txt +++ b/backends/cadence/generic/kernels/CMakeLists.txt @@ -9,7 +9,8 @@ add_library(cadence_kernels kernels.cpp) # Let files say "include ". set(_common_include_directories - ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 + ${EXECUTORCH_SOURCE_INCLUDE_DIR} + ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 ) target_include_directories( diff --git a/backends/cadence/generic/operators/CMakeLists.txt b/backends/cadence/generic/operators/CMakeLists.txt index dbf06e56bee..07862b90a38 100644 --- a/backends/cadence/generic/operators/CMakeLists.txt +++ b/backends/cadence/generic/operators/CMakeLists.txt @@ -13,6 +13,9 @@ endif() include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) # ATen compliant ops that are needed to run this model. set(_aten_ops__srcs @@ -73,11 +76,12 @@ target_link_libraries(aten_ops_cadence PRIVATE cadence_kernels) # Let files say "include ". set(_common_include_directories - ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 + ${EXECUTORCH_SOURCE_INCLUDE_DIR} + ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 ) target_include_directories( - aten_ops_cadence PUBLIC ${ROOT_DIR}/.. ${CMAKE_BINARY_DIR} + aten_ops_cadence PUBLIC ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${CMAKE_BINARY_DIR} ${_common_include_directories} ) @@ -86,7 +90,7 @@ file(GLOB custom_ops_srcs "*.cpp") add_library(custom_ops ${custom_ops_srcs}) target_include_directories( - custom_ops PUBLIC ${ROOT_DIR}/.. ${CMAKE_BINARY_DIR} + custom_ops PUBLIC ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${CMAKE_BINARY_DIR} ${_common_include_directories} ) diff --git a/backends/cadence/hifi/kernels/CMakeLists.txt b/backends/cadence/hifi/kernels/CMakeLists.txt index a7ea9f5963c..942beb91128 100644 --- a/backends/cadence/hifi/kernels/CMakeLists.txt +++ b/backends/cadence/hifi/kernels/CMakeLists.txt @@ -20,7 +20,8 @@ add_library( ) # Let files say "include ". set(_common_include_directories - ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 + ${EXECUTORCH_SOURCE_INCLUDE_DIR} + ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 ) target_include_directories( diff --git a/backends/cadence/hifi/operators/CMakeLists.txt b/backends/cadence/hifi/operators/CMakeLists.txt index b5801f5d488..1e103a9879c 100644 --- a/backends/cadence/hifi/operators/CMakeLists.txt +++ b/backends/cadence/hifi/operators/CMakeLists.txt @@ -13,6 +13,9 @@ endif() include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) # ATen compliant ops that are needed to run this model. set(_aten_ops__srcs @@ -85,11 +88,12 @@ target_link_libraries(aten_ops_cadence PRIVATE cadence_kernels) # Let files say "include ". set(_common_include_directories - ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 + ${EXECUTORCH_SOURCE_INCLUDE_DIR} + ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 ) target_include_directories( - aten_ops_cadence PUBLIC ${ROOT_DIR}/.. ${CMAKE_BINARY_DIR} + aten_ops_cadence PUBLIC ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${CMAKE_BINARY_DIR} ${_common_include_directories} ) @@ -155,7 +159,7 @@ add_library( "op_quantized_fully_connected_asym8uxasym8u_asym8u_per_tensor_out.cpp" ) target_include_directories( - custom_ops PUBLIC ${ROOT_DIR}/.. ${CMAKE_BINARY_DIR} + custom_ops PUBLIC ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${CMAKE_BINARY_DIR} ${_common_include_directories} ) diff --git a/backends/cadence/hifi/operators/tests/CMakeLists.txt b/backends/cadence/hifi/operators/tests/CMakeLists.txt index a12bf22e283..55ba6851e51 100644 --- a/backends/cadence/hifi/operators/tests/CMakeLists.txt +++ b/backends/cadence/hifi/operators/tests/CMakeLists.txt @@ -22,7 +22,8 @@ add_compile_options(-Qunused-arguments -Wno-error) # Let files say "include ". set(_common_include_directories - ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 + ${EXECUTORCH_SOURCE_INCLUDE_DIR} + ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 ) # Build googletest FOR the Xtensa target. find_package(GTest) would resolve the diff --git a/backends/cadence/vision/kernels/CMakeLists.txt b/backends/cadence/vision/kernels/CMakeLists.txt index fa7b2b5203b..0bd07967a7d 100644 --- a/backends/cadence/vision/kernels/CMakeLists.txt +++ b/backends/cadence/vision/kernels/CMakeLists.txt @@ -17,7 +17,8 @@ add_library( # Let files say "include ". set(_common_include_directories - ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 + ${EXECUTORCH_SOURCE_INCLUDE_DIR} + ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 ) target_include_directories( diff --git a/backends/cadence/vision/operators/CMakeLists.txt b/backends/cadence/vision/operators/CMakeLists.txt index 38e4f97f841..a1f82e08983 100644 --- a/backends/cadence/vision/operators/CMakeLists.txt +++ b/backends/cadence/vision/operators/CMakeLists.txt @@ -13,6 +13,9 @@ endif() include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) if(NOT PYTHON_EXECUTABLE) resolve_python_executable() @@ -73,12 +76,14 @@ target_link_libraries(aten_ops_cadence PRIVATE cadence_kernels) # Let files say "include ". set(_common_include_directories - ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 + ${EXECUTORCH_SOURCE_INCLUDE_DIR} + ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 ) target_include_directories( aten_ops_cadence - PUBLIC ${ROOT_DIR}/.. ${CMAKE_BINARY_DIR} ${_common_include_directories} + PUBLIC ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${CMAKE_BINARY_DIR} + ${_common_include_directories} ${CMAKE_CURRENT_SOURCE_DIR}/../third-party ) @@ -97,7 +102,7 @@ add_library( "op_im2row_out.cpp" ) target_include_directories( - custom_ops PUBLIC ${ROOT_DIR}/.. ${CMAKE_BINARY_DIR} + custom_ops PUBLIC ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${CMAKE_BINARY_DIR} ${_common_include_directories} ) diff --git a/backends/cortex_m/CMakeLists.txt b/backends/cortex_m/CMakeLists.txt index 3c901b513de..13361e4f876 100644 --- a/backends/cortex_m/CMakeLists.txt +++ b/backends/cortex_m/CMakeLists.txt @@ -18,6 +18,9 @@ if(NOT EXECUTORCH_ROOT) endif() include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake) include(FetchContent) @@ -138,7 +141,7 @@ if(EXECUTORCH_BUILD_CORTEX_M) ) target_include_directories( - cortex_m_kernels PRIVATE ${EXECUTORCH_ROOT}/.. + cortex_m_kernels PRIVATE ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 ) diff --git a/backends/cuda/CMakeLists.txt b/backends/cuda/CMakeLists.txt index c3e5d17809e..39f56d4c940 100644 --- a/backends/cuda/CMakeLists.txt +++ b/backends/cuda/CMakeLists.txt @@ -194,6 +194,9 @@ endif() # Use ExecuTorch's standard way to find PyTorch libraries for AOTI include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) find_package_torch() # Platform utilities (load_library, close_library, etc.) @@ -203,7 +206,7 @@ add_library(cuda_platform STATIC ${_cuda_platform_sources}) target_include_directories( cuda_platform PUBLIC $ $ - $ + $ ) target_compile_options( diff --git a/backends/cuda/runtime/shims/tests/CMakeLists.txt b/backends/cuda/runtime/shims/tests/CMakeLists.txt index a5c01f42939..34924fc1534 100644 --- a/backends/cuda/runtime/shims/tests/CMakeLists.txt +++ b/backends/cuda/runtime/shims/tests/CMakeLists.txt @@ -31,6 +31,10 @@ FetchContent_MakeAvailable(googletest) if(NOT EXECUTORCH_ROOT) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..) endif() +include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) # Find installed ExecuTorch find_package(executorch CONFIG REQUIRED HINTS ${CMAKE_INSTALL_PREFIX}) @@ -60,7 +64,7 @@ foreach(test_name ${CUDA_SHIM_TESTS}) add_executable(${test_name} ${test_name}.cpp) target_include_directories( - ${test_name} PRIVATE ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT} + ${test_name} PRIVATE ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${EXECUTORCH_ROOT} ${CUDAToolkit_INCLUDE_DIRS} ) @@ -76,8 +80,9 @@ endforeach() add_executable(benchmark_int4_plain_mm benchmark_int4_plain_mm.cu) target_include_directories( - benchmark_int4_plain_mm PRIVATE ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT} - ${CUDAToolkit_INCLUDE_DIRS} + benchmark_int4_plain_mm + PRIVATE ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${EXECUTORCH_ROOT} + ${CUDAToolkit_INCLUDE_DIRS} ) target_compile_definitions(benchmark_int4_plain_mm PRIVATE CUDA_AVAILABLE=1) set_property(TARGET benchmark_int4_plain_mm PROPERTY CUDA_ARCHITECTURES 80) @@ -106,8 +111,9 @@ add_test(NAME benchmark_int4_plain_mm_m4 add_executable(benchmark_int6_plain_mm benchmark_int6_plain_mm.cu) target_include_directories( - benchmark_int6_plain_mm PRIVATE ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT} - ${CUDAToolkit_INCLUDE_DIRS} + benchmark_int6_plain_mm + PRIVATE ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${EXECUTORCH_ROOT} + ${CUDAToolkit_INCLUDE_DIRS} ) target_compile_definitions(benchmark_int6_plain_mm PRIVATE CUDA_AVAILABLE=1) set_property(TARGET benchmark_int6_plain_mm PROPERTY CUDA_ARCHITECTURES 80) @@ -136,8 +142,9 @@ add_test(NAME benchmark_int6_plain_mm_m4 add_executable(benchmark_int5_plain_mm benchmark_int5_plain_mm.cu) target_include_directories( - benchmark_int5_plain_mm PRIVATE ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT} - ${CUDAToolkit_INCLUDE_DIRS} + benchmark_int5_plain_mm + PRIVATE ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${EXECUTORCH_ROOT} + ${CUDAToolkit_INCLUDE_DIRS} ) target_compile_definitions(benchmark_int5_plain_mm PRIVATE CUDA_AVAILABLE=1) set_property(TARGET benchmark_int5_plain_mm PROPERTY CUDA_ARCHITECTURES 80) @@ -168,7 +175,7 @@ foreach(test_name ${CUDA_KERNEL_TESTS}) add_executable(${test_name} ${test_name}.cpp) target_include_directories( - ${test_name} PRIVATE ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT} + ${test_name} PRIVATE ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${EXECUTORCH_ROOT} ${CUDAToolkit_INCLUDE_DIRS} ) diff --git a/backends/mediatek/CMakeLists.txt b/backends/mediatek/CMakeLists.txt index 10c28be0053..77976bd94d3 100644 --- a/backends/mediatek/CMakeLists.txt +++ b/backends/mediatek/CMakeLists.txt @@ -9,7 +9,7 @@ ]] # Let include directory as "executorch/..." -set(_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR}/../../..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) if(EXECUTORCH_BUILD_NEURON_BUFFER_ALLOCATOR) message(STATUS "Neuron buffer allocator Build is enabled") diff --git a/backends/mlx/examples/llm/CMakeLists.txt b/backends/mlx/examples/llm/CMakeLists.txt index fa041b7129a..0a9d158aba1 100644 --- a/backends/mlx/examples/llm/CMakeLists.txt +++ b/backends/mlx/examples/llm/CMakeLists.txt @@ -16,8 +16,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) set(_json_include ${EXECUTORCH_ROOT}/extension/llm/tokenizers/third-party/json/single_include ) diff --git a/backends/nxp/CMakeLists.txt b/backends/nxp/CMakeLists.txt index bfc4c046be6..ca43e7ee355 100644 --- a/backends/nxp/CMakeLists.txt +++ b/backends/nxp/CMakeLists.txt @@ -3,7 +3,7 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. -set(_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR}/../../..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) add_compile_definitions(C10_USING_CUSTOM_GENERATED_MACROS) set(_neutron_sources ${CMAKE_CURRENT_SOURCE_DIR}/runtime/NeutronBackend.cpp) diff --git a/backends/openvino/CMakeLists.txt b/backends/openvino/CMakeLists.txt index 0f3a04e97c2..01a20ff48e5 100644 --- a/backends/openvino/CMakeLists.txt +++ b/backends/openvino/CMakeLists.txt @@ -22,11 +22,14 @@ if(NOT EXECUTORCH_ROOT) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) endif() -# Define common include directories -set(COMMON_INCLUDE_DIRS ${EXECUTORCH_ROOT}/..) - # Include utility CMake scripts from ExecuteTorch include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) + +# Define common include directories +set(COMMON_INCLUDE_DIRS ${EXECUTORCH_SOURCE_INCLUDE_DIR}) # The backend resolves OpenVINO C API symbols via dlopen/dlsym at runtime, so # there is no build-time dependency on the OpenVINO SDK. diff --git a/backends/qualcomm/CMakeLists.txt b/backends/qualcomm/CMakeLists.txt index d46433eb6cb..66cadd69f61 100644 --- a/backends/qualcomm/CMakeLists.txt +++ b/backends/qualcomm/CMakeLists.txt @@ -19,9 +19,7 @@ get_filename_component( QNN_EXECUTORCH_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR} ABSOLUTE ) # Let files say "include ". -get_filename_component( - _common_include_directories "${EXECUTORCH_SOURCE_DIR}/.." ABSOLUTE -) +set(_common_include_directories "${EXECUTORCH_SOURCE_INCLUDE_DIR}") # If QNN_SDK_ROOT was not passed as a CMake variable, fall back to the # environment variable. Prefer downloading the SDK *outside* of CMake (e.g. via diff --git a/backends/samsung/CMakeLists.txt b/backends/samsung/CMakeLists.txt index 1f647c5bbe2..973ac824083 100644 --- a/backends/samsung/CMakeLists.txt +++ b/backends/samsung/CMakeLists.txt @@ -37,7 +37,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release") endif() include_directories( - ${EXECUTORCH_SOURCE_DIR}/.. + ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${EXECUTORCH_SOURCE_DIR}/runtime/core/portable_type/c10 ${EXYNOS_AI_LITECORE_ROOT} ) diff --git a/backends/vulkan/CMakeLists.txt b/backends/vulkan/CMakeLists.txt index 5ee7fc03ef8..663e354840b 100644 --- a/backends/vulkan/CMakeLists.txt +++ b/backends/vulkan/CMakeLists.txt @@ -30,6 +30,9 @@ endif() # allows libraries to be linked with the --whole-archive flag. This is required # for libraries that perform dynamic registration via static initialization. include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) include(cmake/ShaderLibrary.cmake) @@ -60,7 +63,7 @@ if(NOT EXISTS "${VOLK_PATH}/volk.c" endif() set(COMMON_INCLUDES - $ + $ $ $ $ ) diff --git a/backends/vulkan/cmake/ShaderLibrary.cmake b/backends/vulkan/cmake/ShaderLibrary.cmake index d7e55cd3592..43508dbf937 100644 --- a/backends/vulkan/cmake/ShaderLibrary.cmake +++ b/backends/vulkan/cmake/ShaderLibrary.cmake @@ -110,7 +110,7 @@ function(vulkan_shader_lib library_name generated_spv_cpp) target_include_directories( ${library_name} PRIVATE - ${EXECUTORCH_ROOT}/.. + ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${EXECUTORCH_ROOT}/backends/vulkan/third-party/Vulkan-Headers/include ${EXECUTORCH_ROOT}/backends/vulkan/third-party/volk ) @@ -134,7 +134,7 @@ macro(vulkan_shader_library shaders_path library_name) target_include_directories( ${library_name} PRIVATE - ${EXECUTORCH_ROOT}/.. + ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${EXECUTORCH_ROOT}/backends/vulkan/third-party/Vulkan-Headers/include ${EXECUTORCH_ROOT}/backends/vulkan/third-party/volk ) diff --git a/backends/vulkan/test/CMakeLists.txt b/backends/vulkan/test/CMakeLists.txt index e3bce1d8baf..2938640c80c 100644 --- a/backends/vulkan/test/CMakeLists.txt +++ b/backends/vulkan/test/CMakeLists.txt @@ -41,6 +41,9 @@ if(TARGET vulkan_backend) # required for libraries that perform dynamic registration via static # initialization. include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) + executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR + ) include(../cmake/ShaderLibrary.cmake) @@ -55,8 +58,9 @@ if(TARGET vulkan_backend) set(VOLK_PATH ${VULKAN_THIRD_PARTY_PATH}/volk) set(VMA_PATH ${VULKAN_THIRD_PARTY_PATH}/VulkanMemoryAllocator) - set(COMMON_INCLUDES ${EXECUTORCH_ROOT}/.. ${VULKAN_HEADERS_PATH} ${VOLK_PATH} - ${VMA_PATH} ${GTEST_INCLUDE_PATH} ${PYTORCH_PATH} + set(COMMON_INCLUDES + ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${VULKAN_HEADERS_PATH} ${VOLK_PATH} + ${VMA_PATH} ${GTEST_INCLUDE_PATH} ${PYTORCH_PATH} ) # Test Utility files diff --git a/backends/vulkan/test/custom_ops/CMakeLists.txt b/backends/vulkan/test/custom_ops/CMakeLists.txt index f29b518ec06..75580a3891f 100644 --- a/backends/vulkan/test/custom_ops/CMakeLists.txt +++ b/backends/vulkan/test/custom_ops/CMakeLists.txt @@ -34,6 +34,9 @@ if(TARGET vulkan_backend) # Include this file to access executorch_target_link_options_shared_lib include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) + executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR + ) include(${EXECUTORCH_ROOT}/backends/vulkan/cmake/ShaderLibrary.cmake) # Third party include paths @@ -42,8 +45,8 @@ if(TARGET vulkan_backend) set(VOLK_PATH ${VULKAN_THIRD_PARTY_PATH}/volk) set(VMA_PATH ${VULKAN_THIRD_PARTY_PATH}/VulkanMemoryAllocator) - set(COMMON_INCLUDES ${EXECUTORCH_ROOT}/.. ${VULKAN_HEADERS_PATH} ${VOLK_PATH} - ${VMA_PATH} + set(COMMON_INCLUDES ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${VULKAN_HEADERS_PATH} + ${VOLK_PATH} ${VMA_PATH} ) # Prototyping utility files diff --git a/backends/vulkan/test/op_tests/CMakeLists.txt b/backends/vulkan/test/op_tests/CMakeLists.txt index 0f8456accf5..895fcc9281a 100644 --- a/backends/vulkan/test/op_tests/CMakeLists.txt +++ b/backends/vulkan/test/op_tests/CMakeLists.txt @@ -34,6 +34,9 @@ endif() # allows libraries to be linked with the --whole-archive flag. This is required # for libraries that perform dynamic registration via static initialization. include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) get_torch_base_path(TORCH_BASE_PATH) if(NOT TORCH_INSTALL_PREFIX) @@ -57,7 +60,7 @@ set(VOLK_PATH ${VULKAN_THIRD_PARTY_PATH}/volk) set(VMA_PATH ${VULKAN_THIRD_PARTY_PATH}/VulkanMemoryAllocator) set(COMMON_INCLUDES - ${EXECUTORCH_ROOT}/.. + ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${VULKAN_HEADERS_PATH} ${VOLK_PATH} ${VMA_PATH} diff --git a/backends/webgpu/CMakeLists.txt b/backends/webgpu/CMakeLists.txt index 536348ca69f..9d7fa91558a 100644 --- a/backends/webgpu/CMakeLists.txt +++ b/backends/webgpu/CMakeLists.txt @@ -11,6 +11,9 @@ if(NOT EXECUTORCH_ROOT) endif() include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) # Ensure vulkan_schema is available even when EXECUTORCH_BUILD_VULKAN is OFF. # The WebGPU backend reuses the Vulkan FlatBuffer serialization format. @@ -59,7 +62,7 @@ add_custom_target( add_dependencies(webgpu_backend webgpu_wgsl_headers_check) target_include_directories( - webgpu_backend PRIVATE $ + webgpu_backend PRIVATE $ ) target_link_libraries(webgpu_backend PRIVATE vulkan_schema executorch_core) @@ -116,7 +119,7 @@ install( function(add_webgpu_native_test test_name test_src) add_executable(${test_name} ${test_src}) target_include_directories( - ${test_name} PRIVATE $ + ${test_name} PRIVATE $ ) target_link_libraries( ${test_name} @@ -174,7 +177,7 @@ if(EXECUTORCH_BUILD_WEBGPU_TEST) ) target_include_directories( webgpu_op_test_util_test - PRIVATE $ + PRIVATE $ "${EXECUTORCH_ROOT}/third-party/json/single_include" ) target_link_libraries( @@ -219,7 +222,7 @@ if(EXECUTORCH_BUILD_WEBGPU_TEST) ) target_include_directories( webgpu_execution_options_test - PRIVATE $ + PRIVATE $ ) target_link_libraries( webgpu_execution_options_test PRIVATE GTest::gtest GTest::gtest_main diff --git a/codegen/tools/CMakeLists.txt b/codegen/tools/CMakeLists.txt index 143d2c18c6d..129e6c49d3c 100644 --- a/codegen/tools/CMakeLists.txt +++ b/codegen/tools/CMakeLists.txt @@ -21,7 +21,7 @@ target_compile_definitions( # Include directories target_include_directories( - selective_build PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../.. + selective_build PRIVATE ${EXECUTORCH_SOURCE_INCLUDE_DIR} ) # Compile options diff --git a/examples/arm/executor_runner/CMakeLists.txt b/examples/arm/executor_runner/CMakeLists.txt index 9c769868984..b0b8ea80049 100644 --- a/examples/arm/executor_runner/CMakeLists.txt +++ b/examples/arm/executor_runner/CMakeLists.txt @@ -27,15 +27,6 @@ set(ET_DIR_PATH "${EXECUTORCH_ROOT}" CACHE PATH "Kept for backward compatibility; synonym for EXECUTORCH_ROOT" ) -if(NOT DEFINED ET_INCLUDE_PATH) - set(ET_INCLUDE_PATH - "${EXECUTORCH_ROOT}" - CACHE - PATH - "Kept for backward compatibility; include root for ExecuTorch headers" - ) -endif() - if(NOT EXISTS "${EXECUTORCH_ROOT}/CMakeLists.txt") message( FATAL_ERROR @@ -46,6 +37,15 @@ endif() if(NOT COMMAND executorch_target_link_options_shared_lib) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) endif() +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) +if(NOT DEFINED ET_INCLUDE_PATH) + set(ET_INCLUDE_PATH + "${EXECUTORCH_SOURCE_INCLUDE_DIR}" + CACHE PATH "Include root for ExecuTorch source headers" + ) +endif() set(ET_NUM_INFERENCES "1" @@ -318,7 +318,7 @@ endif() # ET headers and generated headers includes target_include_directories( arm_executor_runner - PRIVATE ${ET_INCLUDE_PATH} ${ET_INCLUDE_PATH}/runtime/core/portable_type/c10 + PRIVATE ${ET_INCLUDE_PATH} ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 ${EXECUTORCH_ROOT}/examples/arm/common ${CMAKE_CURRENT_BINARY_DIR} ) target_compile_definitions( diff --git a/examples/arm/image_classification_example_ethos_u/runtime/CMakeLists.txt b/examples/arm/image_classification_example_ethos_u/runtime/CMakeLists.txt index 3ed5acc07ef..689d9bb51d6 100644 --- a/examples/arm/image_classification_example_ethos_u/runtime/CMakeLists.txt +++ b/examples/arm/image_classification_example_ethos_u/runtime/CMakeLists.txt @@ -12,13 +12,15 @@ set(ET_DIR_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../.." CACHE PATH "Path to ExecuTorch dir" ) +include(${ET_DIR_PATH}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir("${ET_DIR_PATH}" EXECUTORCH_SOURCE_INCLUDE_DIR) set(ET_BUILD_DIR_PATH "${ET_DIR_PATH}/cmake-out-arm" CACHE PATH "Path to ExecuTorch build/install dir" ) set(ET_INCLUDE_PATH - "${ET_DIR_PATH}/.." + "${EXECUTORCH_SOURCE_INCLUDE_DIR}" CACHE PATH "Path to ExecuTorch headers" ) diff --git a/examples/arm/mobilesam_prompt_segmentation_example_ethos_u/runtime/CMakeLists.txt b/examples/arm/mobilesam_prompt_segmentation_example_ethos_u/runtime/CMakeLists.txt index 6f30110b95c..213bb6ca66f 100644 --- a/examples/arm/mobilesam_prompt_segmentation_example_ethos_u/runtime/CMakeLists.txt +++ b/examples/arm/mobilesam_prompt_segmentation_example_ethos_u/runtime/CMakeLists.txt @@ -11,12 +11,14 @@ set(ET_DIR_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../.." CACHE PATH "Path to ExecuTorch dir" ) +include(${ET_DIR_PATH}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir("${ET_DIR_PATH}" EXECUTORCH_SOURCE_INCLUDE_DIR) set(ET_BUILD_DIR_PATH "${ET_DIR_PATH}/cmake-out-arm" CACHE PATH "Path to ExecuTorch build/install dir" ) set(ET_INCLUDE_PATH - "${ET_DIR_PATH}/.." + "${EXECUTORCH_SOURCE_INCLUDE_DIR}" CACHE PATH "Path to ExecuTorch headers" ) set(ET_PTE_FILE_PATH diff --git a/examples/arm/silero_vad_example_ethos_u/runtime/CMakeLists.txt b/examples/arm/silero_vad_example_ethos_u/runtime/CMakeLists.txt index cf5917c5642..6cb8ebac728 100644 --- a/examples/arm/silero_vad_example_ethos_u/runtime/CMakeLists.txt +++ b/examples/arm/silero_vad_example_ethos_u/runtime/CMakeLists.txt @@ -11,13 +11,15 @@ set(ET_DIR_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../.." CACHE PATH "Path to ExecuTorch dir" ) +include(${ET_DIR_PATH}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir("${ET_DIR_PATH}" EXECUTORCH_SOURCE_INCLUDE_DIR) set(ET_BUILD_DIR_PATH "${ET_DIR_PATH}/cmake-out-arm" CACHE PATH "Path to ExecuTorch build/install dir" ) set(ET_INCLUDE_PATH - "${ET_DIR_PATH}/.." + "${EXECUTORCH_SOURCE_INCLUDE_DIR}" CACHE PATH "Path to ExecuTorch headers" ) diff --git a/examples/cadence/CMakeLists.txt b/examples/cadence/CMakeLists.txt index 757009bd4df..f9169734b46 100644 --- a/examples/cadence/CMakeLists.txt +++ b/examples/cadence/CMakeLists.txt @@ -20,13 +20,16 @@ if(NOT EXECUTORCH_ROOT) endif() include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) if(NOT PYTHON_EXECUTABLE) resolve_python_executable() endif() # Let files say "include ". -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) # Find prebuilt executorch lib find_package(executorch CONFIG REQUIRED) @@ -113,8 +116,9 @@ add_dependencies(cadence_executorch_example gen_model_header) # lint_cmake: -linelength target_include_directories( - cadence_executorch_example PUBLIC ${ROOT_DIR}/.. ${CMAKE_BINARY_DIR} - ${_common_include_directories} + cadence_executorch_example + PUBLIC ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${CMAKE_BINARY_DIR} + ${_common_include_directories} ) target_link_options( diff --git a/examples/devtools/CMakeLists.txt b/examples/devtools/CMakeLists.txt index c1d44df0d2b..43ce0ac161c 100644 --- a/examples/devtools/CMakeLists.txt +++ b/examples/devtools/CMakeLists.txt @@ -26,6 +26,9 @@ endif() include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) if(NOT PYTHON_EXECUTABLE) resolve_python_executable() @@ -34,7 +37,7 @@ endif() set(_common_compile_options -Wno-deprecated-declarations -fPIC) # Let files say "include ". -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) # Find prebuilt libraries. executorch package should contain portable_ops_lib, # etdump, bundled_program. diff --git a/examples/espressif/executor_runner/CMakeLists.txt b/examples/espressif/executor_runner/CMakeLists.txt index 2a26c53d5e0..810c4723bc5 100644 --- a/examples/espressif/executor_runner/CMakeLists.txt +++ b/examples/espressif/executor_runner/CMakeLists.txt @@ -42,6 +42,10 @@ if(ESP_PLATFORM) "${CMAKE_CURRENT_SOURCE_DIR}/../../.." CACHE PATH "Path to ExecuTorch source dir" ) + include(${ET_DIR_PATH}/tools/cmake/Utils.cmake) + executorch_get_build_include_dir( + "${ET_DIR_PATH}" EXECUTORCH_SOURCE_INCLUDE_DIR + ) set(ET_BUILD_DIR_PATH "${ET_DIR_PATH}/cmake-out-esp" CACHE PATH "Path to ExecuTorch build/install dir for ESP target" @@ -133,7 +137,8 @@ if(ESP_PLATFORM) # Include directories target_include_directories( ${COMPONENT_LIB} - PRIVATE ${ET_DIR_PATH}/.. ${ET_DIR_PATH}/runtime/core/portable_type/c10 + PRIVATE ${EXECUTORCH_SOURCE_INCLUDE_DIR} + ${ET_DIR_PATH}/runtime/core/portable_type/c10 ${CMAKE_CURRENT_BINARY_DIR} ${ET_MODEL_HEADER_DIR} ) @@ -236,12 +241,15 @@ else() CACHE PATH "Path to ExecuTorch dir" ) include(${ET_DIR_PATH}/tools/cmake/Utils.cmake) + executorch_get_build_include_dir( + "${ET_DIR_PATH}" EXECUTORCH_SOURCE_INCLUDE_DIR + ) set(ET_BUILD_DIR_PATH "${ET_DIR_PATH}/cmake-out" CACHE PATH "Path to ExecuTorch build/install dir" ) set(ET_INCLUDE_PATH - "${ET_DIR_PATH}/.." + "${EXECUTORCH_SOURCE_INCLUDE_DIR}" CACHE PATH "Path to ExecuTorch headers" ) set(ET_PTE_FILE_PATH diff --git a/examples/llm_server/cpp/CMakeLists.txt b/examples/llm_server/cpp/CMakeLists.txt index 8b51b8d9b3c..9d8508ed1a5 100644 --- a/examples/llm_server/cpp/CMakeLists.txt +++ b/examples/llm_server/cpp/CMakeLists.txt @@ -16,8 +16,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) # Vendored single-include nlohmann/json for the worker protocol (no new dep). set(_json_include ${EXECUTORCH_ROOT}/extension/llm/tokenizers/third-party/json/single_include diff --git a/examples/mediatek/CMakeLists.txt b/examples/mediatek/CMakeLists.txt index 04d465d0b2a..47bcd07e61e 100644 --- a/examples/mediatek/CMakeLists.txt +++ b/examples/mediatek/CMakeLists.txt @@ -21,6 +21,9 @@ endif() include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) if(NOT PYTHON_EXECUTABLE) resolve_python_executable() @@ -30,7 +33,8 @@ set(_common_compile_options -Wno-deprecated-declarations -fPIC) # Let files say "include ". set(_common_include_directories - ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 + ${EXECUTORCH_SOURCE_INCLUDE_DIR} + ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 ${EXECUTORCH_ROOT}/extension/llm/tokenizers/include ${EXECUTORCH_ROOT}/extension/llm/tokenizers/third-party/json/single_include ) diff --git a/examples/mediatek/executor_runner/llama_runner/CMakeLists.txt b/examples/mediatek/executor_runner/llama_runner/CMakeLists.txt index 0448817d8eb..b958deef634 100644 --- a/examples/mediatek/executor_runner/llama_runner/CMakeLists.txt +++ b/examples/mediatek/executor_runner/llama_runner/CMakeLists.txt @@ -5,13 +5,11 @@ # directory of this source tree for more details. # Let include directory as "executorch/..." -set(_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) include_directories(BEFORE ${_common_include_directories}) # shortcut include directory for neuron headers -include_directories( - BEFORE ${_common_include_directories}/backends/mediatek/runtime/include -) +include_directories(BEFORE ${EXECUTORCH_ROOT}/backends/mediatek/runtime/include) add_library(llm_helper STATIC) target_sources( diff --git a/examples/models/dinov2/CMakeLists.txt b/examples/models/dinov2/CMakeLists.txt index 8e83ee44873..ef1222b7a60 100644 --- a/examples/models/dinov2/CMakeLists.txt +++ b/examples/models/dinov2/CMakeLists.txt @@ -15,9 +15,12 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) # Let files say "include " -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) # Need this for gflags set(gflags_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../../third-party/gflags) diff --git a/examples/models/gemma3/CMakeLists.txt b/examples/models/gemma3/CMakeLists.txt index d228ca53c46..78e4737362f 100644 --- a/examples/models/gemma3/CMakeLists.txt +++ b/examples/models/gemma3/CMakeLists.txt @@ -13,6 +13,9 @@ project(gemma3) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) if(CMAKE_TOOLCHAIN_FILE MATCHES ".*(iOS|ios\.toolchain)\.cmake$") set(CMAKE_TOOLCHAIN_IOS ON) @@ -25,7 +28,7 @@ if(NOT CMAKE_CXX_STANDARD) endif() # Let files say "include " -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) # Need this for gflags for some reason set(gflags_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../../third-party/gflags) diff --git a/examples/models/gemma4/CMakeLists.txt b/examples/models/gemma4/CMakeLists.txt index d4e05e70306..a7d8cbb6a80 100644 --- a/examples/models/gemma4/CMakeLists.txt +++ b/examples/models/gemma4/CMakeLists.txt @@ -13,13 +13,16 @@ project(gemma4) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) endif() # Let files say "include " -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) # Need this for gflags for some reason set(gflags_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../../third-party/gflags) diff --git a/examples/models/gemma4_31b/CMakeLists.txt b/examples/models/gemma4_31b/CMakeLists.txt index 2d43d2baaf0..d24be82bd4a 100644 --- a/examples/models/gemma4_31b/CMakeLists.txt +++ b/examples/models/gemma4_31b/CMakeLists.txt @@ -13,8 +13,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) set(_json_include ${EXECUTORCH_ROOT}/extension/llm/tokenizers/third-party/json/single_include ) diff --git a/examples/models/llama/CMakeLists.txt b/examples/models/llama/CMakeLists.txt index 443ccd01c7e..b893c08a92e 100644 --- a/examples/models/llama/CMakeLists.txt +++ b/examples/models/llama/CMakeLists.txt @@ -45,6 +45,9 @@ set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) set(TORCH_ROOT ${EXECUTORCH_ROOT}/third-party/pytorch) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) if(NOT PYTHON_EXECUTABLE) resolve_python_executable() @@ -68,7 +71,7 @@ else() endif() # Let files say "include ". -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) # For some reason android build is not able to find where gflags is and hence # cannot find corresponding .cmake file diff --git a/examples/models/llama/runner/CMakeLists.txt b/examples/models/llama/runner/CMakeLists.txt index 31bce16dd12..d52f3afc9ee 100644 --- a/examples/models/llama/runner/CMakeLists.txt +++ b/examples/models/llama/runner/CMakeLists.txt @@ -22,6 +22,9 @@ endif() include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) # The buck-based executorch_srcs.cmake setup was crossing package boundaries and # trying to build stuff from executorch/extension/llm/runner and tokenizers. @@ -57,6 +60,6 @@ target_link_libraries(llama_runner PUBLIC tokenizers::tokenizers) target_include_directories( llama_runner PUBLIC ${EXECUTORCH_ROOT}/extension/llm/tokenizers/include - ${EXECUTORCH_ROOT}/.. + ${EXECUTORCH_SOURCE_INCLUDE_DIR} ) target_compile_options(llama_runner PUBLIC ${_preprocessor_flag}) diff --git a/examples/models/llava/CMakeLists.txt b/examples/models/llava/CMakeLists.txt index 8444f41f77f..b96e5ff8f65 100644 --- a/examples/models/llava/CMakeLists.txt +++ b/examples/models/llava/CMakeLists.txt @@ -44,6 +44,9 @@ endif() set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) if(NOT PYTHON_EXECUTABLE) resolve_python_executable() @@ -67,7 +70,7 @@ else() endif() # Let files say "include ". -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) # For some reason android build is not able to find where gflags is and hence # cannot find corresponding .cmake file diff --git a/examples/models/muse-glimmer/CMakeLists.txt b/examples/models/muse-glimmer/CMakeLists.txt index ff7da644771..d3b83b15e58 100644 --- a/examples/models/muse-glimmer/CMakeLists.txt +++ b/examples/models/muse-glimmer/CMakeLists.txt @@ -17,8 +17,11 @@ endif() set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) set(_json_include ${EXECUTORCH_ROOT}/extension/llm/tokenizers/third-party/json/single_include ) diff --git a/examples/models/parakeet/CMakeLists.txt b/examples/models/parakeet/CMakeLists.txt index 9449583c613..cdc94a745fc 100644 --- a/examples/models/parakeet/CMakeLists.txt +++ b/examples/models/parakeet/CMakeLists.txt @@ -15,9 +15,12 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) # Let files say "include " -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) # Need this for gflags set(gflags_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../../third-party/gflags) diff --git a/examples/models/phi-3-mini/CMakeLists.txt b/examples/models/phi-3-mini/CMakeLists.txt index 3c7ed6a4acb..1ded43cb079 100644 --- a/examples/models/phi-3-mini/CMakeLists.txt +++ b/examples/models/phi-3-mini/CMakeLists.txt @@ -21,8 +21,13 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) set(EXECUTORCH_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../..") +include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) set(_common_include_directories - ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 + ${EXECUTORCH_SOURCE_INCLUDE_DIR} + ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 ) list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_CURRENT_BINARY_DIR}/../../..) find_package(executorch CONFIG REQUIRED FIND_ROOT_PATH_BOTH) diff --git a/examples/models/qwen3_5_moe/CMakeLists.txt b/examples/models/qwen3_5_moe/CMakeLists.txt index 65bb7c2015f..ee8a0848bc8 100644 --- a/examples/models/qwen3_5_moe/CMakeLists.txt +++ b/examples/models/qwen3_5_moe/CMakeLists.txt @@ -13,8 +13,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) set(_json_include ${EXECUTORCH_ROOT}/extension/llm/tokenizers/third-party/json/single_include ) diff --git a/examples/models/silero_vad/CMakeLists.txt b/examples/models/silero_vad/CMakeLists.txt index 4ed81b19d84..1750c978900 100644 --- a/examples/models/silero_vad/CMakeLists.txt +++ b/examples/models/silero_vad/CMakeLists.txt @@ -13,9 +13,12 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) # Let files say "include " -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) # Need this for gflags set(gflags_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../../third-party/gflags) diff --git a/examples/models/sortformer/CMakeLists.txt b/examples/models/sortformer/CMakeLists.txt index 171eb726ed2..e77ca10146d 100644 --- a/examples/models/sortformer/CMakeLists.txt +++ b/examples/models/sortformer/CMakeLists.txt @@ -15,9 +15,12 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) # Let files say "include " -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) # Need this for gflags set(gflags_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../../third-party/gflags) diff --git a/examples/models/supertonic/CMakeLists.txt b/examples/models/supertonic/CMakeLists.txt index 2eb01022564..98a94ff9528 100644 --- a/examples/models/supertonic/CMakeLists.txt +++ b/examples/models/supertonic/CMakeLists.txt @@ -29,6 +29,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(EXECUTORCH_SOURCE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include(${EXECUTORCH_SOURCE_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_SOURCE_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) set(_json_include ${EXECUTORCH_SOURCE_ROOT}/extension/llm/tokenizers/third-party/json/single_include @@ -83,7 +86,7 @@ endforeach() add_executable(supertonic_runner runtime/main.cpp ${_helper_sources}) target_compile_definitions(supertonic_runner PRIVATE EXECUTORCH_BUILD_MLX) target_include_directories( - supertonic_runner PRIVATE ${EXECUTORCH_SOURCE_ROOT}/.. runtime + supertonic_runner PRIVATE ${EXECUTORCH_SOURCE_INCLUDE_DIR} runtime ${_json_include} ) target_link_libraries( diff --git a/examples/models/voxtral/CMakeLists.txt b/examples/models/voxtral/CMakeLists.txt index 2e8ebb5c5e9..955672eac7d 100644 --- a/examples/models/voxtral/CMakeLists.txt +++ b/examples/models/voxtral/CMakeLists.txt @@ -13,6 +13,9 @@ project(voxtral) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) if(CMAKE_TOOLCHAIN_FILE MATCHES ".*(iOS|ios\.toolchain)\.cmake$") set(CMAKE_TOOLCHAIN_IOS ON) @@ -25,7 +28,7 @@ if(NOT CMAKE_CXX_STANDARD) endif() # Let files say "include " -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) # Need this for gflags for some reason set(gflags_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../../third-party/gflags) diff --git a/examples/models/voxtral_realtime/CMakeLists.txt b/examples/models/voxtral_realtime/CMakeLists.txt index 2710d86ed83..62c31b69693 100644 --- a/examples/models/voxtral_realtime/CMakeLists.txt +++ b/examples/models/voxtral_realtime/CMakeLists.txt @@ -15,9 +15,12 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) # Let files say "include " -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) # Need this for gflags set(gflags_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../../third-party/gflags) diff --git a/examples/models/voxtral_tts/CMakeLists.txt b/examples/models/voxtral_tts/CMakeLists.txt index bfd17cd9810..a4ce978e71b 100644 --- a/examples/models/voxtral_tts/CMakeLists.txt +++ b/examples/models/voxtral_tts/CMakeLists.txt @@ -13,8 +13,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) # gflags set(gflags_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../../third-party/gflags) diff --git a/examples/models/whisper/CMakeLists.txt b/examples/models/whisper/CMakeLists.txt index 6a1c2902977..4e6d28dee5e 100644 --- a/examples/models/whisper/CMakeLists.txt +++ b/examples/models/whisper/CMakeLists.txt @@ -12,6 +12,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(EXECUTORCH_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../..") include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) if(CMAKE_TOOLCHAIN_FILE MATCHES ".*(iOS|ios\.toolchain)\.cmake$") set(CMAKE_TOOLCHAIN_IOS ON) @@ -20,7 +23,7 @@ else() endif() # Let files say "include " -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) # Need this for gflags for some reason set(gflags_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../../third-party/gflags) diff --git a/examples/models/yolo26/CMakeLists.txt b/examples/models/yolo26/CMakeLists.txt index 7995566b9e8..14b2e6bd553 100644 --- a/examples/models/yolo26/CMakeLists.txt +++ b/examples/models/yolo26/CMakeLists.txt @@ -24,9 +24,12 @@ set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) set(TORCH_ROOT ${EXECUTORCH_ROOT}/third-party/pytorch) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) # Let files say "include ". -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) # find `executorch` libraries Same as for gflags find_package(executorch CONFIG REQUIRED PATHS ${EXECUTORCH_ROOT}/cmake-out) diff --git a/examples/portable/custom_ops/CMakeLists.txt b/examples/portable/custom_ops/CMakeLists.txt index 8e679697b47..54a2d6786d6 100644 --- a/examples/portable/custom_ops/CMakeLists.txt +++ b/examples/portable/custom_ops/CMakeLists.txt @@ -29,6 +29,9 @@ endif() include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) if(NOT PYTHON_EXECUTABLE) resolve_python_executable() @@ -37,7 +40,7 @@ endif() set(_common_compile_options -Wno-deprecated-declarations -fPIC) # Let files say "include ". -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) find_package(executorch CONFIG REQUIRED) find_package( diff --git a/examples/qualcomm/CMakeLists.txt b/examples/qualcomm/CMakeLists.txt index 48dd0904272..e4c9e7a52e8 100644 --- a/examples/qualcomm/CMakeLists.txt +++ b/examples/qualcomm/CMakeLists.txt @@ -17,6 +17,9 @@ endif() include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) if(NOT PYTHON_EXECUTABLE) resolve_python_executable() @@ -65,7 +68,7 @@ target_compile_options( # Let files say "include ". set(_common_include_directories - ${EXECUTORCH_ROOT}/.. + ${EXECUTORCH_SOURCE_INCLUDE_DIR} ${EXECUTORCH_ROOT}/extension/llm/tokenizers/third-party/json/single_include ) diff --git a/exir/backend/test/demos/rpc/CMakeLists.txt b/exir/backend/test/demos/rpc/CMakeLists.txt index af843954601..dad1afb0f6c 100644 --- a/exir/backend/test/demos/rpc/CMakeLists.txt +++ b/exir/backend/test/demos/rpc/CMakeLists.txt @@ -22,8 +22,11 @@ endif() include(${EXECUTORCH_ROOT}/tools/cmake/Test.cmake) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) set(_common_compile_options -Wno-deprecated-declarations -fPIC) add_library( diff --git a/extension/wasm/CMakeLists.txt b/extension/wasm/CMakeLists.txt index 8ffd1801c63..e7f9c4fb07c 100644 --- a/extension/wasm/CMakeLists.txt +++ b/extension/wasm/CMakeLists.txt @@ -27,6 +27,9 @@ if(NOT EXECUTORCH_ROOT) endif() include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) set(_common_compile_options $<$:/W4 /WX @@ -36,7 +39,7 @@ set(_common_compile_options -Wno-deprecated-declarations -fPIC> ) -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) set(link_libraries) list( diff --git a/extension/wasm/tokenizers/CMakeLists.txt b/extension/wasm/tokenizers/CMakeLists.txt index 03b7ea1ff6b..c99f8802572 100644 --- a/extension/wasm/tokenizers/CMakeLists.txt +++ b/extension/wasm/tokenizers/CMakeLists.txt @@ -25,8 +25,11 @@ if(NOT EXECUTORCH_ROOT) endif() include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) set(_common_compile_options -Wno-deprecated-declarations -fPIC -Wall -Werror) -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) set(link_libraries) list(APPEND link_libraries embind tokenizers::tokenizers) diff --git a/runtime/kernel/test/CMakeLists.txt b/runtime/kernel/test/CMakeLists.txt index a8166017e53..2221f347928 100644 --- a/runtime/kernel/test/CMakeLists.txt +++ b/runtime/kernel/test/CMakeLists.txt @@ -23,7 +23,9 @@ target_link_libraries( operator_registry_test GTest::gtest GTest::gtest_main GTest::gmock executorch_core ) -target_include_directories(operator_registry_test PRIVATE ${EXECUTORCH_ROOT}/..) +target_include_directories( + operator_registry_test PRIVATE ${EXECUTORCH_SOURCE_INCLUDE_DIR} +) add_test(operator_registry_test operator_registry_test) add_executable(kernel_runtime_context_test kernel_runtime_context_test.cpp) @@ -32,7 +34,7 @@ target_link_libraries( executorch_core ) target_include_directories( - kernel_runtime_context_test PRIVATE ${EXECUTORCH_ROOT}/.. + kernel_runtime_context_test PRIVATE ${EXECUTORCH_SOURCE_INCLUDE_DIR} ) add_test(kernel_runtime_context_test kernel_runtime_context_test) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 46729af4379..6c0ca2a32a9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -26,6 +26,9 @@ set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +executorch_get_build_include_dir( + "${EXECUTORCH_ROOT}" EXECUTORCH_SOURCE_INCLUDE_DIR +) # Find prebuilt executorch library @@ -33,7 +36,7 @@ list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_CURRENT_BINARY_DIR}/../) find_package(executorch CONFIG REQUIRED FIND_ROOT_PATH_BOTH) # Let files say "include ". -set(_common_include_directories ${EXECUTORCH_ROOT}/..) +set(_common_include_directories ${EXECUTORCH_SOURCE_INCLUDE_DIR}) # # The `__srcs` lists are defined by executorch_load_build_variables. diff --git a/test/run_oss_cpp_tests.sh b/test/run_oss_cpp_tests.sh index 4a7e0199a23..cd5280101f6 100755 --- a/test/run_oss_cpp_tests.sh +++ b/test/run_oss_cpp_tests.sh @@ -28,6 +28,7 @@ fi which "${PYTHON_EXECUTABLE}" build_executorch() { + local source_dir="${EXECUTORCH_CMAKE_SOURCE_DIR:-.}" BUILD_VULKAN="OFF" if [ -x "$(command -v glslc)" ]; then BUILD_VULKAN="ON" @@ -38,7 +39,7 @@ build_executorch() { SANITIZER_FLAG="-DEXECUTORCH_USE_SANITIZER=ON" fi - cmake . \ + cmake "${source_dir}" \ -DCMAKE_INSTALL_PREFIX=cmake-out \ -DEXECUTORCH_USE_CPP_CODE_COVERAGE=ON \ ${SANITIZER_FLAG} \ @@ -59,6 +60,9 @@ build_executorch() { -DEXECUTORCH_BUILD_XNNPACK=ON \ -DEXECUTORCH_BUILD_TESTS=ON \ -Bcmake-out + if [[ -n "${EXECUTORCH_CMAKE_SOURCE_DIR:-}" ]]; then + test cmake-out/executorch_source_include/executorch -ef "${source_dir}" + fi cmake --build cmake-out -j$(( $(nproc 2>/dev/null || sysctl -n hw.ncpu) + 1 )) --target install } diff --git a/test/test_worktree_build.sh b/test/test_worktree_build.sh new file mode 100755 index 00000000000..b4136f5d3fd --- /dev/null +++ b/test/test_worktree_build.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +# 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. + +set -euo pipefail + +repo_root="$(git rev-parse --show-toplevel)" +test_root="$(mktemp -d "${TMPDIR:-/tmp}/executorch-worktree-build.XXXXXX")" +trap 'rm -rf "${test_root}"' EXIT + +source_dir="${test_root}/arbitrary-checkout-name" +build_dir="${test_root}/build" +mkdir "${source_dir}" +while IFS= read -r entry; do + cmake -E create_symlink "${repo_root}/${entry}" "${source_dir}/${entry}" +done < <(git -C "${repo_root}" ls-tree --name-only HEAD) + +# This sibling would be selected by the old `${EXECUTORCH_ROOT}/..` include +# path. A successful build proves headers come through the build-local alias. +mkdir -p "${test_root}/executorch/runtime/core" +printf '#error "included headers from a sibling checkout"\n' \ + > "${test_root}/executorch/runtime/core/error.h" +mkdir -p "${test_root}/executorch/runtime/platform" +printf '#error "included headers from a sibling checkout"\n' \ + > "${test_root}/executorch/runtime/platform/assert.h" + +if [[ $# -gt 0 ]]; then + EXECUTORCH_CMAKE_SOURCE_DIR="${source_dir}" "$@" + exit +fi + +cmake \ + -S "${source_dir}" \ + -B "${build_dir}" \ + -DCMAKE_BUILD_TYPE=Release \ + -DEXECUTORCH_BUILD_CPUINFO=OFF \ + -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \ + -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ + -DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \ + -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ + -DEXECUTORCH_BUILD_EXTENSION_NAMED_DATA_MAP=ON \ + -DEXECUTORCH_BUILD_PTHREADPOOL=OFF \ + -DEXECUTORCH_BUILD_PYBIND=ON \ + -DEXECUTORCH_BUILD_XNNPACK=OFF \ + -DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE:-python3}" + +cmake -S "${source_dir}" -B "${build_dir}" +test "${build_dir}/executorch_source_include/executorch" -ef "${source_dir}" +cmake --build "${build_dir}" --target executorch selective_build --parallel 2 diff --git a/tools/cmake/Utils.cmake b/tools/cmake/Utils.cmake index af009565179..b08f8fd6641 100644 --- a/tools/cmake/Utils.cmake +++ b/tools/cmake/Utils.cmake @@ -18,6 +18,93 @@ # It should also be cmake-lint clean. # +# Create an include root that exposes this checkout as `executorch/`, regardless +# of the checkout directory's name. Source headers keep their public `#include +# ` spelling without relying on the repository's parent +# directory. +function(executorch_get_build_include_dir source_root out_var) + get_filename_component(source_root_real "${source_root}" REALPATH) + set(include_root "${CMAKE_BINARY_DIR}/executorch_source_include") + set(source_link "${include_root}/executorch") + + get_property( + configured_source_root GLOBAL PROPERTY EXECUTORCH_BUILD_INCLUDE_SOURCE_ROOT + ) + if(configured_source_root) + if(NOT "${configured_source_root}" STREQUAL "${source_root_real}") + message( + FATAL_ERROR + "The ExecuTorch source include root is already configured for " + "${configured_source_root}, not ${source_root_real}." + ) + endif() + set(${out_var} + "${include_root}" + PARENT_SCOPE + ) + return() + endif() + + file(MAKE_DIRECTORY "${include_root}") + if(CMAKE_HOST_WIN32) + file(TO_NATIVE_PATH "${source_link}" source_link_native) + file(TO_NATIVE_PATH "${source_root_real}" source_root_native) + execute_process( + COMMAND cmd /c rmdir "${source_link_native}" OUTPUT_QUIET ERROR_QUIET + ) + execute_process( + COMMAND cmd /c mklink /J "${source_link_native}" "${source_root_native}" + RESULT_VARIABLE link_result + OUTPUT_VARIABLE link_output + ERROR_VARIABLE link_error + ) + if(NOT link_result EQUAL 0) + message( + FATAL_ERROR + "Failed to create the ExecuTorch source include junction at " + "${source_link}: ${link_output}${link_error}" + ) + endif() + elseif(EXISTS "${source_link}") + get_filename_component(linked_root "${source_link}" REALPATH) + if(NOT "${linked_root}" STREQUAL "${source_root_real}") + message( + FATAL_ERROR + "${source_link} points to ${linked_root}, not ${source_root_real}. " + "Remove the build directory and configure again." + ) + endif() + elseif(IS_SYMLINK "${source_link}") + message( + FATAL_ERROR + "${source_link} is a broken symbolic link. Remove the build directory " + "and configure again." + ) + else() + execute_process( + COMMAND "${CMAKE_COMMAND}" -E create_symlink "${source_root_real}" + "${source_link}" + RESULT_VARIABLE link_result + OUTPUT_VARIABLE link_output + ERROR_VARIABLE link_error + ) + if(NOT link_result EQUAL 0) + message( + FATAL_ERROR "Failed to create the ExecuTorch source include symlink at " + "${source_link}: ${link_output}${link_error}" + ) + endif() + endif() + + set_property( + GLOBAL PROPERTY EXECUTORCH_BUILD_INCLUDE_SOURCE_ROOT "${source_root_real}" + ) + set(${out_var} + "${include_root}" + PARENT_SCOPE + ) +endfunction() + # This is the funtion to use -Wl, --whole-archive to link static library NB: # target_link_options is broken for this case, it only append the interface link # options of the first library.