Skip to content

cmake-format executorch-config.cmake #9015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Mar 7, 2025
16 changes: 16 additions & 0 deletions build/cmake_deps.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ deps = [
"executorch_core",
]

# HACK: prevent reduce_util from also showing up in custom_ops. The
# actual medium-term fix is to stop using Buck to drive our CMake
# builds.
[targets.reduce_util]
buck_targets = [
"//kernels/portable/cpu/util:reduce_util",
]
filters = [
".cpp$",
]
deps = [
"executorch",
"executorch_core",
]

[targets.optimized_kernels]
buck_targets = [
"//kernels/optimized:generated_lib",
Expand Down Expand Up @@ -414,6 +429,7 @@ deps = [
"optimized_kernels",
"extension_parallel",
"extension_threadpool",
"reduce_util",
"xnnpack_backend",
]

Expand Down
33 changes: 23 additions & 10 deletions build/executorch-config.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
Expand All @@ -16,20 +15,23 @@
#
# This will define the following variables:
#
# EXECUTORCH_FOUND -- True if the system has the ExecuTorch library
# EXECUTORCH_INCLUDE_DIRS -- The include directories for ExecuTorch
# EXECUTORCH_LIBRARIES -- Libraries to link against
# EXECUTORCH_FOUND -- True if the system has the ExecuTorch library
# EXECUTORCH_INCLUDE_DIRS -- The include directories for ExecuTorch
# EXECUTORCH_LIBRARIES -- Libraries to link against
#
# The actual values for these variables will be different from what executorch-config.cmake
# in executorch pip package gives, but we wanted to keep the contract of exposing these
# CMake variables.
# The actual values for these variables will be different from what
# executorch-config.cmake in executorch pip package gives, but we wanted to keep
# the contract of exposing these CMake variables.

cmake_minimum_required(VERSION 3.19)

set(_root "${CMAKE_CURRENT_LIST_DIR}/../../..")
set(required_lib_list executorch executorch_core portable_kernels)
set(EXECUTORCH_LIBRARIES)
set(EXECUTORCH_INCLUDE_DIRS ${_root}/include ${_root}/include/executorch/runtime/core/portable_type/c10 ${_root}/lib)
set(EXECUTORCH_INCLUDE_DIRS
${_root}/include ${_root}/include/executorch/runtime/core/portable_type/c10
${_root}/lib
)
foreach(lib ${required_lib_list})
set(lib_var "LIB_${lib}")
add_library(${lib} STATIC IMPORTED)
Expand All @@ -40,7 +42,12 @@ foreach(lib ${required_lib_list})
)
set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}")
target_compile_definitions(${lib} INTERFACE C10_USING_CUSTOM_GENERATED_MACROS)
target_include_directories(${lib} INTERFACE ${_root}/include ${_root}/include/executorch/runtime/core/portable_type/c10 ${_root}/lib)
target_include_directories(
${lib}
INTERFACE ${_root}/include
${_root}/include/executorch/runtime/core/portable_type/c10
${_root}/lib
)
list(APPEND EXECUTORCH_LIBRARIES ${lib})
endforeach()

Expand All @@ -65,6 +72,7 @@ set(lib_list
neuron_backend
qnn_executorch_backend
portable_ops_lib
custom_ops
extension_module
extension_module_static
extension_parallel
Expand Down Expand Up @@ -111,7 +119,12 @@ foreach(lib ${lib_list})
add_library(${lib} STATIC IMPORTED)
endif()
set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}")
target_include_directories(${lib} INTERFACE ${_root}/include ${_root}/include/executorch/runtime/core/portable_type/c10 ${_root}/lib)
target_include_directories(
${lib}
INTERFACE ${_root}/include
${_root}/include/executorch/runtime/core/portable_type/c10
${_root}/lib
)
list(APPEND EXECUTORCH_LIBRARIES ${lib})
endif()
endforeach()
Expand Down
13 changes: 2 additions & 11 deletions examples/models/llama/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# ~~~
# It should also be cmake-lint clean.
#
cmake_minimum_required(VERSION 3.19)
cmake_minimum_required(VERSION 3.24) # 3.24 is required for WHOLE_ARCHIVE
project(llama_runner)

# Duplicating options as root CMakeLists.txt
Expand Down Expand Up @@ -84,14 +84,6 @@ if(CMAKE_TOOLCHAIN_IOS OR ANDROID)
target_link_options_shared_lib(executorch)
endif()

# custom ops library
if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
add_subdirectory(
${CMAKE_CURRENT_SOURCE_DIR}/../../../extension/llm/custom_ops
${CMAKE_CURRENT_BINARY_DIR}/../../../extension/llm/custom_ops
)
endif()

# llama_runner library
add_subdirectory(runner)

Expand Down Expand Up @@ -119,8 +111,7 @@ target_link_options_shared_lib(quantized_ops_lib)
list(APPEND link_libraries quantized_kernels quantized_ops_lib)

if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
target_link_options_shared_lib(custom_ops)
list(APPEND link_libraries custom_ops)
list(APPEND link_libraries $<LINK_LIBRARY:WHOLE_ARCHIVE,custom_ops>)
endif()

if(EXECUTORCH_BUILD_TORCHAO)
Expand Down
9 changes: 0 additions & 9 deletions examples/models/llava/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,6 @@ if(CMAKE_TOOLCHAIN_IOS OR ANDROID)
target_link_options_shared_lib(executorch)
endif()

# custom ops library
if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
add_subdirectory(
${EXECUTORCH_ROOT}/extension/llm/custom_ops
${CMAKE_CURRENT_BINARY_DIR}/../../../extension/llm/custom_ops
)
endif()

# llava_runner library
add_subdirectory(runner)

Expand Down Expand Up @@ -132,7 +124,6 @@ target_link_options_shared_lib(quantized_ops_lib)
list(APPEND link_libraries quantized_kernels quantized_ops_lib)

if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
target_link_options_shared_lib(custom_ops)
list(APPEND link_libraries custom_ops)
endif()

Expand Down
9 changes: 2 additions & 7 deletions extension/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.19)
cmake_minimum_required(VERSION 3.24) # 3.24 is required for WHOLE_ARCHIVE

project(executorch_jni)

Expand Down Expand Up @@ -115,12 +115,7 @@ if(TARGET vulkan_backend)
endif()

if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
add_subdirectory(
${EXECUTORCH_ROOT}/extension/llm/custom_ops
${CMAKE_CURRENT_BINARY_DIR}/../../extension/llm/custom_ops
)
list(APPEND link_libraries custom_ops)
target_link_options_shared_lib(custom_ops)
list(APPEND link_libraries $<LINK_LIBRARY:WHOLE_ARCHIVE,custom_ops>)
endif()

if(TARGET pthreadpool)
Expand Down
Loading