libtiff: cmake: Use add_compile_definitions and add_compile_options

From ef984ef78663374e734baafe34f605ad796c0e9c Mon Sep 17 00:00:00 2001
From: Roger Leigh <[EMAIL REDACTED]>
Date: Sun, 29 May 2022 20:49:57 +0100
Subject: [PATCH] cmake: Use add_compile_definitions and add_compile_options

It seems that some CMake versions can't export targets using PRIVATE
linking, even though the private target is never used.
---
 CMakeLists.txt                  |  5 ++--
 contrib/addtiffo/CMakeLists.txt |  2 +-
 contrib/dbs/CMakeLists.txt      |  8 +++----
 contrib/iptcutil/CMakeLists.txt |  2 +-
 libtiff/CMakeLists.txt          |  4 +---
 test/CMakeLists.txt             | 28 +++++++++++-----------
 tools/CMakeLists.txt            | 42 ++++++++++++++++-----------------
 7 files changed, 44 insertions(+), 47 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3717a0df..80c69bd5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -131,10 +131,9 @@ find_package(CMath REQUIRED)
 # Release support
 include(Release)
 
-add_library(tiff-options INTERFACE)
 if(MSVC)
-    target_compile_definitions(tiff-options INTERFACE -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS)
-    target_compile_options(tiff-options INTERFACE /wd4996)
+    add_compile_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS)
+    add_compile_options(/wd4996)
 endif()
 
 # Process subdirectories
diff --git a/contrib/addtiffo/CMakeLists.txt b/contrib/addtiffo/CMakeLists.txt
index 84ab2a26..2f3959bc 100644
--- a/contrib/addtiffo/CMakeLists.txt
+++ b/contrib/addtiffo/CMakeLists.txt
@@ -23,7 +23,7 @@
 # OF THIS SOFTWARE.
 
 add_executable(addtiffo addtiffo.c tif_overview.c tif_ovrcache.c tif_ovrcache.h)
-target_link_libraries(addtiffo tiff tiff-options port)
+target_link_libraries(addtiffo tiff port)
 
 if(WEBP_SUPPORT AND EMSCRIPTEN)
   # Emscripten is pretty finnicky about linker flags.
diff --git a/contrib/dbs/CMakeLists.txt b/contrib/dbs/CMakeLists.txt
index 6264d2a1..b5681777 100644
--- a/contrib/dbs/CMakeLists.txt
+++ b/contrib/dbs/CMakeLists.txt
@@ -23,16 +23,16 @@
 # OF THIS SOFTWARE.
 
 add_executable(tiff-bi tiff-bi.c)
-target_link_libraries(tiff-bi tiff tiff-options port)
+target_link_libraries(tiff-bi tiff port)
 
 add_executable(tiff-grayscale tiff-grayscale.c)
-target_link_libraries(tiff-grayscale tiff tiff-options port CMath::CMath)
+target_link_libraries(tiff-grayscale tiff port CMath::CMath)
 
 add_executable(tiff-palette tiff-palette.c)
-target_link_libraries(tiff-palette tiff tiff-options port)
+target_link_libraries(tiff-palette tiff port)
 
 add_executable(tiff-rgb tiff-rgb.c)
-target_link_libraries(tiff-rgb tiff tiff-options port CMath::CMath)
+target_link_libraries(tiff-rgb tiff port CMath::CMath)
 
 if(WEBP_SUPPORT AND EMSCRIPTEN)
   # Emscripten is pretty finnicky about linker flags.
diff --git a/contrib/iptcutil/CMakeLists.txt b/contrib/iptcutil/CMakeLists.txt
index da56779d..39d908c6 100644
--- a/contrib/iptcutil/CMakeLists.txt
+++ b/contrib/iptcutil/CMakeLists.txt
@@ -23,4 +23,4 @@
 # OF THIS SOFTWARE.
 
 add_executable(iptcutil iptcutil.c)
