1# Copyright (c) 2010 Vladimir Prus. 2# Copyright (c) 2013 Steven Watanabe 3# 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) 7 8# Supports the libpng library 9# 10# After 'using libpng', the following targets are available: 11# 12# /libpng//libpng -- The libpng library 13 14import project ; 15import ac ; 16import errors ; 17import feature ; 18import "class" : new ; 19import targets ; 20import path ; 21import modules ; 22import indirect ; 23import property ; 24import property-set ; 25 26header = png.h ; 27 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. 31names = libpng libpng16 png png16 ; 32 33sources = 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 ; 35 36library-id = 0 ; 37 38if --debug-configuration in [ modules.peek : ARGV ] 39{ 40 .debug = true ; 41} 42 43# Initializes the libpng library. 44# 45# libpng can be configured either to use pre-existing binaries 46# or to build the library from source. 47# 48# Options for configuring a prebuilt libpng:: 49# 50# <search> 51# The directory containing the libpng binaries. 52# <name> 53# Overrides the default library name. 54# <include> 55# The directory containing the libpng headers. 56# 57# If none of these options is specified, then the environmental 58# variables LIBPNG_LIBRARY_PATH, LIBPNG_NAME, and LIBPNG_INCLUDE will 59# be used instead. 60# 61# Options for building libpng from source:: 62# 63# <source> 64# The libpng source directory. Defaults to the environmental variable 65# LIBPNG_SOURCE. 66# <tag> 67# A rule which computes the actual name of the compiled 68# libraries based on the build properties. Ignored 69# when using precompiled binaries. 70# <build-name> 71# The base name to use for the compiled library. Ignored 72# when using precompiled binaries. 73# 74# Examples:: 75# 76# # Find libpng in the default system location 77# using libpng ; 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 ; 87# 88rule init ( 89 version ? 90 # The libpng version (currently ignored) 91 92 : options * 93 # A list of the options to use 94 95 : requirements * 96 # The requirements for the libpng target 97 98 : is-default ? 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. 104 ) 105{ 106 local caller = [ project.current ] ; 107 108 if ! $(.initialized) 109 { 110 .initialized = true ; 111 112 project.initialize $(__name__) ; 113 .project = [ project.current ] ; 114 project libpng ; 115 } 116 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) ] ; 123 124 if ! $(library-path) && ! $(include-path) && ! $(source-path) && ! $(library-name) 125 { 126 is-default = true ; 127 } 128 129 condition = [ property-set.create $(requirements) ] ; 130 condition = [ property-set.create [ $(condition).base ] ] ; 131 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) 135 { 136 if $(source-path) || $(tag) || $(build-name) 137 { 138 errors.user-error "incompatible options for libpng:" 139 [ property.select <search> <include> <name> : $(options) ] "and" 140 [ property.select <source> <tag> <build-name> : $(options) ] ; 141 } 142 } 143 else 144 { 145 source-path ?= [ modules.peek : LIBPNG_SOURCE ] ; 146 } 147 148 if $(.configured.$(condition)) 149 { 150 if $(is-default) 151 { 152 if $(.debug) 153 { 154 ECHO "notice: [libpng] libpng is already configured" ; 155 } 156 } 157 else 158 { 159 errors.user-error "libpng is already configured" ; 160 } 161 return ; 162 } 163 else if $(source-path) 164 { 165 build-name ?= png ; 166 library-id = [ CALC $(library-id) + 1 ] ; 167 tag = [ MATCH ^@?(.*)$ : $(tag) ] ; 168 if $(tag) 169 { 170 tag = [ indirect.make $(tag) : [ $(caller).project-module ] ] ; 171 } 172 sources = [ path.glob $(source-path) : $(sources) ] ; 173 if $(.debug) 174 { 175 ECHO "notice: [libpng] Building libpng from source as $(build-name)" ; 176 if $(condition) 177 { 178 ECHO "notice: [libpng] Condition" [ $(condition).raw ] ; 179 } 180 if $(sources) 181 { 182 ECHO "notice: [libpng] found libpng source in $(source-path)" ; 183 } 184 else 185 { 186 ECHO "warning: [libpng] could not find libpng source in $(source-path)" ; 187 } 188 } 189 local target ; 190 if $(sources) { 191 target = [ targets.create-typed-target LIB : $(.project) 192 : $(build-name).$(library-id) 193 : $(sources) 194 : $(requirements) 195 <tag>@$(tag) 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 200 : 201 : <include>$(source-path) ] ; 202 } 203 204 local mt = [ new ac-library libpng : $(.project) : $(condition) ] ; 205 $(mt).set-header $(header) ; 206 $(mt).set-default-names $(names) ; 207 if $(target) 208 { 209 $(mt).set-target $(target) ; 210 } 211 targets.main-target-alternative $(mt) ; 212 } else { 213 if $(.debug) 214 { 215 ECHO "notice: [libpng] Using pre-installed library" ; 216 if $(condition) 217 { 218 ECHO "notice: [libpng] Condition" [ $(condition).raw ] ; 219 } 220 } 221 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) ; 227 } 228 .configured.$(condition) = true ; 229} 230