Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geographiclib: conan v2 support #12264

Merged
merged 4 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions recipes/geographiclib/all/CMakeLists.txt

This file was deleted.

15 changes: 14 additions & 1 deletion recipes/geographiclib/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
116 changes: 56 additions & 60 deletions recipes/geographiclib/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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":
Expand All @@ -52,62 +44,41 @@ 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(".")]
lv2 = [int(v) for v in v2.split(".")]
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):
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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

13 changes: 5 additions & 8 deletions recipes/geographiclib/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
18 changes: 13 additions & 5 deletions recipes/geographiclib/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
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)
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)
if not cross_building(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
14 changes: 14 additions & 0 deletions recipes/geographiclib/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
18 changes: 18 additions & 0 deletions recipes/geographiclib/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)