Skip to content

Commit 091adb8

Browse files
[libc][cmake] move _get_{common|hermetic}_test_compile_options to LLVMLibCTestRules.cmake (#122549)
They're only used in that file, which is more appropriate than LLVMLibCCompileOptionRules.cmake since they're strictly related to tests. Remove unused flags param from _get_hermetic_test_compile_options, and flags that were already set by a prior call to _get_common_test_compile_options.
1 parent 616007d commit 091adb8

File tree

2 files changed

+77
-83
lines changed

2 files changed

+77
-83
lines changed

libc/cmake/modules/LLVMLibCCompileOptionRules.cmake

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -213,85 +213,3 @@ function(_get_common_compile_options output_var flags)
213213
endif()
214214
set(${output_var} ${compile_options} PARENT_SCOPE)
215215
endfunction()
216-
217-
function(_get_common_test_compile_options output_var c_test flags)
218-
_get_compile_options_from_flags(compile_flags ${flags})
219-
220-
set(compile_options
221-
${LIBC_COMPILE_OPTIONS_DEFAULT}
222-
${LIBC_TEST_COMPILE_OPTIONS_DEFAULT}
223-
${compile_flags})
224-
225-
if(LLVM_LIBC_COMPILER_IS_GCC_COMPATIBLE)
226-
list(APPEND compile_options "-fpie")
227-
228-
if(LLVM_LIBC_FULL_BUILD)
229-
list(APPEND compile_options "-DLIBC_FULL_BUILD")
230-
# Only add -ffreestanding flag in full build mode.
231-
list(APPEND compile_options "-ffreestanding")
232-
list(APPEND compile_options "-fno-exceptions")
233-
list(APPEND compile_options "-fno-unwind-tables")
234-
list(APPEND compile_options "-fno-asynchronous-unwind-tables")
235-
if(NOT c_test)
236-
list(APPEND compile_options "-fno-rtti")
237-
endif()
238-
endif()
239-
240-
if(LIBC_COMPILER_HAS_FIXED_POINT)
241-
list(APPEND compile_options "-ffixed-point")
242-
endif()
243-
244-
# list(APPEND compile_options "-Wall")
245-
# list(APPEND compile_options "-Wextra")
246-
# -DLIBC_WNO_ERROR=ON if you can't build cleanly with -Werror.
247-
if(NOT LIBC_WNO_ERROR)
248-
# list(APPEND compile_options "-Werror")
249-
endif()
250-
# list(APPEND compile_options "-Wconversion")
251-
# list(APPEND compile_options "-Wno-sign-conversion")
252-
# list(APPEND compile_options "-Wimplicit-fallthrough")
253-
# list(APPEND compile_options "-Wwrite-strings")
254-
# list(APPEND compile_options "-Wextra-semi")
255-
# Silence this warning because _Complex is a part of C99.
256-
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
257-
if(NOT c_test)
258-
list(APPEND compile_options "-fext-numeric-literals")
259-
endif()
260-
else()
261-
list(APPEND compile_options "-Wno-c99-extensions")
262-
list(APPEND compile_options "-Wno-gnu-imaginary-constant")
263-
endif()
264-
list(APPEND compile_options "-Wno-pedantic")
265-
# if(NOT CMAKE_COMPILER_IS_GNUCXX)
266-
# list(APPEND compile_options "-Wnewline-eof")
267-
# list(APPEND compile_options "-Wnonportable-system-include-path")
268-
# list(APPEND compile_options "-Wstrict-prototypes")
269-
# list(APPEND compile_options "-Wthread-safety")
270-
# list(APPEND compile_options "-Wglobal-constructors")
271-
# endif()
272-
endif()
273-
set(${output_var} ${compile_options} PARENT_SCOPE)
274-
endfunction()
275-
276-
function(_get_hermetic_test_compile_options output_var flags)
277-
_get_common_test_compile_options(compile_options "" "${flags}")
278-
279-
list(APPEND compile_options "-fpie")
280-
list(APPEND compile_options "-ffreestanding")
281-
list(APPEND compile_options "-fno-exceptions")
282-
list(APPEND compile_options "-fno-rtti")
283-
284-
# The GPU build requires overriding the default CMake triple and architecture.
285-
if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
286-
list(APPEND compile_options
287-
-Wno-multi-gpu -nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto
288-
-mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION})
289-
elseif(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
290-
list(APPEND compile_options
291-
"SHELL:-mllvm -nvptx-emit-init-fini-kernel=false"
292-
-Wno-multi-gpu --cuda-path=${LIBC_CUDA_ROOT}
293-
-nogpulib -march=${LIBC_GPU_TARGET_ARCHITECTURE} -fno-use-cxa-atexit)
294-
endif()
295-
296-
set(${output_var} ${compile_options} PARENT_SCOPE)
297-
endfunction()

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,80 @@
1+
function(_get_common_test_compile_options output_var c_test flags)
2+
_get_compile_options_from_flags(compile_flags ${flags})
3+
4+
set(compile_options
5+
${LIBC_COMPILE_OPTIONS_DEFAULT}
6+
${LIBC_TEST_COMPILE_OPTIONS_DEFAULT}
7+
${compile_flags})
8+
9+
if(LLVM_LIBC_COMPILER_IS_GCC_COMPATIBLE)
10+
list(APPEND compile_options "-fpie")
11+
12+
if(LLVM_LIBC_FULL_BUILD)
13+
list(APPEND compile_options "-DLIBC_FULL_BUILD")
14+
# Only add -ffreestanding flag in full build mode.
15+
list(APPEND compile_options "-ffreestanding")
16+
list(APPEND compile_options "-fno-exceptions")
17+
list(APPEND compile_options "-fno-unwind-tables")
18+
list(APPEND compile_options "-fno-asynchronous-unwind-tables")
19+
if(NOT c_test)
20+
list(APPEND compile_options "-fno-rtti")
21+
endif()
22+
endif()
23+
24+
if(LIBC_COMPILER_HAS_FIXED_POINT)
25+
list(APPEND compile_options "-ffixed-point")
26+
endif()
27+
28+
# list(APPEND compile_options "-Wall")
29+
# list(APPEND compile_options "-Wextra")
30+
# -DLIBC_WNO_ERROR=ON if you can't build cleanly with -Werror.
31+
if(NOT LIBC_WNO_ERROR)
32+
# list(APPEND compile_options "-Werror")
33+
endif()
34+
# list(APPEND compile_options "-Wconversion")
35+
# list(APPEND compile_options "-Wno-sign-conversion")
36+
# list(APPEND compile_options "-Wimplicit-fallthrough")
37+
# list(APPEND compile_options "-Wwrite-strings")
38+
# list(APPEND compile_options "-Wextra-semi")
39+
# Silence this warning because _Complex is a part of C99.
40+
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
41+
if(NOT c_test)
42+
list(APPEND compile_options "-fext-numeric-literals")
43+
endif()
44+
else()
45+
list(APPEND compile_options "-Wno-c99-extensions")
46+
list(APPEND compile_options "-Wno-gnu-imaginary-constant")
47+
endif()
48+
list(APPEND compile_options "-Wno-pedantic")
49+
# if(NOT CMAKE_COMPILER_IS_GNUCXX)
50+
# list(APPEND compile_options "-Wnewline-eof")
51+
# list(APPEND compile_options "-Wnonportable-system-include-path")
52+
# list(APPEND compile_options "-Wstrict-prototypes")
53+
# list(APPEND compile_options "-Wthread-safety")
54+
# list(APPEND compile_options "-Wglobal-constructors")
55+
# endif()
56+
endif()
57+
set(${output_var} ${compile_options} PARENT_SCOPE)
58+
endfunction()
59+
60+
function(_get_hermetic_test_compile_options output_var)
61+
_get_common_test_compile_options(compile_options "" "")
62+
63+
# The GPU build requires overriding the default CMake triple and architecture.
64+
if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
65+
list(APPEND compile_options
66+
-Wno-multi-gpu -nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto
67+
-mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION})
68+
elseif(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
69+
list(APPEND compile_options
70+
"SHELL:-mllvm -nvptx-emit-init-fini-kernel=false"
71+
-Wno-multi-gpu --cuda-path=${LIBC_CUDA_ROOT}
72+
-nogpulib -march=${LIBC_GPU_TARGET_ARCHITECTURE} -fno-use-cxa-atexit)
73+
endif()
74+
75+
set(${output_var} ${compile_options} PARENT_SCOPE)
76+
endfunction()
77+
178
# This is a helper function and not a build rule. It is to be used by the
279
# various test rules to generate the full list of object files
380
# recursively produced by "add_entrypoint_object" and "add_object_library"
@@ -100,7 +177,6 @@ function(get_object_files_for_test result skipped_entrypoints_list)
100177

101178
endfunction(get_object_files_for_test)
102179

103-
104180
# Rule to add a libc unittest.
105181
# Usage
106182
# add_libc_unittest(

0 commit comments

Comments
 (0)