Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix c++11 0.27 #1194

Merged
merged 19 commits into from
May 2, 2020
Merged

Fix c++11 0.27 #1194

merged 19 commits into from
May 2, 2020

Conversation

clanmills
Copy link
Collaborator

This is a "quick hack" to provide support for C++11 in Exiv2 v0.27.3. If the review is favourable, this can go into v0.27.3 RC2.

A "proper" fix is to port #601 to 0.27-maintenance and I'm willing to do that if we ever do Exiv2 v0.27.4. I'm unwilling to make such a major change to the code for 0.27.3.

I don't know if we need to do further "dots". The API for v0.28 is different and applications will have to adjust to build with v0.28. And we have removed features (video, ssh and eps) from 0.28.

I feel the way forward is to focus on getting 0.28 published later in 2020.

By the way, there are changes in this PR relating to samples/geotag.cpp. Those are irrelevant and should be on another branch. Git strikes again.

@clanmills clanmills added this to the v0.27.3 milestone May 2, 2020
@clanmills clanmills requested a review from piponazo May 2, 2020 11:35
@clanmills clanmills self-assigned this May 2, 2020
@@ -1,5 +1,9 @@
# These flags applies to exiv2lib, the applications, and to the xmp code

if ( EXIV2_BUILD_USE_C++11 )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we wound need to following. Replace these lines by:

if ( EXIV2_BUILD_USE_C++11 ) 
  set(CMAKE_CXX_STANDARD 11)
else()
  set(CMAKE_CXX_STANDARD 98)
endif()

set(CMAKE_CXX_STANDARD_REQUIRED ON)	
set(CMAKE_CXX_EXTENSIONS ON)

And more important is to remove all the usages of:

target_compile_features(XXX PRIVATE cxx_std_98)

@@ -90,6 +89,10 @@ if ( MINGW OR UNIX OR MSYS ) # MINGW, Linux, APPLE, CYGWIN
endif()
endif()
endif()
if ( EXIV2_BUILD_USE_C++11 )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, replace the usage of CMAKE_CXX_FLAGS by the more appropriate usage of add_compile_options:

  add_compile_options(-Wno-deprecated)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed that 100%. I don't mess with the compile_options for -Wno-deprecated The user can pass that from the command when required. And that's what I've documented in README.md.

#include <unistd.h>
template <typename T>
using auto_ptr = std::unique_ptr<T>;
#else
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a clever trick, I did not think about that.

I think you can remove lines 103 & 104 from here. We do not need the using instruction when not using C++11.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember what using does. I got the code from StackOverflow (in the comment).

@@ -91,10 +91,6 @@ generate_export_header(exiv2lib
STATIC_DEFINE exiv2lib_STATIC
)

target_compile_features(exiv2lib_int PRIVATE cxx_std_98)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some other usages of target_compile_features in the unitTests and samples folders.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got rid of all the target_compile_features magic.

@clanmills
Copy link
Collaborator Author

clanmills commented May 2, 2020

Thanks for the review @piponazo I believe I've removed every target_compile_features(... cxx_std_98)

1100 rmills@rmillsmbp:~/gnu/github/exiv2/0.27-maintenance $ find . -name *.cmake | xargs grep 98
1101 rmills@rmillsmbp:~/gnu/github/exiv2/0.27-maintenance $ find . -name CMakeLists.txt | xargs grep 98
1102 rmills@rmillsmbp:~/gnu/github/exiv2/0.27-maintenance $ find . -name *.cmake | xargs grep target_compile_features
1103 rmills@rmillsmbp:~/gnu/github/exiv2/0.27-maintenance $ find . -name CMakeLists.txt | xargs grep target_compile_features
1104 rmills@rmillsmbp:~/gnu/github/exiv2/0.27-maintenance $ 

I now understand what Mr Bruins was shouting about. We shouldn't try to dictate the tools. We only have to document how to use them! So we don't need any special magic about USE_C++11. The correct way to do this is documented in README.md as:

2.17 Building with C++11 and other compilers

Exiv2 uses the default compiler for your system. Exiv2 v0.27 was written to the C++ 1998 standard and uses auto_ptr. The C++11 and C++14 compilers will issue deprecation warnings about auto_ptr. As auto_ptr support has been removed from C++17, you cannot build Exiv2 v0.27 with C++17 or later compilers. Exiv2 v0.28 and later do not use auto_ptr and will build with all compilers.

To generate a build with C++11:

$ cd <exiv2dir>
$ mkdir build ; cd build
$ cmake .. -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_FLAGS=-Wno-deprecated
$ make

The option -DCMAKE_CXX_FLAGS=-Wno-deprecated suppresses warnings from C++11 concerning auto_ptr and other deprecated features.

@clanmills
Copy link
Collaborator Author

This has been very useful. It shines a clear light on our release strategy from here.

We should only do maintenance on 0.27-maintenance. So, we leave the auto_ptr alone. It is what it is.

We should port new features/fixes in 0.27-maintenance into master and publish 0.28 later this year. I'll make the release and do the publishing on exiv2.org.

How does that sound to you?

@lgtm-com
Copy link

lgtm-com bot commented May 2, 2020

This pull request introduces 3 alerts when merging f1182b8 into 6e5fdb0 - view on LGTM.com

new alerts:

  • 2 for Comparison result is always the same
  • 1 for Multiplication result converted to larger type

@clanmills clanmills merged commit 93cad8c into 0.27-maintenance May 2, 2020
@clanmills clanmills deleted the fix_c++11_0.27 branch May 2, 2020 17:42
README.md Outdated

### 2.17 Building with C++11 and other compilers

Exiv2 uses the default compiler for your system. Exiv2 v0.27 was written to the C++ 1998 standard and will compile with C++11 and C++14. As auto_ptr support is no longer in C++17, you cannot build with that system. Exiv2 v0.28 and later do not use auto_ptr and are fully supported with all compilers.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would replace here the last part of the sentence: "supported with all compilers".
We should say that we require a C++ compiler with support for the C++11 standard.

```bash
$ cd <exiv2dir>
$ mkdir build ; cd build
$ cmake .. -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_FLAGS=-Wno-deprecated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! This is exactly how it should be used. I did not think about it before.

@piponazo
Copy link
Collaborator

piponazo commented May 2, 2020

Ey @clanmills this PR broke the CI in most of the services, let me know if I can help you with this.

@clanmills
Copy link
Collaborator Author

The CI is broken because the output log is so long with all the deprecation warnings. We should probably update the CI to use -Wno_deprecated

I removed the geotag related stuff from the PR, and it removed the files from the 0.27-maintenance branch.

Let me get the product back together and I'll build it on the Mac Mini (macOS, Ubuntu, Cygwin, MinGW, VS2019, SunOS, FreeBSD and NetBSD). Then I'll relax.

@clanmills clanmills mentioned this pull request May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants