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