Skip to content

fix conanfile to build on conan io #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 39 additions & 20 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,75 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
from conan.tools.files import get, copy
from conan.tools.scm import Version
import os

required_conan_version = ">=1.55"


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

# Sources are located in the same place as this recipe, copy them to the recipe
# Sources are located in the same place as this recipe, copy them to the recipe
exports_sources = "CMakeLists.txt", "lib/*", "examples/*", "cmake/*"

# def source(self):
# get(self, **self.conan_data["sources"][self.version])
# get(self, **self.conan_data["sources"][self.version], strip_root=True)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
if self.options.get_safe("shared"):
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self)
cmake_layout(self, src_folder="src")

def generate(self):
tc = CMakeToolchain(self)
tc.variables["ENABLE_ESI_PARSER"] = bool(self.options.with_esi_parser)
tc.generate()
def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 17)

if self.settings.os != "Linux":
raise ConanInvalidConfiguration(
f"{self.ref} is not supported on {self.settings.os}.")

deps = CMakeDeps(self)
deps.generate()
if self.settings.compiler != "gcc":
raise ConanInvalidConfiguration(
f"{self.ref} is not supported on {self.settings.compiler}.")

if self.settings.compiler == 'gcc' and Version(self.settings.compiler.version) < "7":
raise ConanInvalidConfiguration("Building requires GCC >= 7")

def requirements(self):
if self.options.with_esi_parser:
self.requires("tinyxml2/10.0.0")


def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["ENABLE_ESI_PARSER"] = bool(self.options.with_esi_parser)
tc.cache_variables["BUILD_UNIT_TESTS"] = "OFF"
tc.cache_variables["BUILD_EXAMPLES"] = "OFF"
tc.cache_variables["BUILD_SIMULATION"] = "OFF"
tc.cache_variables["BUILD_TOOLS"] = "OFF"
tc.generate()

def build(self):
cmake = CMake(self)
cmake.configure(variables={"BUILD_UNIT_TESTS": "OFF",
"BUILD_EXAMPLES": "OFF",
"BUILD_SIMULATION": "OFF",
"BUILD_TOOLS": "OFF"})
cmake.configure()
cmake.build()

def package(self):
src_folders = ["lib/include", "lib/slave/include", "lib/slave/driver/include", "lib/master/include"]
src_folders = ["lib/include", "lib/slave/include", "lib/slave/driver/include", "lib/master/include", "include"]
for folder in src_folders:
copy(self, "*.h", os.path.join(self.source_folder, folder),
os.path.join(self.package_folder, "include"))
Expand All @@ -59,8 +78,8 @@ def package(self):
os.path.join(self.package_folder, "lib"), keep_path=False)
copy(self, "*.so", self.build_folder,
os.path.join(self.package_folder, "lib"), keep_path=False)
copy(self, "LICENSE", self.source_folder,
os.path.join(self.package_folder, "licenses"))

def package_info(self):
self.cpp_info.libs = ["kickcat"]