This question is related to Instruct Cmake to use CXX and CXXFLAGS when driving link? In the former question, we are trying to instruct CMake to use CXXFLAGS
when it invokes the linker.
add_compile_options
We found that the following code
if (CMAKE_VERSION VERSION_LESS 2.8.12)
add_definitions(-foo)
else()
add_compile_options(-foo)
endif()
message(STATUS, "CXXFLAGS: ${CMAKE_CXX_FLAGS}")
produces the output
CXXFLAGS:
SET CMAKE_CXX_FLAGS
We found that the following code
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -foo" )
message(STATUS, "CXXFLAGS: ${CMAKE_CXX_FLAGS}")
produces the output
CXXFLAGS: -foo
Questions
We found CMake would create object files using -foo
in both cases. So -foo
is definitely making its way into CXXFLAGS
.
What is the difference between the first set of CMake code and the second set of CMake code?
Why is CMAKE_CXX_FLAGS
unset in one instance, and set in the other instance?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…