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: add precision and tools options #4295

Merged
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
78 changes: 62 additions & 16 deletions recipes/geographiclib/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from conans.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.28.0"
required_conan_version = ">=1.29.1"


class GeographiclibConan(ConanFile):
name = "geographiclib"
Expand All @@ -11,22 +12,40 @@ class GeographiclibConan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://geographiclib.sourceforge.io"
license = "MIT"
generators = "cmake"

settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
options = {
"shared": [True, False],
"fPIC": [True, False],
"precision": ["float", "double", "extended", "quadruple", "variable"],
"tools": [True, False]
}
default_options = {
"shared": False,
"fPIC": True,
"precision": "double",
"tools": True
}

exports_sources = ["CMakeLists.txt"]
_source_subfolder = "source_subfolder"
_build_subfolder = "build_subfolder"
generators = "cmake"
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

@property
def _min_compiler_version_default_cxx11(self):
# Minimum compiler version having c++ standard >= 11
# Minimum compiler version having C++11 math functions
return {
"apple-clang": "3.3",
"gcc": "4.9",
Expand All @@ -37,6 +56,7 @@ def _min_compiler_version_default_cxx11(self):
def configure(self):
if self.options.shared:
del self.options.fPIC

if tools.Version(self.version) >= "1.51":
if self.settings.compiler.cppstd:
tools.min_cppstd(self, 11)
Expand All @@ -53,22 +73,48 @@ def lazy_lt_semver(v1, v2):
elif lazy_lt_semver(str(self.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"]:
# 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])
extracted_dir = "GeographicLib-" + self.version
os.rename(extracted_dir, self._source_subfolder)

def _patch_sources(self):
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 _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

@property
def _cmake_option_precision(self):
return {
"float": 1,
"double": 2,
"extended": 3,
"quadruple": 4,
"variable": 5,
}.get(str(self.options.precision))

def build(self):
# it does not work on Windows but is not needed
tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
"add_subdirectory (js)", "")
self._patch_sources()
cmake = self._configure_cmake()
cmake.build()

Expand All @@ -79,12 +125,7 @@ def package(self):
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)))
if self.settings.os == "Linux" or self.settings.os == "Macos":
tools.rmdir(os.path.join(os.path.join(self.package_folder, "bin")))
elif self.settings.os == "Windows":
for item in os.listdir(os.path.join(os.path.join(self.package_folder, "bin"))):
if not item.startswith("Geographic") or item.endswith(".pdb"):
os.remove(os.path.join(self.package_folder, "bin", item))
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "*.pdb")

def package_info(self):
self.cpp_info.filenames["cmake_find_package"] = "geographiclib"
Expand All @@ -93,3 +134,8 @@ def package_info(self):
self.cpp_info.names["cmake_find_package_multi"] = "GeographicLib"
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.defines.append("GEOGRAPHICLIB_SHARED_LIB={}".format("1" if self.options.shared else "0"))

if self.options.tools:
bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bin_path))
self.env_info.PATH.append(bin_path)
8 changes: 4 additions & 4 deletions recipes/geographiclib/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

int main()
{
const GeographicLib::Geodesic& geod = GeographicLib::Geodesic::WGS84();
double lat1 = 40.6, lon1 = -73.8; // JFK Airport
double lat2 = 51.6, lon2 = -0.5; // LHR Airport
double s12;
const GeographicLib::Geodesic& geod = GeographicLib::Geodesic::WGS84();
GeographicLib::Math::real lat1 = 40.6, lon1 = -73.8; // JFK Airport
GeographicLib::Math::real lat2 = 51.6, lon2 = -0.5; // LHR Airport
GeographicLib::Math::real s12;

geod.Inverse(lat1, lon1, lat2, lon2, s12);
std::cout << "The distance from JFK to LHR is " << s12 / 1000 << " km\n";
Expand Down