[cmake-developers] FindBoost.cmake cannot find some libraries when cross-compiling

Guillaume Papin guillaume.papin at parrot.com
Wed Oct 15 10:57:29 EDT 2014


Yes I'm setting these variables.

See my toolchain configuration below:

cmake_minimum_required(VERSION 3.0) # CMAKE_SYSROOT

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv7l)

set(LINARO_PACKAGE_ROOT /opt/gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux/)
set(CMAKE_SYSROOT /home/user/my-project/my-custom-sysroot/)

set(ONLY_CMAKE_FIND_ROOT_PATH TRUE)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

set(CMAKE_C_COMPILER ${LINARO_PACKAGE_ROOT}/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${LINARO_PACKAGE_ROOT}/bin/arm-linux-gnueabihf-g++)

set(TOOLCHAIN_COMPILE_FLAGS
  "-mtune=cortex-a15 -march=armv7-a -mthumb -mfloat-abi=hard -mfpu=neon-vfpv4")

set(CMAKE_C_FLAGS "${TOOLCHAIN_COMPILE_FLAGS}" CACHE STRING
  "Flags used by the compiler during all build types." FORCE)
set(CMAKE_CXX_FLAGS "${TOOLCHAIN_COMPILE_FLAGS} -std=c++11" CACHE STRING
  "Flags used by the compiler during all build types." FORCE)
- Guillaume

________________________________
From: Chuck Atkins [chuck.atkins at kitware.com]
Sent: 15 October 2014 16:40
To: Guillaume Papin
Cc: cmake-developers at cmake.org
Subject: Re: [cmake-developers] FindBoost.cmake cannot find some libraries when cross-compiling

Can you post your toolchain file as well?  Does it set any of the CMAKE_FIND_ROOT_PATHG_MODE_{INCLUDE,PROGRAM,LIBRARY,PACKAGE} variables to anything?

- Chuck

On Wed, Oct 15, 2014 at 10:04 AM, Guillaume Papin <guillaume.papin at parrot.com<mailto:guillaume.papin at parrot.com>> wrote:
Hello CMake developers,

I have a cross-compiled version of Boost and some other libraries under ~/my-project/CrossThirdPartyPrefix.

I invoke CMake with a CMAKE_TOOLCHAIN_FILE and also I sets CMAKE_FIND_ROOT_PATH
to the directory where my cross-compiled Boost is installed.

    cmake -DCMAKE_TOOLCHAIN_FILE=$HOME/my-project/plateforms/arm-toolchain.cmake \
        -DCMAKE_FIND_ROOT_PATH=$HOME/my-project/CrossThirdPartyPrefix \
        ~/my-projects/src/

But I have an error when using FindBoost.cmake:

In my project's CMakeLists.txt:
    find_package(Boost 1.53.0 REQUIRED COMPONENTS atomic thread system)

The error:
     CMake Error at .../share/cmake-3.0/Modules/FindBoost.cmake:1179 (message):
       Unable to find the requested Boost libraries.

       Boost version: 1.55.0

       Boost include path:
       ~/myproject/CrossThirdPartyPrefix/include


       Could not find the following Boost libraries:

               boost_thread
               boost_system

       Some (but not all) of the required Boost libraries were found.  You may
       need to install these additional Boost libraries.  Alternatively, set
       BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
       to the location of Boost.


So the first component library (atomic) is found but not the other ones.

Looking at the code, when the first library is found, Boost_LIBRARY_DIR is set
to the directory that contains the library and then change the further calls of
find_library to use Boost_LIBRARY_DIR as the unique HINTS, and with the
NO_DEFAULT_PATH options set.

    macro(_Boost_FIND_LIBRARY var)
      find_library(${var} ${ARGN})

      if(${var})
        # If this is the first library found then save Boost_LIBRARY_DIR.
        if(NOT Boost_LIBRARY_DIR)
          get_filename_component(_dir "${${var}}" PATH)
          set(Boost_LIBRARY_DIR "${_dir}" CACHE PATH "Boost library directory" FORCE)
        endif()
      elseif(_Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT)
        # Try component-specific hints but do not save Boost_LIBRARY_DIR.
        find_library(${var} HINTS ${_Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT} ${ARGN})
      endif()

      # If Boost_LIBRARY_DIR is known then search only there.
      if(Boost_LIBRARY_DIR)
        set(_boost_LIBRARY_SEARCH_DIRS ${Boost_LIBRARY_DIR} NO_DEFAULT_PATH)
      endif()
    endmacro()

* https://github.com/Kitware/CMake/blob/1b3495d32e1523648da08e138482a654f8765333/Modules/FindBoost.cmake#L322-L325

The issue is that, when using CMAKE_FIND_ROOT_PATH, the Boost_LIBRARY_DIR of the
host (~/myproject/CrossThirdPartyPrefix/lib/ in my case), will be expanded against the root paths.

To find my libraries I can apply the following fix but I'm not sure if it's the
right solution or not.

    diff --git a/Modules/FindBoost.cmake b/Modules/FindBoost.cmake
    index 3642b3e..aad6575 100644
    --- a/Modules/FindBoost.cmake
    +++ b/Modules/FindBoost.cmake
    @@ -321,7 +321,7 @@ macro(_Boost_FIND_LIBRARY var)

       # If Boost_LIBRARY_DIR is known then search only there.
       if(Boost_LIBRARY_DIR)
    -    set(_boost_LIBRARY_SEARCH_DIRS ${Boost_LIBRARY_DIR} NO_DEFAULT_PATH)
    +    set(_boost_LIBRARY_SEARCH_DIRS ${Boost_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
       endif()
     endmacro()

    @@ -855,7 +855,7 @@ if(_Boost_CHANGE_LIBDIR AND NOT _Boost_LIBRARY_DIR_CHANGED)
     endif()

     if(Boost_LIBRARY_DIR)
    -  set(_boost_LIBRARY_SEARCH_DIRS ${Boost_LIBRARY_DIR} NO_DEFAULT_PATH)
    +  set(_boost_LIBRARY_SEARCH_DIRS ${Boost_LIBRARY_DIR} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
     else()
       set(_boost_LIBRARY_SEARCH_DIRS "")
       if(BOOST_LIBRARYDIR)


What I'm wondering is, whether or not Boost_LIBRARY_DIR should be a path on the target or on the host?

Right now, the workaround I have that doesn't require to modify FindBoost.cmake
is to set Boost_LIBRARY_DIR to /lib/, which will be expanded against the CMAKE_FIND_ROOT_PATH.

By the way, I'm a happy CMake user, thanks for all the work!
Guillaume
--

Powered by www.kitware.com<http://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-developers

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20141015/abd4ef15/attachment-0002.html>


More information about the cmake-developers mailing list