Xintrea
Xintrea

Reputation: 388

Why CMake generate Makefile without CMAKE_CXX_FLAGS?

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?

Upvotes: 1

Views: 629

Answers (1)

Florian
Florian

Reputation: 42842

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

Upvotes: 4

Related Questions