Skip to content

Used cmake-format on CMakeLists.txt #11230

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 2 commits into from
May 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 75 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@
# ~~~
# cmake-format -i CMakeLists.txt
# ~~~
# It should also be cmake-lint clean.
# It should also be checked with a linter via
# ~~~
# cmake-lint CMakeLists.txt
# ~~~
#

cmake_minimum_required(VERSION 3.24)
project(executorch)

# MARK: - Start EXECUTORCH_H12025_BUILD_MIGRATION --------------------------------------------------
# MARK: - Start EXECUTORCH_H12025_BUILD_MIGRATION

include(${PROJECT_SOURCE_DIR}/tools/cmake/common/preset.cmake)
include(${PROJECT_SOURCE_DIR}/tools/cmake/Utils.cmake)
Expand Down Expand Up @@ -82,24 +85,25 @@ include(${PROJECT_SOURCE_DIR}/tools/cmake/preset/default.cmake)
# Print all the configs that were called with announce_configured_options.
print_configured_options()

# MARK: - End EXECUTORCH_H12025_BUILD_MIGRATION ----------------------------------------------------
# MARK: - End EXECUTORCH_H12025_BUILD_MIGRATION

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Setup RPATH.
# See https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling
# Setup RPATH. See
# https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling
# Use separate rpaths during build and install phases
set(CMAKE_SKIP_BUILD_RPATH OFF)
# Don't use the install-rpath during the build phase
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
# Automatically add all linked folders that are NOT in the build directory to
# the rpath (per library?)
# TODO: Doesn't work for us right now because we are not installing .so's into the
# correct locations. For example we have libcustom_ops_aot_lib.so depending on
# _portable_lib.so, which was eventually put under <site-packages>/executorch/extension/pybindings/
# but this rpath is not automatically added because at build time it seems `portable_lib`
# is being built under the same directory, so no extra rpath is being added. To
# properly fix this we need to install `portable_lib` into the correct path.
# TODO: Doesn't work for us right now because we are
# not installing .so's into the correct locations. For example we have
# libcustom_ops_aot_lib.so depending on _portable_lib.so, which was eventually
# put under <site-packages>/executorch/extension/pybindings/ but this rpath is
# not automatically added because at build time it seems `portable_lib` is being
# built under the same directory, so no extra rpath is being added. To properly
# fix this we need to install `portable_lib` into the correct path.
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
# ------------------------------ OPTIONS -------------------------------------
# WARNING: Please don't add example specific options in this CMakeLists.txt.
Expand Down Expand Up @@ -177,7 +181,7 @@ endif()

if(NOT DEFINED FXDIV_SOURCE_DIR)
set(ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG
${CMAKE_POSITION_INDEPENDENT_CODE}
${CMAKE_POSITION_INDEPENDENT_CODE}
)
set(FXDIV_SOURCE_DIR "backends/xnnpack/third-party/FXdiv")
add_subdirectory("${FXDIV_SOURCE_DIR}")
Expand Down Expand Up @@ -276,7 +280,10 @@ if(NOT "${_repo_dir_name}" STREQUAL "executorch")
"fix for this restriction."
)
endif()
set(_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/runtime/core/portable_type/c10)
set(_common_include_directories
${CMAKE_CURRENT_SOURCE_DIR}/..
${CMAKE_CURRENT_SOURCE_DIR}/runtime/core/portable_type/c10
)

#
# The `_<target>_srcs` lists are defined by including ${EXECUTORCH_SRCS_FILE}.
Expand Down Expand Up @@ -310,9 +317,9 @@ endif()
# Detect if an Android toolchain is set.
if(CMAKE_TOOLCHAIN_FILE MATCHES ".*android\.toolchain\.cmake$")
set(CMAKE_TOOLCHAIN_ANDROID ON)
if(NOT ANDROID_PLATFORM)
set(ANDROID_PLATFORM android-30)
endif()
if(NOT ANDROID_PLATFORM)
set(ANDROID_PLATFORM android-30)
endif()
else()
set(CMAKE_TOOLCHAIN_ANDROID OFF)
endif()
Expand All @@ -334,7 +341,6 @@ if(EXECUTORCH_USE_CPP_CODE_COVERAGE)
endif()
endif()


