From f594a046e82b910c4406ad7a51480f958185afb5 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Mon, 23 Jan 2023 19:18:56 +0100 Subject: [PATCH] modernize more & few fixes - fix config file name - fix pkgconfig file name - bump iceoryx & openssl - require cmake only if recent version not available on build machine - more elegant removal of vc runtime files --- recipes/cyclonedds/all/conanfile.py | 154 +++++++++--------- .../all/test_package/CMakeLists.txt | 2 +- .../all/test_v1_package/CMakeLists.txt | 11 +- .../all/test_v1_package/conanfile.py | 2 +- 4 files changed, 79 insertions(+), 90 deletions(-) diff --git a/recipes/cyclonedds/all/conanfile.py b/recipes/cyclonedds/all/conanfile.py index 075fb3aa2d0ce..b2c1d4b0e7447 100644 --- a/recipes/cyclonedds/all/conanfile.py +++ b/recipes/cyclonedds/all/conanfile.py @@ -1,11 +1,13 @@ -import os from conan import ConanFile from conan.errors import ConanInvalidConfiguration -from conan.tools import files, build, scm -from conan.tools.microsoft import is_msvc +from conan.tools.build import check_min_cppstd from conan.tools.cmake import CMakeToolchain, CMake, CMakeDeps, cmake_layout +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir +from conan.tools.scm import Version +import os + +required_conan_version = ">=1.53.0" -required_conan_version = ">=1.51.3" class CycloneDDSConan(ConanFile): name = "cyclonedds" @@ -22,42 +24,34 @@ class CycloneDDSConan(ConanFile): "fPIC": [True, False], "with_ssl": [True, False], "with_shm" : [True, False], - "enable_security" : [True, False] + "enable_security" : [True, False], } default_options = { "shared": False, "fPIC": True, "with_ssl": False, "with_shm": False, - "enable_security": False + "enable_security": False, } short_paths = True @property - def _bin_package_folder(self): - return os.path.join(self.package_folder,"bin") - - @property - def _tmp_folder(self): - return os.path.join(self.package_folder,"tmp") - - @property - def _license_folder(self): - return os.path.join(self.package_folder,"licenses") + def _min_cppstd(self): + return "14" @property def _compilers_minimum_version(self): return { "gcc": "7", - "Visual Studio": "16.0", + "Visual Studio": "16", + "msvc": "192", "clang": "7", "apple-clang": "10", } def export_sources(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - files.copy(self,patch["patch_file"],self.recipe_folder, self.export_sources_folder) + export_conandata_patches(self) def config_options(self): if self.settings.os == "Windows": @@ -65,68 +59,70 @@ def config_options(self): def configure(self): if self.options.shared: - try: - del self.options.fPIC - except Exception: - pass - try: - del self.settings.compiler.libcxx - except Exception: - pass - try: - del self.settings.compiler.cppstd - except Exception: - pass + self.options.rm_safe("fPIC") + self.settings.rm_safe("compiler.cppstd") + self.settings.rm_safe("compiler.libcxx") + + def layout(self): + cmake_layout(self,src_folder="src") def requirements(self): if self.options.with_shm: - self.requires("iceoryx/2.0.0") + self.requires("iceoryx/2.0.2") if self.options.with_ssl: - self.requires("openssl/1.1.1q") - - def build_requirements(self): - self.tool_requires("cmake/3.21.7") + self.requires("openssl/1.1.1s") def validate(self): if self.options.enable_security and not self.options.shared: raise ConanInvalidConfiguration(f"{self.ref} currently do not support"\ "static build and security on") - if self.info.settings.compiler.cppstd: - build.check_min_cppstd(self, 14) - minimum_version = self._compilers_minimum_version.get(str(self.info.settings.compiler), False) - if minimum_version and scm.Version(self.info.settings.compiler.version) < minimum_version: - raise ConanInvalidConfiguration(f"{self.ref} is just tested with minimal version "\ - f"{minimum_version} of compiler {self.info.settings.compiler}.") + if self.info.settings.compiler.get_safe("cppstd"): + check_min_cppstd(self, self._min_cppstd) + 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 _cmake_new_enough(self, required_version): + try: + import re + from io import StringIO + output = StringIO() + self.run("cmake --version", output=output) + m = re.search(r"cmake version (\d+\.\d+\.\d+)", output.getvalue()) + return Version(m.group(1)) >= required_version + except: + return False - def source(self): - files.get(self,**self.conan_data["sources"][self.version], strip_root=True, - destination=self.source_folder) + def build_requirements(self): + if not self._cmake_new_enough("3.16"): + self.tool_requires("cmake/3.25.1") - def layout(self): - cmake_layout(self,src_folder="src") + def source(self): + get(self, self,**self.conan_data["sources"][self.version], strip_root=True) def generate(self): - tc = CMakeToolchain(self) # TODO : determine how to do in conan : # - idlc is a code generator that is used as tool (and so not cross compiled) # - other tools like ddsperf is cross compiled for target # - maybe separate package like cyclonedds_idlc - tc.variables["BUILD_IDLC"] = False - tc.variables["BUILD_IDLC_TESTING"] = False - tc.variables["BUILD_DDSPERF"] = False - tc.variables["BUILD_IDLC_TESTING"] = False + tc.variables["BUILD_IDLC"] = False + tc.variables["BUILD_IDLC_TESTING"] = False + tc.variables["BUILD_DDSPERF"] = False + tc.variables["BUILD_IDLC_TESTING"] = False # variables which effects build - tc.variables["ENABLE_SSL"] = self.options.with_ssl - tc.variables["ENABLE_SHM"] = self.options.with_shm - tc.variables["ENABLE_SECURITY"] = self.options.enable_security + tc.variables["ENABLE_SSL"] = self.options.with_ssl + tc.variables["ENABLE_SHM"] = self.options.with_shm + tc.variables["ENABLE_SECURITY"] = self.options.enable_security tc.generate() cd = CMakeDeps(self) cd.generate() def build(self): - files.apply_conandata_patches(self) + apply_conandata_patches(self) cmake = CMake(self) cmake.configure() cmake.build() @@ -134,34 +130,22 @@ def build(self): def package(self): cmake = CMake(self) cmake.install() - files.copy(self, "LICENSE", self.source_folder, self._license_folder) - files.rmdir(self, os.path.join(self.package_folder, "share")) - files.rmdir(self, os.path.join(self.package_folder, "lib","pkgconfig")) - files.rmdir(self, os.path.join(self.package_folder, "lib","cmake")) - - # cyclonedds copies multiple windows dlls to bin folder - # these must be removed and just keep ddsc.dll - if self.settings.os == "Windows": - if self.options.shared: - files.mkdir(self, self._tmp_folder) - files.copy(self, "ddsc.dll", self._bin_package_folder, self._tmp_folder) - files.rmdir(self, self._bin_package_folder) - if self.options.shared: - files.mkdir(self,self._bin_package_folder) - files.copy(self,"ddsc.dll",self._tmp_folder,self._bin_package_folder) - files.rmdir(self, self._tmp_folder) + copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) + rmdir(self, os.path.join(self.package_folder, "share")) + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + if self.settings.os == "Windows" and self.options.shared: + for dll in ("concrt*.dll", "msvcp*.dll", "vcruntime*.dll"): + rm(self, dll, os.path.join(self.package_folder, "bin")) + else: + rmdir(self, os.path.join(self.package_folder, "bin")) def package_info(self): - self.cpp_info.set_property("cmake_file_name", "cyclonedds") - self.cpp_info.filenames["cmake_find_package"] = "cyclonedds" - self.cpp_info.filenames["cmake_find_package_multi"] = "cyclonedds" - self.cpp_info.names["cmake_find_package"] = "CycloneDDS" - self.cpp_info.names["cmake_find_package_multi"] = "CycloneDDS" - self.cpp_info.components["CycloneDDS"].names["cmake_find_package"] = "ddsc" - self.cpp_info.components["CycloneDDS"].names["cmake_find_package_multi"] = "ddsc" + self.cpp_info.set_property("cmake_file_name", "CycloneDDS") + self.cpp_info.set_property("cmake_target_name", "CycloneDDS::ddsc") + self.cpp_info.set_property("pkg_config_name", "CycloneDDS") + # TODO: back to global scope in conan v2 self.cpp_info.components["CycloneDDS"].libs = ["ddsc"] - self.cpp_info.components["CycloneDDS"].set_property("cmake_target_name", - "CycloneDDS::ddsc") requires = [] if self.options.with_shm: requires.append("iceoryx::iceoryx_binding_c") @@ -177,3 +161,11 @@ def package_info(self): "bcrypt", "iphlpapi" ] + + # TODO: to remove in conan v2 + self.cpp_info.names["cmake_find_package"] = "CycloneDDS" + self.cpp_info.names["cmake_find_package_multi"] = "CycloneDDS" + self.cpp_info.components["CycloneDDS"].names["cmake_find_package"] = "ddsc" + self.cpp_info.components["CycloneDDS"].names["cmake_find_package_multi"] = "ddsc" + self.cpp_info.components["CycloneDDS"].set_property("cmake_target_name", "CycloneDDS::ddsc") + self.cpp_info.components["CycloneDDS"].set_property("pkg_config_name", "CycloneDDS") diff --git a/recipes/cyclonedds/all/test_package/CMakeLists.txt b/recipes/cyclonedds/all/test_package/CMakeLists.txt index 9653148f924fa..f30c0b29578a0 100644 --- a/recipes/cyclonedds/all/test_package/CMakeLists.txt +++ b/recipes/cyclonedds/all/test_package/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.8) project(test_package CXX) -find_package(cyclonedds REQUIRED CONFIG) +find_package(CycloneDDS REQUIRED CONFIG) add_executable(test_package test_package.cpp) target_link_libraries(${PROJECT_NAME} PRIVATE CycloneDDS::ddsc) diff --git a/recipes/cyclonedds/all/test_v1_package/CMakeLists.txt b/recipes/cyclonedds/all/test_v1_package/CMakeLists.txt index aa258f41398f0..0d20897301b68 100644 --- a/recipes/cyclonedds/all/test_v1_package/CMakeLists.txt +++ b/recipes/cyclonedds/all/test_v1_package/CMakeLists.txt @@ -1,11 +1,8 @@ -cmake_minimum_required(VERSION 3.8) -project(test_package CXX) +cmake_minimum_required(VERSION 3.1) +project(test_package) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup(TARGETS) -find_package(cyclonedds CONFIG REQUIRED) - -add_executable(${PROJECT_NAME} ../test_package/test_package.cpp) -target_link_libraries(${PROJECT_NAME} PRIVATE CycloneDDS::ddsc) -target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package + ${CMAKE_CURRENT_BINARY_DIR}/test_package) diff --git a/recipes/cyclonedds/all/test_v1_package/conanfile.py b/recipes/cyclonedds/all/test_v1_package/conanfile.py index f7bf754d5a675..1a9e66f7126fc 100644 --- a/recipes/cyclonedds/all/test_v1_package/conanfile.py +++ b/recipes/cyclonedds/all/test_v1_package/conanfile.py @@ -2,7 +2,7 @@ from conans import ConanFile, CMake from conan.tools import build -class CycloneDDSTestConan(ConanFile): +class TestPackageConan(ConanFile): settings = "os", "compiler", "build_type", "arch" generators = ["cmake", "cmake_find_package_multi"]