opencl.jam 2.8 KB

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