Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DistCC and CMake - select between local and distributed build when running make

My project is build using CMake and is compiled with DistCC + GCC.

I configure the compiler as follows:

SET(CMAKE_C_COMPILER "distcc variation-of-gcc")

To build the project, I simply run 'cmake' and then 'make -jXX'.

Although distcc really speeds up things, I sometimes want to build without distribution - I want it to build locally on the machine.

I know I can modify DISTCC_HOSTS to include only localhost - but this still has the overhead of distcc networking, although it is faster than the overhead for other machines...

I can also do that by rerunning cmake again and modifying the CMAKE_C_COMPILER using customization flags.

But I am looking for a way to do that by just adding a flag directly to 'make'.

I.e.
# This will use distcc:
make -jXX ...
# This will run locally:
make LOCAL_BUILD=1 -jX ...

Is there a CMake trick I can use?

like image 222
oferlivny Avatar asked Sep 07 '14 16:09

oferlivny


1 Answers

We use the following to allow make time (rather than cmake time) switching on and off of the -Werror flag.

if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
    # TODO: this approach for the WERROR only works with makefiles not Ninja
    set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> $(WERROR) -o <OBJECT> -c <SOURCE>")
endif()

Then we run

make WERROR=-Werror

to turn on warnings as error.

I expect you could do something similar to have whether to use distcc come from a make variable. Like this:

set(CMAKE_CXX_COMPILE_OBJECT "$(USE_DISTCC) <CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")

And then run either

make USE_DISTCC=distcc

or just

make
like image 122
RoddyM Avatar answered Sep 19 '22 18:09

RoddyM