Feature #1188
Provide build support for C++11
100%
Files
Related issues
Associated revisions
History
Updated by Robin Mills over 5 years ago
In the discussion in #1187, Taras proposed the following change to CMakeLists.txt:
... OPTION( EXIV2_ENABLE_CURL "USE Libcurl for HttpIo" ON ) OPTION( EXIV2_ENABLE_SSH "USE Libssh for SshIo" ON ) +include(CheckCXXCompilerFlag) +CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) +CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) +if(COMPILER_SUPPORTS_CXX11) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++") + message(STATUS "Using C++11") +elseif(COMPILER_SUPPORTS_CXX0X) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -stdlib=libc++") + message(STATUS "Using C++0x") +else() + message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") +endif() + + IF( MINGW OR UNIX ) ...
This patch says "if the compiler supports C++11, use it. I'm not sure that this is desirable. This patch doesn't enable the user to say "don't use C++11 even if it is supported". We need to consider build and test for:
- C++11 support for GCC/Clang and various editions of CL (msvc)
- add an option for C++11 for ./configure, cmake and configure.py (msvc)
- build with C++11 occasionally on the buildserver (once a week or so)
This seems like very good candidate feature for v0.27. http://dev.exiv2.org/news/3
Updated by T Modes over 5 years ago
CMake 3.1 and later has already some support for C++11. Instead of testing on your own (and missing of msvc) have a look at CMAKE_CXX_STANDARD in CMake doc.
SoSET(CMAKE_CXX_STANDARD 11)
in CMakeLists.txt activates the support for C++11 if available by the compiler. Otherwise it will fall back to the lower C++ standard.
If you want to control the behavior wrap it into an if statement.
(Only drawback you will need to update the CMAKE_MINIMUM_REQUIRED( VERSION 3.1 )
But this should not be a problem as CMake is currently at 3.5.2.)
Updated by Robin Mills over 5 years ago
Thanks. As you know, I am not a fan of CMake and will not be working on this issue until v0.26 ships. If you'd like to contribute to this, I will be delighted to accept your help. I have no issue with setting the minimum CMake version to 3.1.
Updated by Taras Kushnir over 5 years ago
At least under OS X 10.10.5 it's not enough just to add
SET(CMAKE_CXX_STANDARD 11)
since "-stdlib=libc++" parameter will not be added to CXX_FLAGS. That was the reason I've added bunch of duplicating stuff.
Updated by T Modes over 5 years ago
- File cxx11.diff cxx11.diff added
Attached patch added a new option to CMake: EXIV2_ENABLE_CXX11.
By default it is off. When set to ON it will compile with C++11 mode of the compiler.
Concerning the OS X issue. Try first if the issue is fixed in current CMake (you did not specify your version).
Updated by Taras Kushnir over 5 years ago
My CMAKE version is quite recent if not the most recent.
> /Applications/CMake.app/Contents/bin/cmake --version cmake version 3.5.2 CMake suite maintained and supported by Kitware (kitware.com/cmake).
The problem is that --stdlib can be ommited by design, while it's vital to have in compiler flags.
Updated by T Modes over 5 years ago
Does it help when you addset(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
to CMake?
Updated by Robin Mills over 5 years ago
- Assignee set to Robin Mills
- Target version changed from 1.0 to 0.28
Updated by Robin Mills about 3 years ago
- Status changed from Assigned to New
- Assignee deleted (
Robin Mills) - Target version changed from 0.27 to 0.28
This is a top priority feature for v0.28.
Updated by Robin Mills about 3 years ago
- Status changed from New to Closed
- Assignee set to Robin Mills
- Target version changed from 0.28 to 0.27
- % Done changed from 0 to 100
- Estimated time set to 1.00 h
I'm closing this issue as part of the Exiv2 v0.27 Review process. The primary focus of Exiv2 v0.28 is to "modernise the code" to C++11 or later.
So, this issue is being closed on Redmine and will get a lot of attention in 2019.
#1188 set -std=c++98 for v0.26. I'll work on C++11 in v0.27. C++11 Deprecates AutoPtr, so supporting C++11 requires some effort.
#1188 Discusses CMake/C++11 in some detail. For v0.26, CMake also sets -std=c++98 r4530