@@ -57,14 +57,6 @@ find_package(gflags REQUIRED)
57
57
#
58
58
# llama_main: test binary to run llama, with tokenizer and sampler integrated
59
59
#
60
- add_executable (
61
- llama_main
62
- main.cpp
63
- ${CMAKE_CURRENT_SOURCE_DIR} /../../../backends/xnnpack/threadpool/cpuinfo_utils.cpp
64
- )
65
- if (CMAKE_BUILD_TYPE EQUAL "RELEASE" )
66
- target_link_options (llama_main PRIVATE "LINKER:--gc-sections" )
67
- endif ()
68
60
69
61
# find `executorch` libraries Same as for gflags
70
62
set (executorch_DIR ${CMAKE_CURRENT_BINARY_DIR} /../../../lib/cmake/ExecuTorch )
@@ -81,18 +73,8 @@ endif()
81
73
# llama_runner library
82
74
add_subdirectory (runner )
83
75
84
- target_include_directories (
85
- llama_main
86
- PUBLIC
87
- ${CMAKE_CURRENT_SOURCE_DIR} /../../../backends/xnnpack/third-party/cpuinfo/include
88
- )
89
- target_include_directories (
90
- llama_main
91
- PUBLIC
92
- ${CMAKE_CURRENT_SOURCE_DIR} /../../../backends/xnnpack/third-party/pthreadpool/include
93
- )
94
-
95
76
set (link_libraries )
77
+ set (_srcs main.cpp )
96
78
97
79
if (EXECUTORCH_BUILD_OPTIMIZED )
98
80
list (
@@ -114,12 +96,25 @@ if(EXECUTORCH_BUILD_CUSTOM)
114
96
list (APPEND link_libraries custom_ops )
115
97
endif ()
116
98
117
- target_link_libraries (llama_main PUBLIC gflags llama_runner )
118
-
119
99
# XNNPACK pthreadpool cpuinfo
120
100
if (TARGET xnnpack_backend )
121
101
set (xnnpack_backend_libs xnnpack_backend XNNPACK pthreadpool cpuinfo )
122
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
123
118
target_link_options_shared_lib (xnnpack_backend )
124
119
endif ()
125
120
@@ -140,9 +135,14 @@ if(ANDROID)
140
135
list (APPEND link_libraries log )
141
136
endif ()
142
137
143
- target_compile_options (llama_main PUBLIC ${_common_compile_options}
144
- -DET_USE_THREADPOOL )
145
- 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} )
146
146
147
147
if (APPLE )
148
148
target_link_options_shared_lib (executorch )
0 commit comments