Howto compile
=============

= Prerequisites

You need at least an installed:

* cmake
* make
* C- and C++-compiler
* and the pcre2-library

= Compiling under Linux

[bash]
----
mkdir build
cd build
cmake ../src/
make
make package # optional, creates a Debian or Redhat package
make install # optional, installs binary locally
# with 'make help' you get additional targets
----

Alternatively, you could use ninja:

[bash]
----
mkdir build
cd build
cmake -G Ninja ../src/
cmake --build .
cmake --build . --target package # optional, creates a Debian or Redhat package
cmake --build . --target install # optional, creates a Debian or Redhat package
----




[TIP]
====
 use "-fstack-check" if you expect highly corrupted TIFF-files
====

== Support for strong ICC checks

If available, the ICCProfLib will be used to  verify ICC profiles more deeply.
Anyway, the ICCProfLib reports warnings and errors. In default checkit_tiff compiles in relaxed mode, so all warnings are ignored.
This makes sense in most cases. To handle warnings as errors, checkit_tiff needs to be compiled with the 'WITH_STRONG_ICC' flag.

[bash]
----
cmake ../src/ -DCMAKE_C_FLAGS="-DWITH_STRONG_ICC"
----

If no ICCProfLib is available, checkit_tiff falls back into sa rudimentary ICC check.

See file link:README.icc[] for details.

To disable the use of ICC proflib, set CMAKE-flag "-DWITHOUT_ICC_PROFLIB=1"

== Support for outdated ICC variants

if you want to allow preferred CMM type "LINO", you should use the cmake-call

[bash]
----
cmake ../src/ -DCMAKE_C_FLAGS="-DALLOW_CMMTYPE_LINO"
----

if you want to allow outdated ICC.1:2001-04 version (2.4.0), you should use the cmake-call

[bash]
----
cmake ../src/ -DCMAKE_C_FLAGS="-DALLOW_ICC1_2001_04"
----

== cross compiling for Windows binaries

alternatively for windows crosscompiling using mingw
(see file FAQ for more detailed manual)

[bash]
----
mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=../src/toolchain-mingw32.cmake -DPCRE2_POSIX_LIBRARY=~/Downloads/pcre2-10.40/.libs/libpcre2-posix.a -DPCRE2_LIBRARY=~/Downloads/pcre2-10.40/.libs/libpcre2-8.a  -DPCRE2_INCLUDE_DIR=~/Downloads/pcre2-10.40/ ../src/
make
----

== examples for specific compile flags

to change compiler or CFLAGS:

* 'cmake ../src/ -DCMAKE_C_COMPILER=$(which gcc)'
* 'cmake ../src/ -DCMAKE_C_FLAGS="-O0 -p -g"'
* 'cmake ../src/ -DCMAKE_C_COMPILER=$(which clang) -DCMAKE_C_FLAGS="-Oz -pedantic"' -DCMAKE_CXX_FLAGS="-Oz"

example SANITIZE options

[bash]
.SANITIZE with clang++
----
cmake ../src/ -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_C_FLAGS="-O0 -g -fsanitize=address -fno-omit-frame-pointer"
make
ASAN_OPTIONS=detect_leaks=1 ./checkit_tiff ...
----

[bash]
.SANITIZE with gcc
----
cmake ../src/ -DCMAKE_C_FLAGS="-Og -g -fsanitize=address -fsanitize=undefined -fsanitize=shift -fsanitize=integer-divide-by-zero -fsanitize=unreachable -fsanitize=vla-bound -fsanitize=null -fsanitize=return -fsanitize=signed-integer-overflow-fno-omit-frame-pointer"
ASAN_OPTIONS=detect_leaks=1 ./checkit_tiff ...
----


[bash]
.compile a static binary
----
cmake ../src/ -DSTATIC=1
----

[bash]
.compile with MUSL
----
cmake ../src/ \
  -G "Ninja" \
  -DCMAKE_CXX_COMPILER="g++" \
  -DCMAKE_C_COMPILER="musl-gcc" \
  -DCMAKE_C_FLAGS="-DALLOW_ICC1_2001_04" \
  -DSTATIC=1 \
  -DWITHOUT_ICC_PROFLIB=1 \
  -DPCRE2_LIBRARY=pcre2-10.40/.libs/ \
  -DPCRE2_POSIX_LIBRARY=pcre2-10.40/.libs/libpcre2-posix.a \
  -DPCRE2_LIBRARY=pcre2-10.40/.libs/libpcre2-8.a \
  -DPCRE2_INCLUDE_DIR=pcre2-10.40/src \
  -DPCRE2_STATIC=1 \
../src/
----

For MUSL you need a MUSL precompiled pcre2-library.

[bash]
.use clang-tidy
----
cmake ../src/ -DCMAKE_C_CLANG_TIDY:STRING="clang-tidy-16;-checks=-*,readability-*" -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DCMAKE_C_COMPILER=/usr/bin/clang-16 -DCMAKE_C_FLAGS="-O0 -g -fno-omit-frame-pointer"
make
run-clang-tidy-16.py -clang-tidy-binary /usr/bin/clang-tidy-16
----
[NOTE]
====
Most compiler flags are not of interest to the standard user, since they are only needed for debugging purposes or for very specific build environments, or are set automatically.

However, here is a list of the most important flags:

* ALLOW_CMMTYPE_LINO
* ALLOW_ICC1_2001_04
* COMPAT_NEED_REALLOCARRAY
* HAVE_IccProfLib
* HAVE_MMAP
* HAVE_MUNMAP
* HAVE_STRNDUP
* PCRE2_STATIC
* WITH_STRONG_ICC
* WITHOUT_ICC_PROFLIB
====

== Testing

you need perl with Test::More

* change to directory 't/'
* run 'perl -I ./ *.t'

Alternatively: run 'make test'

