title: Impact of setting CMAKE_CXX_FLAG in a C++ project
body: <p>I have a C++ project and I want to use CMake in the project. My project has multiple directories and sub-directories.</p>
  
  <p>I have a top-level <code>CMakeLists.txt</code> which builds the whole project. I also have <code>CMakeLists.txt</code> in the sub-directories. I wanted to set the compiler flags but here is what I am confused about. Are the effects of the compiler flags in CMake apply only to the corresponding directory or will it apply to the whole project?</p>
  
  <p>For example, my project (let's call it <code>MyProject</code>) has a <code>CMakeLists.txt</code> associated. The project has two subdirectories <code>A</code> and <code>B</code>. Each with its own <code>CMakeLists.txt</code>. In the <code>A/CMakelist.txt</code>, I have set the compiler flag as below:</p>
  
  <pre><code>set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -Wno-narrowing")
  </code></pre>
  
  <p>The <code>B/CMakeLists.txt</code> is as below:</p>
  
  <pre><code>set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
  </code></pre>
  
  <p>What I do not understand is that whether the compiler will use the flag <code>-Wno-narrowing</code> for the cpp files in subdirectory <code>B</code> also (in general will it apply to the whole project)?</p>
  
  <p>Is the scope of setting a compiler flag (in general any variable) in <code>CMakeList.txt</code> are applicable only to the corresponding directory or it will be applied globally throughout the project?</p>