@@ -49,56 +49,72 @@ set(_common_compile_options -Wno-deprecated-declarations -fPIC)
4949# Let files say "include <executorch/path/to/header.h>".
5050set (_common_include_directories ${EXECUTORCH_ROOT} /..)
5151
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
5454set (gflags_DIR ${CMAKE_CURRENT_BINARY_DIR} /../../../third-party/gflags)
5555find_package (gflags REQUIRED)
5656
5757#
5858# llama_main: test binary to run llama, with tokenizer and sampler integrated
5959#
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 ()
6560
66- # find `executorch` libraries
67- # Same as for gflags
61+ # find `executorch` libraries Same as for gflags
6862set (executorch_DIR ${CMAKE_CURRENT_BINARY_DIR} /../../../lib/cmake/ExecuTorch)
6963find_package (executorch CONFIG REQUIRED)
7064if (CMAKE_TOOLCHAIN_IOS OR ANDROID)
7165 target_link_options_shared_lib(executorch)
7266endif ()
7367
7468# custom ops library
75- add_subdirectory (custom_ops)
69+ if (EXECUTORCH_BUILD_CUSTOM)
70+ add_subdirectory (custom_ops)
71+ endif ()
7672
7773# llama_runner library
7874add_subdirectory (runner)
7975
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-
8576set (link_libraries )
77+ set (_srcs main.cpp)
8678
8779if (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)
9088 target_link_options_shared_lib(optimized_native_cpu_ops_lib)
9189else ()
9290 list (APPEND link_libraries portable_ops_lib portable_kernels)
9391 target_link_options_shared_lib(portable_ops_lib)
9492endif ()
9593
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 ()
9798
9899# XNNPACK pthreadpool cpuinfo
99100if (TARGET xnnpack_backend)
100101 set (xnnpack_backend_libs xnnpack_backend XNNPACK pthreadpool cpuinfo)
101102 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
102118 target_link_options_shared_lib(xnnpack_backend)
103119endif ()
104120
@@ -114,15 +130,19 @@ if(TARGET qnn_executorch_backend)
114130 target_link_options_shared_lib(qnn_executorch_backend)
115131endif ()
116132
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
119134if (ANDROID)
120135 list (APPEND link_libraries log )
121136endif ()
122137
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} )
126146
127147if (APPLE )
128148 target_link_options_shared_lib(executorch)
0 commit comments