The PR Is closed pending me writing a test-case, but I just now updated to the my latest version and rebased on top of master:
https://gitlab.kitware.com/mingwandroid/cmake/commit/b937ff949d8fdaab7d8b812d503f67f8cef69532 Cheers. On Tue, Feb 7, 2017 at 8:37 AM, <joerg.krause@embedded.rocks> wrote: > Hi Ray, > > Am 2017-02-07 02:46, schrieb Ray Donnelly: >> >> I have a PR that asks the linker (via the compiler) what its implicit >> search directories are instead. >> >> It is the right way to do it IMHO, but I need to find time to finish >> it unfortunately. > > > Do you have a link to the PR? > >> On Feb 6, 2017 11:16 PM, "Jörg Krause" <joerg.krause@embedded.rocks> >> wrote: >> >>> On Mon, 2017-02-06 at 22:22 +0100, Jörg Krause wrote: >>>> >>>> Hi, >>>> >>>> On Sun, 2017-02-05 at 23:03 +0100, Jörg Krause wrote: >>>>> >>>>> Hi, >>>>> >>>>> when using CHECK_{SYMBOL,FUNCTION}_EXISTS in a cross-compilation >>>>> environment, CMake passes the host rpath to the linker: >>>>> >>>>> """ CMakeOutput.log >>>>> >>>>> /home/joerg/host/usr/bin/i586-linux-gcc >>>>> --sysroot=/home/joerg/host/usr/i586-buildroot-linux-musl/sysroot >>>>> -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 >>>>> -Os - >>>>> DNDEBUG CMakeFiles/cmTC_cb8f6.dir/CheckSymbolExists.c.o -o >>>>> cmTC_cb8f6 -Wl,-rpath,/usr/lib32 -rdynamic >>>>> /home/joerg/host/usr/i586- >>>>> buildroot-linux-musl/sysroot/usr/lib32/libmbedtls.so >>>>> /home/joerg/host/usr/i586-buildroot-linux- >>>>> musl/sysroot/usr/lib32/libmbedx509.so /home/joerg/host/usr/i586- >>>>> buildroot-linux-musl/sysroot/usr/lib32/libmbedcrypto.so >>>>> >>>>> """ >>>>> >>>>> This leads to a linker error if mbedtls is linked with zlib, as >>> >>> the >>>>> >>>>> linker tries to link with the host zlib and does not find the >>> >>> host >>>>> >>>>> libc: >>>>> >>>>> """ CMakeError.txt >>>>> >>>>> /home/joerg/host/usr/i586-buildroot-linux-musl/bin/ld: warning: >>>>> libc.so.6, needed by /usr/lib32/libz.so.1, not found (try using >>>>> -rpath >>>>> or -rpath-link) >>>>> /usr/lib32/libz.so.1: undefined reference to `strcpy@GLIBC_2.0' >>>>> /usr/lib32/libz.so.1: undefined reference to `free@GLIBC_2.0' >>>>> /usr/lib32/libz.so.1: undefined reference to `fseeko64@GLIBC_2.1 >>>>> [..] >>>>> >>>>> """ >>>>> >>>>> I did not find any solution which allows me to remove the rpath >>>>> from >>>>> the check. Setting CMAKE_SKIP_RPATH does not change the build >>>>> behaviour of the check_symbol_exists macro. >>>>> >>>>> From my understanding, the rpath flag should not be used when >>> >>> the >>>>> >>>>> sysroot flag is passed to the linker, right? >>>>> >>>>> For reference, I added a minimal example which uses Buildroot >>> >>> for >>>>> >>>>> cross-compilation. >>>>> >>>>> """ CMakeLists.txt >>>>> >>>>> cmake_minimum_required(VERSION 2.8.12) >>>>> >>>>> project(test) >>>>> >>>>> list(APPEND CMAKE_MODULE_PATH >>> >>> "${CMAKE_CURRENT_SOURCE_DIR}/cmake") >>>>> >>>>> >>>>> find_package(MbedTLS) >>>>> if(MBEDTLS_FOUND) >>>>> message(STATUS "Using mbedTLS") >>>>> endif() >>>>> >>>>> """ >>>>> >>>>> """ FindMbedTLS.cmake >>>>> >>>>> include(CheckSymbolExists) >>>>> >>>>> find_path(MBEDTLS_INCLUDE_DIRS >>>>> NAMES mbedtls/ssl.h >>>>> PATH_SUFFIXES include >>>>> ) >>>>> >>>>> find_library(MBEDTLS_LIBRARY NAMES mbedtls) >>>>> find_library(MBEDX509_LIBRARY NAMES mbedx509) >>>>> find_library(MBEDCRYPTO_LIBRARY NAMES mbedcrypto) >>>>> >>>>> if(MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY) >>>>> set(CMAKE_REQUIRED_INCLUDES ${MBEDTLS_INCLUDE_DIRS}) >>>>> set(CMAKE_REQUIRED_LIBRARIES ${MBEDTLS_LIBRARY} >>>>> ${MBEDX509_LIBRARY} ${MBEDCRYPTO_LIBRARY}) >>>>> check_symbol_exists(mbedtls_ssl_init "mbedtls/ssl.h" >>>>> MBEDTLS_V2) >>>>> endif() >>>>> >>>>> """ >>>>> >>>>> """ toolchainfile.cmake >>>>> >>>>> string(REPLACE "/usr/share/buildroot" "" RELOCATED_HOST_DIR >>>>> ${CMAKE_CURRENT_LIST_DIR}) >>>>> >>>>> set(CMAKE_SYSTEM_NAME Linux) >>>>> set(CMAKE_SYSTEM_PROCESSOR i586) >>>>> >>>>> set(CMAKE_C_FLAGS_DEBUG "" CACHE STRING "Debug CFLAGS") >>>>> set(CMAKE_CXX_FLAGS_DEBUG "" CACHE STRING "Debug CXXFLAGS") >>>>> set(CMAKE_C_FLAGS_RELEASE " -DNDEBUG" CACHE STRING "Release >>>>> CFLAGS") >>>>> set(CMAKE_CXX_FLAGS_RELEASE " -DNDEBUG" CACHE STRING "Release >>>>> CXXFLAGS") >>>>> >>>>> # Build type from the Buildroot configuration >>>>> set(CMAKE_BUILD_TYPE Release CACHE STRING "Buildroot build >>>>> configuration") >>>>> >>>>> # Buildroot defaults flags. >>>>> set(CMAKE_C_FLAGS "-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE >>>>> -D_FILE_OFFSET_BITS=64 -Os" CACHE STRING "Buildroot CFLAGS") >>>>> set(CMAKE_CXX_FLAGS "-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE >>>>> -D_FILE_OFFSET_BITS=64 -Os" CACHE STRING "Buildroot CXXFLAGS") >>>>> set(CMAKE_EXE_LINKER_FLAGS "" CACHE STRING "Buildroot LDFLAGS >>> >>> for >>>>> >>>>> executables") >>>>> >>>>> set(CMAKE_INSTALL_SO_NO_EXE 0) >>>>> >>>>> set(CMAKE_PROGRAM_PATH "${RELOCATED_HOST_DIR}/usr/bin") >>>>> set(CMAKE_SYSROOT >>> >>> "${RELOCATED_HOST_DIR}/usr/i586-buildroot-linux- >>>>> >>>>> musl/sysroot") >>>>> set(CMAKE_FIND_ROOT_PATH >>> >>> "${RELOCATED_HOST_DIR}/usr/i586-buildroot- >>>>> >>>>> linux-musl/sysroot") >>>>> set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) >>>>> set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) >>>>> set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) >>>>> set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) >>>>> set(ENV{PKG_CONFIG_SYSROOT_DIR} "${RELOCATED_HOST_DIR}/usr/i586- >>>>> buildroot-linux-musl/sysroot") >>>>> >>>>> # This toolchain file can be used both inside and outside >>>>> Buildroot. >>>>> set(CMAKE_C_COMPILER "${RELOCATED_HOST_DIR}/usr/bin/i586-linux- >>>>> gcc") >>>>> set(CMAKE_CXX_COMPILER >>> >>> "${RELOCATED_HOST_DIR}/usr/bin/i586-linux- >>>>> >>>>> g++") >>>>> >>>>> """ >>>>> >>>>> What do I miss? >>>> >>>> >>>> Note, that this project was build using CMake 3.7.2 on Debian. >>> >>> When >>>> >>>> using CMake 3.6.3, CMake does correctly not add rpath to the >>> >>> cross- >>>> >>>> linker and the check_symbol_exists() succeeds. >>> >>> >>> I did a git bisect. The behaviour was introduced in commit >>> 896ad251de49f167f4ce3cbbcf9a6cce85a16681 [1]. >>> >>> My suggestion is to set FIND_LIBRARY_USE_LIB32_PATHS and >>> FIND_LIBRARY_USE_LIB64_PATHS to FALSE when cross-compiling on Linux. >>> >>> [1] >>> https://gitlab.kitware.com/cmake/cmake/commit/896ad251de49f167f4ce3 >>> cbbcf9a6cce85a16681 >>> >>> Best regards, >>> Jörg Krause >>> -- >>> >>> Powered by www.kitware.com [1] >>> >>> Please keep messages on-topic and check the CMake FAQ at: >>> http://www.cmake.org/Wiki/CMake_FAQ [2] >>> >>> Kitware offers various services to support the CMake community. For >>> more information on each offering, please visit: >>> >>> CMake Support: http://cmake.org/cmake/help/support.html [3] >>> CMake Consulting: http://cmake.org/cmake/help/consulting.html [4] >>> CMake Training Courses: http://cmake.org/cmake/help/training.html >>> [5] >>> >>> Visit other Kitware open-source projects at >>> http://www.kitware.com/opensource/opensource.html [6] >>> >>> Follow this link to subscribe/unsubscribe: >>> http://public.kitware.com/mailman/listinfo/cmake [7] >> >> >> >> Links: >> ------ >> [1] http://www.kitware.com >> [2] http://www.cmake.org/Wiki/CMake_FAQ >> [3] http://cmake.org/cmake/help/support.html >> [4] http://cmake.org/cmake/help/consulting.html >> [5] http://cmake.org/cmake/help/training.html >> [6] http://www.kitware.com/opensource/opensource.html >> [7] http://public.kitware.com/mailman/listinfo/cmake > > -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake