[llvm] cd1b950 - [cmake] Fix native tooling when cross-compiling on Linux

Shoaib Meenai via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 20 10:05:25 PDT 2021


Author: Shoaib Meenai
Date: 2021-08-20T10:05:13-07:00
New Revision: cd1b95014121442b79ee91f2002cc82c70b17639

URL: https://github.com/llvm/llvm-project/commit/cd1b95014121442b79ee91f2002cc82c70b17639
DIFF: https://github.com/llvm/llvm-project/commit/cd1b95014121442b79ee91f2002cc82c70b17639.diff

LOG: [cmake] Fix native tooling when cross-compiling on Linux

At least as of CMake 3.20.3, the CMake platform file for Linux doesn't
define the file type prefix and suffix variables, relying on them being
implicitly empty when they're unset. If we're cross-compiling targeting
Windows on a Linux machine, the values of these prefixes and suffixes
populated by the Windows platform file will still be set after including
the Linux platform file, so we'll incorrectly assume the ".exe" suffix
for the host machine. Explicitly unset the variables before including
the platform file, to prevent any previous values from leaking. Thanks
@beanz for suggesting the fix.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D108473

Added: 
    

Modified: 
    llvm/cmake/config-ix.cmake

Removed: 
    


################################################################################
diff  --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index ba5a4a95b03a..0f6110ba7e1d 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -692,6 +692,17 @@ else()
 endif()
 
 function(llvm_get_host_prefixes_and_suffixes)
+  # Not all platform files will set these variables (relying on them being
+  # implicitly empty if they're unset), so unset the variables before including
+  # the platform file, to prevent any values from the target system leaking.
+  unset(CMAKE_STATIC_LIBRARY_PREFIX)
+  unset(CMAKE_STATIC_LIBRARY_SUFFIX)
+  unset(CMAKE_SHARED_LIBRARY_PREFIX)
+  unset(CMAKE_SHARED_LIBRARY_SUFFIX)
+  unset(CMAKE_IMPORT_LIBRARY_PREFIX)
+  unset(CMAKE_IMPORT_LIBRARY_SUFFIX)
+  unset(CMAKE_EXECUTABLE_SUFFIX)
+  unset(CMAKE_LINK_LIBRARY_SUFFIX)
   include(Platform/${CMAKE_HOST_SYSTEM_NAME} OPTIONAL RESULT_VARIABLE _includedFile)
   if (_includedFile)
     set(LLVM_HOST_STATIC_LIBRARY_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX} PARENT_SCOPE)


        


More information about the llvm-commits mailing list