diff --git a/recipes/geographiclib/all/CMakeLists.txt b/recipes/geographiclib/all/CMakeLists.txt deleted file mode 100644 index c986d294c7547..0000000000000 --- a/recipes/geographiclib/all/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 3.1) -project(cmake_wrapper) - -include(conanbuildinfo.cmake) -conan_basic_setup() - -add_subdirectory("source_subfolder") diff --git a/recipes/geographiclib/all/conandata.yml b/recipes/geographiclib/all/conandata.yml index 187450f754da7..c7a7d43bcf927 100644 --- a/recipes/geographiclib/all/conandata.yml +++ b/recipes/geographiclib/all/conandata.yml @@ -9,6 +9,19 @@ sources: url: "https://sourceforge.net/projects/geographiclib/files/distrib/GeographicLib-1.50.1.tar.gz" sha256: "d1765009e068b8cc5e76957e5d6be45ce6cff08c4aad8e5995e84a28354385f1" patches: + "1.52": + - patch_file: "patches/0002-cmake-minimum-required-1.52.patch" + patch_description: "Add cmake_minimum_required() to top CMakeLists" + patch_type: "backport" + patch_source: "https://github.com/geographiclib/geographiclib/commit/d9ca6c6ec0b721326b9a690eee259eac643b927f" + "1.51": + - patch_file: "patches/0002-cmake-minimum-required-1.51.patch" + patch_description: "Add cmake_minimum_required() to top CMakeLists" + patch_type: "backport" + patch_source: "https://github.com/geographiclib/geographiclib/commit/d9ca6c6ec0b721326b9a690eee259eac643b927f" "1.50.1": - patch_file: "patches/0001-streamoff.patch" - base_path: "source_subfolder" + - patch_file: "patches/0002-cmake-minimum-required-1.50.1.patch" + patch_description: "Add cmake_minimum_required() to top CMakeLists" + patch_type: "backport" + patch_source: "https://github.com/geographiclib/geographiclib/commit/d9ca6c6ec0b721326b9a690eee259eac643b927f" diff --git a/recipes/geographiclib/all/conanfile.py b/recipes/geographiclib/all/conanfile.py index 76fb638dfbf33..39ad5c7f95f2a 100644 --- a/recipes/geographiclib/all/conanfile.py +++ b/recipes/geographiclib/all/conanfile.py @@ -1,8 +1,12 @@ -from conans import ConanFile, CMake, tools -from conans.errors import ConanInvalidConfiguration +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import apply_conandata_patches, collect_libs, copy, get, replace_in_file, rm, rmdir +from conan.tools.scm import Version import os -required_conan_version = ">=1.43.0" +required_conan_version = ">=1.50.0" class GeographiclibConan(ConanFile): @@ -27,21 +31,9 @@ class GeographiclibConan(ConanFile): "tools": True, } - generators = "cmake" - _cmake = None - - @property - def _source_subfolder(self): - return "source_subfolder" - - @property - def _build_subfolder(self): - return "build_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"]) + 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": @@ -52,19 +44,19 @@ def configure(self): del self.options.fPIC @property - def _min_compiler_version_default_cxx11(self): + def _compilers_minimum_version(self): # Minimum compiler version having C++11 math functions return { "apple-clang": "3.3", "gcc": "4.9", "clang": "6", - "Visual Studio": "14", # guess - }.get(str(self.settings.compiler), False) + "Visual Studio": "14", # guess + } def validate(self): - if tools.Version(self.version) >= "1.51": - if self.settings.compiler.get_safe("cppstd"): - tools.check_min_cppstd(self, 11) + if Version(self.version) >= "1.51": + if self.info.settings.compiler.cppstd: + check_min_cppstd(self, 11) def lazy_lt_semver(v1, v2): lv1 = [int(v) for v in v1.split(".")] @@ -72,42 +64,21 @@ def lazy_lt_semver(v1, v2): min_length = min(len(lv1), len(lv2)) return lv1[:min_length] < lv2[:min_length] - minimum_version = self._min_compiler_version_default_cxx11 - if not minimum_version: - self.output.warn("geographiclib {} requires C++11 math functions. Your compiler is unknown. Assuming it supports this feature.".format(self.version)) - elif lazy_lt_semver(str(self.settings.compiler.version), minimum_version): + minimum_version = self._compilers_minimum_version.get(str(self.info.settings.compiler), False) + if minimum_version and lazy_lt_semver(str(self.info.settings.compiler.version), minimum_version): raise ConanInvalidConfiguration("geographiclib {} requires C++11 math functions, which your compiler does not support.".format(self.version)) - if self.options.precision not in ["float", "double"]: + if self.info.options.precision not in ["float", "double"]: # FIXME: add support for extended, quadruple and variable precisions # (may require external libs: boost multiprecision for quadruple, mpfr for variable) raise ConanInvalidConfiguration("extended, quadruple and variable precisions not yet supported in this recipe") - def source(self): - tools.get(**self.conan_data["sources"][self.version], - destination=self._source_subfolder, strip_root=True) - - def _patch_sources(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) - cmakelists = os.path.join(self._source_subfolder, "CMakeLists.txt") - # it does not work on Windows but is not needed - tools.replace_in_file(cmakelists, "add_subdirectory (js)", "") - # Don't install system libs - tools.replace_in_file(cmakelists, "include (InstallRequiredSystemLibraries)", "") - # Don't build tools if asked - if not self.options.tools: - tools.replace_in_file(cmakelists, "add_subdirectory (tools)", "") - tools.replace_in_file(os.path.join(self._source_subfolder, "cmake", "CMakeLists.txt"), - "${TOOLS}", "") + def layout(self): + cmake_layout(self, src_folder="src") - def _configure_cmake(self): - if not self._cmake: - self._cmake = CMake(self) - self._cmake.definitions["GEOGRAPHICLIB_LIB_TYPE"] = "SHARED" if self.options.shared else "STATIC" - self._cmake.definitions["GEOGRAPHICLIB_PRECISION"] = self._cmake_option_precision - self._cmake.configure(build_folder=self._build_subfolder) - return self._cmake + def source(self): + get(self, **self.conan_data["sources"][self.version], + destination=self.source_folder, strip_root=True) @property def _cmake_option_precision(self): @@ -119,24 +90,49 @@ def _cmake_option_precision(self): "variable": 5, }.get(str(self.options.precision)) + def generate(self): + tc = CMakeToolchain(self) + tc.variables["GEOGRAPHICLIB_LIB_TYPE"] = "SHARED" if self.options.shared else "STATIC" + tc.variables["GEOGRAPHICLIB_PRECISION"] = self._cmake_option_precision + tc.generate() + + def _patch_sources(self): + apply_conandata_patches(self) + cmakelists = os.path.join(self.source_folder, "CMakeLists.txt") + # it does not work on Windows but is not needed + replace_in_file(self, cmakelists, "add_subdirectory (js)", "") + # Don't install system libs + replace_in_file(self, cmakelists, "include (InstallRequiredSystemLibraries)", "") + # Don't build tools if asked + if not self.options.tools: + replace_in_file(self, cmakelists, "add_subdirectory (tools)", "") + replace_in_file(self, os.path.join(self.source_folder, "cmake", "CMakeLists.txt"), + "${TOOLS}", "") + def build(self): self._patch_sources() - cmake = self._configure_cmake() + cmake = CMake(self) + cmake.configure() cmake.build() def package(self): - self.copy(pattern="LICENSE.txt", dst="licenses", src=self._source_subfolder) - cmake = self._configure_cmake() + copy(self, "LICENSE.txt", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) cmake.install() - for folder in ["share", os.path.join("lib", "python"), os.path.join("lib", "pkgconfig"), - os.path.join("lib", "cmake"), "sbin", "python", "matlab", "doc", "cmake"]: - tools.rmdir(os.path.join(os.path.join(self.package_folder, folder))) - tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "*.pdb") + for folder in [ + "share", "sbin", "python", "matlab", "doc", "cmake", + os.path.join("lib", "python"), + os.path.join("lib", "pkgconfig"), + os.path.join("lib", "cmake"), + ]: + rmdir(self, os.path.join(os.path.join(self.package_folder, folder))) + rm(self, "*.pdb", os.path.join(self.package_folder, "bin")) def package_info(self): self.cpp_info.set_property("cmake_file_name", "geographiclib") self.cpp_info.set_property("cmake_target_name", "GeographicLib::GeographicLib") - self.cpp_info.libs = tools.collect_libs(self) + self.cpp_info.set_property("pkg_config_name", "geographiclib") + self.cpp_info.libs = collect_libs(self) self.cpp_info.defines.append("GEOGRAPHICLIB_SHARED_LIB={}".format("1" if self.options.shared else "0")) if self.options.tools: diff --git a/recipes/geographiclib/all/patches/0002-cmake-minimum-required-1.50.1.patch b/recipes/geographiclib/all/patches/0002-cmake-minimum-required-1.50.1.patch new file mode 100644 index 0000000000000..b288ab87c7f7a --- /dev/null +++ b/recipes/geographiclib/all/patches/0002-cmake-minimum-required-1.50.1.patch @@ -0,0 +1,15 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1,3 +1,4 @@ ++cmake_minimum_required (VERSION 3.13.0) + project (GeographicLib) + + # Version information +@@ -47,7 +48,6 @@ set (LIBVERSION_BUILD 19.0.1) + string (TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER) + string (TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER) + +-cmake_minimum_required (VERSION 3.1.0) # This version was released 2014-12-15 + + # User-settable variables + diff --git a/recipes/geographiclib/all/patches/0002-cmake-minimum-required-1.51.patch b/recipes/geographiclib/all/patches/0002-cmake-minimum-required-1.51.patch new file mode 100644 index 0000000000000..1919e3213be84 --- /dev/null +++ b/recipes/geographiclib/all/patches/0002-cmake-minimum-required-1.51.patch @@ -0,0 +1,15 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1,3 +1,4 @@ ++cmake_minimum_required (VERSION 3.13.0) + project (GeographicLib) + + # Version information +@@ -47,7 +48,6 @@ set (LIBVERSION_BUILD 19.1.0) + string (TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER) + string (TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER) + +-cmake_minimum_required (VERSION 3.7.0) # This version was released 2016-11-11 + + # User-settable variables + diff --git a/recipes/geographiclib/all/patches/0002-cmake-minimum-required-1.52.patch b/recipes/geographiclib/all/patches/0002-cmake-minimum-required-1.52.patch new file mode 100644 index 0000000000000..7f25113816c11 --- /dev/null +++ b/recipes/geographiclib/all/patches/0002-cmake-minimum-required-1.52.patch @@ -0,0 +1,15 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1,3 +1,4 @@ ++cmake_minimum_required (VERSION 3.13.0) + project (GeographicLib) + + # Version information +@@ -47,7 +48,6 @@ set (LIBVERSION_BUILD 19.2.0) + string (TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER) + string (TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER) + +-cmake_minimum_required (VERSION 3.7.0) # This version was released 2016-11-11 + + # User-settable variables + diff --git a/recipes/geographiclib/all/test_package/CMakeLists.txt b/recipes/geographiclib/all/test_package/CMakeLists.txt index 1b9ac27dd343a..91e2ed38f5138 100644 --- a/recipes/geographiclib/all/test_package/CMakeLists.txt +++ b/recipes/geographiclib/all/test_package/CMakeLists.txt @@ -1,14 +1,11 @@ -cmake_minimum_required(VERSION 3.1) -project(test_package CXX) +cmake_minimum_required(VERSION 3.8) +project(test_package LANGUAGES CXX) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - -find_package(geographiclib CONFIG REQUIRED) +find_package(geographiclib REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) -target_link_libraries(${PROJECT_NAME} GeographicLib::GeographicLib) +target_link_libraries(${PROJECT_NAME} PRIVATE GeographicLib::GeographicLib) if(geographiclib_VERSION VERSION_GREATER_EQUAL "1.51") - set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) + target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) endif() diff --git a/recipes/geographiclib/all/test_package/conanfile.py b/recipes/geographiclib/all/test_package/conanfile.py index 38f4483872d47..3a8c6c5442b33 100644 --- a/recipes/geographiclib/all/test_package/conanfile.py +++ b/recipes/geographiclib/all/test_package/conanfile.py @@ -1,10 +1,18 @@ -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.build import cross_building +from conan.tools.cmake import CMake, cmake_layout import os class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "cmake", "cmake_find_package_multi" + 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 not cross_building(self): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/geographiclib/all/test_v1_package/CMakeLists.txt b/recipes/geographiclib/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..9164dbad5458a --- /dev/null +++ b/recipes/geographiclib/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.8) +project(test_package LANGUAGES CXX) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +find_package(geographiclib REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} ../test_package/test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE GeographicLib::GeographicLib) + +if(geographiclib_VERSION VERSION_GREATER_EQUAL "1.51") + target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) +endif() diff --git a/recipes/geographiclib/all/test_v1_package/conanfile.py b/recipes/geographiclib/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..75c0cd81d2d2f --- /dev/null +++ b/recipes/geographiclib/all/test_v1_package/conanfile.py @@ -0,0 +1,18 @@ +# pylint: skip-file +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)