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

basic conversion to C++20 #2645

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/on_PR_meson.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: Linux-GCC${{matrix.cxx}}-deps=${{matrix.deps}}
strategy:
matrix:
cxx: ['7', '13']
cxx: ['9', '13']
deps: ['forcefallback', 'default']
steps:
- uses: actions/checkout@v4
Expand All @@ -23,15 +23,15 @@ jobs:
run: python3 -m pip install meson ninja
- name: Compile and Test
run: |
meson setup "${{github.workspace}}/build" --wrap-mode=${{matrix.deps}} -Dwarning_level=3
meson setup "${{github.workspace}}/build" --wrap-mode=${{matrix.deps}} -Dwarning_level=3 -Dcpp_std=c++2a
meson compile -C "${{github.workspace}}/build"
meson test -C "${{github.workspace}}/build"
Ubuntu-clang:
runs-on: ubuntu-20.04
name: Linux-Clang${{matrix.cxx}}-deps=${{matrix.deps}}
strategy:
matrix:
cxx: ['7', '19']
cxx: ['8', '19']
deps: ['forcefallback', 'default']
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:

- name: Compile and Test
run: |
meson setup "${{github.workspace}}/build" -Dauto_features=${{matrix.deps}} -Dwarning_level=3 -Dcpp_std=c++20
meson setup "${{github.workspace}}/build" -Dauto_features=${{matrix.deps}} -Dwarning_level=3 -Dcpp_std=c++2a
meson compile -C "${{github.workspace}}/build" --verbose
meson test -C "${{github.workspace}}/build" --verbose
MacOS:
Expand Down
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The file ReadMe.txt in a build bundle describes how to install the library on th

# Building, Installing, Using and Uninstalling Exiv2

