pngminus: Update CMake file; rename test scripts; add .gitignore
Raise the minimum required CMake version to 3.5.
Add the configuration option `PNGMINUS_USE_SYSTEM_PNG` for compiling
and linking with the system libpng library instead of the internal one.
Remove the old configuration option `PNGMINUS_USE_STATIC_LIBRARIES`.
When using the internal libpng (via `PNGMINUS_USE_SYSTEM_PNG=OFF`),
simply enforce static linking and produce single-file executables.
Rename the scripts "png2pnm.sh" (etc.) to "test_png2pnm.sh" (etc.),
to make it obvious that they are test drivers, not program launchers.
Add a .gitignore file for project-specific build and test artifacts.
diff --git a/contrib/pngminus/.gitignore b/contrib/pngminus/.gitignore
new file mode 100644
index 0000000..5114c75
--- /dev/null
+++ b/contrib/pngminus/.gitignore
@@ -0,0 +1,11 @@
+# Compiled executables
+png2pnm
+png2pnm.exe
+png2pnm-static*
+pnm2png
+pnm2png.exe
+pnm2png-static*
+
+# Test artifacts
+*.png
+*.p[abgnp]m
diff --git a/contrib/pngminus/CMakeLists.txt b/contrib/pngminus/CMakeLists.txt
index 1f815a5..d789364 100644
--- a/contrib/pngminus/CMakeLists.txt
+++ b/contrib/pngminus/CMakeLists.txt
@@ -1,24 +1,41 @@
-cmake_minimum_required(VERSION 3.1)
-cmake_policy(VERSION 3.1)
+# Copyright (c) 2018-2024 Cosmin Truta
+#
+# This software is released under the MIT license. For conditions of
+# distribution and use, see the LICENSE file part of this package.
+
+cmake_minimum_required(VERSION 3.5)
project(PNGMINUS C)
-option(PNGMINUS_USE_STATIC_LIBRARIES "Use the static library builds" ON)
+option(PNGMINUS_USE_SYSTEM_PNG
+ "Use the libpng build found in the system" OFF)
-# libpng
-add_subdirectory(../.. libpng)
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../..)
-include_directories(${CMAKE_CURRENT_BINARY_DIR}/libpng)
-if(PNGMINUS_USE_STATIC_LIBRARIES)
- set(PNGMINUS_PNG_LIBRARY png_static)
-else()
- set(PNGMINUS_PNG_LIBRARY png)
-endif()
-
-# png2pnm
add_executable(png2pnm png2pnm.c)
-target_link_libraries(png2pnm ${PNGMINUS_PNG_LIBRARY})
-
-# pnm2png
add_executable(pnm2png pnm2png.c)
-target_link_libraries(pnm2png ${PNGMINUS_PNG_LIBRARY})
+
+if(PNGMINUS_USE_SYSTEM_PNG)
+ # Use the system libpng.
+ find_package(PNG REQUIRED)
+ target_link_libraries(png2pnm PRIVATE PNG::PNG)
+ target_link_libraries(pnm2png PRIVATE PNG::PNG)
+else()
+ # Build and use the internal libpng.
+ # Configure libpng for static linking, to produce single-file executables.
+ set(PNG_STATIC ON
+ CACHE STRING "Build the internal libpng as a static library" FORCE)
+ set(PNG_SHARED OFF
+ CACHE STRING "Build the internal libpng as a shared library" FORCE)
+ set(PNG_FRAMEWORK OFF
+ CACHE STRING "Build the internal libpng as a framework bundle" FORCE)
+ add_subdirectory(../.. libpng)
+ target_include_directories(png2pnm PRIVATE
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../..>"
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/libpng>"
+ )
+ target_include_directories(pnm2png PRIVATE
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../..>"
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/libpng>"
+ )
+ target_link_libraries(png2pnm PRIVATE png_static)
+ target_link_libraries(pnm2png PRIVATE png_static)
+endif()
diff --git a/contrib/pngminus/png2pnm.bat b/contrib/pngminus/test_png2pnm.bat
similarity index 100%
rename from contrib/pngminus/png2pnm.bat
rename to contrib/pngminus/test_png2pnm.bat
diff --git a/contrib/pngminus/png2pnm.sh b/contrib/pngminus/test_png2pnm.sh
similarity index 100%
rename from contrib/pngminus/png2pnm.sh
rename to contrib/pngminus/test_png2pnm.sh
diff --git a/contrib/pngminus/pngminus.bat b/contrib/pngminus/test_pngminus.bat
similarity index 100%
rename from contrib/pngminus/pngminus.bat
rename to contrib/pngminus/test_pngminus.bat
diff --git a/contrib/pngminus/pngminus.sh b/contrib/pngminus/test_pngminus.sh
similarity index 100%
rename from contrib/pngminus/pngminus.sh
rename to contrib/pngminus/test_pngminus.sh
diff --git a/contrib/pngminus/pnm2png.bat b/contrib/pngminus/test_pnm2png.bat
similarity index 100%
rename from contrib/pngminus/pnm2png.bat
rename to contrib/pngminus/test_pnm2png.bat
diff --git a/contrib/pngminus/pnm2png.sh b/contrib/pngminus/test_pnm2png.sh
similarity index 100%
rename from contrib/pngminus/pnm2png.sh
rename to contrib/pngminus/test_pnm2png.sh