[CMake] Re: Parsing cmake command line parameters

Alexander Neundorf a.neundorf-work at gmx.net
Tue Dec 18 11:45:29 EST 2007


On Tuesday 18 December 2007, Rodolfo Schulz de Lima wrote:
> James Bigler wrote:
> > What is it that people want beyond -DBUILD_THIS_THAT_WHATEVER:BOOL=TRUE
> > could provide?
> >
> > Do they want: --enable-build_this_that_whatever?
>
> People that work with embedded systems might want a stripped down
> version of a library, for instance. So disabling features might be a
> strong use case.

Yes.
In KDE we have the macro MACRO_OPTIONAL_FIND_PACKAGE(), which adds an option 
around the find_package() call:
http://websvn.kde.org/trunk/KDE/kdelibs/cmake/modules/MacroOptionalFindPackage.cmake?revision=520790&view=markup

Beside that, it is really just a matter of syntax whether you do 
--enable-build-this
or -DENABLE_BUILD_THIS=TRUE

> > I also don't understand why we have to parse the whole CMakeLists.txt
> > structure.  We should treat these command line args like we cache
> > variables like CPack does when you configure different builds.
>
> But in the first time cmake is run, there's no cache and no way to know
> what are the command line parameters. Is must run the whole build to
> know that. So the first time 'cmake . --help' runs, the whole build
> should be parsed and executed.
>
> But... what if we have this extreme case?
>
> IF("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
>       add_command_line_parameter(whatever)
> ENDIF()
>
> That is, the parameter is bound to another parameter? It's not
> impossible to imagine a case where each time we run cmake --help, a
> different set of parameters is shown. I know, that's stupid, but corner
> cases usually are...

Yes, and they must work too, otherwise there will be bug reports.

I have (currently) two ideas:
either a special file, e.g. CMakeCustomArgs.txt, which in some way sets up the 
custom command line parameters.

Or have a cmake modules, which handles this stuff, and which also creates a 
custom target "help-args" or something like that, which prints the available 
args. This would not be available before cmake has successfully run.

Alex


More information about the CMake mailing list