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

Martin O'Brien martin.matthew.obrien at gmail.com
Tue Feb 8 03:06:14 EST 2011


While I too find myself sometimes wanting convenience scripts - some people
find the use of '-DENABLE_<whatever>=ON' instead of --enable-<whatever>'
foreign, for example - the problem with them, IMO, is that they're
impossible to make crossplatform without requiring the presence of some tool
- perl, python, bash, whatever - on each system in a location that can be
located pre-configure, which is exactly what using cmake gets you out of.

Mm
On Feb 8, 2011 2:53 AM, "Michael Wild" <themiwi at gmail.com> wrote:
> 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
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110208/4027ce3c/attachment.htm>


More information about the CMake mailing list