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
17 import "class" : new ;
29 sources = png.c pngerror.c pngget.c pngmem.c pngpread.c pngread.c pngrio.c pngrtran.c pngrutil.c
30 pngset.c pngtrans.c pngwio.c pngwrite.c pngwtran.c pngwutil.c ;
34 if --debug-configuration in [ modules.peek : ARGV ]
39 # Initializes the libpng library.
41 # libpng can be configured either to use pre-existing binaries
42 # or to build the library from source.
44 # Options for configuring a prebuilt libpng::
47 # The directory containing the libpng binaries.
49 # Overrides the default library name.
51 # The directory containing the libpng headers.
53 # If none of these options is specified, then the environmental
54 # variables LIBPNG_LIBRARY_PATH, LIBPNG_NAME, and LIBPNG_INCLUDE will
57 # Options for building libpng from source::
60 # The libpng source directory. Defaults to the environmental variable
63 # A rule which computes the actual name of the compiled
64 # libraries based on the build properties. Ignored
65 # when using precompiled binaries.
67 # The base name to use for the compiled library. Ignored
68 # when using precompiled binaries.
72 # # Find libpng in the default system location
74 # # Build libpng from source
75 # using libpng : 1.5.4 : <source>/home/steven/libpng-1.5.4 ;
76 # # Find libpng in /usr/local
77 # using libpng : 1.5.4
78 # : <include>/usr/local/include <search>/usr/local/lib ;
79 # # Build libpng from source for msvc and find
80 # # prebuilt binaries for gcc.
81 # using libpng : 1.5.4 : <source>C:/Devel/src/libpng-1.5.4 : <toolset>msvc ;
82 # using libpng : 1.5.4 : : <toolset>gcc ;
86 # The libpng version (currently ignored)
89 # A list of the options to use
92 # The requirements for the libpng target
95 # Default configurations are only used when libpng
96 # has not yet been configured.
99 local caller = [ project.current ] ;
103 .initialized = true ;
105 project.initialize $(__name__) ;
106 .project = [ project.current ] ;
110 local library-path = [ property.select <search> : $(options) ] ;
111 library-path = $(library-path:G=) ;
112 local include-path = [ property.select <include> : $(options) ] ;
113 include-path = $(include-path:G=) ;
114 local source-path = [ property.select <source> : $(options) ] ;
115 source-path = $(source-path:G=) ;
116 local library-name = [ property.select <name> : $(options) ] ;
117 library-name = $(library-name:G=) ;
118 local tag = [ property.select <tag> : $(options) ] ;
120 local build-name = [ property.select <build-name> : $(options) ] ;
121 build-name = $(build-name:G=) ;
123 condition = [ property-set.create $(requirements) ] ;
124 condition = [ property-set.create [ $(condition).base ] ] ;
126 local no-build-from-source ;
127 # Ignore environmental LIBPNG_SOURCE if this initialization
128 # requested to search for a specific pre-built library.
129 if $(library-path) || $(include-path) || $(library-name)
131 if $(source-path) || $(tag) || $(build-name)
133 errors.user-error "incompatible options for libpng:"
134 [ property.select <search> <include> <name> : $(options) ] "and"
135 [ property.select <source> <tag> <build-name> : $(options) ] ;
139 no-build-from-source = true ;
143 source-path ?= [ modules.peek : LIBPNG_SOURCE ] ;
145 if $(.configured.$(condition))
151 ECHO "notice: [libpng] libpng is already configured" ;
156 errors.user-error "libpng is already configured" ;
160 else if $(source-path) && ! $(no-build-from-source)
163 library-id = [ CALC $(library-id) + 1 ] ;
164 tag = [ MATCH ^@?(.*)$ : $(tag) ] ;
165 if $(tag) && ! [ MATCH ^([^%]*)%([^%]+)$ : $(tag) ]
167 tag = [ indirect.make $(tag) : [ $(caller).project-module ] ] ;
169 sources = [ path.glob $(source-path) : $(sources) ] ;
172 ECHO "notice: [libpng] Building libpng from source as $(build-name)" ;
175 ECHO "notice: [libpng] Condition" [ $(condition).raw ] ;
179 ECHO "notice: [libpng] found libpng source in $(source-path)" ;
183 ECHO "warning: [libpng] could not find libpng source in $(source-path)" ;
188 target = [ targets.create-typed-target LIB : $(.project)
189 : $(build-name).$(library-id)
193 <include>$(source-path)
194 <toolset>msvc:<define>_CRT_SECURE_NO_DEPRECATE
195 <toolset>msvc:<define>_SCL_SECURE_NO_DEPRECATE
196 <link>shared:<define>LIBPNG_DLL
198 : <include>$(source-path) ] ;
201 local mt = [ new ac-library libpng : $(.project) : $(condition) ] ;
202 $(mt).set-header $(header) ;
203 $(mt).set-default-names $(names) ;
206 $(mt).set-target $(target) ;
208 targets.main-target-alternative $(mt) ;
212 ECHO "notice: [libpng] Using pre-installed library" ;
215 ECHO "notice: [libpng] Condition" [ $(condition).raw ] ;
219 local mt = [ new ac-library libpng : $(.project) : $(condition) :
220 $(include-path) : $(library-path) : $(library-name) : $(root) ] ;
221 $(mt).set-header $(header) ;
222 $(mt).set-default-names $(names) ;
223 targets.main-target-alternative $(mt) ;
225 .configured.$(condition) = true ;