Skip to content

Commit a3f0bf7

Browse files
committed
Update
[ghstack-poisoned]
1 parent 3e19e67 commit a3f0bf7

File tree

6 files changed

+27
-25
lines changed

6 files changed

+27
-25
lines changed

CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,11 +706,7 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
706706

707707
add_executable(executor_runner ${_executor_runner__srcs})
708708
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
709-
if(APPLE)
710-
target_link_options(executor_runner PRIVATE "LINKER:-dead_strip")
711-
else()
712-
target_link_options(executor_runner PRIVATE "LINKER:--gc-sections")
713-
endif()
709+
target_link_options_gc_sections(executor_runner)
714710
endif()
715711
target_link_libraries(executor_runner ${_executor_runner_libs})
716712
target_compile_options(executor_runner PUBLIC ${_common_compile_options})

examples/models/llama/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,9 @@ endif()
210210

211211
add_executable(llama_main ${_srcs})
212212
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
213-
if(APPLE)
214-
target_link_options(llama_main PRIVATE "LINKER:-dead_strip")
215-
else()
216-
target_link_options(llama_main PRIVATE "LINKER:--gc-sections,-s")
213+
target_link_options_gc_sections(llama_main)
214+
if(NOT APPLE)
215+
target_link_options(llama_main PRIVATE "LINKER:-s")
217216
endif()
218217
endif()
219218

examples/models/llava/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,9 @@ list(APPEND _common_include_directories ${stb_SOURCE_DIR}
198198

199199
add_executable(llava_main ${_srcs})
200200
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
201-
if(APPLE)
202-
target_link_options(llava_main PRIVATE "LINKER:-dead_strip,-s")
203-
else()
204-
target_link_options(llava_main PRIVATE "LINKER:--gc-sections,-s")
201+
target_link_options_gc_sections(llama_main)
202+
if(NOT APPLE)
203+
target_link_options(llama_main PRIVATE "LINKER:-s")
205204
endif()
206205
endif()
207206

examples/selective_build/CMakeLists.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,22 @@ gen_selected_ops(
123123
)
124124

125125
generate_bindings_for_kernels(
126-
LIB_NAME
127-
"select_build_lib"
126+
LIB_NAME
127+
"select_build_lib"
128128
FUNCTIONS_YAML
129-
${EXECUTORCH_ROOT}/kernels/portable/functions.yaml
129+
${EXECUTORCH_ROOT}/kernels/portable/functions.yaml
130130
CUSTOM_OPS_YAML
131131
"${_custom_ops_yaml}"
132132
DTYPE_SELECTIVE_BUILD
133133
"${EXECUTORCH_DTYPE_SELECTIVE_BUILD}"
134134
)
135135

136136
gen_operators_lib(
137-
LIB_NAME
138-
"select_build_lib"
139-
KERNEL_LIBS
140-
${_kernel_lib}
141-
DEPS
137+
LIB_NAME
138+
"select_build_lib"
139+
KERNEL_LIBS
140+
${_kernel_lib}
141+
DEPS
142142
executorch_core
143143
DTYPE_SELECTIVE_BUILD
144144
"${EXECUTORCH_DTYPE_SELECTIVE_BUILD}"
@@ -152,7 +152,7 @@ list(TRANSFORM _executor_runner__srcs PREPEND "${EXECUTORCH_ROOT}/")
152152
#
153153
add_executable(selective_build_test ${_executor_runner__srcs})
154154
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
155-
target_link_options(selective_build_test PRIVATE "LINKER:--gc-sections")
155+
target_link_options_gc_sections(selective_build_test)
156156
endif()
157157
target_link_libraries(
158158
selective_build_test PRIVATE executorch_core gflags select_build_lib

test/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ list(TRANSFORM _size_test__srcs PREPEND "${EXECUTORCH_ROOT}/")
5353
add_executable(size_test ${_size_test__srcs})
5454
target_link_libraries(size_test executorch)
5555
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
56-
target_link_options(size_test PRIVATE "LINKER:--gc-sections")
56+
target_link_options_gc_sections(size_test)
5757
endif()
5858

5959
#
@@ -65,7 +65,7 @@ target_link_libraries(
6565
size_test_all_ops executorch portable_ops_lib portable_kernels
6666
)
6767
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
68-
target_link_options(size_test_all_ops PRIVATE "LINKER:--gc-sections")
68+
target_link_options_gc_sections(size_test_all_ops)
6969
endif()
7070

7171
#
@@ -77,6 +77,6 @@ target_link_options_shared_lib(optimized_native_cpu_ops_lib)
7777
target_link_libraries(
7878
size_test_all_optimized_ops executorch optimized_native_cpu_ops_lib)
7979
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
80-
target_link_options(size_test_all_optimized_ops PRIVATE "LINKER:--gc-sections")
80+
target_link_options_gc_sections(size_test_all_optimized_ops)
8181
endif()
8282
endif()

tools/cmake/Utils.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ function(target_link_options_shared_lib target_name)
5959
endif()
6060
endfunction()
6161

62+
function(target_link_options_gc_sections target_name)
63+
if(APPLE)
64+
target_link_options(${target_name} PRIVATE "LINKER:-dead_strip")
65+
else()
66+
target_link_options(${target_name} PRIVATE "LINKER:--gc-sections")
67+
endif()
68+
endfunction()
69+
6270
# Extract source files based on toml config. This is useful to keep buck2 and
6371
# cmake aligned. Do not regenerate if file exists.
6472
function(extract_sources sources_file)

0 commit comments

Comments
 (0)