libtiff: cmake: allow running the tests with a read-only source directory

From edc9177227aea393c8134191a7b25bd55aa753a1 Mon Sep 17 00:00:00 2001
From: Alex Richardson <[EMAIL REDACTED]>
Date: Sun, 15 May 2022 00:16:19 +0000
Subject: [PATCH] cmake: allow running the tests with a read-only source

Prior to this commit CTest would invoke all simple_tests tests with the
current working directory set to the source directory. However, some of
the tests (e.g. rewrite) will output files to the current working
directory and will therefore fail when run with a read-only source
directory. This can happen e.g. when testing a cross-compiled version of
libtiff where the sources are mounted read-only in the virtual machine.

Simply changing the working directory to CMAKE_CURRENT_BINARY_DIR allows
all but raw_decode to pass. The raw_decode test looks for files in the
source directory, and uses the `srcdir` environment variable to find, so
we also have to add a set_tests_properties() call to specify that env var.
 test/CMakeLists.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 47e21d40..66de9376 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -242,7 +242,9 @@ function(tiff_test_stdout_noargs name command)
           -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffTest.cmake"
+  set_tests_properties("${name}" PROPERTIES ENVIRONMENT
+          "srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
 function(tiff_test_reader name command infile)