@@ -17,6 +17,16 @@ if(NOT EXECUTORCH_ROOT)
1717endif ()
1818
1919list (TRANSFORM _extension_module__srcs PREPEND "${EXECUTORCH_ROOT} /" )
20+
21+ # Always add bundled_module.cpp to ensure it's included
22+ list (APPEND _extension_module__srcs "${EXECUTORCH_ROOT} /extension/module/bundled_module.cpp" )
23+
24+ # Also add bundled_module sources if they exist (in case there are additional files)
25+ if (DEFINED _extension_bundled_module__srcs)
26+ list (TRANSFORM _extension_bundled_module__srcs PREPEND "${EXECUTORCH_ROOT} /" )
27+ list (APPEND _extension_module__srcs ${_extension_bundled_module__srcs} )
28+ endif ()
29+
2030if (CMAKE_TOOLCHAIN_IOS
2131 OR CMAKE_TOOLCHAIN_ANDROID
2232 OR APPLE
2939endif ()
3040target_link_libraries (
3141 extension_module PRIVATE executorch_core extension_data_loader
32- extension_flat_tensor
42+ extension_flat_tensor bundled_program
3343)
3444target_include_directories (
3545 extension_module PUBLIC ${_common_include_directories}
@@ -38,12 +48,25 @@ target_compile_options(
3848 extension_module PUBLIC -Wno-deprecated-declarations -fPIC
3949)
4050
51+ # Only set USE_ATEN_LIB if PyTorch is actually available
52+ # This prevents build failures in OSS CMake CI where ATen headers are not available
53+ if (EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
54+ # Try to find PyTorch headers to check if ATen is available
55+ find_package (Torch CONFIG QUIET )
56+ if (TARGET torch)
57+ target_compile_definitions (extension_module PRIVATE USE_ATEN_LIB)
58+ message (STATUS "extension_module: Using ATen library (USE_ATEN_LIB enabled)" )
59+ else ()
60+ message (STATUS "extension_module: PyTorch not found, building without ATen support" )
61+ endif ()
62+ endif ()
63+
4164# Module extension built as a static library. TODO(gjcomer) Remove this target
4265# after cleaning up CMake targets.
4366add_library (extension_module_static STATIC ${_extension_module__srcs} )
4467target_link_libraries (
4568 extension_module_static PRIVATE executorch_core extension_data_loader
46- extension_flat_tensor
69+ extension_flat_tensor bundled_program
4770)
4871target_include_directories (
4972 extension_module_static PUBLIC ${_common_include_directories}
@@ -52,6 +75,19 @@ target_compile_options(
5275 extension_module_static PUBLIC -Wno-deprecated-declarations -fPIC
5376)
5477
78+ # Only set USE_ATEN_LIB if PyTorch is actually available
79+ # This prevents build failures in OSS CMake CI where ATen headers are not available
80+ if (EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
81+ # Try to find PyTorch headers to check if ATen is available
82+ find_package (Torch CONFIG QUIET )
83+ if (TARGET torch)
84+ target_compile_definitions (extension_module_static PRIVATE USE_ATEN_LIB)
85+ message (STATUS "extension_module_static: Using ATen library (USE_ATEN_LIB enabled)" )
86+ else ()
87+ message (STATUS "extension_module_static: PyTorch not found, building without ATen support" )
88+ endif ()
89+ endif ()
90+
5591# Install libraries
5692install (
5793 TARGETS extension_module extension_module_static
0 commit comments