@@ -49,56 +49,72 @@ set(_common_compile_options -Wno-deprecated-declarations -fPIC)
49
49
# Let files say "include <executorch/path/to/header.h>".
50
50
set (_common_include_directories ${EXECUTORCH_ROOT} /..)
51
51
52
- # For some reason android build is not able to find where gflags is
53
- # and hence cannot find corresponding .cmake file
52
+ # For some reason android build is not able to find where gflags is and hence
53
+ # cannot find corresponding .cmake file
54
54
set (gflags_DIR ${CMAKE_CURRENT_BINARY_DIR} /../../../third-party/gflags)
55
55
find_package (gflags REQUIRED)
56
56
57
57
#
58
58
# llama_main: test binary to run llama, with tokenizer and sampler integrated
59
59
#
60
- add_executable (llama_main main.cpp
61
- ${CMAKE_CURRENT_SOURCE_DIR} /../../../backends/xnnpack/threadpool/cpuinfo_utils.cpp)
62
- if (CMAKE_BUILD_TYPE EQUAL "RELEASE" )
63
- target_link_options (llama_main PRIVATE "LINKER:--gc-sections" )
64
- endif ()
65
60
66
- # find `executorch` libraries
67
- # Same as for gflags
61
+ # find `executorch` libraries Same as for gflags
68
62
set (executorch_DIR ${CMAKE_CURRENT_BINARY_DIR} /../../../lib/cmake/ExecuTorch)
69
63
find_package (executorch CONFIG REQUIRED)
70
64
if (CMAKE_TOOLCHAIN_IOS OR ANDROID)
71
65
target_link_options_shared_lib(executorch)
72
66
endif ()
73
67
74
68
# custom ops library
75
- add_subdirectory (custom_ops)
69
+ if (EXECUTORCH_BUILD_CUSTOM)
70
+ add_subdirectory (custom_ops)
71
+ endif ()
76
72
77
73
# llama_runner library
78
74
add_subdirectory (runner)
79
75
80
- target_include_directories (llama_main PUBLIC
81
- ${CMAKE_CURRENT_SOURCE_DIR} /../../../backends/xnnpack/third-party/cpuinfo/include )
82
- target_include_directories (llama_main PUBLIC
83
- ${CMAKE_CURRENT_SOURCE_DIR} /../../../backends/xnnpack/third-party/pthreadpool/include )
84
-
85
76
set (link_libraries )
77
+ set (_srcs main.cpp)
86
78
87
79
if (EXECUTORCH_BUILD_OPTIMIZED)
88
- list (APPEND link_libraries optimized_native_cpu_ops_lib optimized_kernels
89
- portable_kernels cpublas eigen_blas)
80
+ list (
81
+ APPEND
82
+ link_libraries
83
+ optimized_native_cpu_ops_lib
84
+ optimized_kernels
85
+ portable_kernels
86
+ cpublas
87
+ eigen_blas)
90
88
target_link_options_shared_lib(optimized_native_cpu_ops_lib)
91
89
else ()
92
90
list (APPEND link_libraries portable_ops_lib portable_kernels)
93
91
target_link_options_shared_lib(portable_ops_lib)
94
92
endif ()
95
93
96
- target_link_libraries (llama_main PUBLIC gflags llama_runner custom_ops_lib)
94
+ if (EXECUTORCH_BUILD_CUSTOM)
95
+ target_link_options_shared_lib(custom_ops_lib)
96
+ list (APPEND link_libraries custom_ops_lib)
97
+ endif ()
97
98
98
99
# XNNPACK pthreadpool cpuinfo
99
100
if (TARGET xnnpack_backend)
100
101
set (xnnpack_backend_libs xnnpack_backend XNNPACK pthreadpool cpuinfo)
101
102
list (APPEND link_libraries ${xnnpack_backend_libs} )
103
+ # HACK: main only include these when xnnpack backend is availabe, so that we
104
+ # have all the threadpool sources under xnnpack.
105
+ list (APPEND _common_compile_options -DET_USE_THREADPOOL)
106
+ list (
107
+ APPEND
108
+ _srcs
109
+ ${CMAKE_CURRENT_SOURCE_DIR} /../../../backends/xnnpack/threadpool/cpuinfo_utils.cpp
110
+ )
111
+ list (
112
+ APPEND
113
+ _common_include_directories
114
+ ${CMAKE_CURRENT_SOURCE_DIR} /../../../backends/xnnpack/third-party/cpuinfo/include
115
+ ${CMAKE_CURRENT_SOURCE_DIR} /../../../backends/xnnpack/third-party/pthreadpool/include
116
+ )
117
+ # end of hack
102
118
target_link_options_shared_lib(xnnpack_backend)
103
119
endif ()
104
120
@@ -114,15 +130,19 @@ if(TARGET qnn_executorch_backend)
114
130
target_link_options_shared_lib(qnn_executorch_backend)
115
131
endif ()
116
132
117
- # This one is needed for cpuinfo where it uses android
118
- # specific log lib
133
+ # This one is needed for cpuinfo where it uses android specific log lib
119
134
if (ANDROID)
120
135
list (APPEND link_libraries log )
121
136
endif ()
122
137
123
- target_compile_options (llama_main PUBLIC ${_common_compile_options}
124
- -DET_USE_THREADPOOL)
125
- target_link_libraries (llama_main PUBLIC ${link_libraries} )
138
+ add_executable (llama_main ${_srcs} )
139
+ if (CMAKE_BUILD_TYPE EQUAL "RELEASE" )
140
+ target_link_options (llama_main PRIVATE "LINKER:--gc-sections" )
141
+ endif ()
142
+
143
+ target_include_directories (llama_main PUBLIC ${_common_include_directories} )
144
+ target_link_libraries (llama_main PUBLIC gflags llama_runner ${link_libraries} )
145
+ target_compile_options (llama_main PUBLIC ${_common_compile_options} )
126
146
127
147
if (APPLE )
128
148
target_link_options_shared_lib(executorch)
0 commit comments