[CMake] CMake generated makefiles try to build a target that does not exist (make[2]: *** No rule to make target ...)

Bill Tonkin wmt at clinton.com
Fri Oct 6 16:14:02 EDT 2006


Alan,

Thank you for your suggestion.  I'm confident it would work if I could make
the changes.  Unfortunately, in my production environment the directories
represented by '/users/wmt/cmake_system/' in the example are not writable.
(They are the root of a clearcase mvfs, i.e. /clearcase/vob.)  I could (in
theory) move 'systems' and 'libraries' down one level, giving me a writable
directory into which I could place my topmost CMakeLists.txt, locating it
above both 'my_one' and 'my_a'.  This would, however, break the current
build system, and it would be a _huge_ job to get it working again after the
change.  (In the production system there are many, many projects and
libraries. The existing hand rolled makefiles are both lengthly and
brittle.)

Thus my desire to find a way to get CMake to work with an add_subdirectory()
that points outside of the directory sub-tree rooted at 'systems'.  I could
be wrong but I think this is supposed to work.

Best Regards,
Bill Tonkin


-----Original Message-----
From: Alan W. Irwin [mailto:irwin at beluga.phys.uvic.ca]
Sent: Friday, October 06, 2006 3:23 PM
To: Bill Tonkin
Cc: cmake at cmake.org
Subject: Re: [CMake] CMake generated makefiles try to build a target
that does not exist (make[2]: *** No rule to make target ...)


On 2006-10-06 14:35-0400 Bill Tonkin wrote:

> The directory layout is:
>
>
>     /users/wmt/cmake_system/
>                            |
>                            systems/my_one/
>                            |             |
>                            |             CMakeLists.txt [1]
>                            |             main.C
>                            |
>                            libraries/my_a/
>                            |             |
>                            |             CMakeLists.txt [2]
>                            |             my_a.C
>                            |             my_a.h
>                            |
>                            |
>                            cmake_build/
>                                       |
>                                       systems/my_one/
>                                       |             |
>                                       |             CMakeCache.txt
>                                       |
>                                       libraries/my_a/

I haven't followed your error messages and results in detail, but I believe
what you are trying to do (only have CMakeLists.txt files in subdirectories
of the source tree and run cmake from a subdirectory of the build tree) is
the source of the problem, and there is a straightforward way to build your
projct using a top-level style approach where everything starts in the
top-level source tree and cmake is run from the top-level build tree.

Here is what you do to change to that "top-level" style (which works well
for me).

Create a top-level CMakeLists.txt file in
/users/wmt/cmake_system/ which contains the following:

project (my_one)
add_subdirectory(libraries/my_a)
add_subdirectory(systems/my_one)

The contents of libraries/my_a/CmakeLists.txt should continue to be

add_library (my_a my_a.C)

The contents of systems/my_one/CmakeLists.txt should be changed to

add_executable (my_one_exe main.C)
target_link_libraries (my_one_exe my_a)

Note, that last command refers to a target created in a different
subdirectory, but that is fine, target information is universal in CMake (so
long as the subdirectory that creates the target is processed before
subdirectories that refer to it as in the top-level CMakeLists.txt above.

Then completely clean out your old build tree since cmake and make create
everything there, and you don't want past bad attempts to confuse issues.

rm -rf /users/wmt/cmake_system/cmake_build

Then build your project from the top-level of the build tree.

mkdir /users/wmt/cmake_system/cmake_build
cd /users/wmt/cmake_system/cmake_build
cmake ../
make

Note how the cmake command refers specifically to the top-level directory
of the source tree where the top-level CMakeLists.txt file exists.

Hope this helps.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the Yorick front-end to PLplot (yplot.sf.net); the
Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________






More information about the CMake mailing list