You need [CMake](https://cmake.org/download/) to configure the Exiv2 project, any C++ compiler implementing the C++ 17 standard and the associated tool chain.
You need [CMake](https://cmake.org/download/) to configure the Exiv2 project, any C++ compiler implementing the C++ 20 standard and the associated tool chain.

<div id="B_I_U_Unix">

Expand All @@ -88,7 +88,7 @@ $ ctest --test-dir build --verbose # Run tests
$ sudo cmake --install build # Run the install target (install library, public headers, application and CMake files)
```

This will install the library into the "standard locations". The library will be installed in `/usr/local/lib`, executables (including the exiv2 command-line program) in `/usr/local/bin/` and header files in `/usr/local/include/exiv2`. The target directory for the installation can be modified by using the CMake option `-DCMAKE_INSTALL_PREFIX`.
This will install the library into the "standard locations". The library will be installed in `/usr/local/lib`, executables (including the exiv2 command-line program) in `/usr/local/bin/` and header files in `/usr/local/include/exiv2`. The target directory for the installation can be modified by using the CMake option `-DCMAKE_INSTALL_PREFIX`.

CMake analyzes the project configuration from the source code directory and generates files into the build directory. It generates the project/solution/makefiles required to build the exiv2 library and command line application (and optionally sample applications and test runners). CMake also creates the files `exv_conf.h` and `exiv2lib_export.h` which contain compiler directives about the build options you have chosen and the availability of libraries on your machine.

Expand Down Expand Up @@ -190,7 +190,7 @@ Preset CMake variables:
-- Conan: checking conan executable
-- Conan: Found program C:/dev/envs/conan/Scripts/conan.exe
-- Conan: Version found Conan version 1.47.0
-- Conan executing: C:/dev/envs/conan/Scripts/conan.exe install .. --remote conancenter --build missing --options webready=True --settings arch=x86_64 --settings build_type=Release --settings compiler=Visual Studio --settings compiler.version=17 --settings compiler.runtime=MD
-- Conan executing: C:/dev/envs/conan/Scripts/conan.exe install .. --remote conancenter --build missing --options webready=True --settings arch=x86_64 --settings build_type=Release --settings compiler=Visual Studio --settings compiler.version=20 --settings compiler.runtime=MD
...

# CMake finds the project dependencies which were automatically handled by conan
Expand All @@ -206,7 +206,7 @@ Preset CMake variables:
-- CMake Generator: Ninja
-- CMAKE_BUILD_TYPE: Release
-- Compiler info: MSVC (C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe) ; version: 19.30.30705.0
-- CMAKE_CXX_STANDARD:17
-- CMAKE_CXX_STANDARD:20
-- --- Compiler flags ---
-- General: /DWIN32 /D_WINDOWS /W3 /GR /EHsc
/MP
Expand Down Expand Up @@ -298,7 +298,7 @@ The library libiconv is a GNU library and we do not recommend using libiconv wit

Exiv2 includes the file cmake/FindIconv.cmake which contains a guard to prevent CMake from finding libiconv when you build with Visual Studio. This was added because of issues reported when Visual Studio attempted to link libiconv libraries installed by Cygwin, or MinGW or gnuwin32. [https://github.com/Exiv2/exiv2/issues/1250](https://github.com/Exiv2/exiv2/issues/1250)

There are build instructions about Visual Studio in libiconv-1.16/INSTALL.window require you to install Cygwin. There is an article here about building libiconv with Visual Studio. [https://www.codeproject.com/Articles/302012/How-to-Build-libiconv-with-Microsoft-Visual-Studio](https://www.codeproject.com/Articles/302012/How-to-Build-libiconv-with-Microsoft-Visual-Studio).
There are build instructions about Visual Studio in libiconv-1.16/INSTALL.window require you to install Cygwin. There is an article here about building libiconv with Visual Studio. [https://www.codeproject.com/Articles/302012/How-to-Build-libiconv-with-Microsoft-Visual-Studio](https://www.codeproject.com/Articles/302012/How-to-Build-libiconv-with-Microsoft-Visual-Studio).

If you wish to use libiconv with Visual Studio you will have to build libiconv and remove the "guard" in cmake/FindIconv.cmake. Team Exiv2 will not provide support concerning libiconv and Visual Studio.

Expand Down Expand Up @@ -326,7 +326,7 @@ In general you need to do the following:
The following is a typical command to build and link with libexiv2:

```bash
$ g++ -std=c++17 myprog.cpp -o myprog -I/usr/local/include -L/usr/local/lib -lexiv2
$ g++ -std=c++20 myprog.cpp -o myprog -I/usr/local/include -L/usr/local/lib -lexiv2
```

[TOC](#TOC)
Expand All @@ -346,7 +346,7 @@ $ cat - > CMakeLists.txt <<EOF
cmake_minimum_required(VERSION 3.11)
project(exifprint VERSION 0.0.1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)

find_package(exiv2 REQUIRED CONFIG NAMES exiv2) # search ${CMAKE_INSTALL_PREFIX}/lib/cmake/exiv2/
Expand Down Expand Up @@ -382,7 +382,7 @@ LDFLAGS := `pkg-config exiv2 --libs`
If you are not using make, you can use pkg-config as follows:

```bash
g++ -std=c++17 myprogram.cpp -o myprogram $(pkg-config exiv2 --libs --cflags)
g++ -std=c++20 myprogram.cpp -o myprogram $(pkg-config exiv2 --libs --cflags)
```

[TOC](#TOC)
Expand Down Expand Up @@ -502,19 +502,19 @@ To build the documentation, you must install the following products:

## Building Exiv2 Tag Webpages

Exiv2 provides many built-in metadata tags which are listed in the sub-pages of https://exiv2.org/metadata.html
and https://pre-release.exiv2.org/metadata.html. Those tag webpages are generated using tag information
Exiv2 provides many built-in metadata tags which are listed in the sub-pages of https://exiv2.org/metadata.html
and https://pre-release.exiv2.org/metadata.html. Those tag webpages are generated using tag information
extracted from the Exiv2 source code.

The tag webpage build files are in the `<exiv2dir>/doc/templates` directory. If changes are made to
tag groups in the Exiv2 source code then the build files need to be updated. Any changes made
The tag webpage build files are in the `<exiv2dir>/doc/templates` directory. If changes are made to
tag groups in the Exiv2 source code then the build files need to be updated. Any changes made
to individual tags in an existing tag group are automatically included.

Building the tag webpages requires building the Exiv2 sample programs and using scripts which have additional dependencies on
[BASH](https://www.gnu.org/software/bash/), [make](https://manpages.org/make), [xsltproc](https://manpages.org/xsltproc)
Building the tag webpages requires building the Exiv2 sample programs and using scripts which have additional dependencies on
[BASH](https://www.gnu.org/software/bash/), [make](https://manpages.org/make), [xsltproc](https://manpages.org/xsltproc)
and [Python3](https://www.python.org/).

To build the tag webpages, first [build Exiv2 from source](#TOC) with the `-DEXIV2_BUILD_SAMPLES=ON`
To build the tag webpages, first [build Exiv2 from source](#TOC) with the `-DEXIV2_BUILD_SAMPLES=ON`
option enabled. This is required as the [taglist](README-SAMPLES.md#taglist) sample program is used by one of the scripts.

Next, set the `EXIV2_BINDIR` environment variable (see [Exiv2 environment variables](#EnvironmentVariables)).
Expand All @@ -526,7 +526,7 @@ $ cd <exiv2dir>/doc/templates
$ make
```

After processing, the generated webpages are stored in the `<exiv2dir>/doc/templates` directory.
After processing, the generated webpages are stored in the `<exiv2dir>/doc/templates` directory.
When the Exiv2 websites are updated, the generated tag webpages are reformatted before use.

[TOC](#TOC)
Expand Down Expand Up @@ -858,7 +858,7 @@ You will find that 3 tests fail at the end of the test suite. It is safe to ign

## Static and Shared Libraries

You can build either static or shared libraries. Both can be linked with either static or shared run-time libraries. You specify the shared/static with the option `-BUILD_SHARED_LIBS=ON|OFF` You specify the run-time with the option `-DEXIV2_ENABLE_DYNAMIC_RUNTIME=ON|OFF`. The default for both options default is ON. So you build shared and use the shared libraries which are `.dll` on Windows (msvc, Cygwin and MinGW/msys), `.dylib` on macOS and `.so` on Linux and UNIX.
You can build either static or shared libraries. Both can be linked with either static or shared run-time libraries. You specify the shared/static with the option `-BUILD_SHARED_LIBS=ON|OFF` You specify the run-time with the option `-DEXIV2_ENABLE_DYNAMIC_RUNTIME=ON|OFF`. The default for both options default is ON. So you build shared and use the shared libraries which are `.dll` on Windows (msvc, Cygwin and MinGW/msys), `.dylib` on macOS and `.so` on Linux and UNIX.

CMake creates your build artefacts in the directories `bin` and `lib`. The `bin` directory contains your executables and .DLLs. The `lib` directory contains your static libraries. When you install exiv2, the build artefacts are copied to your system's prefix directory which by default is `/usr/local/`. If you wish to test and use your build without installing, you will have to set you PATH appropriately. Linux/Unix users should also set `LD_LIBRARY_PATH` and macOS users should set `DYLD_LIBRARY_PATH`.

Expand Down Expand Up @@ -1005,7 +1005,7 @@ The Variable EXIV2\_PORT or EXIV2\_HTTP can be set to None to skip http tests.
You can run tests directly from the build:

```bash
$ cmake -S . -B build -G "Unix Makefiles" -DEXIV2_BUILD_UNIT_TESTS=ON
$ cmake -S . -B build -G "Unix Makefiles" -DEXIV2_BUILD_UNIT_TESTS=ON
... lots of output and build summary ...
$ cmake --build build
... lots of output ...
Expand Down Expand Up @@ -1045,7 +1045,7 @@ $
> set PATH=c:\Python37;%PATH%
```

You can execute the test suite in a similar manner to that described for UNIX-like systems. You _**must**_ provide the `-C` config option to ctest for Visual Studio builds.
You can execute the test suite in a similar manner to that described for UNIX-like systems. You _**must**_ provide the `-C` config option to ctest for Visual Studio builds.

```cmd
> cd <exiv2dir>
Expand Down Expand Up @@ -1111,7 +1111,7 @@ You can run the bugfix tests from the build directory:

```bash
$ cd <exiv2dir>
$ ctest --test-dir build -R bugfix
$ ctest --test-dir build -R bugfix
```

If you wish to run in verbose mode:
Expand Down
2 changes: 1 addition & 1 deletion cmake/compilerFlags.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# These flags applies to exiv2lib, the applications, and to the xmp code
include(CheckCXXCompilerFlag)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)

Expand Down
14 changes: 0 additions & 14 deletions include/exiv2/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@
#endif
#endif

#ifndef __LITTLE_ENDIAN__
#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__)
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define __LITTLE_ENDIAN__ 1
#endif
#endif
#endif

#ifndef __LITTLE_ENDIAN__
#if defined(_WIN32) || defined(__CYGWIN__)
#define __LITTLE_ENDIAN__ 1
#endif
#endif

/*
If you're using Solaris and the Solaris Studio compiler
you must -library=stdcxx4 along with these inclusions below
Expand Down
10 changes: 0 additions & 10 deletions include/exiv2/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,6 @@ class EXIV2API Image {
void printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStructureOption option, size_t start, bool bSwap,
char c, size_t depth);

/*!
@brief is the host platform bigEndian
*/
static bool isBigEndianPlatform();

/*!
@brief is the host platform littleEndian
*/
static bool isLittleEndianPlatform();

static bool isStringType(uint16_t type);
static bool isShortType(uint16_t type);
static bool isLongType(uint16_t type);
Expand Down
2 changes: 0 additions & 2 deletions include/exiv2/pgfimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class EXIV2API PgfImage : public Image {
//@}

private:
bool bSwap_; // true for bigEndian hardware, else false
/*!
@brief Provides the main implementation of writeMetadata() by
writing all buffered metadata to the provided BasicIo.
Expand All @@ -71,7 +70,6 @@ class EXIV2API PgfImage : public Image {
//! Read header structure.
DataBuf readPgfHeaderStructure(BasicIo& iIo, uint32_t& width, uint32_t& height) const;
//@}

}; // class PgfImage

// *****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(
'cpp',
version: '1.0.0',
meson_version: '>=0.54.1',
default_options: ['warning_level=0', 'cpp_std=c++17'],
default_options: ['warning_level=0', 'cpp_std=c++20'],
)

cargs = []
Expand Down
9 changes: 4 additions & 5 deletions src/asfvideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// included header files
#include "asfvideo.hpp"

#include <bit>
#include <cstring>
#include <iostream>
#include <sstream>
Expand Down Expand Up @@ -51,11 +52,9 @@ AsfVideo::GUIDTag::GUIDTag(const uint8_t* bytes) {
std::memcpy(&data2_, bytes + DWORD, WORD);
std::memcpy(&data3_, bytes + DWORD + WORD, WORD);
std::copy(bytes + QWORD, bytes + 2 * QWORD, data4_.begin());
if (isBigEndianPlatform()) {
data1_ = byteSwap(data1_, true);
data2_ = byteSwap(data2_, true);
data3_ = byteSwap(data3_, true);
}
data1_ = byteSwap(data1_, std::endian::native == std::endian::big);
data2_ = byteSwap(data2_, std::endian::native == std::endian::big);
data3_ = byteSwap(data3_, std::endian::native == std::endian::big);
}

std::string AsfVideo::GUIDTag::to_string() {
Expand Down
3 changes: 2 additions & 1 deletion src/bmffimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#endif

// + standard includes
#include <bit>
#include <cinttypes>
#include <cstdio>
#include <cstring>
Expand Down Expand Up @@ -88,7 +89,7 @@ BmffImage::BmffImage(BasicIo::UniquePtr io, bool /* create */, size_t max_box_de
std::string BmffImage::toAscii(uint32_t n) {
const auto p = reinterpret_cast<const char*>(&n);
std::string result(p, p + 4);
if (!isBigEndianPlatform())
if constexpr (std::endian::native == std::endian::little)
std::reverse(result.begin(), result.end());
// show 0 as _
std::replace(result.begin(), result.end(), '\0', '_');
Expand Down
Loading
Loading