[CMake] Re: Find* and cross compiling

Alexander Neundorf a.neundorf-work at gmx.net
Sun Dec 30 12:01:01 EST 2007


On Sunday 30 December 2007, Alexander Neundorf wrote:
> On Sunday 30 December 2007, E. Wing wrote:
> > Ugh, sorry, accidentally botched the first replies because the
> > original reply was not to the list.
> >
> > On 12/28/07, Rodolfo Lima <rodolfo at rodsoft.org> wrote:
> > > On Fri, Dec 28, 2007 at 05:40:59PM -0800, E. Wing wrote:
> > > > I didn't know cross-compiling was a feature now.
> > >
> > > Yes, works very well once you provide a 'toolchain file' with the
> > > correct setup.
> > >
> > > > But the FindLua, FindFreeType modules should be fine. According to
> > > > the documentation, the listed paths should only be searched last,
> > > > after all other CMake standard paths have been searched. If those
> > > > paths are being picked up, it means nothing in the standard
> > > > environment produced a hit.
> > >
> > > But then something would be found that wasn't compiled for the target.
> > > The scripts should make <LIB>_FOUND false. The standard paths you
> > > specify are already taken in consideration by cmake as long you don't
> > > pass NO_DEFAULT_PATHS to find_library/path. And it manages them quite
> > > well in a cross-compiling build.
> >
> > So the explicit path listing is somewhat of an anachronism. Once upon
> > a time, on some platforms, these search paths which should have been
> > searched were not. I think some of these have been fixed by now, but I
> > think some of them have not. The problem is that people just add them
> > to the script and don't report the problem to Kitware so this remains
> > unfixed. So I can't really remove these safely without breaking
> > somebody. Since they are simply redundant and searched last, it didn't
> > matter much before this feature.
>
> I'll check, but they shouldn't be searched anyway if the mode is set up
> correctly.

Ok, checked.
Here's my cmake file:

------------------------------------
find_library(MYLIB jpeg PATHS /usr/lib NO_DEFAULT_PATH )
message(STATUS "MYLIB: -${MYLIB}-")
add_executable(hello main.c)
------------------------------------

So I'm searching for the jpeg library and add /usr/lib explicitely.
Here's my toolchain file:
------------------------------------
# this one is important
SET(CMAKE_SYSTEM_NAME Linux)

# specify the cross compiler
SET(CMAKE_C_COMPILER   /usr/bin/gcc)
SET(CMAKE_CXX_COMPILER /usr/bin/g++)

# where is the target environment
SET(CMAKE_FIND_ROOT_PATH  /opt/xyz)

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
------------------------------------

Please note the ROOT_PATH, which is /opt/xyz which doesn't exist on my system. 
The mode for libs is set to ONLY, so it should search ONLY inside the 
ROOT_PATH.
Running cmake:
------------------------------------
strace /opt/cmake-HEAD/bin/cmake -DCMAKE_TOOLCHAIN_FILE=../tc.cmake .. 2> 
cmake.log
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Check size of void*
-- Check size of void* - done
-- Check for working CXX compiler: /usr/bin/g++
-- Check for working CXX compiler: /usr/bin/g++ -- works
-- MYLIB: -MYLIB-NOTFOUND-
-- Configuring done
-- Generating done
-- Build files have been written to: /home/alex/src/tests/crosstest/b
------------------------------------

So libjpeg.so (which exists in /usr/lib/) hasn't been found.
Let's check what strace says:

------------------------------------
hammer:~/src/tests/crosstest/b$ grep jpeg cmake.log
read(3, "find_library(MYLIB jpeg PATHS /u"..., 8192) = 123
access("/opt/xyz/usr/lib/libjpeg.so", R_OK) = -1 ENOENT (No such file or 
directory)
access("/opt/xyz/usr/lib/libjpeg.a", R_OK) = -1 ENOENT (No such file or 
directory)
hammer:~/src/tests/crosstest/b$         
------------------------------------

So it really searched only inside ROOT_PATH, not outside. So absolute paths 
used in FIND_XXX() calls will also be prefixed with the ROOT_PATH.

Rodolfo, can you please create a small reproducable test case ?

Alex


More information about the CMake mailing list