[CMake] Setting default make options for Makefiles generator

Michael Wild themiwi at gmail.com
Thu Mar 5 05:11:59 EST 2009


On 5. Mar, 2009, at 10:53, Adolfo Rodríguez wrote:

> I would definitely support the idea. It's more or less what I was  
> looking
> for. I have a question on the proposal: Would the -Go flags have to  
> be set
> once per build folder (as the -G flag is), or could it be reset in  
> succesive
> runs of cmake? Both alternatives would work for me, but I think I  
> prefer the
> latter. For example, consider the example of parallel builds:
>
> mkdir build; cd build; cmake -G"Unix Makefiles" -Go" -j" ../
>
> then at some later point, run
>
> cmake -Go"" ../
>
> say, to ease console debugging on highly parallel machines.
>
> Let's see what other people think about the idea, and the pros/cons of
> supporting it (either as a -Go flag, a CMake variable, or whatever
> implementation is deemed more convenient).
>
> Cheers,
>
> Adolfo
>
> On Thu, Mar 5, 2009 at 9:46 AM, Eric Noulard  
> <eric.noulard at gmail.com> wrote:
>
>> 2009/3/5 Adolfo Rodríguez <dofo79 at gmail.com>:
>>> Thanks Philip,
>>>
>>> I had considered the alias option before, but wanted to rule out  
>>> that
>> there
>>> was no way of doing it the scope of a cmake project, however  
>>> strange that
>>> may sound. I will probably take that path now.
>>
>> Note that I find the idea of being able to pass generator-specific
>> options/file
>> to cmake as a good idea. It could be done via a cmake command line  
>> option
>>
>> cmake -G"Unix Makefiles" -Go"whatever option passed to the specific
>> generator"
>>
>> the -Go flags may be used to pass on generator specific options to  
>> the
>> generator itself. It may be used to pass some options such as the  
>> parallel
>> build
>> for the makefile generator  or  whatever fancy VisualStudio specific
>> option to it etc...
>>
>> -Go <string>
>> would be a placeholder which should be passed "as-is" to the  
>> generator
>> which may implement it's own way to handle its specific options
>> (more flags, file names containing things, etc...)
>>
>> the baseline would be that generator shall not require -Go string  
>> but "may"
>> support specific options.
>>
>> Do you (all) think it's worth a feature request ?
>>
>> --
>> Erk
>>
>
>


I did some thinking how such a feature might be implemented in GNU  
Make, and it turned out to be quite tricky. Here is what I came up  
with for a very simple and stupid proof of concept:

.DEFAULT: all

.PHONY: all all-master all-parallel

TARGETS = t.1 t.2 t.3 t.4

# in the first recursive call, detect whether --jobserver is in the  
PROTECTEDFLAGS variable
ifeq ($(MAKELEVEL),1)
   ifeq (,$(findstring --jobserver,$(PROTECTEDFLAGS)))
     $(info [$(MAKELEVEL)]: user DID NOT pass -j, forcing to -j 3)
     JOBFLAG = -j3
   else
     $(info [$(MAKELEVEL)]: user started in parallel, using his values!)
     JOBFLAG =
   endif
endif

# this is what the user calls. i have to copy the MAKEFLAGS variable  
into a PROTECTEDFLAGS
# variable like this because --jobserver is removed from MAKEFLAGS  
outside of rules
# (this is GNU Make 3.81, Mac OS X)
all:
         @$(MAKE) PROTECTEDFLAGS="$(MAKEFLAGS)" all-master

# this is the rule where we launch the parallel jobs if the user did  
not do so already
all-master:
         @$(MAKE) $(JOBFLAG) all-parallel

# this is the "all" target for the parallel jobs
all-parallel: $(TARGETS)

% just some dumb rule which makes the parallelization visible
t.%:
         @sleep 3;\
         touch $@;\
         echo "[$(MAKELEVEL)]: finished $@";

clean:
         rm -f $(TARGETS)


It honors the users choice if he calls make directly with -j, but  
defaults to -j3 if he does not.

Michael


More information about the CMake mailing list