title: cmake: c++: error: ${CFLAGS}: No such file or directory
body: <p>I'm trying to follow this <a href="https://www.johnlamp.net/cmake-tutorial-1-getting-started.html" rel="nofollow noreferrer">cmake tutorial</a>. But when it comes to calling cmake for the first time I get the following error:</p>
  
  <pre><code>cmake -G "Unix Makefiles" .. --debug-trycompile
  debug trycompile on
  -- The C compiler identification is GNU 6.3.1
  -- The CXX compiler identification is unknown
  -- Check for working C compiler: /usr/bin/cc
  -- Check for working C compiler: /usr/bin/cc -- works
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Check for working CXX compiler: /usr/bin/c++
  -- Check for working CXX compiler: /usr/bin/c++ -- broken
  CMake Error at /usr/share/cmake-3.7/Modules/CMakeTestCXXCompiler.cmake:44 (message):
    The C++ compiler "/usr/bin/c++" is not able to compile a simple test
    program.
  
    It fails with the following output:
  
     Change Dir: /home/user01/code/tests/cmake_tutorial_02/build/CMakeFiles/CMakeTmp
  
  
  
    Run Build Command:"/usr/bin/make" "cmTC_7a86e/fast"
  
    /usr/bin/make -f CMakeFiles/cmTC_7a86e.dir/build.make
    CMakeFiles/cmTC_7a86e.dir/build
  
    make[1]: Entering directory
    '/home/user01/code/tests/cmake_tutorial_02/build/CMakeFiles/CMakeTmp'
  
    Building CXX object CMakeFiles/cmTC_7a86e.dir/testCXXCompiler.cxx.o
  
    /usr/bin/c++ -march=native -O2 -pipe -fstack-protector-strong -o
    CMakeFiles/cmTC_7a86e.dir/testCXXCompiler.cxx.o -c
    /home/user01/code/tests/cmake_tutorial_02/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
  
  
    Linking CXX executable cmTC_7a86e
  
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_7a86e.dir/link.txt
    --verbose=1
  
    /usr/bin/c++ ${CFLAGS} CMakeFiles/cmTC_7a86e.dir/testCXXCompiler.cxx.o -o
    cmTC_7a86e
  
    c++: error: ${CFLAGS}: No such file or directory
  </code></pre>
  
  <p>When I call <code>echo $CFLAGS</code> in bash the value is:</p>
  
  <pre><code>-march=native -O2 -pipe -fstack-protector-strong
  </code></pre>
  
  <p>But it looks like <code>${CFLAGS}</code> is not defined while executing cmake_link_script. To verify I changed <code>${CFLAGS}</code> in link.txt to <code>-march=native -O2 -pipe -fstack-protector-strong</code> and manually called:</p>
  
  <pre><code>/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_7a86e.dir/link.txt
  </code></pre>
  
  <p>which works.</p>
  
  <p>Next I tried adding the following line to CMakeLists.txt:</p>
  
  <pre><code>set (CFLAGS -O2)
  </code></pre>
  
  <p>which didn't help.</p>
  
  <p>Neither did calling:</p>
  
  <pre><code>cmake -DCFLAGS=-O2 -G "Unix Makefiles" ..
  </code></pre>
  
  <p>So my question is, how to define CFLAGS so it is defined when calling the cmake_link_script in cmake's command mode?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>It looks like cmake fails withe the "Unix Makefiles" generator and doesn't even get to the code from the Tutorial.</p>
  
  <p>the CMakeLists.txt just looks like this:</p>
  
  <pre><code>project("To Do List")
  
  add_executable(toDo main.cc
                      ToDo.cc)
  </code></pre>
  
  <p><strong>EDIT2</strong></p>
  
  <p>I found a workaround.
  For some reason the generator sets <code>CMAKE_CXX_FLAGS:STRING='${CFLAGS} '</code> in CMakeCache.txt.
  But when the generator gets invoked with:</p>
  
  <pre><code>cmake -DCMAKE_CXX_FLAGS:STRING="${CFLAGS} " -G "Unix Makefiles" ..
  </code></pre>
  
  <p>everything works. Even the "The CXX compiler identification is unknown" message is gone.
  However, I would still like to know why the generator failed before?</p>