Skip to content

Commit

Permalink
Update conanfile to modern standards
Browse files Browse the repository at this point in the history
[CURA-10475]
  • Loading branch information
jellespijker committed Apr 18, 2023
1 parent c664e6c commit d124a92
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 73 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
cmake_policy(SET CMP0091 NEW)
project(libarcus)
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23)
find_package(standardprojectsettings REQUIRED)

find_package(protobuf 3.17.1 REQUIRED)
find_package(protobuf REQUIRED)

set(arcus_SRCS
src/Socket.cpp
Expand All @@ -19,6 +17,8 @@ else()
add_library(Arcus STATIC ${arcus_SRCS})
endif()

set_project_warnings(Arcus)
enable_sanitizers(Arcus)
use_threads(Arcus)

target_include_directories(Arcus
Expand Down
16 changes: 0 additions & 16 deletions conandata.yml

This file was deleted.

89 changes: 57 additions & 32 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.files import AutoPackager
from conan.tools.build import check_min_cppstd
from os import path

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import copy, AutoPackager
from conan.tools.microsoft import check_min_vs, is_msvc, is_msvc_static_runtime
from conan.tools.scm import Version

required_conan_version = ">=1.56.0"
required_conan_version = ">=1.55.0"


class ArcusConan(ConanFile):
Expand All @@ -14,12 +20,7 @@ class ArcusConan(ConanFile):
description = "Communication library between internal components for Ultimaker software"
topics = ("conan", "binding", "cura", "protobuf", "c++")
settings = "os", "compiler", "build_type", "arch"
revision_mode = "scm"
exports = "LICENSE*"
generators = "CMakeDeps", "CMakeToolchain", "VirtualBuildEnv", "VirtualRunEnv"

python_requires = "umbase/[>=0.1.7]@ultimaker/stable"
python_requires_extend = "umbase.UMBaseConanfile"

options = {
"shared": [True, False],
Expand All @@ -29,32 +30,25 @@ class ArcusConan(ConanFile):
"shared": True,
"fPIC": True,
}
scm = {
"type": "git",
"subfolder": ".",
"url": "auto",
"revision": "auto"
}

def set_version(self):
if self.version is None:
self.version = self._umdefault_version()
@property
def _min_cppstd(self):
return 17

def requirements(self):
self.requires("standardprojectsettings/[>=0.1.0]@ultimaker/stable")
for req in self._um_data()["requirements"]:
self.requires(req)

def config_options(self):
if self.options.shared and self.settings.compiler == "Visual Studio":
del self.options.fPIC
@property
def _compilers_minimum_version(self):
return {
"gcc": "9",
"clang": "9",
"apple-clang": "9",
"msvc": "192",
"visual_studio": "14",
}

def configure(self):
self.options["protobuf"].shared = True

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 17)
def export_sources(self):
copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder)
copy(self, "*", path.join(self.recipe_folder, "src"), path.join(self.export_sources_folder, "src"))
copy(self, "*", path.join(self.recipe_folder, "include"), path.join(self.export_sources_folder, "include"))

def layout(self):
cmake_layout(self)
Expand All @@ -67,11 +61,42 @@ def layout(self):
elif self.settings.os == "Windows":
self.cpp.package.system_libs = ["ws2_32"]

def requirements(self):
self.requires("protobuf/3.21.4", transitive_headers=True)

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
check_min_vs(self, 192) # TODO: remove in Conan 2.0
if not is_msvc(self):
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

def build_requirements(self):
self.test_requires("standardprojectsettings/[>=0.1.0]@ultimaker/stable")

def generate(self):
tc = CMakeToolchain(self)
if is_msvc(self):
tc.variables["USE_MSVC_RUNTIME_LIBRARY_DLL"] = not is_msvc_static_runtime(self)
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
tc.generate()

tc = CMakeDeps(self)
tc.generate()

tc = VirtualBuildEnv(self)
tc.generate(scope="build")

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, pattern="LICENSE*", dst="licenses", src=self.source_folder)
packager = AutoPackager(self)
packager.run()
3 changes: 1 addition & 2 deletions test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ cmake_policy(SET CMP0091 NEW)
cmake_minimum_required(VERSION 3.20)
project(PackageTest CXX)

include(../cmake/StandardProjectSettings.cmake)

find_package(standardprojectsettings REQUIRED)
find_package(arcus REQUIRED)
find_package(protobuf 3.17.1 REQUIRED)
protobuf_generate_cpp(generated_PROTOBUF_SOURCES generated_PROTOBUF_HEADERS test.proto)
Expand Down
31 changes: 12 additions & 19 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake
from conan.tools.env import VirtualRunEnv
from conans import tools
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake


class ArcusTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def generate(self):
cmake = CMakeDeps(self)
cmake.generate()
def build_requirements(self):
self.test_requires("standardprojectsettings/[>=0.1.0]@ultimaker/stable")
def requirements(self):
self.requires(self.tested_reference_str)
self.requires("protobuf/3.21.4")

venv = VirtualRunEnv(self)
venv.generate()

tc = CMakeToolchain(self, generator = "Ninja")
if self.settings.compiler == "Visual Studio":
tc.blocks["generic_system"].values["generator_platform"] = None
tc.blocks["generic_system"].values["toolset"] = None
tc.generate()
def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def imports(self):
if self.settings.os == "Windows" and not tools.cross_building(self, skip_x64_x86 = True):
self.copy("*.dll", dst=".", src="@bindirs")

def test(self):
if not tools.cross_building(self):
if can_run(self):
ext = ".exe" if self.settings.os == "Windows" else ""
prefix_path = "" if self.settings.os == "Windows" else "./"
self.run(f"{prefix_path}test{ext}", env = "conanrun")

0 comments on commit d124a92

Please sign in to comment.