• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright © 2017 Intel Corporation
2
3# Permission is hereby granted, free of charge, to any person obtaining a copy
4# of this software and associated documentation files (the "Software"), to deal
5# in the Software without restriction, including without limitation the rights
6# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7# copies of the Software, and to permit persons to whom the Software is
8# furnished to do so, subject to the following conditions:
9
10# The above copyright notice and this permission notice shall be included in
11# all copies or substantial portions of the Software.
12
13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19# SOFTWARE.
20
21opencl_link_args = []
22opencl_link_deps = []
23opencl_version = '1'
24
25if with_ld_version_script
26  opencl_link_args += [
27    '-Wl,--version-script', join_paths(meson.current_source_dir(), 'opencl.sym')
28  ]
29  opencl_link_deps += files('opencl.sym')
30endif
31
32llvm_libdir = dep_llvm.get_variable(cmake : 'LLVM_LIBRARY_DIR', configtool: 'libdir')
33opencl_libname = with_opencl_icd ? 'MesaOpenCL' : 'OpenCL'
34
35polly_dep = null_dep
36polly_isl_dep = null_dep
37if dep_llvm.version().version_compare('>=10.0.0')
38  polly_dep = cpp.find_library('Polly', dirs : llvm_libdir, required : false)
39  polly_isl_dep = cpp.find_library('PollyISL', dirs : llvm_libdir, required : false)
40endif
41
42dep_clang = cpp.find_library('clang-cpp', dirs : llvm_libdir, required : false)
43
44# meson will return clang-cpp from system dirs if it's not found in llvm_libdir
45linker_rpath_arg = '-Wl,--rpath=@0@'.format(llvm_libdir)
46clang_test_code = '''
47  #include <clang/Basic/Version.h>
48  int main (void) {
49    size_t found_pos = clang::getClangFullVersion().find(CLANG_VERSION_STRING);
50    return found_pos == ::std::string::npos ? 1 : 0;
51  }
52'''
53can_check_clang = (not meson.is_cross_build() or meson.can_run_host_binaries()) and cpp.has_link_argument(linker_rpath_arg)
54if can_check_clang
55  test_run = cpp.run(clang_test_code, name : 'dep-clang-usable',
56                     dependencies : [dep_llvm, dep_clang], args : linker_rpath_arg)
57  dep_clang_usable = test_run.compiled() and test_run.returncode() == 0
58else
59  dep_clang_usable = true
60endif
61if not _shared_llvm or not (dep_clang.found() and dep_clang_usable)
62  dep_clang = [
63    cpp.find_library('clangCodeGen', dirs : llvm_libdir),
64    cpp.find_library('clangFrontendTool', dirs : llvm_libdir),
65    cpp.find_library('clangFrontend', dirs : llvm_libdir),
66    cpp.find_library('clangDriver', dirs : llvm_libdir),
67    cpp.find_library('clangSerialization', dirs : llvm_libdir),
68    cpp.find_library('clangParse', dirs : llvm_libdir),
69    cpp.find_library('clangSema', dirs : llvm_libdir),
70    cpp.find_library('clangAnalysis', dirs : llvm_libdir),
71    cpp.find_library('clangAST', dirs : llvm_libdir),
72    cpp.find_library('clangASTMatchers', dirs : llvm_libdir),
73    cpp.find_library('clangEdit', dirs : llvm_libdir),
74    cpp.find_library('clangLex', dirs : llvm_libdir),
75    cpp.find_library('clangBasic', dirs : llvm_libdir),
76    polly_dep, polly_isl_dep,
77  ]
78  if dep_llvm.version().version_compare('>= 15.0')
79    dep_clang += cpp.find_library('clangSupport', dirs : llvm_libdir)
80  endif
81
82  # check clang once more
83  if can_check_clang
84    test_run = cpp.run(clang_test_code, name : 'dep-clang-usable',
85                       dependencies : [dep_llvm, dep_clang], args : linker_rpath_arg)
86    if not test_run.compiled() or test_run.returncode() != 0
87      error('No usable clang found!')
88    endif
89  endif
90endif
91
92ocldef_in = files(opencl_libname + '.def.in')[0]
93ocldef = custom_target(
94  'ocldef.def',
95  input: ocldef_in,
96  output : 'ocldef.def',
97  command : gen_vs_module_defs_normal_command,
98)
99
100libopencl = shared_library(
101  opencl_libname,
102  [],
103  vs_module_defs : ocldef,
104  link_args : [ld_args_gc_sections, opencl_link_args],
105  link_depends : opencl_link_deps,
106  link_whole : libclover,
107  link_with : [libpipe_loader_dynamic, libgallium],
108  dependencies : [
109    idep_mesautil,
110    dep_clock, dep_dl, dep_unwind, dep_elf, dep_clang, dep_version
111  ],
112  name_prefix : host_machine.system() == 'windows' ? '' : [],  # otherwise mingw will create libOpenCL-1.dll or libMesaOpenCL-1.dll
113  version : '@0@.0.0'.format(opencl_version),
114  soversion : host_machine.system() == 'windows' ? '' : opencl_version,
115  install : true,
116)
117
118if with_opencl_icd
119  _config = configuration_data()
120  _config.set('OPENCL_LIBNAME', 'MesaOpenCL')
121  _config.set('OPENCL_VERSION', opencl_version)
122  configure_file(
123    configuration : _config,
124    input : 'mesa.icd.in',
125    output : 'mesa.icd',
126    install : true,
127    install_tag : 'runtime',
128    install_dir : join_paths(get_option('sysconfdir'), 'OpenCL', 'vendors'),
129  )
130
131  # .so is hardcoded in the icd as well
132  devenv.prepend(
133    'OCL_ICD_FILENAMES',
134    meson.current_build_dir() / 'libMesaOpenCL.so.@0@'.format(opencl_version)
135  )
136endif
137