On 2019-05-24 19:38+0200 Haio Maio wrote:

Manually-specified variables were not used by the project
MY_VAR

when I call

cmake -DMY_VAR= ...


The goal is
if(NOT DEFINED MY_VAR)
...
else()
...
if()

in order to tell cmake over the command line what to do.

How to achieve this ?

This functionality just works for me (using cmake version 3.13.4).

For example, here is a simple test case:

irwin@merlin> cat /tmp/CMakeLists.txt if(NOT DEFINED MY_VAR)
  message(STATUS "MY_VAR is not DEFINED")
else()
  message(STATUS "MY_VAR is DEFINED")
endif()

irwin@merlin> cmake -P /tmp/CMakeLists.txt -- MY_VAR is not DEFINED irwin@merlin> cmake -DMY_VAR=OFF -P /tmp/CMakeLists.txt -- MY_VAR is DEFINED irwin@merlin> cmake -DMY_VAR=ON -P /tmp/CMakeLists.txt -- MY_VAR is DEFINED

So just like the documentation says at 
<https://cmake.org/cmake/help/latest/command/if.html>
what is tested is whether *any* true or false value has been set.  What is more 
problematic
is how to make sure the variable is not set with the -D option, and the only 
way I
know how to do that is the first test above (i.e., do not use -DMY_VAR=??? at 
all).

I hope this simple example helps you to figure out what is going on with your 
more complex
example.

Alan
__________________________
Alan W. Irwin

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.org); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________

Linux-powered Science
__________________________
--

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

Reply via email to