[CMake] if(ON) not considered true?

Mario Emmenlauer mario at emmenlauer.de
Sat Jan 26 10:04:52 EST 2019


Dear All,

I'm plagued by an issue that I do not understand. An if-statement
(in a package configuration file) evaluates ON to false:

IF(ON)
    ...some code here
ENDIF()

The part inside IF is *not* executed. Replacing ON by TRUE does not
help, only replacing it by 1 helps. Is this correct behaviour? I can
not understand this from the documentation. The docs seem to say "ON"
would be a valid token for true: https://cmake.org/cmake/help/v3.6/command/if.html

The full user story is that in the package configuration I'd like to
treat shared libraries specially, so I use "IF(@BUILD_SHARED_LIBS@)".
The user configures the build with

    cmake -DBUILD_SHARED_LIBS=ON .

so the package configuration gets resolved to "IF(ON)". I have not
too much control about the way users specify the options, so I'd
like to solve this on my end. If options should not keep the value
"ON", how can I cleanly resolve them to the corresponding number 0/1?

Am I doing something wrong?

All the best,

    Mario Emmenlauer


--
BioDataAnalysis GmbH, Mario Emmenlauer     Tel. Office: +49-89-74677203
Balanstr. 43                   mailto: memmenlauer * biodataanalysis.de
D-81669 Munich                           http://www.biodataanalysis.de/


More information about the CMake mailing list