title: Checking for CMake Variables
body: <p>I have the following CMake code snippet in my CMakeLists.txt:</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)
  
  message(STATUS "Before setting - ${MY_VARIABLE}")
  
  # first check
  if(NOT DEFINED ${MY_VARIABLE})
    set(MY_VARIABLE true)
  endif(NOT DEFINED ${MY_VARIABLE})
  
  message(STATUS "After setting - ${MY_VARIABLE}")
  
  # second check
  if(NOT DEFINED ${MY_VARIABLE})
    message(STATUS "What - ${MY_VARIABLE}")
  endif(NOT DEFINED ${MY_VARIABLE})
  </code></pre>
  
  <p>The output from CMake configuration is:</p>
  
  <pre><code>-- The C compiler identification is GNU 4.8.4
  -- The CXX compiler identification is GNU 4.8.4
  -- Check for working C compiler: /usr/local/bin/cc
  -- Check for working C compiler: /usr/local/bin/cc -- works
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working CXX compiler: /usr/local/bin/c++
  -- Check for working CXX compiler: /usr/local/bin/c++ -- works
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Before setting - 
  -- After setting - true
  -- What - true
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /tmp/build
  </code></pre>
  
  <p><strong>Question</strong>:
  Why does the second check for variable definition report the variable is not defined even though it is defined? Surprisingly, the value of the variable is also printed correctly!</p>