4
4
from conan import ConanFile
5
5
from conan .errors import ConanInvalidConfiguration
6
6
from conan .tools .apple import is_apple_os
7
+ from conan .tools .build import check_min_cppstd
7
8
from conan .tools .cmake import CMake , CMakeToolchain , cmake_layout
8
- from conan .tools .files import apply_conandata_patches , collect_libs , copy , export_conandata_patches , get , replace_in_file , save
9
+ from conan .tools .env import VirtualBuildEnv
10
+ from conan .tools .files import apply_conandata_patches , copy , export_conandata_patches , get , replace_in_file , save , move_folder_contents , rmdir
9
11
from conan .tools .scm import Version
10
12
11
13
required_conan_version = ">=1.53.0"
@@ -21,26 +23,27 @@ class LLVMOpenMpConan(ConanFile):
21
23
"implementation." )
22
24
license = "Apache-2.0 WITH LLVM-exception"
23
25
url = "https://github.com/conan-io/conan-center-index"
24
- homepage = "https://github.com/llvm/llvm-project/tree/master /openmp"
26
+ homepage = "https://github.com/llvm/llvm-project/blob/main /openmp"
25
27
topics = ("llvm" , "openmp" , "parallelism" )
26
28
27
29
package_type = "library"
28
30
settings = "os" , "arch" , "compiler" , "build_type"
29
31
options = {
30
32
"shared" : [True , False ],
31
33
"fPIC" : [True , False ],
34
+ "build_libomptarget" : [True , False ],
32
35
}
33
36
default_options = {
34
37
"shared" : False ,
35
38
"fPIC" : True ,
39
+ "build_libomptarget" : False ,
40
+ }
41
+ options_description = {
42
+ "build_libomptarget" : (
43
+ "Build the LLVM OpenMP Offloading Runtime Library (libomptarget) "
44
+ "in addition to the OpenMP Runtime Library (libomp)."
45
+ )
36
46
}
37
-
38
- def export_sources (self ):
39
- export_conandata_patches (self )
40
-
41
- def config_options (self ):
42
- if self .settings .os == "Windows" :
43
- del self .options .fPIC
44
47
45
48
def _supports_compiler (self ):
46
49
supported_compilers_by_os = {
@@ -51,40 +54,93 @@ def _supports_compiler(self):
51
54
the_compiler , the_os = self .settings .compiler .value , self .settings .os .value
52
55
return the_compiler in supported_compilers_by_os .get (the_os , [])
53
56
57
+ @property
58
+ def _compilers_minimum_version (self ):
59
+ return {
60
+ "gcc" : "7" ,
61
+ "clang" : "6" ,
62
+ "apple-clang" : "10" ,
63
+ }
64
+
65
+ @property
66
+ def _version_major (self ):
67
+ return Version (self .version ).major
68
+
69
+ def export_sources (self ):
70
+ export_conandata_patches (self )
71
+
72
+ def config_options (self ):
73
+ if self .settings .os == "Windows" :
74
+ del self .options .fPIC
75
+
54
76
def configure (self ):
55
77
if self .options .shared :
56
78
self .options .rm_safe ("fPIC" )
57
- if not self ._supports_compiler ():
58
- raise ConanInvalidConfiguration ("llvm-openmp doesn't support compiler: {} on OS: {}." .
59
- format (self .settings .compiler , self .settings .os ))
60
79
80
+ def requirements (self ):
81
+ if self .options .build_libomptarget and self ._version_major >= 13 :
82
+ self .requires (f"llvm-core/{ self .version } " )
61
83
62
84
def layout (self ):
63
85
cmake_layout (self , src_folder = "src" )
64
86
65
87
def validate (self ):
66
- if (
67
- Version (self .version ) <= "10.0.0"
68
- and is_apple_os (self )
69
- and self .settings .arch == "armv8"
70
- ):
71
- raise ConanInvalidConfiguration ("ARM v8 not supported" )
88
+ if not self ._supports_compiler ():
89
+ raise ConanInvalidConfiguration ("llvm-openmp doesn't support compiler: "
90
+ f"{ self .settings .compiler } on OS: { self .settings .os } ." )
91
+ if self ._version_major >= 17 :
92
+ if self .settings .compiler .cppstd :
93
+ check_min_cppstd (self , 17 )
94
+ minimum_version = self ._compilers_minimum_version .get (str (self .settings .compiler ), False )
95
+ if minimum_version and Version (self .settings .compiler .version ) < minimum_version :
96
+ raise ConanInvalidConfiguration (f"{ self .ref } requires C++17, which your compiler does not support." )
97
+ if is_apple_os (self ) and self .settings .arch == "armv8" :
98
+ if self ._version_major <= 10 :
99
+ raise ConanInvalidConfiguration ("ARM v8 not supported" )
100
+ if self ._version_major != 11 and self .settings .build_type == "Debug" :
101
+ # All versions except for v11 crash with a segfault for the simple test_package.cpp test
102
+ raise ConanInvalidConfiguration ("Debug mode not supported for ARM v8" )
103
+
104
+ def build_requirements (self ):
105
+ if self ._version_major >= 17 :
106
+ self .tool_requires ("cmake/[>=3.20 <4]" )
72
107
73
108
def source (self ):
74
- get (self , ** self .conan_data ["sources" ][self .version ], strip_root = True )
109
+ if self ._version_major >= 15 :
110
+ get (self , ** self .conan_data ["sources" ][self .version ]["openmp" ], strip_root = True )
111
+ get (self , ** self .conan_data ["sources" ][self .version ]["cmake" ], strip_root = True , destination = self .export_sources_folder )
112
+ copy (self , "*.cmake" ,
113
+ src = os .path .join (self .export_sources_folder , "Modules" ),
114
+ dst = os .path .join (self .source_folder , "cmake" ))
115
+ elif self ._version_major == 14 :
116
+ # v14 source archives also includes a cmake/ directory in the archive root
117
+ get (self , ** self .conan_data ["sources" ][self .version ], destination = self .export_sources_folder )
118
+ move_folder_contents (self , os .path .join (self .export_sources_folder , f"openmp-{ self .version } .src" ), self .source_folder )
119
+ copy (self , "*.cmake" ,
120
+ src = os .path .join (self .export_sources_folder , "cmake" , "Modules" ),
121
+ dst = os .path .join (self .source_folder , "cmake" ))
122
+ else :
123
+ get (self , ** self .conan_data ["sources" ][self .version ], strip_root = True )
75
124
76
125
def generate (self ):
126
+ env = VirtualBuildEnv (self )
127
+ env .generate ()
77
128
tc = CMakeToolchain (self )
78
129
tc .variables ["OPENMP_STANDALONE_BUILD" ] = True
79
130
tc .variables ["LIBOMP_ENABLE_SHARED" ] = self .options .shared
80
- if self .settings .os in ["Linux" , "FreeBSD" ]:
81
- tc .variables ["OPENMP_ENABLE_LIBOMPTARGET" ] = self .options .shared
131
+ tc .variables ["OPENMP_ENABLE_LIBOMPTARGET" ] = self .options .build_libomptarget
132
+ # Do not buidl OpenMP Tools Interface (OMPT)
133
+ tc .variables ["LIBOMP_OMPT_SUPPORT" ] = False
82
134
tc .generate ()
83
135
84
136
def _patch_sources (self ):
85
137
apply_conandata_patches (self )
86
- replace_in_file (self ,os .path .join (self .source_folder , "runtime" , "CMakeLists.txt" ),
138
+ replace_in_file (self , os .path .join (self .source_folder , "runtime" , "CMakeLists.txt" ),
87
139
"add_subdirectory(test)" , "" )
140
+ if self ._version_major == 12 :
141
+ # v12 can be built without LLVM includes
142
+ replace_in_file (self , os .path .join (self .source_folder , "libomptarget" , "CMakeLists.txt" ),
143
+ "if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS)" , "if (FALSE)" )
88
144
89
145
def build (self ):
90
146
self ._patch_sources ()
@@ -98,6 +154,7 @@ def package(self):
98
154
dst = os .path .join (self .package_folder , "licenses" ))
99
155
cmake = CMake (self )
100
156
cmake .install ()
157
+ rmdir (self , os .path .join (self .package_folder , "lib" , "cmake" ))
101
158
102
159
# TODO: to remove in conan v2 once cmake_find_package* generators removed
103
160
self ._create_cmake_module_alias_targets (
0 commit comments