3939# ~~~ 
4040# cmake-format -i CMakeLists.txt 
4141# ~~~ 
42- # It should also be cmake-lint clean. 
42+ # It should also be checked with a linter via 
43+ # ~~~ 
44+ # cmake-lint CMakeLists.txt 
45+ # ~~~ 
4346# 
4447
4548cmake_minimum_required (VERSION  3.24)
4649project (executorch)
4750
48- # MARK: - Start EXECUTORCH_H12025_BUILD_MIGRATION --------------------------------------------------  
51+ # MARK: - Start EXECUTORCH_H12025_BUILD_MIGRATION 
4952
5053include (${PROJECT_SOURCE_DIR} /tools/cmake/common/preset.cmake)
5154include (${PROJECT_SOURCE_DIR} /tools/cmake/Utils.cmake)
@@ -82,24 +85,25 @@ include(${PROJECT_SOURCE_DIR}/tools/cmake/preset/default.cmake)
8285# Print all the configs that were called with announce_configured_options. 
8386print_configured_options()
8487
85- # MARK: - End EXECUTORCH_H12025_BUILD_MIGRATION ----------------------------------------------------  
88+ # MARK: - End EXECUTORCH_H12025_BUILD_MIGRATION 
8689
8790set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
8891
89- # Setup RPATH. 
90- # See  https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling 
92+ # Setup RPATH. See  
93+ # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling 
9194# Use separate rpaths during build and install phases 
9295set (CMAKE_SKIP_BUILD_RPATH  OFF )
9396# Don't use the install-rpath during the build phase 
9497set (CMAKE_BUILD_WITH_INSTALL_RPATH  ON )
9598# Automatically add all linked folders that are NOT in the build directory to 
9699# the rpath (per library?) 
97- # TODO: Doesn't work for us right now because we are not installing .so's into the 
98- # correct locations. For example we have libcustom_ops_aot_lib.so depending on 
99- # _portable_lib.so, which was eventually put under <site-packages>/executorch/extension/pybindings/ 
100- # but this rpath is not automatically added because at build time it seems `portable_lib` 
101- # is being built under the same directory, so no extra rpath is being added. To 
102- # properly fix this we need to install `portable_lib` into the correct path. 
100+ # TODO: Doesn't work for us right now because we are 
101+ # not installing .so's into the correct locations. For example we have 
102+ # libcustom_ops_aot_lib.so depending on _portable_lib.so, which was eventually 
103+ # put under <site-packages>/executorch/extension/pybindings/ but this rpath is 
104+ # not automatically added because at build time it seems `portable_lib` is being 
105+ # built under the same directory, so no extra rpath is being added. To properly 
106+ # fix this we need to install `portable_lib` into the correct path. 
103107set (CMAKE_INSTALL_RPATH_USE_LINK_PATH  ON )
104108# ------------------------------ OPTIONS ------------------------------------- 
105109# WARNING: Please don't add example specific options in this CMakeLists.txt. 
@@ -143,6 +147,11 @@ else()
143147  set (CMAKE_CXX_FLAGS_RELEASE  "-O2 ${CMAKE_CXX_FLAGS_RELEASE} " )
144148endif ()
145149
150+ if (EXECUTORCH_BUILD_TESTS)
151+   set (EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR ON )
152+   include (CTest)
153+ endif ()
154+ 
146155add_subdirectory (third-party)
147156
148157if (EXECUTORCH_BUILD_EXTENSION_TRAINING)
@@ -172,7 +181,7 @@ endif()
172181
173182if (NOT  DEFINED  FXDIV_SOURCE_DIR)
174183  set (ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG
175-     ${CMAKE_POSITION_INDEPENDENT_CODE} 
184+        ${CMAKE_POSITION_INDEPENDENT_CODE} 
176185  )
177186  set (FXDIV_SOURCE_DIR "backends/xnnpack/third-party/FXdiv" )
178187  add_subdirectory ("${FXDIV_SOURCE_DIR} " )
@@ -254,11 +263,6 @@ if(EXECUTORCH_BUILD_PTHREADPOOL)
254263  )
255264endif ()
256265
257- if (EXECUTORCH_BUILD_TESTS)
258-   set (EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR ON )
259-   include (CTest)
260- endif ()
261- 
262266# TODO(dbort): Fix these warnings and remove this flag. 
263267set (_common_compile_options -Wno-deprecated-declarations -fPIC)
264268
@@ -276,7 +280,10 @@ if(NOT "${_repo_dir_name}" STREQUAL "executorch")
276280      "fix for this restriction." 
277281  )
278282endif ()
279- set (_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR} /.. ${CMAKE_CURRENT_SOURCE_DIR} /runtime/core/portable_type/c10)
283+ set (_common_include_directories
284+     ${CMAKE_CURRENT_SOURCE_DIR} /..
285+     ${CMAKE_CURRENT_SOURCE_DIR} /runtime/core/portable_type/c10
286+ )
280287
281288# 
282289# The `_<target>_srcs` lists are defined by including ${EXECUTORCH_SRCS_FILE}. 
@@ -310,9 +317,9 @@ endif()
310317# Detect if an Android toolchain is set. 
311318if (CMAKE_TOOLCHAIN_FILE MATCHES  ".*android\. toolchain\. cmake$" )
312319  set (CMAKE_TOOLCHAIN_ANDROID ON )
313- if (NOT  ANDROID_PLATFORM)
314-   set (ANDROID_PLATFORM android-30)
315- endif ()
320+    if (NOT  ANDROID_PLATFORM)
321+      set (ANDROID_PLATFORM android-30)
322+    endif ()
316323else ()
317324  set (CMAKE_TOOLCHAIN_ANDROID OFF )
318325endif ()
@@ -334,7 +341,6 @@ if(EXECUTORCH_USE_CPP_CODE_COVERAGE)
334341  endif ()
335342endif ()
336343
337- 
338344# 
339345# program_schema: Generated .h files from schema/*.fbs inputs 
340346# 
@@ -376,7 +382,9 @@ endif()
376382target_include_directories (
377383  executorch_core PUBLIC  ${_common_include_directories} 
378384)
379- target_compile_definitions (executorch_core PUBLIC  C10_USING_CUSTOM_GENERATED_MACROS)
385+ target_compile_definitions (
386+   executorch_core PUBLIC  C10_USING_CUSTOM_GENERATED_MACROS
387+ )
380388target_compile_options (executorch_core PUBLIC  ${_common_compile_options} )
381389if (MAX_KERNEL_NUM)
382390  target_compile_definitions (
@@ -386,9 +394,7 @@ endif()
386394
387395if (EXECUTORCH_BUILD_PYBIND AND  APPLE )
388396  # shared version 
389-   add_library (
390-     executorch_core_shared SHARED ${_executorch_core__srcs} 
391-   )
397+   add_library (executorch_core_shared SHARED ${_executorch_core__srcs} )
392398  target_link_libraries (executorch_core_shared PRIVATE  program_schema)
393399  if (DL_LIBRARY_EXISTS)
394400    # For dladdr() 
@@ -397,7 +403,9 @@ if(EXECUTORCH_BUILD_PYBIND AND APPLE)
397403  target_include_directories (
398404    executorch_core_shared PUBLIC  ${_common_include_directories} 
399405  )
400-   target_compile_definitions (executorch_core_shared PUBLIC  C10_USING_CUSTOM_GENERATED_MACROS)
406+   target_compile_definitions (
407+     executorch_core_shared PUBLIC  C10_USING_CUSTOM_GENERATED_MACROS
408+   )
401409  target_compile_options (
402410    executorch_core_shared PUBLIC  ${_common_compile_options} 
403411  )
@@ -430,9 +438,8 @@ target_link_options_shared_lib(executorch)
430438# operators necessary for the models that will run. 
431439# 
432440if (EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
433-   # find pytorch lib here to make it available to all 
434-   # sub-directories. Find it before including portable so that 
435-   # optimized_portable_kernels can use it. 
441+   # find pytorch lib here to make it available to all sub-directories. Find it 
442+   # before including portable so that optimized_portable_kernels can use it. 
436443  find_package_torch_headers()
437444endif ()
438445
@@ -458,24 +465,50 @@ endif()
458465
459466# Install `executorch` library as well as `executorch-config.cmake` under 
460467# ${CMAKE_INSTALL_PREFIX}/ 
461- install (DIRECTORY  runtime/core/  DESTINATION  include /executorch/runtime/core FILES_MATCHING PATTERN "*.h" )
462- install (DIRECTORY  runtime/kernel/  DESTINATION  include /executorch/runtime/kernel FILES_MATCHING PATTERN "*.h" )
463- install (DIRECTORY  runtime/platform/  DESTINATION  include /executorch/runtime/platform FILES_MATCHING PATTERN "*.h" )
464- install (DIRECTORY  extension/kernel_util/  DESTINATION  include /executorch/extension/kernel_util FILES_MATCHING PATTERN "*.h" )
465- install (DIRECTORY  extension/tensor/  DESTINATION  include /executorch/extension/tensor FILES_MATCHING PATTERN "*.h" )
466- install (DIRECTORY  extension/threadpool/  DESTINATION  include /executorch/extension/threadpool FILES_MATCHING PATTERN "*.h" )
468+ install (
469+   DIRECTORY  runtime/core/
470+   DESTINATION  include /executorch/runtime/core
471+   FILES_MATCHING
472+   PATTERN "*.h" 
473+ )
474+ install (
475+   DIRECTORY  runtime/kernel/
476+   DESTINATION  include /executorch/runtime/kernel
477+   FILES_MATCHING
478+   PATTERN "*.h" 
479+ )
480+ install (
481+   DIRECTORY  runtime/platform/
482+   DESTINATION  include /executorch/runtime/platform
483+   FILES_MATCHING
484+   PATTERN "*.h" 
485+ )
486+ install (
487+   DIRECTORY  extension/kernel_util/
488+   DESTINATION  include /executorch/extension/kernel_util
489+   FILES_MATCHING
490+   PATTERN "*.h" 
491+ )
492+ install (
493+   DIRECTORY  extension/tensor/
494+   DESTINATION  include /executorch/extension/tensor
495+   FILES_MATCHING
496+   PATTERN "*.h" 
497+ )
498+ install (
499+   DIRECTORY  extension/threadpool/
500+   DESTINATION  include /executorch/extension/threadpool
501+   FILES_MATCHING
502+   PATTERN "*.h" 
503+ )
467504install (
468505  TARGETS executorch executorch_core
469-   DESTINATION  lib
470506  INCLUDES
471507  DESTINATION  ${_common_include_directories} 
472508)
473- install (FILES  tools/cmake/executorch-config.cmake DESTINATION  lib/cmake/ExecuTorch)
474- 
475- # Add googletest if any test targets should be built 
476- if (BUILD_TESTING)
477-   add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR} /third-party/googletest)
478- endif ()
509+ install (FILES  tools/cmake/executorch-config.cmake
510+         DESTINATION  lib/cmake/ExecuTorch
511+ )
479512
480513if (EXECUTORCH_BUILD_ARM_BAREMETAL)
481514  add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR} /backends/arm)
@@ -613,17 +646,14 @@ if(EXECUTORCH_BUILD_PYBIND)
613646  endif ()
614647
615648  if (EXECUTORCH_BUILD_XNNPACK)
616-     # need to explicitly specify XNNPACK and microkernels-prod 
617-     # here otherwise  uses XNNPACK and microkernel-prod symbols from libtorch_cpu 
649+     # need to explicitly specify XNNPACK and microkernels-prod here otherwise  
650+     # uses XNNPACK and microkernel-prod symbols from libtorch_cpu 
618651    list (APPEND  _dep_libs xnnpack_backend XNNPACK microkernels-prod)
619652  endif ()
620653
621654  # compile options for pybind 
622-   set (_pybind_compile_options
623-       -Wno-deprecated-declarations
624-       -fPIC
625-       -frtti
626-       -fexceptions
655+   set (_pybind_compile_options -Wno-deprecated-declarations -fPIC -frtti
656+                               -fexceptions
627657  )
628658
629659  # util lib 
0 commit comments