Fix crossbuild on CentOS (#43189)
authorJan Vorlicek <janvorli@microsoft.com>
Fri, 9 Oct 2020 22:27:16 +0000 (00:27 +0200)
committerGitHub <noreply@github.com>
Fri, 9 Oct 2020 22:27:16 +0000 (00:27 +0200)
* Fix crossbuild on CentOS

This change fixes the crossbuilding to work on CentOS. Clang
frontend presets some of the compiler options based on the
host OS and I guess that's causing the need to add the
`--rpath-link`.
The ranlib change to use llvm ranlib fixed a problem where
cmake attempted to use ranlib from the rootfs for some
reason.

* Reflect PR feedback

eng/common/cross/toolchain.cmake
eng/native/configuretools.cmake

index 137736c..8b437d8 100644 (file)
@@ -139,6 +139,10 @@ function(add_toolchain_linker_flag Flag)
   set("CMAKE_SHARED_LINKER_FLAGS${CONFIG_SUFFIX}" "${CMAKE_SHARED_LINKER_FLAGS${CONFIG_SUFFIX}} ${Flag}" PARENT_SCOPE)
 endfunction()
 
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+  add_toolchain_linker_flag("-Wl,--rpath-link=${CROSS_ROOTFS}/lib/${TOOLCHAIN}")
+  add_toolchain_linker_flag("-Wl,--rpath-link=${CROSS_ROOTFS}/usr/lib/${TOOLCHAIN}")
+endif()
 
 if(TARGET_ARCH_NAME STREQUAL "armel")
   if(DEFINED TIZEN_TOOLCHAIN) # For Tizen only
index 0edbe2e..85e6bac 100644 (file)
@@ -41,10 +41,9 @@ if(NOT WIN32 AND NOT CLR_CMAKE_TARGET_BROWSER)
 
   locate_toolchain_exec(ar CMAKE_AR)
   locate_toolchain_exec(nm CMAKE_NM)
+  locate_toolchain_exec(ranlib CMAKE_RANLIB)
 
-  if(CMAKE_C_COMPILER_ID MATCHES "GNU")
-    locate_toolchain_exec(ranlib CMAKE_RANLIB)
-  else()
+  if(CMAKE_C_COMPILER_ID MATCHES "Clang")
     locate_toolchain_exec(link CMAKE_LINKER)
   endif()