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?

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, this is work. But where in official documentation told about this feature (after the project)? I found project page cmake.org/cmake/help/v3.10/command/project.html but there is nothing said about the CXX option and project.
@Xintrea It's part of the CMake Toolchains - Languages documentation. I'll add this to my answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.