Skip to content

Commit 85e0ce8

Browse files
committed
Fix check_assembler_flag to work with cmake 3.20
In the earliest version of cmake supported by LLVM, `try_compile` doesn't understand convenient `SOURCE_FROM_CONTENT` option, so we must manually write our (empty) assembly source file and pass it to `try_compile` by filename. It also doesn't understand `NO_CACHE`, so in order to avoid making a spurious cache entry called `success` which would confuse the next run, I'm putting the result directly into the user-specified output variable. This leads to a less helpful comment in CMakeCache.txt, but what can you do.
1 parent 2b16ac1 commit 85e0ce8

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

compiler-rt/cmake/Modules/CheckAssemblerFlag.cmake

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@ function(check_assembler_flag outvar flag)
2020
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
2121

2222
# Try to assemble an empty file with a .S name, using the provided flag.
23-
try_compile(success
24-
SOURCE_FROM_CONTENT "CheckAssemblerFlag.s" ""
25-
COMPILE_DEFINITIONS ${flag}
26-
NO_CACHE)
23+
set(asm_source_file
24+
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckAssemblerFlag.S)
25+
write_file(${asm_source_file} "")
26+
try_compile(${outvar}
27+
${CMAKE_BINARY_DIR}
28+
SOURCES ${asm_source_file}
29+
COMPILE_DEFINITIONS ${flag})
2730

2831
if(NOT CMAKE_REQUIRED_QUIET)
29-
if(success)
32+
if(${outvar})
3033
message(CHECK_PASS "Accepted")
31-
set(${outvar} 1 CACHE INTERNAL "Test assembler flag ${flag}")
3234
else()
3335
message(CHECK_FAIL "Not accepted")
34-
set(${outvar} "" CACHE INTERNAL "Test assembler flag ${flag}")
3536
endif()
3637
endif()
3738
endif()

0 commit comments

Comments
 (0)