[cmake-developers] C++11 and target_compiler_feature proposal

Brad King brad.king at kitware.com
Wed Oct 9 11:23:44 EDT 2013


On 10/09/2013 10:44 AM, Stephen Kelly wrote:
>  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})

This assumes a linear ordering among standards, which is true for the
actual standards, but may not be true for the compiler feature levels.
For example, the GNU compiler has a "gnu" variant branching off from
each standard level.

> 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

Perhaps each feature can map to the minimum standard spec flag
it needs:

 if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
   set(CMAKE_CXX_FEATURE_FLAG_final -std=c++11)
   set(CMAKE_CXX_FEATURE_FLAG_override -std=c++11)
 endif()
 if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
   set(CMAKE_CXX_FEATURE_FLAG_generalized_lambda_capture -std=c++1y)
   set(CMAKE_CXX_FEATURE_FLAG_return_type_deduction -std=c++1y)
 endif()

Then have a graph of flags subsuming others:

  set(CMAKE_CXX_STANDARD_SUBSUMES_-std=c++1y -std=c++11)

Then from the needed features, their corresponding flags,
and the "subsume" graph, compute the possible flags.
Then provide a way for the project and/or user to specify
their preferred flag and use it or error if it is not one
of those possible.  If no preference is given, choose the
"oldest" flag.

-Brad



More information about the cmake-developers mailing list