[CMake] How to query compiler definitions?

Eric Noulard eric.noulard at gmail.com
Thu Jan 20 10:54:17 EST 2011


2011/1/20 SF Markus Elfring <elfring at users.sourceforge.net>:
>> Probably that would be pretty difficult to achieve and definitely would
>> break backwards-compatibility beyond resurrection.
>
> I have got a different opinion. I imagine that a property with a new name
> can provide the desired service to retrieve target parameters in a portable
> way from the build environment.
> Otherwise: Would the addition of a CMake command make more sense for this
> purpose?
>
>
>> You shouldn't check for a preprocessor symbol in CMake.
>
> It's just the way I would prefer to adapt the build process to the
> requirements of the source files at the moment.
>
> It seems that the evaluation of compilation parameters (variable
> "CMAKE_CXX_FLAGS...") with regular expressions is an approach that will
> currently work to some degree. The used pattern determines how many
> compilers will be supported.
>
>
>> Instead, probably do a find_package(TinyXML)
>
> I would appreciate if a corresponding module (search script) will become
> generally available for CMake.
>
>
>> and then depending on the result offer the user an option variable
>
> I guess that the term "user" needs to be distinguished for its various
> meanings.
>
> There are some switches involved that might only interest a subset of them.

When you have such different "levels" of option you may do something like:

OPTION(DEVELOPER_OPT_ENABLE  "Enable developer options" OFF)
OPTION(SYSTEM_INTEGRATOR_OPT_ENABLE  "Enable system integrator
specific options" OFF)
OPTION(TOOL_USERS_OPT_ENABLE  "Enable tool users options" ON)

> - software developers
> - system integrators
> - tool users

then you do

IF (DEVELOPER_OPT_ENABLE)
    OPTION(DEV_OPT1 "blah blah" ON)
    OPTION(DEV_OPT2 "blah blah" OFF)
ENDIF(DEVELOPER_OPT_ENABLE)

IF (TOOL_USERS_OPT_ENABLE)
    OPTION(USR_OPT1 "blah blah" ON)
    OPTION(USR_OPT2 "blah blah" OFF)
    OPTION(USR_OPT3 "blah blah" ON)
ENDIF(TOOL_USERS_OPT_ENABLE)

so an option may perfectly depend on another option, such kind of config
may need several "configure" steps but its works well (at least for me).

With sensible default option value average user will get its appropriate option
in CMake GUI whereas developers knows how to get more.



-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org


More information about the CMake mailing list