-target_link_libraries(iptcutil tiff tiff-options port)
+target_link_libraries(iptcutil tiff port)
diff --git a/libtiff/CMakeLists.txt b/libtiff/CMakeLists.txt
index cf423241..b6b31677 100755
--- a/libtiff/CMakeLists.txt
+++ b/libtiff/CMakeLists.txt
@@ -109,8 +109,6 @@ target_include_directories(tiff
 set(tiff_libs_private_list "") # cmake list
 set(tiff_requires_private "") # cmake string
 
-target_link_libraries(tiff PRIVATE tiff-options)
-
 if(ZIP_SUPPORT)
   target_link_libraries(tiff PRIVATE ZLIB::ZLIB)
   string(APPEND tiff_requires_private " zlib")
@@ -195,7 +193,7 @@ if(CXX_SUPPORT)
   target_sources(tiffxx PRIVATE
           ${tiffxx_HEADERS}
           tif_stream.cxx)
-  target_link_libraries(tiffxx PUBLIC tiff PRIVATE tiff-options)
+  target_link_libraries(tiffxx tiff)
   set_target_properties(tiffxx PROPERTIES SOVERSION ${SO_COMPATVERSION})
   if(NOT CYGWIN)
     # This property causes shared libraries on Linux to have the full version
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 80f0b982..66de9376 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -102,77 +102,77 @@ set(simple_tests)
 
 add_executable(test_signed_tags ../placeholder.h)
 target_sources(test_signed_tags PRIVATE test_signed_tags.c)
-target_link_libraries(test_signed_tags PRIVATE tiff tiff-options port)
+target_link_libraries(test_signed_tags PRIVATE tiff port)
 list(APPEND simple_tests test_signed_tags)
 
 add_executable(ascii_tag ../placeholder.h)
 target_sources(ascii_tag PRIVATE ascii_tag.c)
-target_link_libraries(ascii_tag PRIVATE tiff tiff-options port)
+target_link_libraries(ascii_tag PRIVATE tiff port)
 list(APPEND simple_tests ascii_tag)
 
 add_executable(long_tag ../placeholder.h)
 target_sources(long_tag PRIVATE long_tag.c check_tag.c)
-target_link_libraries(long_tag PRIVATE tiff tiff-options port)
+target_link_libraries(long_tag PRIVATE tiff port)
 list(APPEND simple_tests long_tag)
 
 add_executable(short_tag ../placeholder.h)
 target_sources(short_tag PRIVATE short_tag.c check_tag.c)
-target_link_libraries(short_tag PRIVATE tiff tiff-options port)
+target_link_libraries(short_tag PRIVATE tiff port)
 list(APPEND simple_tests short_tag)
 
 add_executable(strip_rw ../placeholder.h)
 target_sources(strip_rw PRIVATE strip_rw.c strip.c test_arrays.c test_arrays.h)
-target_link_libraries(strip_rw PRIVATE tiff tiff-options port)
+target_link_libraries(strip_rw PRIVATE tiff port)
 list(APPEND simple_tests strip_rw)
 
 add_executable(rewrite ../placeholder.h)
 target_sources(rewrite PRIVATE rewrite_tag.c)
-target_link_libraries(rewrite PRIVATE tiff tiff-options port)
+target_link_libraries(rewrite PRIVATE tiff port)
 list(APPEND simple_tests rewrite)
 
 if(JPEG_SUPPORT)
   add_executable(raw_decode ../placeholder.h)
   target_sources(raw_decode PRIVATE raw_decode.c)
-  target_link_libraries(raw_decode PRIVATE tiff tiff-options port JPEG::JPEG)
+  target_link_libraries(raw_decode PRIVATE tiff port JPEG::JPEG)
   list(APPEND simple_tests raw_decode)
 endif()
 
 add_executable(custom_dir ../placeholder.h)
 target_sources(custom_dir PRIVATE custom_dir.c)
-target_link_libraries(custom_dir PRIVATE tiff tiff-options port)
+target_link_libraries(custom_dir PRIVATE tiff port)
 list(APPEND simple_tests custom_dir)
 
 # Uses private functions from static library
 if(NOT BUILD_SHARED_LIBS)
   add_executable(rational_precision2double ../placeholder.h)
   target_sources(rational_precision2double PRIVATE rational_precision2double.c)
-  target_link_libraries(rational_precision2double PRIVATE tiff tiff-options port)
+  target_link_libraries(rational_precision2double PRIVATE tiff port)
   list(APPEND simple_tests rational_precision2double)
 endif()
 
 add_executable(custom_dir_EXIF_231 ../placeholder.h)
 target_sources(custom_dir_EXIF_231 PRIVATE custom_dir_EXIF_231.c)
-target_link_libraries(custom_dir_EXIF_231 PRIVATE tiff tiff-options port)
+target_link_libraries(custom_dir_EXIF_231 PRIVATE tiff port)
 list(APPEND simple_tests custom_dir_EXIF_231)
 
 add_executable(defer_strile_loading ../placeholder.h)
 target_sources(defer_strile_loading PRIVATE defer_strile_loading.c)
-target_link_libraries(defer_strile_loading PRIVATE tiff tiff-options port)
+target_link_libraries(defer_strile_loading PRIVATE tiff port)
 list(APPEND simple_tests defer_strile_loading)
 
 add_executable(defer_strile_writing ../placeholder.h)
 target_sources(defer_strile_writing PRIVATE defer_strile_writing.c)
-target_link_libraries(defer_strile_writing PRIVATE tiff tiff-options port)
+target_link_libraries(defer_strile_writing PRIVATE tiff port)
 list(APPEND simple_tests defer_strile_writing)
 
 add_executable(test_directory ../placeholder.h)
 target_sources(test_directory PRIVATE test_directory.c)
-target_link_libraries(test_directory PRIVATE tiff tiff-options port)
+target_link_libraries(test_directory PRIVATE tiff port)
 list(APPEND simple_tests test_directory)
 
 add_executable(testtypes ../placeholder.h)
 target_sources(testtypes PRIVATE testtypes.c)
-target_link_libraries(testtypes PRIVATE tiff tiff-options port)
+target_link_libraries(testtypes PRIVATE tiff port)
 list(APPEND simple_tests testtypes)
 
 if(WEBP_SUPPORT AND EMSCRIPTEN)
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index 2e63c325..ac64bd84 100755
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -24,83 +24,83 @@
 
 add_executable(fax2ps ../placeholder.h)
 target_sources(fax2ps PRIVATE fax2ps.c)
-target_link_libraries(fax2ps PRIVATE tiff tiff-options port)
+target_link_libraries(fax2ps PRIVATE tiff port)
 
 add_executable(fax2tiff ../placeholder.h)
 target_sources(fax2tiff PRIVATE fax2tiff.c)
-target_link_libraries(fax2tiff PRIVATE tiff tiff-options port)
+target_link_libraries(fax2tiff PRIVATE tiff port)
 
 add_executable(pal2rgb ../placeholder.h)
 target_sources(pal2rgb PRIVATE pal2rgb.c)
-target_link_libraries(pal2rgb PRIVATE tiff tiff-options port)
+target_link_libraries(pal2rgb PRIVATE tiff port)
 
 add_executable(ppm2tiff ../placeholder.h)
 target_sources(ppm2tiff PRIVATE ppm2tiff.c)
-target_link_libraries(ppm2tiff PRIVATE tiff tiff-options port)
+target_link_libraries(ppm2tiff PRIVATE tiff port)
 
 add_executable(raw2tiff ../placeholder.h)
 target_sources(raw2tiff PRIVATE raw2tiff.c)
-target_link_libraries(raw2tiff PRIVATE tiff tiff-options port CMath::CMath)
+target_link_libraries(raw2tiff PRIVATE tiff port CMath::CMath)
 
 add_executable(rgb2ycbcr ../placeholder.h)
 target_sources(rgb2ycbcr PRIVATE rgb2ycbcr.c)
-target_link_libraries(rgb2ycbcr PRIVATE tiff tiff-options port)
+target_link_libraries(rgb2ycbcr PRIVATE tiff port)
 
 add_executable(thumbnail ../placeholder.h)
 target_sources(thumbnail PRIVATE thumbnail.c)
-target_link_libraries(thumbnail PRIVATE tiff tiff-options port CMath::CMath)
+target_link_libraries(thumbnail PRIVATE tiff port CMath::CMath)
 
 add_executable(tiff2bw ../placeholder.h)
 target_sources(tiff2bw PRIVATE tiff2bw.c)
-target_link_libraries(tiff2bw PRIVATE tiff tiff-options port)
+target_link_libraries(tiff2bw PRIVATE tiff port)
 
 add_executable(tiff2pdf ../placeholder.h)
 target_sources(tiff2pdf PRIVATE tiff2pdf.c)
-target_link_libraries(tiff2pdf PRIVATE tiff tiff-options port)
+target_link_libraries(tiff2pdf PRIVATE tiff port)
 
 add_executable(tiff2ps ../placeholder.h)
 target_sources(tiff2ps PRIVATE tiff2ps.c)
-target_link_libraries(tiff2ps PRIVATE tiff tiff-options port CMath::CMath)
+target_link_libraries(tiff2ps PRIVATE tiff port CMath::CMath)
 
 add_executable(tiff2rgba ../placeholder.h)
 target_sources(tiff2rgba PRIVATE tiff2rgba.c)
-target_link_libraries(tiff2rgba PRIVATE tiff tiff-options port)
+target_link_libraries(tiff2rgba PRIVATE tiff port)
 
 add_executable(tiffcmp ../placeholder.h)
 target_sources(tiffcmp PRIVATE tiffcmp.c)
-target_link_libraries(tiffcmp PRIVATE tiff tiff-options port)
+target_link_libraries(tiffcmp PRIVATE tiff port)
 
 add_executable(tiffcp ../placeholder.h)
 target_sources(tiffcp PRIVATE tiffcp.c)
-target_link_libraries(tiffcp PRIVATE tiff tiff-options port)
+target_link_libraries(tiffcp PRIVATE tiff port)
 
 add_executable(tiffcrop ../placeholder.h)
 target_sources(tiffcrop PRIVATE tiffcrop.c)
-target_link_libraries(tiffcrop PRIVATE tiff tiff-options port CMath::CMath)
+target_link_libraries(tiffcrop PRIVATE tiff port CMath::CMath)
 
 add_executable(tiffdither ../placeholder.h)
 target_sources(tiffdither PRIVATE tiffdither.c)
-target_link_libraries(tiffdither PRIVATE tiff tiff-options port)
+target_link_libraries(tiffdither PRIVATE tiff port)
 
 add_executable(tiffdump ../placeholder.h)
 target_sources(tiffdump PRIVATE tiffdump.c)
-target_link_libraries(tiffdump PRIVATE tiff tiff-options port)
+target_link_libraries(tiffdump PRIVATE tiff port)
 
 add_executable(tiffinfo ../placeholder.h)
 target_sources(tiffinfo PRIVATE tiffinfo.c)
-target_link_libraries(tiffinfo PRIVATE tiff tiff-options port)
+target_link_libraries(tiffinfo PRIVATE tiff port)
 
 add_executable(tiffmedian ../placeholder.h)
 target_sources(tiffmedian PRIVATE tiffmedian.c)
-target_link_libraries(tiffmedian PRIVATE tiff tiff-options port)
+target_link_libraries(tiffmedian PRIVATE tiff port)
 
 add_executable(tiffset ../placeholder.h)
 target_sources(tiffset PRIVATE tiffset.c)
-target_link_libraries(tiffset PRIVATE tiff tiff-options port)
+target_link_libraries(tiffset PRIVATE tiff port)
 
 add_executable(tiffsplit ../placeholder.h)
 target_sources(tiffsplit PRIVATE tiffsplit.c)
-target_link_libraries(tiffsplit PRIVATE tiff tiff-options port)
+target_link_libraries(tiffsplit PRIVATE tiff port)
 
 # rgb2ycbcr and thumbnail are intended to *NOT* be installed. They are for
 # testing purposes only.
@@ -127,7 +127,7 @@ install(TARGETS fax2ps
 if(HAVE_OPENGL)
   add_executable(tiffgt ../placeholder.h)
   target_sources(tiffgt PRIVATE tiffgt.c)
-  target_link_libraries(tiffgt PRIVATE tiff tiff-options port)
+  target_link_libraries(tiffgt PRIVATE tiff port)
   target_link_libraries(tiffgt PRIVATE OpenGL::GL GLUT::GLUT)
 
   install(TARGETS tiffgt