oferlivny oferlivny - 1 year ago 158
C++ Question

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 if 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?
Can anyone assist?

Thanks!
Ofer

Answer Source

The simplest thing to do (IMO) is write a little script in your project that invokes the compiler, and change your cmake files to run that script instead of containing the name of the compiler directly:

SET(CMAKE_C_COMPILER "my-gcc-script")

Now you can have that script normally run distcc but (based on an environment variable or something) also run without distcc. No need to change anything in your cmake files.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download