diff --git a/recipes/cspice/all/CMakeLists.txt b/recipes/cspice/all/CMakeLists.txt index 72fbce3897f3d..8630af1db4d4a 100644 --- a/recipes/cspice/all/CMakeLists.txt +++ b/recipes/cspice/all/CMakeLists.txt @@ -1,12 +1,9 @@ cmake_minimum_required(VERSION 3.7) -project(cspice C) - -include(conanbuildinfo.cmake) -conan_basic_setup(KEEP_RPATHS) +project(cspice LANGUAGES C) include(GNUInstallDirs) -option(BUILD_UTILITIES "Build cspice utilities" ON) +option(CSPICE_BUILD_UTILITIES "Build cspice utilities" ON) add_compile_options( $<$,$>:-Wno-implicit-int> @@ -30,7 +27,7 @@ add_compile_options( $<$,$>:-Wno-error=implicit-function-declaration> ) -set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/source_subfolder/src) +set(SRC_DIR ${CSPICE_SRC_DIR}/src) file(GLOB CSPICE_SRC_FILES ${SRC_DIR}/cspice/*.c) add_library(cspice ${CSPICE_SRC_FILES}) @@ -54,10 +51,10 @@ install( ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) -file(GLOB INCLUDE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/source_subfolder/include/*.h) +file(GLOB INCLUDE_FILES ${CSPICE_SRC_DIR}/include/*.h) install(FILES ${INCLUDE_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -if(BUILD_UTILITIES) +if(CSPICE_BUILD_UTILITIES) # csupport is common to all utilities file(GLOB CSUPPORT_SRC_FILES "${SRC_DIR}/csupport/*.c") add_library(csupport STATIC ${CSUPPORT_SRC_FILES}) diff --git a/recipes/cspice/all/conandata.yml b/recipes/cspice/all/conandata.yml index 40e1197679b19..ed4687777f4ca 100644 --- a/recipes/cspice/all/conandata.yml +++ b/recipes/cspice/all/conandata.yml @@ -115,9 +115,8 @@ sources: patches: "0067": - patch_file: "patches/isatty.patch" - base_path: "source_subfolder" "0066": - patch_file: "patches/isatty.patch" - base_path: "source_subfolder" - - patch_file: "patches/patches20171106.patch" # from https://naif.jpl.nasa.gov/pub/naif/misc/toolkit_N0066_patches - base_path: "source_subfolder" + - patch_file: "patches/patches20171106.patch" + patch_type: "backport" + patch_source: "https://naif.jpl.nasa.gov/pub/naif/misc/toolkit_N0066_patches" diff --git a/recipes/cspice/all/conanfile.py b/recipes/cspice/all/conanfile.py index 752191634f33f..4d9de47239cb0 100644 --- a/recipes/cspice/all/conanfile.py +++ b/recipes/cspice/all/conanfile.py @@ -1,8 +1,10 @@ -from conans import ConanFile, CMake, tools -from conans.errors import ConanInvalidConfiguration +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import apply_conandata_patches, chdir, copy, download, get, load, rename, rmdir, save import os -required_conan_version = ">=1.33.0" +required_conan_version = ">=1.47.0" class CspiceConan(ConanFile): @@ -25,17 +27,10 @@ class CspiceConan(ConanFile): "utilities": True, } - generators = "cmake" - _cmake = None - - @property - def _source_subfolder(self): - return "source_subfolder" - def export_sources(self): - self.copy("CMakeLists.txt") - for patch in self.conan_data.get("patches", {}).get(self.version, []): - self.copy(patch["patch_file"]) + copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder) + for p in self.conan_data.get("patches", {}).get(self.version, []): + copy(self, p["patch_file"], self.recipe_folder, self.export_sources_folder) def config_options(self): if self.settings.os == "Windows": @@ -44,25 +39,31 @@ def config_options(self): def configure(self): if self.options.shared: del self.options.fPIC - del self.settings.compiler.libcxx - del self.settings.compiler.cppstd + try: + del self.settings.compiler.libcxx + except Exception: + pass + try: + del self.settings.compiler.cppstd + except Exception: + pass def validate(self): sources_url_per_triplet = self.conan_data["sources"][self.version] - the_os = self._get_os_or_subsystem() - if the_os not in sources_url_per_triplet: + host_os = self._get_os_or_subsystem() + if host_os not in sources_url_per_triplet: raise ConanInvalidConfiguration( - "cspice N{0} does not support {1}".format(self.version, the_os) + f"cspice N{self.version} does not support {host_os}", ) - compiler = str(self.settings.compiler) - if compiler not in sources_url_per_triplet[the_os]: + compiler = str(self.info.settings.compiler) + if compiler not in sources_url_per_triplet[host_os]: raise ConanInvalidConfiguration( - "cspice N{0} does not support {1} on {2}".format(self.version, compiler, the_os) + f"cspice N{self.version} does not support {compiler} on {host_os}", ) - arch = str(self.settings.arch) - if arch not in sources_url_per_triplet[the_os][compiler]: + arch = str(self.info.settings.arch) + if arch not in sources_url_per_triplet[host_os][compiler]: raise ConanInvalidConfiguration( - "cspice N{0} does not support {1} on {2} {3}".format(self.version, compiler, the_os, arch) + f"cspice N{self.version} does not support {compiler} on {host_os} {arch}", ) def _get_os_or_subsystem(self): @@ -72,47 +73,53 @@ def _get_os_or_subsystem(self): os_or_subsystem = str(self.settings.os) return os_or_subsystem + def layout(self): + cmake_layout(self, src_folder="src") + def source(self): pass - def build(self): - self._get_sources() - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) - cmake = self._configure_cmake() - cmake.build() + def generate(self): + tc = CMakeToolchain(self) + tc.variables["CSPICE_SRC_DIR"] = self.source_folder.replace("\\", "/") + tc.variables["CSPICE_BUILD_UTILITIES"] = self.options.utilities + tc.generate() + + @property + def _parent_source_folder(self): + return os.path.join(self.source_folder, os.pardir) def _get_sources(self): - the_os = self._get_os_or_subsystem() - compiler = str(self.settings.compiler) - arch = str(self.settings.arch) - data = self.conan_data["sources"][self.version][the_os][compiler][arch] - url = data["url"] - if url.endswith(".tar.Z"): # Python doesn't have any module to uncompress .Z files - filename = os.path.basename(url) - tools.download(url, filename, sha256=data["sha256"]) - command = "zcat {} | tar -xf -".format(filename) - self.run(command=command) - os.remove(filename) - else: - tools.get(**data) - tools.rename(self.name, self._source_subfolder) + with chdir(self, self._parent_source_folder): + host_os = self._get_os_or_subsystem() + compiler = str(self.settings.compiler) + arch = str(self.settings.arch) + data = self.conan_data["sources"][self.version][host_os][compiler][arch] + url = data["url"] + if url.endswith(".tar.Z"): # Python doesn't have any module to uncompress .Z files + tarball = os.path.basename(url) + download(self, url, tarball, sha256=data["sha256"]) + self.run(f"zcat {tarball} | tar -xf -") + os.remove(tarball) + else: + get(self, **data) + rmdir(self, self.source_folder) + rename(self, "cspice", os.path.basename(self.source_folder)) - def _configure_cmake(self): - if self._cmake: - return self._cmake - self._cmake = CMake(self) - self._cmake.definitions["BUILD_UTILITIES"] = self.options.utilities - self._cmake.configure() - return self._cmake + def build(self): + self._get_sources() + apply_conandata_patches(self) + cmake = CMake(self) + cmake.configure(build_script_folder=self._parent_source_folder) + cmake.build() def package(self): - tools.save(os.path.join(self.package_folder, "licenses", "LICENSE"), self._extract_license()) - cmake = self._configure_cmake() + save(self, os.path.join(self.package_folder, "licenses", "LICENSE"), self._extract_license()) + cmake = CMake(self) cmake.install() def _extract_license(self): - spiceusr_header = tools.load(os.path.join(self._source_subfolder, "include", "SpiceUsr.h")) + spiceusr_header = load(self, os.path.join(self.source_folder, "include", "SpiceUsr.h")) begin = spiceusr_header.find("-Disclaimer") end = spiceusr_header.find("-Required_Reading", begin) return spiceusr_header[begin:end] @@ -124,5 +131,5 @@ def package_info(self): if self.options.utilities: bin_path = os.path.join(self.package_folder, "bin") - self.output.info("Appending PATH environment variable: {}".format(bin_path)) + self.output.info(f"Appending PATH environment variable: {bin_path}") self.env_info.PATH.append(bin_path) diff --git a/recipes/cspice/all/test_package/CMakeLists.txt b/recipes/cspice/all/test_package/CMakeLists.txt index 7b9b613cbb24a..19e72e03db2a8 100644 --- a/recipes/cspice/all/test_package/CMakeLists.txt +++ b/recipes/cspice/all/test_package/CMakeLists.txt @@ -1,8 +1,7 @@ cmake_minimum_required(VERSION 3.1) -project(test_package C) +project(test_package LANGUAGES C) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() +find_package(cspice REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.c) -target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) +target_link_libraries(${PROJECT_NAME} PRIVATE cspice::cspice) diff --git a/recipes/cspice/all/test_package/conanfile.py b/recipes/cspice/all/test_package/conanfile.py index 5c09494bc67c0..d120a992c06a6 100644 --- a/recipes/cspice/all/test_package/conanfile.py +++ b/recipes/cspice/all/test_package/conanfile.py @@ -1,10 +1,18 @@ -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout import os class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "cmake" + generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) def build(self): cmake = CMake(self) @@ -12,6 +20,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - 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.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/cspice/all/test_v1_package/CMakeLists.txt b/recipes/cspice/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..a8e7e9f7503eb --- /dev/null +++ b/recipes/cspice/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.1) +project(test_package LANGUAGES C) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +find_package(cspice REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} ../test_package/test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE cspice::cspice) diff --git a/recipes/cspice/all/test_v1_package/conanfile.py b/recipes/cspice/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..38f4483872d47 --- /dev/null +++ b/recipes/cspice/all/test_v1_package/conanfile.py @@ -0,0 +1,17 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True)