From e8e75ed0fa618879679c0f0f772038f33dc8fc49 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Thu, 20 Jul 2023 23:15:59 +0300 Subject: [PATCH 1/8] ignition-tools: migrate to Conan v2 --- recipes/ignition-tools/all/CMakeLists.txt | 9 -- recipes/ignition-tools/all/conandata.yml | 5 +- recipes/ignition-tools/all/conanfile.py | 117 +++++++++++------- .../all/test_package/CMakeLists.txt | 7 +- .../all/test_package/conanfile.py | 30 +++-- .../all/test_package/test_package.cpp | 4 +- .../all/test_v1_package/CMakeLists.txt | 8 ++ .../all/test_v1_package/conanfile.py | 17 +++ 8 files changed, 123 insertions(+), 74 deletions(-) delete mode 100644 recipes/ignition-tools/all/CMakeLists.txt create mode 100644 recipes/ignition-tools/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/ignition-tools/all/test_v1_package/conanfile.py diff --git a/recipes/ignition-tools/all/CMakeLists.txt b/recipes/ignition-tools/all/CMakeLists.txt deleted file mode 100644 index f980aea13cc6d..0000000000000 --- a/recipes/ignition-tools/all/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -cmake_minimum_required(VERSION 3.10.2) -project(cmake_wrapper) - -include(conanbuildinfo.cmake) -conan_basic_setup(KEEP_RPATHS) - -set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) - -add_subdirectory(source_subfolder) diff --git a/recipes/ignition-tools/all/conandata.yml b/recipes/ignition-tools/all/conandata.yml index 8a58ba77dc143..d24204d55510c 100644 --- a/recipes/ignition-tools/all/conandata.yml +++ b/recipes/ignition-tools/all/conandata.yml @@ -1,8 +1,7 @@ sources: "1.4.0": url: "https://github.com/ignitionrobotics/ign-tools/archive/refs/tags/ignition-tools_1.4.0.tar.gz" - sha256: "fa3f7984ebb8f412133ea93368395adce426ae36c715a9f94f9509af7dac3b03" + sha256: "8ceebefcd1977dc2e26beede347a9c06d851b89ec0fd7d5c86126f43a49ac178" patches: "1.4.0": - - base_path: "source_subfolder" - patch_file: "patches/0003-ign-tools-1.4.0-cmake-fixes.patch" + - patch_file: "patches/0003-ign-tools-1.4.0-cmake-fixes.patch" diff --git a/recipes/ignition-tools/all/conanfile.py b/recipes/ignition-tools/all/conanfile.py index ba8d22e6561de..e8e1e684ceff3 100644 --- a/recipes/ignition-tools/all/conanfile.py +++ b/recipes/ignition-tools/all/conanfile.py @@ -1,23 +1,33 @@ import os -from conans import CMake, ConanFile, tools -from conans.errors import ConanInvalidConfiguration -required_conan_version = ">=1.29.1" +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir +from conan.tools.scm import Version + +required_conan_version = ">=1.53.0" class IgnitionToolsConan(ConanFile): name = "ignition-tools" + description = "Provides general purpose classes and functions designed for robotic applications.." license = "Apache-2.0" - homepage = "https://ignitionrobotics.org/libs/tools" url = "https://github.com/conan-io/conan-center-index" - description = "Provides general purpose classes and functions designed for robotic applications.." + homepage = "https://ignitionrobotics.org/libs/tools" topics = ("ignition", "robotics", "tools") - settings = "os", "compiler", "build_type", "arch" - options = {"shared": [True, False], "fPIC": [True, False]} - default_options = {"shared": False, "fPIC": True} - generators = "cmake", "cmake_find_package_multi" - exports_sources = "CMakeLists.txt", "patches/**" - _cmake = None + + package_type = "build-scripts" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } @property def _minimum_cpp_standard(self): @@ -27,14 +37,14 @@ def _minimum_cpp_standard(self): def _minimum_compilers_version(self): return { "Visual Studio": "16", + "msvc": "192", "gcc": "7", "clang": "5", "apple-clang": "10", } - @property - def _source_subfolder(self): - return "source_subfolder" + def export_sources(self): + export_conandata_patches(self) def config_options(self): if self.settings.os == "Windows": @@ -42,64 +52,77 @@ def config_options(self): def configure(self): if self.options.shared: - del self.options.fPIC + self.options.rm_safe("fPIC") + + def layout(self): + cmake_layout(self, src_folder="src") def validate(self): if self.settings.compiler.cppstd: - tools.check_min_cppstd(self, self._minimum_cpp_standard) + check_min_cppstd(self, self._minimum_cpp_standard) min_version = self._minimum_compilers_version.get(str(self.settings.compiler)) if not min_version: - self.output.warn( + self.output.warning( "{} recipe lacks information about the {} compiler support.".format( self.name, self.settings.compiler ) ) else: - if tools.Version(self.settings.compiler.version) < min_version: + if Version(self.settings.compiler.version) < min_version: raise ConanInvalidConfiguration( "{} requires c++17 support. The current compiler {} {} does not support it.".format( - self.name, - self.settings.compiler, - self.settings.compiler.version, + self.name, self.settings.compiler, self.settings.compiler.version ) ) def source(self): - tools.get(**self.conan_data["sources"][self.version],destination=self._source_subfolder, strip_root=True) + get(self, **self.conan_data["sources"][self.version], strip_root=True) - def _configure_cmake(self): - if self._cmake is not None: - return self._cmake - self._cmake = CMake(self) - self._cmake.definitions["BUILD_TESTING"] = False - self._cmake.configure() - return self._cmake + def generate(self): + tc = CMakeToolchain(self) + tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True + tc.variables["BUILD_TESTING"] = False + tc.generate() + tc = CMakeDeps(self) + tc.generate() def build(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) - cmake = self._configure_cmake() + apply_conandata_patches(self) + cmake = CMake(self) + cmake.configure() cmake.build() def package(self): - self.copy("LICENSE", dst="licenses", src=self._source_subfolder) - cmake = self._configure_cmake() + copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + cmake = CMake(self) cmake.install() - tools.rmdir(os.path.join(self.package_folder, "share")) - tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) - tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) + 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")) # Remove MS runtime files for dll_pattern_to_remove in ["concrt*.dll", "msvcp*.dll", "vcruntime*.dll"]: - tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), dll_pattern_to_remove) + rm(self, dll_pattern_to_remove, os.path.join(self.package_folder, "bin"), recursive=True) def package_info(self): - version_major = tools.Version(self.version).major - self.cpp_info.names["cmake_find_package"] = "ignition-tools{}".format(version_major) - self.cpp_info.names["cmake_find_package_multi"] = "ignition-tools{}".format(version_major) - - self.cpp_info.components["libignition-tools"].libs = ["ignition-tools-backward"] - self.cpp_info.components["libignition-tools"].includedirs.append("include/ignition/tools{}".format(version_major)) - self.cpp_info.components["libignition-tools"].names["cmake_find_package"] = "ignition-tools{}".format(version_major) - self.cpp_info.components["libignition-tools"].names["cmake_find_package_multi"] = "ignition-tools{}".format(version_major) - self.cpp_info.components["libignition-tools"].names["pkg_config"] = "ignition-tools{}".format(version_major) + self.cpp_info.includedirs = [] + self.cpp_info.libdirs = [] + self.cpp_info.frameworkdirs = [] + self.cpp_info.bindirs = [] + + version_major = Version(self.version).major + pkg_name = f"ignition-tools{version_major}" + self.cpp_info.set_property("cmake_file_name", pkg_name) + self.cpp_info.set_property("cmake_target_name", f"{pkg_name}::{pkg_name}") + + component = self.cpp_info.components["libignition-tools"] + component.libs = ["ignition-tools-backward"] + component.includedirs.append(f"include/ignition/tools{version_major}") + component.set_property("cmake_target_name", pkg_name) + component.set_property("pkg_config_name", pkg_name) + + # TODO: to remove in conan v2 once cmake_find_package_* generators removed + self.cpp_info.names["cmake_find_package"] = pkg_name + self.cpp_info.names["cmake_find_package_multi"] = pkg_name + component.names["cmake_find_package"] = pkg_name + component.names["cmake_find_package_multi"] = pkg_name diff --git a/recipes/ignition-tools/all/test_package/CMakeLists.txt b/recipes/ignition-tools/all/test_package/CMakeLists.txt index 294e2c5ebc47c..a3968e98e25dd 100644 --- a/recipes/ignition-tools/all/test_package/CMakeLists.txt +++ b/recipes/ignition-tools/all/test_package/CMakeLists.txt @@ -1,8 +1,5 @@ -cmake_minimum_required(VERSION 3.8) -project(test_package) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES CXX) set(IGN_TOOLS_MAJOR_VER "" CACHE STRING "Version of igition-tools") diff --git a/recipes/ignition-tools/all/test_package/conanfile.py b/recipes/ignition-tools/all/test_package/conanfile.py index ad00162038ccc..e75f7677ac5b7 100644 --- a/recipes/ignition-tools/all/test_package/conanfile.py +++ b/recipes/ignition-tools/all/test_package/conanfile.py @@ -1,17 +1,33 @@ -from conans import ConanFile, CMake, tools import os +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain +from conan.tools.scm import Version + + class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake", "cmake_find_package_multi" + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["IGN_TOOLS_MAJOR_VER"] = Version(self.dependencies["ignition-tools"].ref.version).major + tc.generate() def build(self): cmake = CMake(self) - cmake.definitions["IGN_TOOLS_MAJOR_VER"] = tools.Version(self.deps_cpp_info["ignition-tools"].version).major cmake.configure() cmake.build() def test(self): - if not tools.cross_building(self.settings): - bin_path = os.path.join("bin", "test_package") - self.run(bin_path, run_environment=True) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/ignition-tools/all/test_package/test_package.cpp b/recipes/ignition-tools/all/test_package/test_package.cpp index 262e67cc01fba..e7e472dbae28a 100644 --- a/recipes/ignition-tools/all/test_package/test_package.cpp +++ b/recipes/ignition-tools/all/test_package/test_package.cpp @@ -1,7 +1,5 @@ #include - -int main(int argc, char **argv) -{ +int main() { std::cout << "Hello from ignition-tools test_package\n"; } diff --git a/recipes/ignition-tools/all/test_v1_package/CMakeLists.txt b/recipes/ignition-tools/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..91630d79f4abb --- /dev/null +++ b/recipes/ignition-tools/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ + ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/ignition-tools/all/test_v1_package/conanfile.py b/recipes/ignition-tools/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..ad00162038ccc --- /dev/null +++ b/recipes/ignition-tools/all/test_v1_package/conanfile.py @@ -0,0 +1,17 @@ +from conans import ConanFile, CMake, tools +import os + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.definitions["IGN_TOOLS_MAJOR_VER"] = tools.Version(self.deps_cpp_info["ignition-tools"].version).major + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self.settings): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) From 9e694d862f94c6119e048ca266a01089ab6c652e Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Wed, 26 Jul 2023 23:22:45 +0300 Subject: [PATCH 2/8] ignition-tools: restore VirtualRunEnv in test_package --- recipes/ignition-tools/all/test_package/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/ignition-tools/all/test_package/conanfile.py b/recipes/ignition-tools/all/test_package/conanfile.py index e75f7677ac5b7..b1040edb571c8 100644 --- a/recipes/ignition-tools/all/test_package/conanfile.py +++ b/recipes/ignition-tools/all/test_package/conanfile.py @@ -8,7 +8,7 @@ class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "CMakeDeps" + generators = "CMakeDeps", "VirtualRunEnv" test_type = "explicit" def requirements(self): From 13afff6004182ec61131e9109cd40244593ccb4b Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sun, 6 Aug 2023 20:27:10 +0300 Subject: [PATCH 3/8] ignition-tools: improve patching --- recipes/ignition-tools/all/conandata.yml | 3 --- recipes/ignition-tools/all/conanfile.py | 17 +++++++------ .../0001-ign-tools-1.0.0-cmake-fixes.patch | 25 ------------------- .../0002-ign-tools-1.2.0-cmake-fixes.patch | 25 ------------------- .../0003-ign-tools-1.4.0-cmake-fixes.patch | 25 ------------------- 5 files changed, 10 insertions(+), 85 deletions(-) delete mode 100644 recipes/ignition-tools/all/patches/0001-ign-tools-1.0.0-cmake-fixes.patch delete mode 100644 recipes/ignition-tools/all/patches/0002-ign-tools-1.2.0-cmake-fixes.patch delete mode 100644 recipes/ignition-tools/all/patches/0003-ign-tools-1.4.0-cmake-fixes.patch diff --git a/recipes/ignition-tools/all/conandata.yml b/recipes/ignition-tools/all/conandata.yml index d24204d55510c..369fb6e0f8b7f 100644 --- a/recipes/ignition-tools/all/conandata.yml +++ b/recipes/ignition-tools/all/conandata.yml @@ -2,6 +2,3 @@ sources: "1.4.0": url: "https://github.com/ignitionrobotics/ign-tools/archive/refs/tags/ignition-tools_1.4.0.tar.gz" sha256: "8ceebefcd1977dc2e26beede347a9c06d851b89ec0fd7d5c86126f43a49ac178" -patches: - "1.4.0": - - patch_file: "patches/0003-ign-tools-1.4.0-cmake-fixes.patch" diff --git a/recipes/ignition-tools/all/conanfile.py b/recipes/ignition-tools/all/conanfile.py index e8e1e684ceff3..521cbffff8715 100644 --- a/recipes/ignition-tools/all/conanfile.py +++ b/recipes/ignition-tools/all/conanfile.py @@ -4,7 +4,7 @@ from conan.errors import ConanInvalidConfiguration from conan.tools.build import check_min_cppstd from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout -from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir +from conan.tools.files import copy, get, rm, rmdir, replace_in_file from conan.tools.scm import Version required_conan_version = ">=1.53.0" @@ -12,13 +12,13 @@ class IgnitionToolsConan(ConanFile): name = "ignition-tools" - description = "Provides general purpose classes and functions designed for robotic applications.." + description = "Provides general purpose classes and functions designed for robotic applications." license = "Apache-2.0" url = "https://github.com/conan-io/conan-center-index" homepage = "https://ignitionrobotics.org/libs/tools" topics = ("ignition", "robotics", "tools") - package_type = "build-scripts" + package_type = "library" settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], @@ -43,9 +43,6 @@ def _minimum_compilers_version(self): "apple-clang": "10", } - def export_sources(self): - export_conandata_patches(self) - def config_options(self): if self.settings.os == "Windows": del self.options.fPIC @@ -86,8 +83,14 @@ def generate(self): tc = CMakeDeps(self) tc.generate() + def _patch_sources(self): + replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), + "${CMAKE_SOURCE_DIR}", "${PROJECT_SOURCE_DIR}") + replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), + "ADD_DEFINITIONS(-fPIC)", "") + def build(self): - apply_conandata_patches(self) + self._patch_sources() cmake = CMake(self) cmake.configure() cmake.build() diff --git a/recipes/ignition-tools/all/patches/0001-ign-tools-1.0.0-cmake-fixes.patch b/recipes/ignition-tools/all/patches/0001-ign-tools-1.0.0-cmake-fixes.patch deleted file mode 100644 index a02000ed7c157..0000000000000 --- a/recipes/ignition-tools/all/patches/0001-ign-tools-1.0.0-cmake-fixes.patch +++ /dev/null @@ -1,25 +0,0 @@ ---- CMakeLists.txt -+++ CMakeLists.txt -@@ -251,7 +251,7 @@ else (build_errors) - ######################################## - # Make the package config files - configure_file( -- ${CMAKE_SOURCE_DIR}/cmake/pkgconfig/ignition.in -+ ${PROJECT_SOURCE_DIR}/cmake/pkgconfig/ignition.in - ${CMAKE_CURRENT_BINARY_DIR}/cmake/pkgconfig/${PROJECT_NAME_LOWER}.pc @ONLY) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/pkgconfig/${PROJECT_NAME_LOWER}.pc - DESTINATION ${LIB_INSTALL_DIR}/pkgconfig - ---- doc/CMakeLists.txt -+++ doc/CMakeLists.txt -@@ -1,8 +1,8 @@ - find_package(Doxygen) - - if (DOXYGEN_FOUND) -- configure_file(${CMAKE_SOURCE_DIR}/doc/ignition.in -- ${CMAKE_BINARY_DIR}/ignition.dox @ONLY) -+ configure_file(${PROJECT_SOURCE_DIR}/doc/ignition.in -+ ${PROJECT_BINARY_DIR}/ignition.dox @ONLY) - - add_custom_target(doc - diff --git a/recipes/ignition-tools/all/patches/0002-ign-tools-1.2.0-cmake-fixes.patch b/recipes/ignition-tools/all/patches/0002-ign-tools-1.2.0-cmake-fixes.patch deleted file mode 100644 index 301608c99c533..0000000000000 --- a/recipes/ignition-tools/all/patches/0002-ign-tools-1.2.0-cmake-fixes.patch +++ /dev/null @@ -1,25 +0,0 @@ ---- CMakeLists.txt -+++ CMakeLists.txt -@@ -257,7 +257,7 @@ else (build_errors) - "${CMAKE_INSTALL_PREFIX}" - ) - configure_file( -- ${CMAKE_SOURCE_DIR}/cmake/pkgconfig/ignition.in -+ ${PROJECT_SOURCE_DIR}/cmake/pkgconfig/ignition.in - ${CMAKE_CURRENT_BINARY_DIR}/cmake/pkgconfig/${PROJECT_NAME_LOWER}.pc @ONLY) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/pkgconfig/${PROJECT_NAME_LOWER}.pc - DESTINATION ${PC_CONFIG_INSTALL_DIR} - ---- doc/CMakeLists.txt -+++ doc/CMakeLists.txt -@@ -1,8 +1,8 @@ - find_package(Doxygen) - - if (DOXYGEN_FOUND) -- configure_file(${CMAKE_SOURCE_DIR}/doc/ignition.in -- ${CMAKE_BINARY_DIR}/ignition.dox @ONLY) -+ configure_file(${PROJECT_SOURCE_DIR}/doc/ignition.in -+ ${PROJECT_BINARY_DIR}/ignition.dox @ONLY) - - add_custom_target(doc - diff --git a/recipes/ignition-tools/all/patches/0003-ign-tools-1.4.0-cmake-fixes.patch b/recipes/ignition-tools/all/patches/0003-ign-tools-1.4.0-cmake-fixes.patch deleted file mode 100644 index 3e856a0a90956..0000000000000 --- a/recipes/ignition-tools/all/patches/0003-ign-tools-1.4.0-cmake-fixes.patch +++ /dev/null @@ -1,25 +0,0 @@ ---- CMakeLists.txt -+++ CMakeLists.txt -@@ -185,7 +185,7 @@ else (build_errors) - "${CMAKE_INSTALL_PREFIX}" - ) - configure_file( -- ${CMAKE_SOURCE_DIR}/cmake/pkgconfig/ignition.in -+ ${PROJECT_SOURCE_DIR}/cmake/pkgconfig/ignition.in - ${CMAKE_CURRENT_BINARY_DIR}/cmake/pkgconfig/${PROJECT_NAME_LOWER}.pc @ONLY) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/pkgconfig/${PROJECT_NAME_LOWER}.pc - DESTINATION ${PC_CONFIG_INSTALL_DIR} - ---- doc/CMakeLists.txt -+++ doc/CMakeLists.txt -@@ -1,8 +1,8 @@ - find_package(Doxygen) - - if (DOXYGEN_FOUND) -- configure_file(${CMAKE_SOURCE_DIR}/doc/ignition.in -- ${CMAKE_BINARY_DIR}/ignition.dox @ONLY) -+ configure_file(${PROJECT_SOURCE_DIR}/doc/ignition.in -+ ${PROJECT_BINARY_DIR}/ignition.dox @ONLY) - - add_custom_target(doc - From 034798bdf506e17c64aacefe7ed5f5258829280d Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sun, 6 Aug 2023 21:24:24 +0300 Subject: [PATCH 4/8] ignition-tools: set correct package_type, unvendor bacward-cpp --- recipes/ignition-tools/all/conanfile.py | 60 +++++++++++-------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/recipes/ignition-tools/all/conanfile.py b/recipes/ignition-tools/all/conanfile.py index 521cbffff8715..f9d4bead0c7a3 100644 --- a/recipes/ignition-tools/all/conanfile.py +++ b/recipes/ignition-tools/all/conanfile.py @@ -4,7 +4,7 @@ from conan.errors import ConanInvalidConfiguration from conan.tools.build import check_min_cppstd from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout -from conan.tools.files import copy, get, rm, rmdir, replace_in_file +from conan.tools.files import copy, get, rm, rmdir, replace_in_file, load, save from conan.tools.scm import Version required_conan_version = ">=1.53.0" @@ -12,22 +12,14 @@ class IgnitionToolsConan(ConanFile): name = "ignition-tools" - description = "Provides general purpose classes and functions designed for robotic applications." + description = "Ignition entry point for using all the suite of ignition tools." license = "Apache-2.0" url = "https://github.com/conan-io/conan-center-index" homepage = "https://ignitionrobotics.org/libs/tools" topics = ("ignition", "robotics", "tools") - package_type = "library" + package_type = "application" settings = "os", "arch", "compiler", "build_type" - options = { - "shared": [True, False], - "fPIC": [True, False], - } - default_options = { - "shared": False, - "fPIC": True, - } @property def _minimum_cpp_standard(self): @@ -43,33 +35,25 @@ def _minimum_compilers_version(self): "apple-clang": "10", } - def config_options(self): - if self.settings.os == "Windows": - del self.options.fPIC - - def configure(self): - if self.options.shared: - self.options.rm_safe("fPIC") - def layout(self): cmake_layout(self, src_folder="src") + def requirements(self): + self.requires("backward-cpp/1.6") + def validate(self): if self.settings.compiler.cppstd: check_min_cppstd(self, self._minimum_cpp_standard) min_version = self._minimum_compilers_version.get(str(self.settings.compiler)) if not min_version: self.output.warning( - "{} recipe lacks information about the {} compiler support.".format( - self.name, self.settings.compiler - ) + f"{self.name} recipe lacks information about the {self.settings.compiler} compiler support." ) else: if Version(self.settings.compiler.version) < min_version: raise ConanInvalidConfiguration( - "{} requires c++17 support. The current compiler {} {} does not support it.".format( - self.name, self.settings.compiler, self.settings.compiler.version - ) + f"{self.name} requires c++17 support. " + f"The current compiler {self.settings.compiler} {self.settings.compiler.version} does not support it." ) def source(self): @@ -77,6 +61,7 @@ def source(self): def generate(self): tc = CMakeToolchain(self) + tc.cache_variables["USE_SYSTEM_BACKWARDCPP"] = True tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True tc.variables["BUILD_TESTING"] = False tc.generate() @@ -84,10 +69,12 @@ def generate(self): tc.generate() def _patch_sources(self): - replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), - "${CMAKE_SOURCE_DIR}", "${PROJECT_SOURCE_DIR}") - replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), - "ADD_DEFINITIONS(-fPIC)", "") + for cmakelists in self.source_path.rglob("CMakeLists.txt"): + replace_in_file(self, cmakelists, "${CMAKE_SOURCE_DIR}", "${PROJECT_SOURCE_DIR}", strict=False) + replace_in_file(self, cmakelists, "${CMAKE_BINARY_DIR}", "${PROJECT_BINARY_DIR}", strict=False) + # Generating ign.rb fails on Windows, do it outside of CMake in package() instead + replace_in_file(self, os.path.join(self.source_folder, "src", "CMakeLists.txt"), + "# Two steps to create `ign`", "return() #") def build(self): self._patch_sources() @@ -97,8 +84,17 @@ def build(self): def package(self): copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + cmake = CMake(self) cmake.install() + + # Generate ign.rb + ign_rb_content = load(self, os.path.join(self.source_folder, "src", "ign.in")) + ign_rb_content = ign_rb_content.replace("@CMAKE_INSTALL_PREFIX@", self.package_folder.replace("\\", "/")) + ign_rb_content = ign_rb_content.replace("@ENV_PATH_DELIMITER@", os.pathsep) + suffix = ".rb" if self.settings.os == "Windows" else "" + save(self, os.path.join(self.package_folder, "bin", f"ign{suffix}"), ign_rb_content) + 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")) @@ -109,9 +105,6 @@ def package(self): def package_info(self): self.cpp_info.includedirs = [] - self.cpp_info.libdirs = [] - self.cpp_info.frameworkdirs = [] - self.cpp_info.bindirs = [] version_major = Version(self.version).major pkg_name = f"ignition-tools{version_major}" @@ -119,8 +112,9 @@ def package_info(self): self.cpp_info.set_property("cmake_target_name", f"{pkg_name}::{pkg_name}") component = self.cpp_info.components["libignition-tools"] + component.includedirs = [] component.libs = ["ignition-tools-backward"] - component.includedirs.append(f"include/ignition/tools{version_major}") + component.requires = ["backward-cpp::backward-cpp"] component.set_property("cmake_target_name", pkg_name) component.set_property("pkg_config_name", pkg_name) From b675c7bd582622c851a2dc5467377d261762f2d5 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sun, 6 Aug 2023 21:34:27 +0300 Subject: [PATCH 5/8] ignition-tools: apply chmod +x to ign.rb --- recipes/ignition-tools/all/conanfile.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/recipes/ignition-tools/all/conanfile.py b/recipes/ignition-tools/all/conanfile.py index f9d4bead0c7a3..20ea961b272dd 100644 --- a/recipes/ignition-tools/all/conanfile.py +++ b/recipes/ignition-tools/all/conanfile.py @@ -82,6 +82,11 @@ def build(self): cmake.configure() cmake.build() + @staticmethod + def _chmod_plus_x(filename): + if os.name == "posix": + os.chmod(filename, os.stat(filename).st_mode | 0o111) + def package(self): copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) @@ -93,7 +98,9 @@ def package(self): ign_rb_content = ign_rb_content.replace("@CMAKE_INSTALL_PREFIX@", self.package_folder.replace("\\", "/")) ign_rb_content = ign_rb_content.replace("@ENV_PATH_DELIMITER@", os.pathsep) suffix = ".rb" if self.settings.os == "Windows" else "" - save(self, os.path.join(self.package_folder, "bin", f"ign{suffix}"), ign_rb_content) + ign_rb_path = os.path.join(self.package_folder, "bin", f"ign{suffix}") + save(self, ign_rb_path, ign_rb_content) + self._chmod_plus_x(ign_rb_path) rmdir(self, os.path.join(self.package_folder, "share")) rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) From e256ab5c3da5ca43725dd7a44e0e8efe56cecf08 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sun, 6 Aug 2023 21:39:24 +0300 Subject: [PATCH 6/8] ignition-tools: add "gazebo" tag --- recipes/ignition-tools/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/ignition-tools/all/conanfile.py b/recipes/ignition-tools/all/conanfile.py index 20ea961b272dd..e6a5d1fe1b981 100644 --- a/recipes/ignition-tools/all/conanfile.py +++ b/recipes/ignition-tools/all/conanfile.py @@ -16,7 +16,7 @@ class IgnitionToolsConan(ConanFile): license = "Apache-2.0" url = "https://github.com/conan-io/conan-center-index" homepage = "https://ignitionrobotics.org/libs/tools" - topics = ("ignition", "robotics", "tools") + topics = ("ignition", "robotics", "tools", "gazebo") package_type = "application" settings = "os", "arch", "compiler", "build_type" From b418da196af38f6a42c32be4db7c00a9d8e8aec9 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Tue, 16 Jan 2024 14:43:06 +0200 Subject: [PATCH 7/8] ignition-tools: do not export a library, update test_package accordingly --- recipes/ignition-tools/all/conanfile.py | 44 ++++++++----------- .../all/test_package/CMakeLists.txt | 18 -------- .../all/test_package/conanfile.py | 30 ++++--------- .../all/test_package/test_package.cpp | 5 --- .../all/test_v1_package/conanfile.py | 15 +++---- 5 files changed, 32 insertions(+), 80 deletions(-) delete mode 100644 recipes/ignition-tools/all/test_package/CMakeLists.txt delete mode 100644 recipes/ignition-tools/all/test_package/test_package.cpp diff --git a/recipes/ignition-tools/all/conanfile.py b/recipes/ignition-tools/all/conanfile.py index e6a5d1fe1b981..1a952d068e8ed 100644 --- a/recipes/ignition-tools/all/conanfile.py +++ b/recipes/ignition-tools/all/conanfile.py @@ -45,16 +45,17 @@ def validate(self): if self.settings.compiler.cppstd: check_min_cppstd(self, self._minimum_cpp_standard) min_version = self._minimum_compilers_version.get(str(self.settings.compiler)) - if not min_version: - self.output.warning( - f"{self.name} recipe lacks information about the {self.settings.compiler} compiler support." + if min_version and Version(self.settings.compiler.version) < min_version: + raise ConanInvalidConfiguration( + f"{self.name} requires c++17 support. " + f"The current compiler {self.settings.compiler} {self.settings.compiler.version} does not support it." ) - else: - if Version(self.settings.compiler.version) < min_version: - raise ConanInvalidConfiguration( - f"{self.name} requires c++17 support. " - f"The current compiler {self.settings.compiler} {self.settings.compiler.version} does not support it." - ) + + def build_requirements(self): + # FIXME: Ruby is required as a transitive dependency for the `ign` Ruby script + # FIXME: The ign script has additional Ruby dependencies + # self.tool_requires("ruby/3.1.0") + pass def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) @@ -95,6 +96,7 @@ def package(self): # Generate ign.rb ign_rb_content = load(self, os.path.join(self.source_folder, "src", "ign.in")) + # FIXME: this is not relocatable ign_rb_content = ign_rb_content.replace("@CMAKE_INSTALL_PREFIX@", self.package_folder.replace("\\", "/")) ign_rb_content = ign_rb_content.replace("@ENV_PATH_DELIMITER@", os.pathsep) suffix = ".rb" if self.settings.os == "Windows" else "" @@ -112,21 +114,11 @@ def package(self): def package_info(self): self.cpp_info.includedirs = [] + self.cpp_info.libdirs = [] + + # The package builds an ignition-tools-backward wrapper library, + # but it's only meant to be used as a runtime dependency of the ign script - version_major = Version(self.version).major - pkg_name = f"ignition-tools{version_major}" - self.cpp_info.set_property("cmake_file_name", pkg_name) - self.cpp_info.set_property("cmake_target_name", f"{pkg_name}::{pkg_name}") - - component = self.cpp_info.components["libignition-tools"] - component.includedirs = [] - component.libs = ["ignition-tools-backward"] - component.requires = ["backward-cpp::backward-cpp"] - component.set_property("cmake_target_name", pkg_name) - component.set_property("pkg_config_name", pkg_name) - - # TODO: to remove in conan v2 once cmake_find_package_* generators removed - self.cpp_info.names["cmake_find_package"] = pkg_name - self.cpp_info.names["cmake_find_package_multi"] = pkg_name - component.names["cmake_find_package"] = pkg_name - component.names["cmake_find_package_multi"] = pkg_name + # TODO: Legacy, to be removed on Conan 2.0 + bin_folder = os.path.join(self.package_folder, "bin") + self.env_info.PATH.append(bin_folder) diff --git a/recipes/ignition-tools/all/test_package/CMakeLists.txt b/recipes/ignition-tools/all/test_package/CMakeLists.txt deleted file mode 100644 index a3968e98e25dd..0000000000000 --- a/recipes/ignition-tools/all/test_package/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(test_package LANGUAGES CXX) - -set(IGN_TOOLS_MAJOR_VER "" CACHE STRING "Version of igition-tools") - -if(NOT IGN_TOOLS_MAJOR_VER) - message(FATAL_ERROR "IGN_MAJOR_MAJOR_VER not set") -endif() - -find_package(ignition-tools${IGN_TOOLS_MAJOR_VER} REQUIRED CONFIG) - -add_executable(${PROJECT_NAME} test_package.cpp) -target_link_libraries(${PROJECT_NAME} ignition-tools${IGN_TOOLS_MAJOR_VER}::ignition-tools${IGN_TOOLS_MAJOR_VER}) -set_target_properties(${PROJECT_NAME} PROPERTIES - CXX_STANDARD 17 - CXX_STANDARD_REQUIRED ON - CXX_EXTENSIONS ON -) diff --git a/recipes/ignition-tools/all/test_package/conanfile.py b/recipes/ignition-tools/all/test_package/conanfile.py index b1040edb571c8..871b2e239dd5a 100644 --- a/recipes/ignition-tools/all/test_package/conanfile.py +++ b/recipes/ignition-tools/all/test_package/conanfile.py @@ -1,33 +1,21 @@ -import os - from conan import ConanFile -from conan.tools.build import can_run -from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain -from conan.tools.scm import Version +from conan.tools.layout import basic_layout class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "CMakeDeps", "VirtualRunEnv" + generators = "VirtualRunEnv" test_type = "explicit" def requirements(self): - self.requires(self.tested_reference_str) + self.requires(self.tested_reference_str, run=True) def layout(self): - cmake_layout(self) - - def generate(self): - tc = CMakeToolchain(self) - tc.variables["IGN_TOOLS_MAJOR_VER"] = Version(self.dependencies["ignition-tools"].ref.version).major - tc.generate() - - def build(self): - cmake = CMake(self) - cmake.configure() - cmake.build() + basic_layout(self) def test(self): - if can_run(self): - bin_path = os.path.join(self.cpp.build.bindir, "test_package") - self.run(bin_path, env="conanrun") + # FIXME: Can't actually run this since Ruby and required Ruby gems are not set up + if self.settings.os == "Windows": + self.run("where ign", scope="conanrun") + else: + self.run("which ign", scope="conanrun") diff --git a/recipes/ignition-tools/all/test_package/test_package.cpp b/recipes/ignition-tools/all/test_package/test_package.cpp deleted file mode 100644 index e7e472dbae28a..0000000000000 --- a/recipes/ignition-tools/all/test_package/test_package.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include - -int main() { - std::cout << "Hello from ignition-tools test_package\n"; -} diff --git a/recipes/ignition-tools/all/test_v1_package/conanfile.py b/recipes/ignition-tools/all/test_v1_package/conanfile.py index ad00162038ccc..ea88616e34310 100644 --- a/recipes/ignition-tools/all/test_v1_package/conanfile.py +++ b/recipes/ignition-tools/all/test_v1_package/conanfile.py @@ -1,17 +1,12 @@ from conans import ConanFile, CMake, tools -import os class TestPackageConan(ConanFile): settings = "os", "compiler", "build_type", "arch" generators = "cmake", "cmake_find_package_multi" - def build(self): - cmake = CMake(self) - cmake.definitions["IGN_TOOLS_MAJOR_VER"] = tools.Version(self.deps_cpp_info["ignition-tools"].version).major - cmake.configure() - cmake.build() - def test(self): - if not tools.cross_building(self.settings): - bin_path = os.path.join("bin", "test_package") - self.run(bin_path, run_environment=True) + # FIXME: Can't actually run this since Ruby and required Ruby gems are not set up + if self.settings.os == "Windows": + self.run("where ign", run_environment=True) + else: + self.run("which ign", run_environment=True) From 91b5f14972e5b559ebcb5766526387f59d34fcd1 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Wed, 13 Nov 2024 14:13:53 +0200 Subject: [PATCH 8/8] ignition-tools: drop test_v1_package --- .../all/test_v1_package/CMakeLists.txt | 8 -------- .../ignition-tools/all/test_v1_package/conanfile.py | 12 ------------ 2 files changed, 20 deletions(-) delete mode 100644 recipes/ignition-tools/all/test_v1_package/CMakeLists.txt delete mode 100644 recipes/ignition-tools/all/test_v1_package/conanfile.py diff --git a/recipes/ignition-tools/all/test_v1_package/CMakeLists.txt b/recipes/ignition-tools/all/test_v1_package/CMakeLists.txt deleted file mode 100644 index 91630d79f4abb..0000000000000 --- a/recipes/ignition-tools/all/test_v1_package/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(test_package) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ - ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/ignition-tools/all/test_v1_package/conanfile.py b/recipes/ignition-tools/all/test_v1_package/conanfile.py deleted file mode 100644 index ea88616e34310..0000000000000 --- a/recipes/ignition-tools/all/test_v1_package/conanfile.py +++ /dev/null @@ -1,12 +0,0 @@ -from conans import ConanFile, CMake, tools - -class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake", "cmake_find_package_multi" - - def test(self): - # FIXME: Can't actually run this since Ruby and required Ruby gems are not set up - if self.settings.os == "Windows": - self.run("where ign", run_environment=True) - else: - self.run("which ign", run_environment=True)