[CMake] if(ON) not considered true?

Bruce Stephens bruce.r.stephens at gmail.com
Sat Jan 26 12:31:47 EST 2019


The behaviour's controlled by CMP0012. (The documentation for if()
doesn't seem as helpful as it could be. It does seem to suggest that
ON, TRUE, etc., ought to be true, without mentioning CMP0012.)

On Sat, 26 Jan 2019 at 17:22, frodak17 <frodak17 at gmail.com> wrote:
>
> $ cmake --version
> cmake version 3.13.2
>
> $ cmake -S src -B testON
> ON is ON
> -- Configuring done
> -- Generating done
> -- Build files have been written to:...
>
> $ cat src/CMakeLists.txt
> cmake_minimum_required(VERSION 3.12)
>
> project(sample C)
>
> if(ON)
>   message("ON is ON")
> endif()
>
> What version are you using?
>
> On Sat, Jan 26, 2019 at 10:39 AM Mario Emmenlauer <mario at emmenlauer.de> wrote:
>>
>>
>> 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/
>> --
>>
>> Powered by www.kitware.com
>>
>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>>
>> CMake Support: http://cmake.org/cmake/help/support.html
>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Follow this link to subscribe/unsubscribe:
>> https://cmake.org/mailman/listinfo/cmake
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list