Skip to content

Commit 8fc13a8

Browse files
committed
cmake: Enable the libpng framework build by default on Apple systems
The PNG_FRAMEWORK option used to be off by default. It was possible to turn it on, regardless of the underlying operating system, but doing so outside of an Apple OS broke the libpng build. PNG_FRAMEWORK is now on by default, conditionally defined on Apple systems only, and it is ignored (without breaking the build) elsewhere. Other minor changes have also been applied.
1 parent 1460b3c commit 8fc13a8

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

CMakeLists.txt

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,17 @@ set(PNG_DEBUG_POSTFIX "d"
6868
set(DFA_XTRA ""
6969
CACHE FILEPATH "File containing extra configuration settings")
7070

71-
# Allow the users to configure the following build options.
72-
option(PNG_SHARED "Build libpng as a shared lib" ON)
73-
option(PNG_STATIC "Build libpng as a static lib" ON)
74-
option(PNG_FRAMEWORK "Build libpng as a Mac OS X framework" OFF)
71+
# Allow the users to switch on/off various library build types.
72+
option(PNG_SHARED "Build libpng as a shared library" ON)
73+
option(PNG_STATIC "Build libpng as a static library" ON)
74+
if(APPLE)
75+
option(PNG_FRAMEWORK "Build libpng as a framework bundle" ON)
76+
endif()
77+
78+
# Allow the users to switch on/off the auxiliary build and test artifacts.
79+
# NOTE: These artifacts are NOT part of libpng proper, and are subject to change at any time.
7580
option(PNG_TESTS "Build the libpng tests" ON)
7681
option(PNG_TOOLS "Build the libpng tools" ON)
77-
option(PNG_DEBUG "Enable debug output" OFF)
78-
option(PNG_HARDWARE_OPTIMIZATIONS "Enable hardware optimizations" ON)
7982

8083
# Maintain backwards compatibility with the deprecated option PNG_EXECUTABLES.
8184
option(PNG_EXECUTABLES "[Deprecated; please use PNG_TOOLS]" ON)
@@ -88,6 +91,10 @@ if(NOT PNG_EXECUTABLES)
8891
endif()
8992
endif()
9093

94+
# Allow the users to configure various compilation options.
95+
option(PNG_DEBUG "Enable debug output" OFF)
96+
option(PNG_HARDWARE_OPTIMIZATIONS "Enable hardware optimizations" ON)
97+
9198
# Allow the users to specify a location of zlib.
9299
# Useful if zlib is being built alongside this as a sub-project.
93100
option(PNG_BUILD_ZLIB "Custom zlib location, else find_package is used" OFF)
@@ -659,7 +666,11 @@ if(PNG_SHARED)
659666
LINK_FLAGS "-Wl,-M -Wl,'${CMAKE_CURRENT_BINARY_DIR}/libpng.vers'")
660667
endif()
661668
endif()
662-
if(WIN32)
669+
if(APPLE)
670+
# Avoid CMake's implicit compile definition "png_shared_EXPORTS".
671+
set_target_properties(png_shared PROPERTIES DEFINE_SYMBOL "")
672+
elseif(WIN32)
673+
# Use the explicit compile definition "PNG_BUILD_DLL" for Windows DLLs.
663674
set_target_properties(png_shared PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
664675
endif()
665676
target_include_directories(png_shared
@@ -685,7 +696,7 @@ if(PNG_STATIC)
685696
target_link_libraries(png_static PUBLIC ZLIB::ZLIB ${M_LIBRARY})
686697
endif()
687698

688-
if(PNG_FRAMEWORK)
699+
if(PNG_FRAMEWORK AND APPLE)
689700
add_library(png_framework SHARED ${libpng_sources})
690701
add_dependencies(png_framework png_genfiles)
691702
list(APPEND PNG_LIBRARY_TARGETS png_framework)
@@ -697,7 +708,10 @@ if(PNG_FRAMEWORK)
697708
MACOSX_FRAMEWORK_IDENTIFIER "org.libpng.libpng"
698709
XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
699710
PUBLIC_HEADER "${libpng_public_hdrs}"
700-
OUTPUT_NAME "png")
711+
OUTPUT_NAME "png"
712+
DEBUG_POSTFIX "${PNG_DEBUG_POSTFIX}")
713+
# Avoid CMake's implicit compile definition "-Dpng_framework_EXPORTS".
714+
set_target_properties(png_framework PROPERTIES DEFINE_SYMBOL "")
701715
target_include_directories(png_framework
702716
PUBLIC
703717
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/libpng${PNGLIB_ABI_VERSION}>

0 commit comments

Comments
 (0)