From fd5cd809356dc73d2ede5bb2f0db25098771cb8e Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Wed, 7 Feb 2024 18:30:11 +0100 Subject: 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. --- png/CMakeLists.txt | 100 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 31 deletions(-) (limited to 'png') 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 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 ) -- cgit v1.2.3