Request for Changes-95: Compile OTB with C++14 by default

From OTBWiki
Jump to: navigation, search

[Request for Changes - 95] Compile OTB with C++14 by default

Status

  • Author: Jordi Inglada
  • Additional Contributors (if different than authors): Manuel Grizonnet
  • Submitted on 16.06.2017
  • Proposed target release: 6.2
  • Adopted (3 "+1")
  • Link to a public git branch or pull request corresponding to the changes: [1]
  • Merged : [2]

Summary

Make the necessary changes so that OTB is compiled using the C++14 standard by default.

Rationale

This is step 1 of Request_for_Comments-36:_Move_OTB_to_C++14.

Implementation details

Classes and files

Files touched

   M   CMakeLists.txt
   M   Modules/Core/ImageBase/include/otbImage.h
   M   CMake/OTBCheckCpp11Keywords.cmake
   M   CMake/OTBModuleEnablement.cmake
   M   CMake/OTBModuleMacros.cmake
   M   CMakeLists.txt
   M   Modules/Core/ImageBase/include/otbImage.h
   M   Modules/Core/ImageBase/src/otbImageIOBase.cxx
   M   Modules/ThirdParty/MuParserX/otb-module.cmake
   M   Modules/ThirdParty/Shark/otb-module.cmake
   M   Modules/Visualization/Mapla/src/CMakeLists.txt
   M   Modules/Visualization/Monteverdi/src/CMakeLists.txt
   M   SuperBuild/CMake/External_muparserx.cmake
   M   SuperBuild/CMake/External_shark.cmake
   M   SuperBuild/CMake/SuperBuild_Macro.cmake
   M   SuperBuild/CMakeLists.txt

In CMakeLists.txt we update the minimum required CMake version to use the macros allowing to set the standard:

   cmake_minimum_required(VERSION 3.1.0)

And then we set the C++14 standard as required and we disable specific compiler extensions:

   set(CMAKE_CXX_STANDARD 14)
   set(CMAKE_CXX_STANDARD_REQUIRED ON)
   set(CMAKE_CXX_EXTENSIONS OFF)

Moreover, we use a C++14 feature to check that OTB builds OK in otbImage.h and otbImageIOBase.cxx (delete keyword and string_literals)

   diff --git a/Modules/Core/ImageBase/include/otbImage.h b/Modules/Core/ImageBase/include/otbImage.h
   index c13d9b9..f3c10b8 100644
   --- a/Modules/Core/ImageBase/include/otbImage.h
   +++ b/Modules/Core/ImageBase/include/otbImage.h
   @@ -197,10 +197,10 @@ protected:
      ~Image() ITK_OVERRIDE {}

    private:
   -  Image(const Self &) = delete;
   +  Image(const Self &); //purposely not implemented
      void operator =(const Self&); //purposely not implemented
    
   -    /** Return the ImageMetadataInterfacePointer associated to the data
   +  /** Return the ImageMetadataInterfacePointer associated to the data
       *  and creates it on first call
       */
      ImageMetadataInterfacePointerType GetMetaDataInterface() const;
   diff --git a/Modules/Core/ImageBase/src/otbImageIOBase.cxx b/Modules/Core/ImageBase/src/otbImageIOBase.cxx
   index 1e01c55..d88d601 100644
   --- a/Modules/Core/ImageBase/src/otbImageIOBase.cxx
   +++ b/Modules/Core/ImageBase/src/otbImageIOBase.cxx
   @@ -1320,8 +1320,8 @@ ImageIOBase
    void ImageIOBase::PrintSelf(std::ostream& os, itk::Indent indent) const
    {
      Superclass::PrintSelf(os, indent);
   -  using namespace std::string_literals;
   -  os << indent << "FileName: "s << m_FileName << std::endl;
   +
   +  os << indent << "FileName: " << m_FileName << std::endl;
      os << indent << "FileType: " << this->GetFileTypeAsString(m_FileType) << std::endl;
      os << indent << "ByteOrder: " << this->GetByteOrderAsString(m_ByteOrder) << std::endl;
      os << indent << "IORegion: " << std::endl;

Finally, we remove internal checks of c++11 from OTB and also from the superbuild. Note that I've chosen for now to force also c++14 by default also in the superbuild. It allows to compile muparserx/shark external projects without extra cmake configuration (for now the configuration fails as muparserx compilation is activated and no c++11 or c++14 flags are set):

https://git.orfeo-toolbox.org/otb.git/commitdiff/8ca2f075e1e712823f18a4dfe5d130579eb02a73

https://git.orfeo-toolbox.org/otb.git/commitdiff/4c95d67e121dff815a1c6089a3602076ddfcbaa7

I think it is more coherent with otb default behavior and simplify the logic in the superbuild.

Note that we keep the public cmake macro otb_module_requires_cxx11 used in remote modules for backward compatability (the macro does nothing just display a warning). We can remove this macro in otb 6.4.

- Finally fix 2 cmake warnings related to Mapla and Monteverdi targets -> I did not find the reason why we were building these libraries as static libraries even if BUILD_SHARED_LIBS=ON. Now both libraries can be built as shared libs:

https://git.orfeo-toolbox.org/otb.git/commitdiff/852b55c4252d601471c56ee04d2e1782b8979df0

Applications

None

Tests

None

Documentation

Add information in compiling from source section to explain that OTB with C++14 by default

Additional notes

List remaining open issues if any, and additional notes.