[Cmake] linux cmake 1.8 INCLUDE out-of-source problem

Brad King brad . king at kitware . com
Tue, 30 Dec 2003 11:59:20 -0500 (EST)


On Tue, 30 Dec 2003, Zennard Sun wrote:

> Hi,
>     I have tested the following with SunOS and Linux setups using CMake
> versions 1.6 and 1.8.  I only have this problem with Linux CMake version
> 1.8 (with both 1.8.1 and 1.8.2 whereas Linux version 1.6.7 works).  I
> have the following setup:
>
> folder/src
> (where the source files are as well as CMakeLists.txt)
>
> folder/obj/linux
> (the build directory where the out-of-source build goes)
>
> folder/helper.txt
> (a file I want to include into my CMakeLists.txt)
>
> Inside folder/src/CMakeLists.txt I have the following two lines:
>
> SET(file_path .. CACHE PATH "Offset to file location")
> INCLUDE(${file_path}/helper.txt)
>
> When I want to do an out of source build, I go to the folder/obj/linux
> and type:
>
> cmake ../../src -Dfile_path:string=../..
>
> Since I am running an out-of-source build, I need to change the
> file_path so it is correct from the build directory.  This used to work
> with CMake version 1.6, however, now I get the following error:
>
> INCLUDE Could not find include file: ../../helper.txt
>
> This file does exist at the given location relative to the build
> directory.  Any thoughts?

In CMake 1.6, the INCLUDE command did not support relative paths.  The
only reason it seemed to be working for you was because the current
working directory when you ran CMake happened to be the right place for
your relative path specification to work.

In CMake 1.8, the INCLUDE command expands paths relative to the
CMakeLists.txt file in which the command is processed.  Therefore when you
specify ../.., it is looking in folder/src/../.. instead of
folder/obj/../.. as was accidentally working in CMake 1.6 for your
specific case.

The right solution for you depends on what you're trying to do.  What is
helper.txt?  If it is always in the same place relative to the source
directory, then you should not need the cache entry at all.  Just use
something like

  INCLUDE(${PROJECT_SOURCE_DIR}/../helper.txt)

If it is a file that can be located anywhere, then the full path should be
specified in file_path.  Note also that the type is not needed in CMake
1.8 if the SET(file_path ...) command gives the cache type.  You can just
run

  cmake ../../src -Dfile_path=~/folder

-Brad