1# Copyright (c) 2018 Stefan Seefeld 2# 3# Use, modification and distribution is subject to the Boost Software 4# License Version 1.0. (See accompanying file LICENSE_1_0.txt or 5# http://www.boost.org/LICENSE_1_0.txt) 6 7# Supports the opencl library 8# 9# After 'using opencl', the following targets are available: 10# 11# /opencl//opencl -- The OpenCL library 12 13import project ; 14import ac ; 15import errors ; 16import feature ; 17import "class" : new ; 18import targets ; 19import modules ; 20import property-set ; 21 22header = CL/cl.h ; 23names = OpenCL ; 24 25library-id = 0 ; 26 27if --debug-configuration in [ modules.peek : ARGV ] 28{ 29 .debug = true ; 30} 31 32# Initializes the opencl library. 33# 34# Options for configuring opencl:: 35# 36# <search> 37# The directory containing the OpenCL library. 38# <name> 39# Overrides the default library name. 40# <include> 41# The directory containing the OpenCL headers. 42# 43# Examples:: 44# 45# # Find OpenCL in the default system location 46# using opencl ; 47# # Find opencl in /usr/local 48# using opencl : 1.2.7 49# : <include>/usr/local/include <search>/usr/local/lib ; 50# 51rule init ( version ? : # The opencl version (currently ignored) 52 options * : # A list of the options to use 53 requirements * ) # The requirements for the opencl target 54{ 55 local caller = [ project.current ] ; 56 57 if ! $(.initialized) 58 { 59 .initialized = true ; 60 61 project.initialize $(__name__) ; 62 .project = [ project.current ] ; 63 project opencl ; 64 } 65 66 local library-path = [ feature.get-values <search> : $(options) ] ; 67 local include-path = [ feature.get-values <include> : $(options) ] ; 68 local library-name = [ feature.get-values <name> : $(options) ] ; 69 70 if ! $(library-path) && ! $(include-path) && ! $(library-name) 71 { 72 is-default = true ; 73 } 74 75 condition = [ property-set.create $(requirements) ] ; 76 condition = [ property-set.create [ $(condition).base ] ] ; 77 78 if $(.configured.$(condition)) 79 { 80 if $(is-default) 81 { 82 if $(.debug) 83 { 84 ECHO "notice: [opencl] opencl is already configured" ; 85 } 86 } 87 else 88 { 89 errors.user-error "opencl is already configured" ; 90 } 91 return ; 92 } 93 else 94 { 95 if $(.debug) 96 { 97 ECHO "notice: [opencl] Using pre-installed library" ; 98 if $(condition) 99 { 100 ECHO "notice: [opencl] Condition" [ $(condition).raw ] ; 101 } 102 } 103 104 local mt = [ new ac-library opencl : $(.project) : $(condition) : 105 $(include-path) : $(library-path) : $(library-name) ] ; 106 $(mt).set-header $(header) ; 107 $(mt).set-default-names $(names) ; 108 targets.main-target-alternative $(mt) ; 109 } 110 .configured.$(condition) = true ; 111} 112