#
# program_schema: Generated .h files from schema/*.fbs inputs
#
Expand Down Expand Up @@ -376,7 +382,9 @@ endif()
target_include_directories(
executorch_core PUBLIC ${_common_include_directories}
)
target_compile_definitions(executorch_core PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
target_compile_definitions(
executorch_core PUBLIC C10_USING_CUSTOM_GENERATED_MACROS
)
target_compile_options(executorch_core PUBLIC ${_common_compile_options})
if(MAX_KERNEL_NUM)
target_compile_definitions(
Expand All @@ -386,9 +394,7 @@ endif()

if(EXECUTORCH_BUILD_PYBIND AND APPLE)
# shared version
add_library(
executorch_core_shared SHARED ${_executorch_core__srcs}
)
add_library(executorch_core_shared SHARED ${_executorch_core__srcs})
target_link_libraries(executorch_core_shared PRIVATE program_schema)
if(DL_LIBRARY_EXISTS)
# For dladdr()
Expand All @@ -397,7 +403,9 @@ if(EXECUTORCH_BUILD_PYBIND AND APPLE)
target_include_directories(
executorch_core_shared PUBLIC ${_common_include_directories}
)
target_compile_definitions(executorch_core_shared PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
target_compile_definitions(
executorch_core_shared PUBLIC C10_USING_CUSTOM_GENERATED_MACROS
)
target_compile_options(
executorch_core_shared PUBLIC ${_common_compile_options}
)
Expand Down Expand Up @@ -430,9 +438,8 @@ target_link_options_shared_lib(executorch)
# operators necessary for the models that will run.
#
if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
# find pytorch lib here to make it available to all
# sub-directories. Find it before including portable so that
# optimized_portable_kernels can use it.
# find pytorch lib here to make it available to all sub-directories. Find it
# before including portable so that optimized_portable_kernels can use it.
find_package_torch_headers()
endif()

Expand All @@ -458,19 +465,50 @@ endif()

# Install `executorch` library as well as `executorch-config.cmake` under
# ${CMAKE_INSTALL_PREFIX}/
install(DIRECTORY runtime/core/ DESTINATION include/executorch/runtime/core FILES_MATCHING PATTERN "*.h")
install(DIRECTORY runtime/kernel/ DESTINATION include/executorch/runtime/kernel FILES_MATCHING PATTERN "*.h")
install(DIRECTORY runtime/platform/ DESTINATION include/executorch/runtime/platform FILES_MATCHING PATTERN "*.h")
install(DIRECTORY extension/kernel_util/ DESTINATION include/executorch/extension/kernel_util FILES_MATCHING PATTERN "*.h")
install(DIRECTORY extension/tensor/ DESTINATION include/executorch/extension/tensor FILES_MATCHING PATTERN "*.h")
install(DIRECTORY extension/threadpool/ DESTINATION include/executorch/extension/threadpool FILES_MATCHING PATTERN "*.h")
install(
DIRECTORY runtime/core/
DESTINATION include/executorch/runtime/core
FILES_MATCHING
PATTERN "*.h"
)
install(
DIRECTORY runtime/kernel/
DESTINATION include/executorch/runtime/kernel
FILES_MATCHING
PATTERN "*.h"
)
install(
DIRECTORY runtime/platform/
DESTINATION include/executorch/runtime/platform
FILES_MATCHING
PATTERN "*.h"
)
install(
DIRECTORY extension/kernel_util/
DESTINATION include/executorch/extension/kernel_util
FILES_MATCHING
PATTERN "*.h"
)
install(
DIRECTORY extension/tensor/
DESTINATION include/executorch/extension/tensor
FILES_MATCHING
PATTERN "*.h"
)
install(
DIRECTORY extension/threadpool/
DESTINATION include/executorch/extension/threadpool
FILES_MATCHING
PATTERN "*.h"
)
install(
TARGETS executorch executorch_core
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories}
)
install(FILES tools/cmake/executorch-config.cmake DESTINATION lib/cmake/ExecuTorch)
install(FILES tools/cmake/executorch-config.cmake
DESTINATION lib/cmake/ExecuTorch
)

if(EXECUTORCH_BUILD_ARM_BAREMETAL)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/arm)
Expand Down Expand Up @@ -608,17 +646,14 @@ if(EXECUTORCH_BUILD_PYBIND)
endif()

if(EXECUTORCH_BUILD_XNNPACK)
# need to explicitly specify XNNPACK and microkernels-prod
# here otherwise uses XNNPACK and microkernel-prod symbols from libtorch_cpu
# need to explicitly specify XNNPACK and microkernels-prod here otherwise
# uses XNNPACK and microkernel-prod symbols from libtorch_cpu
list(APPEND _dep_libs xnnpack_backend XNNPACK microkernels-prod)
endif()

# compile options for pybind
set(_pybind_compile_options
-Wno-deprecated-declarations
-fPIC
-frtti
-fexceptions
set(_pybind_compile_options -Wno-deprecated-declarations -fPIC -frtti
-fexceptions
)

# util lib
Expand Down