@@ -17,6 +17,21 @@ if(NOT EXECUTORCH_ROOT)
1717endif ()
1818
1919list (TRANSFORM _extension_module__srcs PREPEND "${EXECUTORCH_ROOT} /" )
20+
21+ # Only add bundled_module.cpp if devtools is being built (required for bundled_program schema)
22+ if (EXECUTORCH_BUILD_DEVTOOLS)
23+ list (APPEND _extension_module__srcs "${EXECUTORCH_ROOT} /extension/module/bundled_module.cpp" )
24+ message (STATUS "extension_module: Including bundled_module.cpp (devtools enabled)" )
25+ else ()
26+ message (STATUS "extension_module: Excluding bundled_module.cpp (devtools disabled)" )
27+ endif ()
28+
29+ # Also add bundled_module sources if they exist (in case there are additional files)
30+ if (DEFINED _extension_bundled_module__srcs)
31+ list (TRANSFORM _extension_bundled_module__srcs PREPEND "${EXECUTORCH_ROOT} /" )
32+ list (APPEND _extension_module__srcs ${_extension_bundled_module__srcs} )
33+ endif ()
34+
2035if (CMAKE_TOOLCHAIN_IOS
2136 OR CMAKE_TOOLCHAIN_ANDROID
2237 OR APPLE
@@ -27,31 +42,75 @@ if(CMAKE_TOOLCHAIN_IOS
2742else ()
2843 add_library (extension_module SHARED ${_extension_module__srcs} )
2944endif ()
30- target_link_libraries (
31- extension_module PRIVATE executorch_core extension_data_loader
32- extension_flat_tensor
33- )
45+ # Link libraries - only link bundled_program if devtools is enabled
46+ if (EXECUTORCH_BUILD_DEVTOOLS)
47+ target_link_libraries (
48+ extension_module PRIVATE executorch_core extension_data_loader
49+ extension_flat_tensor bundled_program
50+ )
51+ target_compile_definitions (extension_module PRIVATE EXECUTORCH_BUILD_DEVTOOLS)
52+ else ()
53+ target_link_libraries (
54+ extension_module PRIVATE executorch_core extension_data_loader
55+ extension_flat_tensor
56+ )
57+ endif ()
3458target_include_directories (
3559 extension_module PUBLIC ${_common_include_directories}
3660)
3761target_compile_options (
3862 extension_module PUBLIC -Wno-deprecated-declarations -fPIC
3963)
4064
65+ # Only set USE_ATEN_LIB if PyTorch is actually available
66+ # This prevents build failures in OSS CMake CI where ATen headers are not available
67+ if (EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
68+ # Try to find PyTorch headers to check if ATen is available
69+ find_package (Torch CONFIG QUIET )
70+ if (TARGET torch)
71+ target_compile_definitions (extension_module PRIVATE USE_ATEN_LIB)
72+ message (STATUS "extension_module: Using ATen library (USE_ATEN_LIB enabled)" )
73+ else ()
74+ message (STATUS "extension_module: PyTorch not found, building without ATen support" )
75+ endif ()
76+ endif ()
77+
4178# Module extension built as a static library. TODO(gjcomer) Remove this target
4279# after cleaning up CMake targets.
4380add_library (extension_module_static STATIC ${_extension_module__srcs} )
44- target_link_libraries (
45- extension_module_static PRIVATE executorch_core extension_data_loader
46- extension_flat_tensor
47- )
81+ # Link libraries - only link bundled_program if devtools is enabled
82+ if (EXECUTORCH_BUILD_DEVTOOLS)
83+ target_link_libraries (
84+ extension_module_static PRIVATE executorch_core extension_data_loader
85+ extension_flat_tensor bundled_program
86+ )
87+ target_compile_definitions (extension_module_static PRIVATE EXECUTORCH_BUILD_DEVTOOLS)
88+ else ()
89+ target_link_libraries (
90+ extension_module_static PRIVATE executorch_core extension_data_loader
91+ extension_flat_tensor
92+ )
93+ endif ()
4894target_include_directories (
4995 extension_module_static PUBLIC ${_common_include_directories}
5096)
5197target_compile_options (
5298 extension_module_static PUBLIC -Wno-deprecated-declarations -fPIC
5399)
54100
101+ # Only set USE_ATEN_LIB if PyTorch is actually available
102+ # This prevents build failures in OSS CMake CI where ATen headers are not available
103+ if (EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
104+ # Try to find PyTorch headers to check if ATen is available
105+ find_package (Torch CONFIG QUIET )
106+ if (TARGET torch)
107+ target_compile_definitions (extension_module_static PRIVATE USE_ATEN_LIB)
108+ message (STATUS "extension_module_static: Using ATen library (USE_ATEN_LIB enabled)" )
109+ else ()
110+ message (STATUS "extension_module_static: PyTorch not found, building without ATen support" )
111+ endif ()
112+ endif ()
113+
55114# Install libraries
56115install (
57116 TARGETS extension_module extension_module_static
0 commit comments