[llvm] f28e48f - [cmake] Don't try creating an executable when detecting the linker
Louis Dionne via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 8 11:37:05 PDT 2022
Author: Louis Dionne
Date: 2022-06-08T14:36:54-04:00
New Revision: f28e48f3ef5aad3552a21f858aa501b4139a6f69
URL: https://github.com/llvm/llvm-project/commit/f28e48f3ef5aad3552a21f858aa501b4139a6f69
DIFF: https://github.com/llvm/llvm-project/commit/f28e48f3ef5aad3552a21f858aa501b4139a6f69.diff
LOG: [cmake] Don't try creating an executable when detecting the linker
On most platforms, the linker detection command that we run ends up being
something like `clang++ -Wl,-v` or `clang++ -Wl,--version`. This usually
fails with a missing reference to `_main` because we don't have any input
file. However, when compiling for a target that is implicitly freestanding,
the invocation actually succeeds and a dummy `a.out` file is created in
the current working directory. This is extremely annoying because it
creates a `a.out` file at the root of the monorepo when running CMake
configuration from the root.
Differential Revision: https://reviews.llvm.org/D125827
Added:
Modified:
llvm/cmake/modules/AddLLVM.cmake
Removed:
################################################################################
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 64d719f2626c9..ffc5d84227831 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -177,11 +177,17 @@ if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
set(version_flag "-Wl,--version")
endif()
+ if (CMAKE_HOST_WIN32)
+ set(DEVNULL "NUL")
+ else()
+ set(DEVNULL "/dev/null")
+ endif()
+
if(LLVM_USE_LINKER)
- set(command ${CMAKE_C_COMPILER} -fuse-ld=${LLVM_USE_LINKER} ${version_flag})
+ set(command ${CMAKE_C_COMPILER} -fuse-ld=${LLVM_USE_LINKER} ${version_flag} -o ${DEVNULL})
else()
separate_arguments(flags UNIX_COMMAND "${CMAKE_EXE_LINKER_FLAGS}")
- set(command ${CMAKE_C_COMPILER} ${flags} ${version_flag})
+ set(command ${CMAKE_C_COMPILER} ${flags} ${version_flag} -o ${DEVNULL})
endif()
execute_process(
COMMAND ${command}
More information about the llvm-commits
mailing list