[CMake] How to determine origin of variable

David Cole david.cole at kitware.com
Thu Aug 25 11:54:51 EDT 2011


On Thu, Aug 25, 2011 at 11:45 AM, Martin Weber <m.weber at razorcat.com> wrote:
> Am 25.08.2011 17:39, schrieb David Cole:
>>
>> On Thu, Aug 25, 2011 at 7:34 AM, Martin Weber<m.weber at razorcat.com>
>>  wrote:
>>>
>>> Hi all,
>>>
>>> is there a way in CMake to detect, whether a variable has been set on the
>>> command-line (with the -D option) and not in a CMakelists.txt?
>>>
>>> For example, GNU-make has the origin function do do something similar.
>>>
>>> Thanks,
>>>  Martin
>>>
>>> --
>>> ☂ E-Mails sollten Text sein, Text und nur Text.
>>> Wenn Gott gewollt hätte, dass E-Mails in HTML geschrieben würden,
>>> endeten Gebete traditionell mit</amen>.
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the CMake FAQ at:
>>> http://www.cmake.org/Wiki/CMake_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.cmake.org/mailman/listinfo/cmake
>>
>> No, there's no way to tell.
>>
>> Why do you ask?
>
> My CMakelists.txt changes the value of CMAKE_INSTALL_PREFIX by replacing the
> trailing directory. But it should do this only if the user did not specify a
> value on the commandline.
>
>
> --
> E-Mails sollten Text sein, Text und nur Text.
> Wenn Gott gewollt hätte, dass E-Mails in HTML geschrieben würden,
> endeten Gebete traditionell mit </amen>.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake

See this recent bug report for some advice in the notes:
http://public.kitware.com/Bug/view.php?id=12340

And this old email on the list that contains basically the same advice:
http://www.cmake.org/pipermail/cmake/2007-August/015814.html

You can also search for CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT --
you can use that value near the top of your top-level CMakeLists.txt
file to force-initialize CMAKE_INSTALL_PREFIX to your own default
value if you want to.


HTH,
David


More information about the CMake mailing list