[cmake-developers] C++11 and target_compiler_feature proposal
Stephen Kelly
steveire at gmail.com
Wed Oct 9 10:44:47 EDT 2013
Brad King wrote:
> Steve, please explain your proposal in more detail. How does the list of
> requested features get mapped to the proper -std=cxx11 or equivalent flag?
>
In my branch that is determined by which list the feature appears in. Eg,
from GNU-CXX.cmake:
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
list(APPEND CMAKE_CXX11_COMPILER_FEATURES
final
override
)
endif()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
list(APPEND CMAKE_CXX14_COMPILER_FEATURES
generalized_lambda_capture
return_type_deduction
)
endif()
Then, in the implementation of target_compiler_feature,
list(FIND CMAKE_CXX11_COMPILER_FEATURES ${FEATURE_NAME} needs11)
list(FIND CMAKE_CXX14_COMPILER_FEATURES ${FEATURE_NAME} needs14)
list(FIND CMAKE_CXX17_COMPILER_FEATURES ${FEATURE_NAME} needs17)
if(NOT needs17 EQUAL -1)
set(standard 17)
elseif(NOT needs14 EQUAL -1)
set(standard 14)
elseif(NOT needs11 EQUAL -1)
set(standard 11)
endif()
# ...
set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD ${standard})
Then, in cmLocalGenerator:
const char *standard = target->GetProperty("CXX_STANDARD");
std::string compile_option =
"CMAKE_CXX" + std::string(standard) + "_STANDARD_COMPILE_OPTION";
if (const char *opt =
target->GetMakefile()->GetDefinition(compile_option.c_str()))
{
this->AppendFlags(flags, opt);
}
This is where I have an open question in the branch:
# TODO: Gnu extensions supported by -std=gnu++98 ?
# And others. http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/C-Dialect-Options.html#C-Dialect-Options
# TODO: Maybe instead we should define like this:
#
# set(CMAKE_C_COMPILE_OPTIONS_STD "-std=")
# set(CMAKE_CXX_COMPILE_OPTIONS_STD "-std=")
#
# so that the CXX_STANDARD target property can contain the argument string
# (including possibly extensions).
# That might call for some kind of mapping though because XL uses different
# values (eg extended0x)
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11")
endif()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9
# AND VERSION_LESS 4.11 # Speculative
)
set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++1y")
endif()
# if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.11) # Speculative
# set(CMAKE_CXX14_STANDARD_COMPILE_OPTION -std=c++14)
# endif()
More information about the cmake-developers
mailing list