| Codecov | OSS-Fuzz | Repology | Chat |
| :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: |
| [](https://codecov.io/gh/Exiv2/exiv2) | [](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:exiv2) | [](https://repology.org/metapackage/exiv2/versions) | [](https://matrix.to/#/#exiv2-chat:matrix.org) |
| **CI Status:** | | |
|:-- |:-- |:-- |
| [](https://github.com/Exiv2/exiv2/actions/workflows/on_push_BasicWinLinMac.yml) | [](https://github.com/Exiv2/exiv2/actions/workflows/nightly_Linux_distributions.yml) | [](https://github.com/Exiv2/exiv2/actions/workflows/on_push_ExtraJobsForMain.yml) |
# Welcome to Exiv2

Exiv2 is a C++ library and a command-line utility to read,
write, delete and modify Exif, IPTC, XMP and ICC image metadata.
| Exiv2 Resource | Location |
|:---------- |:------ |
| Releases and Documentation
Prereleases:
Project Resources
License (GPLv2)
CMake Downloads | [https://exiv2.org](https://exiv2.org)
[https://pre-release.exiv2.org](https://pre-release.exiv2.org)
[https://github.com/Exiv2/exiv2](https://github.com/Exiv2/exiv2)
[COPYING](COPYING)
[https://cmake.org/download/](https://cmake.org/download/) |
| README.md
README-CONAN.md
README-SAMPLES.md | User Manual. _This document_
Conan User Manual _[click here](README-CONAN.md)_
Sample Code Manual. _[click here](README-SAMPLES.md)_ |
The file ReadMe.txt in a build bundle describes how to install the library on the platform. ReadMe.txt also documents how to compile and link code on the platform.
# TABLE OF CONTENTS
- [Welcome to Exiv2](#Welcome)
- [Building, Installing, Using and Uninstalling Exiv2](#B_I_U)
- [Build, Install, Use and Uninstall Exiv2 on a UNIX-like system](#B_I_U_Unix)
- [Build and Install Exiv2 with Visual Studio](#B_I_U_VisualStudio)
- [Configure the project with CMake presets](#CMakePresets)
- [Build Options](#BuildOptions)
- [Dependencies](#Dependencies)
- [Building and linking your code with Exiv2](#BuildAndLinkYourCode)
- [Consuming Exiv2 with CMake](#ConsumeExiv2WithCmake)
- [Using pkg-config to compile and link your code with Exiv2](#ConsumeWithPkgConfig)
- [Localisation](#Localisation)
- [Building Exiv2 Documentation](#BuildDoc)
- [Building Exiv2 Tag Webpages](#BuildTagWebpages)
- [Building Exiv2 Packages](#GeneratePackages)
- [Debugging Exiv2](#Debugging)
- [Building Exiv2 with Clang and other build chains](#BuildWithClangAndOthers)
- [Building Exiv2 with ccache](#CCache)
- [Thread Safety](#ThreadSafety)
- [Library Initialisation and Cleanup](#InitAndCleanup)
- [Cross Platform Build and Test on Linux for MinGW](#CrossPlatformSupport)
- [Static and Shared Libraries](#StaticShared)
- [Support for BMFF files (e.g., CR3, HEIF, HEIC, AVIF, and JPEG XL)](#BMFF)
- [License and Support](#LicenseSupport)
- [License](#License)
- [Support](#Support)
- [Test Suite](#TestSuite)
- [Exiv2 Environment Variables](#EnvironmentVariables)
- [Running tests on a UNIX-like system](#TestsOnUnix)
- [Running tests on Visual Studio builds](#TestsOnVisualStudio)
- [Unit Tests](#UnitTests)
- [Bugfix Tests](#BugfixTests)
- [Fuzzing](#FuzzingTests)
- [OSS-Fuzz](#OssFuzz)
- [Platform Notes](#PlatformNotes)
- [Linux](#PlatformLinux)
- [macOS](#PlatformMacOs)
- [MinGW/msys2](#PlatformMinGWMSYS)
- [Cygwin](#PlatformCygwin)
- [Visual Studio](#PlatformVisualStudio)
- [Unix](#PlatformUnix)
[TOC](#TOC)
# 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.
## Build, Install, Use Exiv2 on a UNIX-like system
```bash
$ cd ~/gnu/github/exiv2 # Location of the project code
$ cmake -S . -B build -DCMAKE_BUILD_TYPE=Release # Configure the project with CMake
$ cmake --build build # Compile the project
$ 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`.
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.
### Using the exiv2 command-line program
To execute the exiv2 command line program, you should update your path to search /usr/local/bin/
```bash
$ export PATH="/usr/local/bin:$PATH"
```
You will also need to locate libexiv2 at run time:
```bash
$ export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" # Linux, Cygwin, MinGW/msys2
$ export DYLD_LIBRARY_PATH="/usr/local/lib:$DYLD_LIBRARY_PATH" # macOS
```
### Uninstall
I don't know why anybody would uninstall Exiv2.
```bash
$ cd ~/gnu/github/exiv2 # location of the project code
$ cd build
$ cmake --build build --target uninstall
```
These commands will run the `uninstall` target and remove all the files which were installed by the `install` target.
Note that this mechanism is not perfect and it is not able to remove the sub-directories created in the installation
path.
[TOC](#TOC)
## Build and Install Exiv2 with Visual Studio
We recommend to use conan to download the Exiv2 external dependencies on Windows. On other platforms (macOS, Linux and others), traditionally the platform package managers have been used. However, conan can be used in any platform/architecture to bring the project dependencies. These are discussed at [Platform Notes](#PlatformNotes). The options to configure and compile the project using Visual Studio are similar to UNIX like systems.
See [README-CONAN](README-CONAN.md) for more information about Conan.
When you build, you may install with the following command.
```cmd
> cmake --install build
```
This will create and copy the exiv2 build artifacts to `%ProgramFiles%/exiv2`. To be able to run the `exiv2` command line application from any terminal you should modify your path to include `%ProgramFiles%/exiv2/bin`.
[TOC](#TOC)
## Configure the project with the CMake presets
CMake presets (see documentation [here](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html)) were added recently to the project to ease the CMake configuration process for typical configurations. The presets are defined in the file `CMakePresets.json` and they can be used from the terminal or interpreted by different IDEs. Please note that one needs to use a recent version of CMake (>= 3.21) supporting the presets feature.
One can list the available presets using the `--list-presets` option:
```bash
# Running the command from a Windows terminal
$ cmake --list-presets
Available configure presets:
"msvc" - Visual Studio cl toolchain (also usable from VS Code)
"win-debug" - Windows Debug with configured architecture
"win-release" - Windows Release with configured architecture
# Running the command from a Linux terminal
$ cmake --list-presets
Available configure presets:
"linux-debug" - Linux Debug with default architecture
"linux-release" - Linux Release with default architecture
```
The project configuration with a specific preset can be choosen with the CMake `--preset` option. In the following terminal output we comment out some interesting things happening during the project configuration:
```bash
# Configuring the project using a preset
$ cmake --preset win-release
Preset CMake variables:
# Note that with the usage of a preset, we pass many different options to CMake.
BUILD_SHARED_LIBS:BOOL="TRUE"
CMAKE_BUILD_TYPE="Release"
CMAKE_INSTALL_PREFIX:PATH="C:/dev/personal/exiv2/build-win-release/install"
# A build & install directory are configured with the preset
CONAN_AUTO_INSTALL:BOOL="TRUE"
EXIV2_BUILD_SAMPLES:BOOL="TRUE"
EXIV2_BUILD_UNIT_TESTS:BOOL="TRUE"
EXIV2_ENABLE_BMFF:BOOL="TRUE"
EXIV2_ENABLE_CURL:BOOL="TRUE"
EXIV2_ENABLE_NLS:BOOL="FALSE"
EXIV2_ENABLE_VIDEO:BOOL="TRUE"
EXIV2_ENABLE_PNG:BOOL="TRUE"
EXIV2_ENABLE_WEBREADY:BOOL="TRUE"
EXIV2_TEAM_WARNINGS_AS_ERRORS:BOOL="TRUE"
# Conan can be automatically detected in your system and it is run automatically to bring the
# project dependencies
-- Conan: Detected VS runtime: MD
-- 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
...
# CMake finds the project dependencies which were automatically handled by conan
-- Conan: Using autogenerated FindZLIB.cmake
-- Library zlib found C:/Users/luis/.conan/data/zlib/1.2.11/_/_/package/
-- Conan: Using autogenerated FindCURL.cmake
-- Library libcurl_imp found C:/Users/luis/.conan/data/libcurl/7.79.0/_/_/package/
...
# CMake finish the project configuration and prints a report
-- Install prefix: C:/dev/personal/exiv2/build-win-release/install
-- ------------------------------------------------------------------
-- 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
-- --- Compiler flags ---
-- General: /DWIN32 /D_WINDOWS /W3 /GR /EHsc
/MP
/utf-8
/WX
-- Extra:
-- Debug: /MDd /Zi /Ob0 /Ox /Zo
-- Release: /MD /O2 /DNDEBUG
-- RelWithDebInfo: /MD /Zi /O2 /DNDEBUG
-- MinSizeRel: /MD /O1 /DNDEBUG
-- --- Linker flags ---
-- General: /machine:x64 /WX
-- Debug: /debug /INCREMENTAL
-- Release: /INCREMENTAL:NO
-- RelWithDebInfo: /debug /INCREMENTAL
-- MinSizeRel: /INCREMENTAL:NO
--
...
-- Build files have been written to: C:/dev/personal/exiv2/build-win-release
```
Note that the usage of CMake presets allow the project contributors to use the same set of options easily in different environments (using terminal, IDEs or CI).
[TOC](#TOC)
## Build options
There are two groups of CMake options which are relevant to the project: global CMake options and project specific ones. Here are some of the global options which are particularly useful:
| Options | Purpose (_default_) |
|:------------- |:------------- |
| CMAKE\_INSTALL\_PREFIX
CMAKE\_BUILD\_TYPE
BUILD\_SHARED\_LIBS | Where to install on your computer _**(/usr/local)**_
Type of build _**(Release)**_ See: [Debugging Exiv2](#Debugging)
Build exiv2lib as SHARED or STATIC |
Options defined at `exiv2/CMakeLists.txt` include:
```bash
576 rmills@rmillsmm:~/gnu/github/exiv2/exiv2 $ grep ^option CMakeLists.txt
option( BUILD_SHARED_LIBS "Build exiv2lib as a shared library" ON )
option( EXIV2_ENABLE_XMP "Build with XMP metadata support" ON )
option( EXIV2_ENABLE_EXTERNAL_XMP "Use external version of XMP" OFF )
option( EXIV2_ENABLE_PNG "Build with png support (requires libz)" ON )
...
option( EXIV2_ENABLE_BMFF "Build with BMFF support (brotli recommended)" ON )
option( EXIV2_ENABLE_BROTLI "Use Brotli for JPEG XL compressed boxes (BMFF)" ON )
577 rmills@rmillsmm:~/gnu/github/exiv2/exiv2 $
```
Using the command-line, these variables can be set/updated using the option `-D`:
```bash
$ cmake -DBUILD_SHARED_LIBS=ON -DEXIV2_ENABLE_NLS=OFF
```
[TOC](#TOC)
## Dependencies
The following Exiv2 features require external libraries:
| Feature | Package | Default | To change default | Availability |
|:------------------------ |:-------- |:-------:|:--------------------------- |:------------ |
| PNG image support | zlib | ON | -DEXIV2\_ENABLE\_PNG=OFF | [http://zlib.net/](http://zlib.net/) |
| XMP support | expat | ON | -DEXIV2\_ENABLE\_XMP=OFF | [http://expat.sourceforge.net](http://expat.sourceforge.net)/
Use _**Expat 2.2.6**_ and later |
| Natural language system | gettext | OFF | -DEXIV2\_ENABLE\_NLS=ON | [http://www.gnu.org/software/gettext/](http://www.gnu.org/software/gettext/) |
| JPEG XL brob support | brotli | ON | -DEXIV2\_ENABLE\_BROTLI=OFF | [https://github.com/google/brotli](https://github.com/google/brotli) |
| Character set conversion | libiconv | | Disabled for Visual Studio.
Linked when installed on UNIX like platforms. | [https://www.gnu.org/software/libiconv/](https://www.gnu.org/software/libiconv/) |
On UNIX systems, you may install the dependencies using the distribution's package management system. Install the
development package of a dependency to install the header files and libraries required to build Exiv2. The script
`ci/install_dependencies.sh` is used to setup the CI images on which we build and test Exiv2. You may find that helpful in setting up your platform dependencies.
Natural language system is discussed in more detail here: [Localisation](#Localisation)
Notes about different platforms are included here: [Platform Notes](#PlatformNotes)
You may choose to install dependences with conan. This is supported on all platforms and is especially useful for users of Visual Studio.
See [README-CONAN](README-CONAN.md) for more information.
### Libiconv
The library libiconv is used to perform character set encoding in the tags Exif.Photo.UserComment, Exif.GPSInfo.GPSProcessingMethod and Exif.GPSInfo.GPSAreaInformation. This is documented in the [exiv2 man page](exiv2.md).
CMake will detect libiconv of all UNIX like systems including Linux, macOS, UNIX, Cygwin64 and MinGW/msys2. If you have installed libiconv on your machine, Exiv2 will link and use it.
The library libiconv is a GNU library and we do not recommend using libiconv with Exiv2 when building with Visual Studio.
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).
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.
[TOC](#TOC)
## Building and linking your code with Exiv2
There are detailed platform notes about compiling and linking in `releasenotes/{platform}/ReadMe.txt`
where `platform: { CYGWIN | Darwin | Linux | MinGW | msvc | Unix }`
In general you need to do the following:
1) Application code should be written in C++98 and include exiv2 headers:
```cpp
#include
```
2) Compile your C++ code with the directive: **`-I/usr/local/include`**
3) Link your code with libexiv2 using the linker options: **`-lexiv2`** and **`-L/usr/local/lib`**
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
```
[TOC](#TOC)
## Consuming Exiv2 with CMake
When exiv2 is installed, the files required to consume Exiv2 with CMake are installed in `${CMAKE_INSTALL_PREFIX}/lib/cmake/exiv2`
You can build samples/exifprint.cpp as follows:
```bash
$ cd
$ mkdir exifprint
$ cd exifprint
$ cat - > CMakeLists.txt <
## Using pkg-config to compile and link your code with Exiv2
When exiv2 is installed, the file exiv2.pc used by pkg-config is installed in `${CMAKE_INSTALL_PREFIX}/lib/pkgconfig` You will need to set the following in your environment:
```bash
$ export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
```
To compile and link using exiv2.pc, you usually add the following to your Makefile.
```bash
PKGCONFIG=pkg-config
CPPFLAGS := `pkg-config exiv2 --cflags`
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)
```
[TOC](#TOC)
## Localisation
Localisation is supported on a UNIX-like platform: Linux, macOS, Cygwin and MinGW/msys2. Localisation is not supported for Visual Studio builds.
Crowdin have provided Exiv2 with a free open-source license to use their services. The Exiv2 localisation project is located at [https://crowdin.com/project/exiv2](https://crowdin.com/project/exiv2). You will also need to register to have a free user account on Crowdin. The Crowdin setup is discussed here: [https://github.com/Exiv2/exiv2/issues/1510](https://github.com/Exiv2/exiv2/issues/1510). It is recommended that you coordinate with Leonardo before contributing localisation changes on Crowdin. You can contact Leonardo by via GitHub.
To build localisation support, use the CMake option `-DEXIV2_ENABLE_NLS=ON`. You must install the `gettext` package with your package manager or from source. The `gettext` package is available from [http://www.gnu.org/software/gettext/](http://www.gnu.org/software/gettext/) and includes the library `libintl` and utilities to build localisation files. If CMake produces error messages which mention libintl or gettext, you should verify that the package `gettext` has been correctly built and installed.
You must install the build to test localisation. This ensures that the localisation message files can be found at run-time. You cannot test localisation in the directory `build\bin`.
1) Running exiv2 in another language
```bash
$ env LANG=fr_FR exiv2 # env LANGUAGE=fr_FR exiv2 on Linux!
exiv2: Une action doit être spécifié
exiv2: Au moins un fichier est nécessaire
Utilisation : exiv2 [ option [ arg ] ]+ [ action ] fichier ...
Image metadata manipulation tool.
$
```
2) Adding additional languages to exiv2
To support a new language which we'll designate 'xy' for this discussion:
2.1) Generate a po file from the po template:
```bash
$ cd
$ mkdir -p po/xy
$ msginit --input=po/exiv2.pot --locale=xy --output=po/xy.po
```
2.2) Edit/Translate the strings in po/xy.po
I edited the following:
```bash
#: src/exiv2.cpp:237
msgid "Image metadata manipulation tool.\n"
msgstr ""
```
to:
```bash
#: src/exiv2.cpp:237
msgid "Image metadata manipulation tool.\n"
msgstr "Manipulate image metadata.\n"
```
2.3) Generate the messages file:
```bash
$ mkdir -p po/xy/LC_MESSAGES
$ msgfmt --output-file=po/xy/LC_MESSAGES/exiv2.mo po/xy.po
```
2.4) Install and test your messages:
You have to install your messages to test them. It's not possible to test a messages file by executing build/bin/exiv2.
```bash
$ sudo mkdir -p /usr/local/share/locale/xy/LC_MESSAGES
$ sudo cp -R po/xy/LC_MESSAGES/exiv2.mo /usr/local/share/locale/xy/LC_MESSAGES
$ env LANG=xy exiv2 # env LANGUAGE=xy on Linux!
exiv2: An action must be specified
exiv2: At least one file is required
Usage: exiv2 [ option [ arg ] ]+ [ action ] file ...
Manipulate image metadata. <--------- Edited message!
$
```
2.5) Submitting your new language file for inclusion in future versions of Exiv2:
You may submit a PR which contains po/xy.po AND a modification to po/CMakeLists.txt
Or, open a new issue on https://github.com/exiv2/exiv2 and attach the file xy.po.zip which can be created as follows:
```
$ zip xy.po.zip po/xy.po
adding: po/xy.po (deflated 78%)
ls -l xy.po.zip
-rw-r--r--+ 1 rmills staff 130417 25 Jun 10:15 xy.po.zip
$
```
[TOC](#TOC)
## Building Exiv2 Documentation
Building documentation requires installing special tools. You will probably prefer to
read the documentation on-line from the project website: https://exiv2.org
To build documentation, use the CMake option **`-DEXIV2_BUILD_DOC=ON`**.
Additionally, you will require an additional build step to actually build the documentation.
```bash
$ cmake ..options.. -DEXIV2_BUILD_DOC=ON
$ cmake --build build --target doc
```
To build the documentation, you must install the following products:
| Product | Availability |
|:------------ |:------------ |
| doxygen
graphviz
python
xsltproc
md5sum | [http://www.doxygen.org/](http://www.doxygen.org/)
[http://www.graphviz.org/](http://www.graphviz.org/)
[http://www.python.org/](http://www.python.org/)
[http://xmlsoft.org/XSLT/](http://xmlsoft.org/XSLT/)
[http://www.microbrew.org/tools/md5sha1sum/](http://www.microbrew.org/tools/md5sha1sum/) |
[TOC](#TOC)
## 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
extracted from the Exiv2 source code.
The tag webpage build files are in the `
/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 dependancies 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`
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)).
Then, change directory to `doc/templates` and run `make`.
```bash
$ cd /doc/templates
$ make
```
After processing, the generated webpages are stored in the `/doc/templates` directory.
When the Exiv2 websites are updated, the generated tag webpages are reformatted before use.
[TOC](#TOC)
## Building Exiv2 Packages
To enable the building of Exiv2 packages, use the CMake option `-DEXIV2_TEAM_PACKAGING=ON`.
You should not build Exiv2 Packages. This feature is intended for use by Team Exiv2 to create Platform and Source Packages on the buildserver.
There are two types of Exiv2 packages which are generated by cpack from the CMake command-line.
1) Platform Package (header files, binary library and samples. Some documentation and release notes)
Create and build exiv2 for your platform.
```bash
$ git clone https://github.com/exiv2/exiv2
$ cd exiv2
$ cmake -S . -B build -G "Unix Makefiles" -DEXIV2_TEAM_PACKAGING=ON
...
-- Build files have been written to: .../build
$ cmake --build build --config Release
...
[100%] Built target addmoddel
$ cmake --build build --target package
...
CPack: - package: /path/to/exiv2/build/exiv2-0.27.1-Linux.tar.gz generated.
```
2) Source Package
```bash
$ cmake --build build --target package_source
Run CPack packaging tool for source...
...
CPack: - package: /path/to/exiv2/build/exiv2-0.27.1-Source.tar.gz generated.
```
[TOC](#TOC)
## Debugging Exiv2
1) Generating and installing a debug library
In general to generate a debug library, you should use the *CMake* option `-DCMAKE_RELEASE_TYPE=Debug` and build in the usual way.
```bash
$ cd
$ cmake -S . -B build -G "Unix Makefiles" "-DCMAKE_BUILD_TYPE=Debug"
$ cmake --build build
```
You must install the library to ensure that your code is linked to the debug library.
You can check that you have generated a debug build with the command:
```bash
$ exiv2 -vVg debug
exiv2 0.27.1
debug=1
$
```
2) About preprocessor symbols `NDEBUG` and `EXIV2_DEBUG_MESSAGES`
Exiv2 respects the symbol `NDEBUG` which is set only for Release builds. There are sequences of code which are defined within:
```cpp
#ifdef EXIV2_DEBUG_MESSAGES
....
#endif
```
Those blocks of code are not compiled unless you define `EXIV2_DEBUG_MESSAGES`. They are provided for additional debugging information. For example, if you are interested in additional output from webpimage.cpp, you can update your build as follows:
```bash
$ cd && cd build
$ cmake -S . -B build -DCMAKE_CXX_FLAGS=-DEXIV2_DEBUG_MESSAGES
$ cmake --build build
$ bin/exiv2 ...
-- or --
$ cmake --install build
$ exiv2 ...
```
If you are debugging library code, it is recommended that you use the exiv2 command-line program as your test harness as Team Exiv2 is very familiar with this tool and able to give support.
3) Starting the debugger
This is platform specific. On Linux:
```bash
$ gdb exiv2
```
4) Using Debugger IDEs such as Xcode, CLion, Visual Studio, Eclipse or QtCreator
I have used all those IDEs to debug the Exiv2 library and applications. All of them work. You may find it takes initial effort, however I assure you that they all work well.
I work on macOS and use Xcode to develop Exiv2. For a couple of years, Team Exiv2 had free
open-source licences from JetBrains for CLion. I really liked CLion as it is cross platform
and runs on Windows, Mac and Linux. It has excellent integration with CMake and will automatically
add **`-DCMAKE_BUILD_TYPE=Debug`** to the CMake command. It keeps build types in separate directories
such as **`/cmake-build-debug`**.
5) cmake --build build options **`--config Release|Debug`** and **`--target install`**
Visual Studio and Xcode can build debug or release builds without using the option **`-DCMAKE_BUILD_TYPE`** because the generated project files can build multiple types. The option **`--config Debug`** can be specified on the CMake command-line to specify the build type. Alternatively, if you prefer to build in the IDE, the UI provides options to select the configuration and target.
With the Unix Makefile generator, the targets can be listed:
```bash
$ cmake --build build --target help
The following are some of the valid targets for this Makefile:
... all (the default if no target is provided)
... clean
... depend
... install/local
.........
```
[TOC](#TOC)
## Building Exiv2 with **clang** and other build chains
1) On Linux
```bash
$ cd
$ rm -rf build
$ cmake -S . -B build -DCMAKE_C_COMPILER=$(which clang) -DCMAKE_CXX_COMPILER=$(which clang++)
$ cmake --build build
```
**_OR_**
```bash
$ export CC=$(which clang)
$ export CXX=$(which clang++)
$ cd
$ rm -rf build
$ cmake -S . -B build
$ cmake --build build
```
2) On macOS
Apple provide clang with Xcode. GCC has not been supported by Apple since 2013. The _"normal unix build"_ uses Clang.
3) On Cygwin, MinGW/msys2, Windows (using clang-cl) and Visual Studio.
I have been unable to get clang to work on any of those platforms.
[TOC](#TOC)
## Building Exiv2 with ccache
To speed up compilation, the utility ccache can be installed to cache the output of the compiler. This greatly speeds up the build when you frequently built code that has not been modified.
Installing and using ccache (and other similar utilities), is platform dependent. On Ubuntu:
```bash
$ sudo apt install --yes ccache
```
To build with ccache, use the CMake option **-DBUILD\_WITH\_CCACHE=ON**
```bash
$ cd
$ mkdir build
$ cmake -S . -B build -G "Unix Makefiles" -DBUILD_WITH_CCACHE=ON
$ cmake --build build
# Build again to appreciate the performance gain
$ cmake --build build --target clean
$ cmake --build build
```
Due to the way in which ccache is installed in Fedora (and other Linux distros), ccache effectively replaces the compiler. A default build or **-DBUILD\_WITH\_CCACHE=OFF** is not effective and the environment variable CCACHE_DISABLE is required to disable ccache. [https://github.com/Exiv2/exiv2/issues/361](https://github.com/Exiv2/exiv2/issues/361)
[TOC](#TOC)
## Thread Safety
Exiv2 heavily relies on standard C++ containers. Static or global variables are used read-only, with the exception of the XMP namespace registration function (see below). Thus Exiv2 is thread safe in the same sense as C++ containers:
Different instances of the same class can safely be used concurrently in multiple threads.
In order to use the same instance of a class concurrently in multiple threads the application must serialize all write access to the object.
The level of thread safety within Exiv2 varies depending on the type of metadata: The Exif and IPTC code is reentrant. The XMP code uses the Adobe XMP toolkit (XMP SDK), which according to its documentation is thread-safe. It actually uses mutexes to serialize critical sections. However, the XMP SDK initialisation function is not mutex protected, thus Exiv2::XmpParser::initialize is not thread-safe. In addition, Exiv2::XmpProperties::registerNs writes to a static class variable, and is also not thread-safe.
Therefore, multi-threaded applications need to ensure that these two XMP functions are serialized, e.g., by calling them from an initialization section which is run before any threads are started. All exiv2 sample applications begin with:
```cpp
#include
int main(int argc, const char* argv[])
{
Exiv2::XmpParser::initialize();
::atexit(Exiv2::XmpParser::terminate);
#ifdef EXV_ENABLE_BMFF
Exiv2::enableBMFF(true);
#endif
...
}
```
The use of the _**thread unsafe function**_ Exiv2::enableBMFF(true) is discussed in [Support for BMFF files (e.g., CR3, HEIF, HEIC, AVIF, and JPEG XL)](#BMFF)
[TOC](#TOC)
## Library Initialisation and Cleanup
As discussed in the section on Thread Safety, Exiv2 classes for Exif and IPTC metadata are fully reentrant and require no initialisation or cleanup.
Adobe's XMPsdk is generally thread-safe, however it has to be initialized and terminated before and after starting any threads to access XMP metadata. The Exiv2 library will initialize this if necessary, however it does not terminate the XMPsdk.
The exiv2 command-line program and sample applications call the following at the outset:
```cpp
Exiv2::XmpParser::initialize();
::atexit(Exiv2::XmpParser::terminate);
#ifdef EXV_ENABLE_BMFF
Exiv2::enableBMFF(true);
#endif
```
[TOC](#TOC)