1 # Copyright (c) 2010 Vladimir Prus.
2 # Copyright (c) 2013 Steven Watanabe
4 # Use, modification and distribution is subject to the Boost Software
5 # License Version 1.0. (See accompanying file LICENSE_1_0.txt or
6 # http://www.boost.org/LICENSE_1_0.txt)
8 # Supports the libpng library
10 # After 'using libpng', the following targets are available:
12 # /libpng//libpng -- The libpng library
18 import "class" : new ;
28 # On Windows, binary distributions of libpng and package managers
29 # name the library differently (e.g. vcpkg installs libpng16.lib).
30 # Listing popular names increases chances of successful look-up.
31 names = libpng libpng16 png png16 ;
33 sources = png.c pngerror.c pngget.c pngmem.c pngpread.c pngread.c pngrio.c pngrtran.c pngrutil.c
34 pngset.c pngtrans.c pngwio.c pngwrite.c pngwtran.c pngwutil.c ;
38 if --debug-configuration in [ modules.peek : ARGV ]
43 # Initializes the libpng library.
45 # libpng can be configured either to use pre-existing binaries
46 # or to build the library from source.
48 # Options for configuring a prebuilt libpng::
51 # The directory containing the libpng binaries.
53 # Overrides the default library name.
55 # The directory containing the libpng headers.
57 # If none of these options is specified, then the environmental
58 # variables LIBPNG_LIBRARY_PATH, LIBPNG_NAME, and LIBPNG_INCLUDE will
61 # Options for building libpng from source::
64 # The libpng source directory. Defaults to the environmental variable
67 # A rule which computes the actual name of the compiled
68 # libraries based on the build properties. Ignored
69 # when using precompiled binaries.
71 # The base name to use for the compiled library. Ignored
72 # when using precompiled binaries.
76 # # Find libpng in the default system location
78 # # Build libpng from source
79 # using libpng : 1.5.4 : <source>/home/steven/libpng-1.5.4 ;
80 # # Find libpng in /usr/local
81 # using libpng : 1.5.4
82 # : <include>/usr/local/include <search>/usr/local/lib ;
83 # # Build libpng from source for msvc and find
84 # # prebuilt binaries for gcc.
85 # using libpng : 1.5.4 : <source>C:/Devel/src/libpng-1.5.4 : <toolset>msvc ;
86 # using libpng : 1.5.4 : : <toolset>gcc ;
90 # The libpng version (currently ignored)
93 # A list of the options to use
96 # The requirements for the libpng target
99 # Default configurations are only used when libpng
100 # has not yet been configured. This option is
101 # deprecated. A configuration will be treated
102 # as a default when none of <include>, <search>,
103 # <name>, and <source> are present.
106 local caller = [ project.current ] ;
110 .initialized = true ;
112 project.initialize $(__name__) ;
113 .project = [ project.current ] ;
117 local library-path = [ feature.get-values <search> : $(options) ] ;
118 local include-path = [ feature.get-values <include> : $(options) ] ;
119 local source-path = [ feature.get-values <source> : $(options) ] ;
120 local library-name = [ feature.get-values <name> : $(options) ] ;
121 local tag = [ feature.get-values <tag> : $(options) ] ;
122 local build-name = [ feature.get-values <build-name> : $(options) ] ;
124 if ! $(library-path) && ! $(include-path) && ! $(source-path) && ! $(library-name)
129 condition = [ property-set.create $(requirements) ] ;
130 condition = [ property-set.create [ $(condition).base ] ] ;
132 # Ignore environmental LIBPNG_SOURCE if this initialization
133 # requested to search for a specific pre-built library.
134 if $(library-path) || $(include-path) || $(library-name)
136 if $(source-path) || $(tag) || $(build-name)
138 errors.user-error "incompatible options for libpng:"
139 [ property.select <search> <include> <name> : $(options) ] "and"
140 [ property.select <source> <tag> <build-name> : $(options) ] ;
145 source-path ?= [ modules.peek : LIBPNG_SOURCE ] ;
148 if $(.configured.$(condition))
154 ECHO "notice: [libpng] libpng is already configured" ;
159 errors.user-error "libpng is already configured" ;
163 else if $(source-path)
166 library-id = [ CALC $(library-id) + 1 ] ;
167 tag = [ MATCH ^@?(.*)$ : $(tag) ] ;
170 tag = [ indirect.make $(tag) : [ $(caller).project-module ] ] ;
172 sources = [ path.glob $(source-path) : $(sources) ] ;
175 ECHO "notice: [libpng] Building libpng from source as $(build-name)" ;
178 ECHO "notice: [libpng] Condition" [ $(condition).raw ] ;
182 ECHO "notice: [libpng] found libpng source in $(source-path)" ;
186 ECHO "warning: [libpng] could not find libpng source in $(source-path)" ;
191 target = [ targets.create-typed-target LIB : $(.project)
192 : $(build-name).$(library-id)
196 <include>$(source-path)
197 <toolset>msvc:<define>_CRT_SECURE_NO_DEPRECATE
198 <toolset>msvc:<define>_SCL_SECURE_NO_DEPRECATE
199 <link>shared:<define>LIBPNG_DLL
201 : <include>$(source-path) ] ;
204 local mt = [ new ac-library libpng : $(.project) : $(condition) ] ;
205 $(mt).set-header $(header) ;
206 $(mt).set-default-names $(names) ;
209 $(mt).set-target $(target) ;
211 targets.main-target-alternative $(mt) ;
215 ECHO "notice: [libpng] Using pre-installed library" ;
218 ECHO "notice: [libpng] Condition" [ $(condition).raw ] ;
222 local mt = [ new ac-library libpng : $(.project) : $(condition) :
223 $(include-path) : $(library-path) : $(library-name) : $(root) ] ;
224 $(mt).set-header $(header) ;
225 $(mt).set-default-names $(names) ;
226 targets.main-target-alternative $(mt) ;
228 .configured.$(condition) = true ;