Skip to content

Commit 71a4d86

Browse files
authored
fix conanfile to build on conan io (#200)
1 parent 3c74314 commit 71a4d86

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

conanfile.py

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,75 @@
11
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
35
from conan.tools.files import get, copy
6+
from conan.tools.scm import Version
47
import os
58

69
required_conan_version = ">=1.55"
710

11+
812
class KickCATRecipe(ConanFile):
913
name = "kickcat"
1014
url = "https://github.com/conan-io/conan-center-index"
1115
homepage = "https://github.com/Siviuze/KickCAT"
1216
description = "Thin EtherCAT stack designed to be embedded in a more complex software and with efficiency in mind"
1317
license = "CeCILL-C"
1418
topics = ("ethercat")
19+
package_type = "library"
1520
settings = "os", "compiler", "build_type", "arch"
1621
options = {"shared": [True, False], "fPIC": [True, False], "with_esi_parser": [True, False]}
1722
default_options = {"shared": False, "fPIC": True, "with_esi_parser": False}
1823

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
2025
exports_sources = "CMakeLists.txt", "lib/*", "examples/*", "cmake/*"
2126

2227
# def source(self):
23-
# get(self, **self.conan_data["sources"][self.version])
28+
# get(self, **self.conan_data["sources"][self.version], strip_root=True)
2429

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")
2833

2934
def layout(self):
30-
cmake_layout(self)
35+
cmake_layout(self, src_folder="src")
3136

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}.")
3644

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}.")
3948

49+
if self.settings.compiler == 'gcc' and Version(self.settings.compiler.version) < "7":
50+
raise ConanInvalidConfiguration("Building requires GCC >= 7")
51+
4052
def requirements(self):
4153
if self.options.with_esi_parser:
4254
self.requires("tinyxml2/10.0.0")
4355

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+
4466
def build(self):
4567
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()
5069
cmake.build()
5170

5271
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"]
5473
for folder in src_folders:
5574
copy(self, "*.h", os.path.join(self.source_folder, folder),
5675
os.path.join(self.package_folder, "include"))
@@ -59,8 +78,8 @@ def package(self):
5978
os.path.join(self.package_folder, "lib"), keep_path=False)
6079
copy(self, "*.so", self.build_folder,
6180
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"))
6283

6384
def package_info(self):
6485
self.cpp_info.libs = ["kickcat"]
65-
66-

0 commit comments

Comments
 (0)