[CMake] Automatic out of source build's possible?

Michael Wild themiwi at gmail.com
Tue Feb 8 02:53:14 EST 2011


That's not how CMake works. With CMake developers usually have many
binary trees referring to one single source tree (optimized/debug, 32/64
bit, with/without some optional dependencies, etc.). There is no good
way that CMake could automate the choice of suitable name of the binary
tree (and scons fails there too, IMHO). So, AFAIK, the design choice was
to leave it up to the user.

Some projects provide simple shell scripts or Makefiles to automate this
for a few simple cases (much the way you do), but IMHO it's not worth
the hassle... If somebody is tech-savvy enough to build from source, you
can assume (s)he knows how to create a directory and what the CWD is.

My 2c

Michael

On 02/08/2011 05:50 AM, Campbell Barton wrote:
> For blender we currently support 2 build systems - SCons and CMake,
> Quite a few technical users build from source on *nix just to get the
> latest version and use scons, I suspect this is because scons
> configures every time and its simple just to type "scons" in the
> source dir and end up with a build.
> We have SCons configured to do an out-of-source build by default with
> a predefined directory.
> 
> I wasn't aware of anything similar for CMake so I write a GNUmakefile
> (included below) in the root source dir to do something similar for
> CMake.
> (note, we don't allow in-source builds at the moment so there is no
> conflict with possible in-source makefiles).
> 
> This makefile creates a per-defined out-of-source build dir if
> necessary and runs make, since we explicitly list source files and
> headers in the CMakeLists.txt cmake will re-configure if needed.
> 
> So my questions are...
> - Do other projects do this? is there some preferred way to do this?
> - Is it possible to setup the CMakeLists.txt so the generated
> makefiles are written to a directory other then the CWD?
> - Is there any way to default to our-of-source build when running
> "cmake ." in the source dir? (rather then aborting which is what we do
> now).
> 
> Probably our users should just get the hang on setting up out of
> source builds but I think they like the convenience.
> 
> # ------------
> # This Makefile does an out-of-source CMake build in ../build/`OS`_`CPU`
> # eg:
> #   ../build/Linux_i386
> # This is for users who like to configure & build blender with a single command.
> 
> # System Vars
> OS:=$(shell uname -s)
> OS_NCASE:=$(shell uname -s | tr '[A-Z]' '[a-z]')
> 
> # Source and Build DIR's
> BLENDER_DIR:=$(shell pwd -P)
> BUILD_DIR:=$(shell dirname $(BLENDER_DIR))/build/$(OS_NCASE)
> 
> # Get the number of cores for threaded build
> NPROCS:=1
> ifeq ($(OS), Linux)
>     NPROCS:=$(shell grep -c ^processor /proc/cpuinfo)
> endif
> ifeq ($(OS), Darwin)
>     NPROCS:=$(shell system_profiler | awk '/Number Of CPUs/{print $4}{next;}')
> endif
> ifeq ($(OS), FreeBSD)
>     NPROCS:=$(shell sysctl -a | grep "hw.ncpu " | cut -d" " -f3 )
> endif
> ifeq ($(OS), NetBSD)
>     NPROCS:=$(shell sysctl -a | grep "hw.ncpu " | cut -d" " -f3 )
> endif
> 
> 
> # Build Blender
> all:
>     @echo
>     @echo Configuring Blender ...
> 
>     if test ! -f $(BUILD_DIR)/CMakeCache.txt ; then \
>         mkdir -p $(BUILD_DIR) ; \
>         cd $(BUILD_DIR) ; \
>         cmake $(BLENDER_DIR) -DCMAKE_BUILD_TYPE:STRING=Release ; \
>     fi
> 
>     @echo
>     @echo Building Blender ...
>     cd $(BUILD_DIR) ; make -s -j $(NPROCS)
>     @echo
>     @echo run blender from "$(BUILD_DIR)/bin/blender"
>     @echo
> 
> .PHONY: all
> 
> # ------------
> 
> - Campbell



More information about the CMake mailing list