1
1
from conan import ConanFile
2
- from conan .tools .cmake import CMakeToolchain , CMake , cmake_layout , CMakeDeps
2
+ from conan .errors import ConanInvalidConfiguration
3
+ from conan .tools .build import check_min_cppstd
4
+ from conan .tools .cmake import CMakeToolchain , CMake , cmake_layout
3
5
from conan .tools .files import get , copy
6
+ from conan .tools .scm import Version
4
7
import os
5
8
6
9
required_conan_version = ">=1.55"
7
10
11
+
8
12
class KickCATRecipe (ConanFile ):
9
13
name = "kickcat"
10
14
url = "https://github.com/conan-io/conan-center-index"
11
15
homepage = "https://github.com/Siviuze/KickCAT"
12
16
description = "Thin EtherCAT stack designed to be embedded in a more complex software and with efficiency in mind"
13
17
license = "CeCILL-C"
14
18
topics = ("ethercat" )
19
+ package_type = "library"
15
20
settings = "os" , "compiler" , "build_type" , "arch"
16
21
options = {"shared" : [True , False ], "fPIC" : [True , False ], "with_esi_parser" : [True , False ]}
17
22
default_options = {"shared" : False , "fPIC" : True , "with_esi_parser" : False }
18
23
19
- # Sources are located in the same place as this recipe, copy them to the recipe
24
+ # Sources are located in the same place as this recipe, copy them to the recipe
20
25
exports_sources = "CMakeLists.txt" , "lib/*" , "examples/*" , "cmake/*"
21
26
22
27
# def source(self):
23
- # get(self, **self.conan_data["sources"][self.version])
28
+ # get(self, **self.conan_data["sources"][self.version], strip_root=True )
24
29
25
- def config_options (self ):
26
- if self .settings . os == "Windows" :
27
- del self .options .fPIC
30
+ def configure (self ):
31
+ if self .options . get_safe ( "shared" ) :
32
+ self .options .rm_safe ( " fPIC" )
28
33
29
34
def layout (self ):
30
- cmake_layout (self )
35
+ cmake_layout (self , src_folder = "src" )
31
36
32
- def generate (self ):
33
- tc = CMakeToolchain (self )
34
- tc .variables ["ENABLE_ESI_PARSER" ] = bool (self .options .with_esi_parser )
35
- tc .generate ()
37
+ def validate (self ):
38
+ if self .settings .compiler .get_safe ("cppstd" ):
39
+ check_min_cppstd (self , 17 )
40
+
41
+ if self .settings .os != "Linux" :
42
+ raise ConanInvalidConfiguration (
43
+ f"{ self .ref } is not supported on { self .settings .os } ." )
36
44
37
- deps = CMakeDeps (self )
38
- deps .generate ()
45
+ if self .settings .compiler != "gcc" :
46
+ raise ConanInvalidConfiguration (
47
+ f"{ self .ref } is not supported on { self .settings .compiler } ." )
39
48
49
+ if self .settings .compiler == 'gcc' and Version (self .settings .compiler .version ) < "7" :
50
+ raise ConanInvalidConfiguration ("Building requires GCC >= 7" )
51
+
40
52
def requirements (self ):
41
53
if self .options .with_esi_parser :
42
54
self .requires ("tinyxml2/10.0.0" )
43
55
56
+
57
+ def generate (self ):
58
+ tc = CMakeToolchain (self )
59
+ tc .cache_variables ["ENABLE_ESI_PARSER" ] = bool (self .options .with_esi_parser )
60
+ tc .cache_variables ["BUILD_UNIT_TESTS" ] = "OFF"
61
+ tc .cache_variables ["BUILD_EXAMPLES" ] = "OFF"
62
+ tc .cache_variables ["BUILD_SIMULATION" ] = "OFF"
63
+ tc .cache_variables ["BUILD_TOOLS" ] = "OFF"
64
+ tc .generate ()
65
+
44
66
def build (self ):
45
67
cmake = CMake (self )
46
- cmake .configure (variables = {"BUILD_UNIT_TESTS" : "OFF" ,
47
- "BUILD_EXAMPLES" : "OFF" ,
48
- "BUILD_SIMULATION" : "OFF" ,
49
- "BUILD_TOOLS" : "OFF" })
68
+ cmake .configure ()
50
69
cmake .build ()
51
70
52
71
def package (self ):
53
- src_folders = ["lib/include" , "lib/slave/include" , "lib/slave/driver/include" , "lib/master/include" ]
72
+ src_folders = ["lib/include" , "lib/slave/include" , "lib/slave/driver/include" , "lib/master/include" , "include" ]
54
73
for folder in src_folders :
55
74
copy (self , "*.h" , os .path .join (self .source_folder , folder ),
56
75
os .path .join (self .package_folder , "include" ))
@@ -59,8 +78,8 @@ def package(self):
59
78
os .path .join (self .package_folder , "lib" ), keep_path = False )
60
79
copy (self , "*.so" , self .build_folder ,
61
80
os .path .join (self .package_folder , "lib" ), keep_path = False )
81
+ copy (self , "LICENSE" , self .source_folder ,
82
+ os .path .join (self .package_folder , "licenses" ))
62
83
63
84
def package_info (self ):
64
85
self .cpp_info .libs = ["kickcat" ]
65
-
66
-
0 commit comments