summaryrefslogtreecommitdiff
path: root/png
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2024-02-07 18:30:11 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2024-02-07 18:37:34 +0100
commitfd5cd809356dc73d2ede5bb2f0db25098771cb8e (patch)
tree70c82946eb7d11eba910bb387dc3bcc20abfd42c /png
parent1cf6fdfa8562fafa0566e1008f74ea94f71356e4 (diff)
Introduce "Modern CMake" in FLTK
This is a big commit and there are too many changes to list them all. The main changes are: - rename all CMake build options to 'FLTK_*' - export library targets with namespace (prefix) 'fltk::' - standardize shared library target names with suffix '-shared' - set public build properties on libraries for consumers - document library names and aliases in README.CMake.txt - document changes in "Migrating Code from FLTK 1.3 to 1.4" - partial backwards compatibility for old user projects Included but not directly related changes: - fix Windows (Visual Studio) DLL build - add CMake function fl_debug_target() to show target properties - don't build test programs if FLTK is a subproject - internal: reformat CMake code: remove space before '(' Thanks to Matthias and Manolo for their help, testing, and feeback.
Diffstat (limited to 'png')
-rw-r--r--png/CMakeLists.txt100
1 files changed, 69 insertions, 31 deletions
diff --git a/png/CMakeLists.txt b/png/CMakeLists.txt
index c61b1a544..e873e9be0 100644
--- a/png/CMakeLists.txt
+++ b/png/CMakeLists.txt
@@ -1,7 +1,7 @@
#
# PNG library CMake configuration for the Fast Light Toolkit (FLTK).
#
-# Copyright 1998-2023 by Bill Spitzak and others.
+# Copyright 1998-2024 by Bill Spitzak and others.
#
# This library is free software. Distribution and use rights are outlined in
# the file "COPYING" which should have been included with this file. If this
@@ -15,7 +15,7 @@
#
# source files for png
-set (PNG_SRCS
+set(PNG_SRCS
png.c
pngerror.c
pngget.c
@@ -36,8 +36,8 @@ set (PNG_SRCS
#######################################################################
# Note: This file is used only if we build the bundled PNG library,
# and if we do this we MUST also build and use the *bundled* ZLIB,
-# hence we MUST also link against the bundled ZLIB (see below).
-# There's no need to check which ZLIB version to use in this context.
+# hence we also link against the bundled ZLIB. Therefore there's
+# no need to check which ZLIB version to use in this context.
#######################################################################
#######################################################################
@@ -49,55 +49,93 @@ set (PNG_SRCS
# compile these files even if this results in some warnings.
# This includes all non-macOS platforms.
-if (CMAKE_OSX_ARCHITECTURES)
- string (REGEX MATCH "arm64" is_arm "${CMAKE_OSX_ARCHITECTURES}")
-else ()
- set (is_arm TRUE)
-endif ()
-
-if (is_arm)
- LIST (APPEND PNG_SRCS
- arm/arm_init.c
- arm/filter_neon_intrinsics.c
- arm/palette_neon_intrinsics.c
+if(CMAKE_OSX_ARCHITECTURES)
+ string(REGEX MATCH "arm64" is_arm "${CMAKE_OSX_ARCHITECTURES}")
+else()
+ set(is_arm TRUE)
+endif()
+
+if(is_arm)
+ list(APPEND PNG_SRCS
+ arm/arm_init.c
+ arm/filter_neon_intrinsics.c
+ arm/palette_neon_intrinsics.c
)
-endif ()
+endif()
-unset (is_arm)
+unset(is_arm)
#######################################################################
-# Build some files on ppc64
-# We compile these files whatever the architecture resulting in void code
-# on non-ppc64 architectures.
+# Build some files on ppc64.
+# We compile these files whatever the architecture resulting in
+# void code on non-ppc64 architectures.
#######################################################################
-LIST (APPEND PNG_SRCS
- powerpc/powerpc_init.c
- powerpc/filter_vsx_intrinsics.c
+list(APPEND PNG_SRCS
+ powerpc/powerpc_init.c
+ powerpc/filter_vsx_intrinsics.c
+)
+
+#######################################################################
+# Set common variables for static and shared builds
+#######################################################################
+
+set(compile_defs
+ HAVE_PNG_H=1
+ HAVE_PNG_GET_VALID=1
+ HAVE_PNG_SET_TRNS_TO_ALPHA=1
+)
+
+set(include_dirs
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+ $<INSTALL_INTERFACE:include>
)
#######################################################################
# Build the static library
#######################################################################
-FL_ADD_LIBRARY (fltk_png STATIC "${PNG_SRCS}")
-target_link_libraries (fltk_png PUBLIC fltk_z)
+fl_add_library(fltk_png STATIC "${PNG_SRCS}")
+set(target fltk_png)
+
+target_link_libraries (${target} PUBLIC fltk::z)
+target_compile_definitions(${target} PUBLIC ${compile_defs})
+target_include_directories(${target} PUBLIC ${include_dirs})
+
+list(APPEND FLTK_IMAGE_LIBRARIES fltk::png)
+
+# Propagate to parent scope (modified by fl_add_library and here)
+set(FLTK_LIBRARIES ${FLTK_LIBRARIES} PARENT_SCOPE)
+set(FLTK_IMAGE_LIBRARIES ${FLTK_IMAGE_LIBRARIES} PARENT_SCOPE)
#######################################################################
# Build the shared library (optional)
#######################################################################
-if (OPTION_BUILD_SHARED_LIBS)
+if(FLTK_BUILD_SHARED_LIBS)
+
+ # ensure to export all symbols for Windows DLL's
+ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
+
+ fl_add_library(fltk_png SHARED "${PNG_SRCS}")
+ set(target fltk_png-shared)
+
+ target_link_libraries (${target} PUBLIC fltk::z-shared)
+ target_compile_definitions(${target} PUBLIC ${compile_defs})
+ target_include_directories(${target} PUBLIC ${include_dirs})
+
+ list(APPEND FLTK_IMAGE_LIBRARIES_SHARED fltk::png-shared)
- FL_ADD_LIBRARY (fltk_png SHARED "${PNG_SRCS}")
- target_link_libraries (fltk_png_SHARED PUBLIC fltk_z_SHARED)
+ # Propagate to parent scope (modified by fl_add_library and here)
+ set(FLTK_LIBRARIES_SHARED ${FLTK_LIBRARIES_SHARED} PARENT_SCOPE)
+ set(FLTK_IMAGE_LIBRARIES_SHARED ${FLTK_IMAGE_LIBRARIES_SHARED} PARENT_SCOPE)
-endif ()
+endif()
#######################################################################
# Install the library headers
#######################################################################
-install (FILES png.h pngconf.h pnglibconf.h pngprefix.h
- DESTINATION ${FLTK_INCLUDEDIR}/FL/images
+install(FILES png.h pngconf.h pnglibconf.h pngprefix.h
+ DESTINATION ${FLTK_INCLUDEDIR}/FL/images
)