Am Dienstag, 13. August 2013, 00:13:19 schrieb Stephen Kelly:
> Rolf Eike Beer wrote:
> >> 5)
> >>
> >> This is not nice API:
> >>#if defined (CXXFEATURES_NULLPTR_FOUND)
> >>void *nix = nullptr;
> >>#else /* CXXFEATURES_NULLPTR_FOUND */
> >>void *nix = 0;
> >>#endif /* CXXFEATURES_NULLPTR_FOUND */
> >>
> >> Much better would be:
> >>void *nix = CXXFEATURES_NULLPTR;
> >>
> >> where -DCXXFEATURES_NULLPTR=0 or -DCXXFEATURES_NULLPTR=nullptr.
> >> 
> >> See what Qt does for other similar API decisions on what should be
> >> defined to something (like nullptr, constexpr, final etc), and what
> >> should be a 'guard' define like above (eg lambdas, variadic templates
> >> etc).
> >> 
> >> Note also that by defining the CXXFEATURES_FINAL to something, you get to
> >> use the 'sealed' extension, which does the same thing, and works with
> >> VC2005. See qcompilerdetection.h.
> > 
> > The module returns just a list of CMake flags. How this is passed to the
> > user (header, defines, whatever) is currently something the user must
> > decide. I will not do anything fancy in the testcase for now.
> 
> Imagine I wanted to set Grantlee_FINAL to empty or final based on whether
> c++11 was active or not. How would I do that?
> 
> I might do this:
> 
>  # This seems like an API smell. With g++ I want to wrap the add_definitions
> # in a condition for enabling c++11 at all. Does this mean that c++11 #
> features are not made available when using MSVC?
>  if(CXX11_COMPILER_FLAGS)
>    # Can't use add_compile_options as CXX11_COMPILER_FLAGS is a string, not
>    # a list.
>    # This means that -std=c++11 is also passed when linking.
>    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_COMPILER_FLAGS}")
> 
>    if (CXXFeatures_class_override_final_FOUND)
>      add_definitions(-DGrantlee_FINAL=final)
>      set(_final_defined 1)
>    endif()
>  endif()
> 
>  if (NOT _final_defined)
>    add_definitions(-DGrantlee_FINAL=)
>  endif()
> 
> 
> Do you have any more-real-world examples of what code using your module
> would look like?
> 
> My c++ code would then look like:
> 
>  struct A Grantlee_FINAL
>  {
>    int data;
>  };
> 
> However, now downstreams need to define Grantlee_FINAL to something in order
> to compile. We can help of course by putting Grantlee_FINAL in the
> INTERFACE_COMPILE_DEFINITIONS of Grantlee.

That is a problem I did not try to solve now. The idea was to get your targets 
compiled. Even if your target is a library used by the outside and full of 
C++11 stuff you can keep the interface clean of C++11 specifics.

Having the interface in a full-featured C++11 way is step 2 or 3 on the way. I 
would like to solve the first step first.

Eike

Attachment: signature.asc
Description: This is a digitally signed message part.

--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Reply via email to