[CMake] CMake being too clever?

Amitha Perera perera at cs.rpi.edu
Fri Jul 22 16:02:46 EDT 2005


On Fri 22 Jul 2005, Brad King wrote on the topic of relative and
absolute paths:

> The problem is that CMake IS remembering this [user supplied paths].
> It no longer uses realpath.  It is generating the proper relative
> path taking the symlink into account.  Then MAKE is evaluating the
> relative path with respect to the realpath and not the logical path.
> There is nothing we can do about that :(

What I'm saying is that CMake should not suppose a relationship
between the source tree and binary tree, whether that relationship be
via relative or absolute paths, and should rely completely on what
the user provided as the relationship. When CMake is first run, it is
given the relationship between the binary directory and the source
directory:

    /my/bin/path$ cmake /my/src/path

At this point, CMake knows that /my/bin/path (call it BIN) relates to
/my/src/path (call it SRC). Each SUBDIRS command introduces further
relationships: SUBDIRS( x ) implies SRC/x is related to BIN/x, and a
SUBDIRS( y ) in x implies SRC/x/y/ is related to BIN/x/y. Now, to
move between directories, CMake should only assume ".." relationships
in the binary tree, which it fully controls.

So, if desired, CMake can infer that BIN/x/y/.. is equivalent to
BIN/x, but it cannot infer that SRC/x is equivalent to SRC/x/y/..

Therefore, in a Makefile, CMake should never refer to .. except
within the binary tree. CMake will always use full paths to files
outside the binary tree, but those paths would be as the user
specified them. So, if the user wants a relocatable coding tree, he
could go

$ mkdir myproject
$ mkdir myproject/src
$ mkdir myproject/bin
$ cd myproject/bin
$ cmake ../src

and then the "myproject" directory can be moved at will.

Going one step further, BIN will be determined at runtime to be the
location of the CMakeCache.txt file.

Then, the following will work

$ ln -s /pathA/src src
$ mkdir bin
bin$ cmake ../src
bin$ cd ..
$ ln -sf /pathB/src src
$ cd bin
bin$ make     # still okay: cmake only uses ../src
              # and that's still valid
              # BIN=/full/path/to/bin   SRC=../src
bin$ cd ..
$ mv bin bin2
$ cd bin2
bin2$ make    # still okay: relative relationships are still valid.
              # BIN=/full/path/to/bin2  SRC=../src


Does this analysis miss some situation?

Amitha.


More information about the CMake mailing list