1

This is my full CMakeLists.txt file:

set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wshadow")

set(PROJECT sample)
project(${PROJECT})

set(HEADERS
    Main.h
)
set(SOURCES 
    Main.cpp
)

# Add souce file to project for compile
add_executable (${PROJECT} ${HEADERS} ${SOURCES})

target_link_libraries( ${PROJECT} )

But, in Makefile i don't seek substring "-Wall" and other option from CMAKE_CXX_FLAGS.

Why?

Xintrea
  • 388
  • 3
  • 12

1 Answers1

3

The CMAKE_CXX_FLAGS variable is initially set with the project() command. Move the set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ...") after the project() command.

From CMake Toolchains - Languages documenation:

Languages are enabled by the project() command. Language-specific built-in variables, such as CMAKE_CXX_COMPILER, CMAKE_CXX_COMPILER_ID etc are set by invoking the project() command. If no project command is in the top-level CMakeLists file, one will be implicitly generated. By default the enabled languages are C and CXX.

References

Florian
  • 39,996
  • 9
  • 133
  • 149
  • Thanks, this is work. But where in official documentation told about this feature (after the project)? I found project page https://cmake.org/cmake/help/v3.10/command/project.html but there is nothing said about the CXX option and project. – Xintrea Dec 08 '17 at 13:07
  • @Xintrea It's part of the [CMake Toolchains - Languages](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#languages) documentation. I'll add this to my answer. – Florian Dec 09 '17 at 20:46