[CMake] Problem finding files while cross-compiling

Alexander Neundorf a.neundorf-work at gmx.net
Sun Feb 14 12:18:20 EST 2010


On Friday 12 February 2010, Pablo Yanez Trujillo wrote:
> Hi
>
> I need to compile a project with a arm cross-compiler. I've used
> http://www.vtk.org/Wiki/CMake_Cross_Compiling to create my toolchain file=
>
>
> ----
> # system name
> set(CMAKE_SYSTEM_NAME "Linux")
>
> # system version (in this case I choosed the kernel version)
> set(CMAKE_SYSTEM_VERSION  "2.6.14-M5")
>
> # the system pro
> set(CMAKE_SYSTEM_PROCESSOR "armv4")
>
>
> set(CMAKE_COMPILER_NAME_PREFIX "arm-9tdmi-linux-gnu-")
>
> # the C Compiler
> set(CMAKE_C_COMPILER "${CMAKE_COMPILER_NAME_PREFIX}gcc")
>
> # the C++ Compiler
> set(CMAKE_CXX_COMPILER "${CMAKE_COMPILER_NAME_PREFIX}g++")
>
> # hardcode path just for test
> SET(CMAKE_FIND_ROOT_PATH /home/PSE/yanez/projects/matrix500/buildtarget)
>
> # 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)
> SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
> -----
>
> Then I call cmake -DCMAKE_TOOLCHAIN_FILE=3D../arm-cross.cmake  ..
>
> In /home/.../buildtarget I have libraries (e.g. ncurses) and tools that
> already have been compiled with the arm-9tdmi-linux-gnu compiler.
>
> My problem is that find_file/file_path do dot work as I expect. I have
> some header files whose location path is determined by find_path but
> cmake does not find the files: for example ncurses.h
>
> find_path(NC_H ncurses.h DOC "...")
> message("NC_H is ${NC_H}")
>
> All I get is "NC_H is NC_H-NOTFOUND". When I use find_package(Curses)
> then this file is found without problems. I've looked into the
> FindCurses.cmake file and this file calls find_path twice and it seems
> that it only functions if you call it so:
>
> find_path(NC_H ncurses/ncurses.h ...)

I assume that your ncurses.h is located 
in /home/PSE/yanez/projects/matrix500/buildtarget/include/ncurses/ncurses.h

Now if you call 
find_path(NC_H ncurses.h)

it will look for ncurses.h in the set of include directories, e.g. it will 
look for ncurses.h directly 
in /home/PSE/yanez/projects/matrix500/buildtarget/include/. 
But since it is not located there, but in a subdirectory, it 
returns "NOTFOUND".

So if you have header files which are usually included as <foo/foo.h>, you 
also have to use foo/foo.h when searching for them with 
find_path()/find_file(), and not only search for foo.h.

Alex


More information about the CMake mailing list