1# $Id$ 2# Copyright 2006-2007 Roland Schwarz. 3# Copyright 2007 Anthony Williams 4# Copyright 2011-2012 Vicente J.Botet Escriba. 5# Distributed under the Boost Software License, Version 1.0. (See 6# accompanying file LICENSE_1_0.txt or copy at 7# http://www.boost.org/LICENSE_1_0.txt) 8 9######################################################################### 10# The boost threading library can be built on top of different API's 11# Currently this is the win32 API and the pthreads API. 12# Pthread is native on unix variants. 13# To get pthread on windows you need the pthread win32 library 14# http://sourceware.org/pthreads-win32 which is available under LGPL. 15# 16# You need to provide the include path and lib path in the variables 17# PTW32_INCLUDE and PTW32_LIB respectively. You can specify these 18# paths in site-config.jam, user-config.jam or in the environment. 19# A new feature is provided to request a specific API: 20# <threadapi>win32 and <threadapi>pthread. 21# 22# The naming of the resulting libraries is mostly the same for the 23# variant native to the build platform, i.e. 24# boost_thread and the boost specific tagging. 25# For the library variant that is not native on the build platform 26# an additional tag is applied: 27# boost_thread_pthread for the pthread variant on windows, and 28# boost_thread_win32 for the win32 variant (likely when built on cygwin). 29# 30# To request the pthread variant on windows, from boost root you would 31# say e.g: 32# bjam msvc-8.0 --with-thread install threadapi=pthread 33######################################################################### 34 35import os ; 36import indirect ; 37import path ; 38import configure ; 39import threadapi-feature ; 40 41exe has_atomic_flag_lockfree : ../build/has_atomic_flag_lockfree_test.cpp ; 42 43project boost/thread 44 : source-location ../src 45 : requirements <threading>multi 46 #<link>static:<define>BOOST_THREAD_STATIC_LINK=1 47 #<link>shared:<define>BOOST_THREAD_DYN_LINK=1 48 <link>static:<define>BOOST_THREAD_BUILD_LIB=1 49 <link>shared:<define>BOOST_THREAD_BUILD_DLL=1 50 -<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag 51 <tag>@$(__name__).tag 52 <toolset>gcc:<cxxflags>-Wno-long-long 53 #<define>BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED 54 #<define>BOOST_SYSTEM_NO_DEPRECATED 55 #<define>BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS 56 57 #-pedantic -ansi -std=gnu++0x -Wextra -fpermissive 58 <warnings>all 59 <toolset>gcc:<cxxflags>-Wextra 60 <toolset>gcc:<cxxflags>-pedantic 61 <toolset>gcc:<cxxflags>-Wno-long-long 62 #<toolset>gcc:<cxxflags>-ansi 63 #<toolset>gcc:<cxxflags>-fpermissive 64 <toolset>gcc-4:<cxxflags>-Wno-variadic-macros 65 <toolset>gcc-5:<cxxflags>-Wno-variadic-macros 66 #<toolset>gcc:<cxxflags>-Wunused-local-typedefs 67 <toolset>gcc:<cxxflags>-Wunused-function 68 <toolset>gcc:<cxxflags>-Wno-unused-parameter 69 70 <toolset>darwin:<cxxflags>-Wextra 71 <toolset>darwin:<cxxflags>-pedantic 72 #<toolset>darwin:<cxxflags>-ansi 73 <toolset>darwin:<cxxflags>-fpermissive 74 <toolset>darwin:<cxxflags>-Wno-long-long 75 #<toolset>darwin:<cxxflags>-Wno-variadic-macros 76 <toolset>darwin-4:<cxxflags>-Wno-variadic-macros 77 <toolset>darwin-5:<cxxflags>-Wno-variadic-macros 78 #<toolset>darwin:<cxxflags>-Wunused-local-typedefs 79 <toolset>darwin:<cxxflags>-Wunused-function 80 <toolset>darwin:<cxxflags>-Wno-unused-parameter 81 82 #<toolset>pathscale:<cxxflags>-Wextra 83 <toolset>pathscale:<cxxflags>-Wno-long-long 84 <toolset>pathscale:<cxxflags>-pedantic 85 86 <toolset>clang:<warnings>on 87 <toolset>clang:<cxxflags>-Wextra 88 #<toolset>clang:<cxxflags>-ansi 89 #<toolset>clang:<cxxflags>-fpermissive 90 <toolset>clang:<cxxflags>-Wno-long-long 91 <toolset>clang:<cxxflags>-Wunused-function 92 <toolset>clang:<cxxflags>-Wno-variadic-macros 93 <toolset>clang:<cxxflags>-Wno-unused-parameter 94 95 #<toolset>gcc-mingw-4.4.0:<cxxflags>-fdiagnostics-show-option 96 #<toolset>gcc-mingw-4.5.0:<cxxflags>-fdiagnostics-show-option 97 #<toolset>gcc-mingw-4.6.0:<cxxflags>-fdiagnostics-show-option 98 #<toolset>gcc-mingw-4.6.3:<cxxflags>-fdiagnostics-show-option 99 #<toolset>gcc-mingw-4.7.0:<cxxflags>-fdiagnostics-show-option 100 #<toolset>gcc-mingw-4.8.0:<cxxflags>-fdiagnostics-show-option 101 #<toolset>gcc:<cxxflags>-Wno-missing-field-initializers 102 103 <toolset>darwin-4.6.2:<cxxflags>-Wno-delete-non-virtual-dtor 104 <toolset>darwin-4.7.0:<cxxflags>-Wno-delete-non-virtual-dtor 105 106 #<toolset>clang-2.8:<cxxflags>-Wno-delete-non-virtual-dtor 107 #<toolset>clang-2.8:<cxxflags>-Wno-unused-function 108 #<toolset>clang-2.9:<cxxflags>-Wno-delete-non-virtual-dtor 109 #<toolset>clang-2.9:<cxxflags>-Wno-unused-function 110 <toolset>clang-3.0:<cxxflags>-Wno-delete-non-virtual-dtor 111 #<toolset>clang-3.0:<cxxflags>-Wno-unused-function 112 #<toolset>clang-3.0:<cxxflags>-Wno-unused-variable 113 114# Note: Some of the remarks from the Intel compiler are disabled 115# remark #193: zero used for undefined preprocessing identifier "XXX" 116# remark #304: access control not specified ("public" by default) 117# remark #593: variable "XXX" was set but never used 118# remark #1418: external function definition with no prior declaration 119# remark #2415: variable "XXX" of static storage duration was declared but never referenced 120 121 <toolset>intel:<cxxflags>-wd193,304,383,444 122 <toolset>intel:<cxxflags>-wd593,981 123 <toolset>intel:<cxxflags>-wd1418 124 <toolset>intel:<cxxflags>-wd2415 125 126 <toolset>msvc:<cxxflags>/wd4100 127 <toolset>msvc:<cxxflags>/wd4512 128 <toolset>msvc:<cxxflags>/wd6246 129 130 <target-os>windows:<define>WIN32_LEAN_AND_MEAN 131 <target-os>windows:<define>BOOST_USE_WINDOWS_H 132 133 # : default-build <threading>multi 134 : usage-requirements # pass these requirement to dependents (i.e. users) 135 #<link>static:<define>BOOST_THREAD_STATIC_LINK=1 136 #<link>shared:<define>BOOST_THREAD_DYN_LINK=1 137 <link>static:<define>BOOST_THREAD_BUILD_LIB=1 138 <link>shared:<define>BOOST_THREAD_BUILD_DLL=1 139 #<define>BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED 140 #<define>BOOST_SYSTEM_NO_DEPRECATED 141 #<define>BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS 142 ; 143 144rule tag ( name : type ? : property-set ) 145{ 146 local result = $(name) ; 147 148 if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB 149 { 150 local api = [ $(property-set).get <threadapi> ] ; 151 152 # non native api gets additional tag 153 if $(api) != [ threadapi-feature.get-default $(property-set) ] { 154 result = $(result)_$(api) ; 155 } 156 } 157 158 # forward to the boost tagging rule 159 return [ indirect.call $(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag 160 $(result) : $(type) : $(property-set) ] ; 161} 162 163rule win32_pthread_paths ( properties * ) 164{ 165 local result ; 166 local PTW32_INCLUDE ; 167 local PTW32_LIB ; 168 PTW32_INCLUDE = [ modules.peek : PTW32_INCLUDE ] ; 169 PTW32_LIB = [ modules.peek : PTW32_LIB ] ; 170 PTW32_INCLUDE ?= [ modules.peek user-config : PTW32_INCLUDE ] ; 171 PTW32_LIB ?= [ modules.peek user-config : PTW32_LIB ] ; 172 PTW32_INCLUDE ?= [ modules.peek site-config : PTW32_INCLUDE ] ; 173 PTW32_LIB ?= [ modules.peek site-config : PTW32_LIB ] ; 174 175 if ! ( $(PTW32_INCLUDE) && $(PTW32_LIB) ) 176 { 177 if ! $(.notified) 178 { 179 echo "************************************************************" ; 180 echo "Trying to build Boost.Thread with pthread support." ; 181 echo "If you need pthread you should specify the paths." ; 182 echo "You can specify them in site-config.jam, user-config.jam" ; 183 echo "or in the environment." ; 184 echo "For example:" ; 185 echo "PTW32_INCLUDE=C:\\Program Files\\ptw32\\Pre-built2\\include" ; 186 echo "PTW32_LIB=C:\\Program Files\\ptw32\\Pre-built2\\lib" ; 187 echo "************************************************************" ; 188 .notified = true ; 189 } 190 } 191 else 192 { 193 local include_path = [ path.make $(PTW32_INCLUDE) ] ; 194 local lib_path = [ path.make $(PTW32_LIB) ] ; 195 local libname = pthread ; 196 if <toolset>msvc in $(properties) 197 { 198 libname = $(libname)VC2.lib ; 199 } 200 if <toolset>gcc in $(properties) 201 { 202 libname = lib$(libname)GC2.a ; 203 } 204 lib_path = [ path.glob $(lib_path) : $(libname) ] ; 205 if ! $(lib_path) 206 { 207 if ! $(.notified) 208 { 209 echo "************************************************************" ; 210 echo "Trying to build Boost.Thread with pthread support." ; 211 echo "But the library" $(libname) "could not be found in path" ; 212 echo $(PTW32_LIB) ; 213 echo "************************************************************" ; 214 .notified = true ; 215 } 216 } 217 else 218 { 219 result += <include>$(include_path) ; 220 result += <library>$(lib_path) ; 221 } 222 } 223 return $(result) ; 224} 225 226rule usage-requirements ( properties * ) 227{ 228 local result ; 229 if <threadapi>pthread in $(properties) 230 { 231 result += <define>BOOST_THREAD_POSIX ; 232 if <target-os>windows in $(properties) 233 { 234 result += [ win32_pthread_paths $(properties) ] ; 235 # TODO: What is for static linking? Is the <library> also needed 236 # in that case? 237 } 238 } 239 if <threadapi>win32 in $(properties) 240 { 241 result += <define>BOOST_THREAD_WIN32 ; 242 } 243 244 #if ! <toolset>vacpp in $(properties) || <toolset-vacpp:version>11.1 in $(properties) || <toolset-vacpp:version>12.1.0.1 in $(properties) || <toolset-vacpp:version>12.1 in $(properties) 245 #{ 246 result += <library>/boost/chrono//boost_chrono ; 247 #} 248 249 return $(result) ; 250} 251 252rule requirements ( properties * ) 253{ 254 local result ; 255 256 if <threadapi>pthread in $(properties) 257 { 258 result += <define>BOOST_THREAD_POSIX ; 259 if <target-os>windows in $(properties) 260 { 261 local paths = [ win32_pthread_paths $(properties) ] ; 262 if $(paths) 263 { 264 result += $(paths) ; 265 } 266 else 267 { 268 result = <build>no ; 269 } 270 } 271 result += <define>BOOST_THREAD_DONT_USE_CHRONO ; 272 if ! [ configure.builds has_atomic_flag_lockfree 273 : $(properties) : "lockfree boost::atomic_flag" ] { 274 result += <library>/boost/atomic//boost_atomic ; 275 } 276 } else { 277 if <threadapi>win32 in $(properties) 278 { 279 result += <define>BOOST_THREAD_WIN32 ; 280 } 281 result += <define>BOOST_THREAD_USES_CHRONO ; 282 result += <library>/boost/chrono//boost_chrono ; 283 } 284 285 return $(result) ; 286} 287 288alias thread_sources 289 : ## win32 sources ## 290 win32/thread.cpp 291 win32/tss_dll.cpp 292 win32/tss_pe.cpp 293 win32/thread_primitives.cpp 294 future.cpp 295 : ## requirements ## 296 <threadapi>win32 297 ; 298 299alias thread_sources 300 : ## pthread sources ## 301 pthread/thread.cpp 302 pthread/once.cpp 303 future.cpp 304 : ## requirements ## 305 <threadapi>pthread 306 ; 307 308explicit thread_sources ; 309 310lib boost_thread 311 : thread_sources 312 : <conditional>@requirements 313 : 314 : <link>shared:<define>BOOST_THREAD_USE_DLL=1 315 <link>static:<define>BOOST_THREAD_USE_LIB=1 316 <conditional>@usage-requirements 317 ; 318 319boost-install boost_thread ;