[CMake] In/Out of source build question

Brad King brad.king at kitware.com
Wed Jan 19 13:58:42 EST 2005


Jeff Stein wrote:
>    So I've been reading the mailing list for a few months now, I have 
> the cmake book and thus far I have NOT found a satisfactory way of doing 
> what I want to do with cmake.
> 
> I want to have CMake work such that when it runs the following files are 
> stored and end up in the following directories.
> 
> /project/      CMakeList.txt & Makefile
> /project/src    <source files .h .cpp>
> /project/obj    <.o's go here>
> /project/lib    (.a's & .so's go here>
> /project/bin    (binarys go here)
> 
> The only way I've found to do this is have a custom command run 
> POST-BUILD and move the .o's into the obj directory and so on.  I've 
> tried setting different variables such as LIBRARY-OUTPUT etc. and 
> nothing seems to do as I wish.
> 
> Does anybody have any suggestions.  I'm sorry if i'm being vague but I'm 
> not by my computer that has my sample CMakeList.txt but still I would 
> think this is a simple question.

CMake is not intended to produce customizable Makefile generation.  It 
will generate whatever makefiles it wants to produce the project's 
targets.  The output location of the final targets can be configured, 
but the intermediate files go wherever CMake puts them.

However, you may be able to get close to the behavior you want.  In the 
CMakeLists.txt file add the source files with a relative path:

ADD_EXECUTABLE(myexe src/src1.cxx)

Then run CMake like this:

$ cd /project/obj
$ cmake .. -DEXECUTABLE_OUTPUT_PATH:PATH=/project/bin 
-DLIBRARY_OUTPUT_PATH:PATH=/project/lib

There are two differences between what this will produce and what you 
want.  First, the Makefile will be in /projects/obj.  You may have to 
add your own Makefile to cd into that directory and run make again. 
Second, the .o files are in /projects/obj/src, not /projects/obj. 
Future versions of CMake are free to put the .o files wherever they 
want, though.

-Brad


More information about the CMake mailing list