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: fix cmake name + add topics + del fPIC option if shared #2349

Merged
merged 3 commits into from Aug 12, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 18 additions & 7 deletions recipes/geographiclib/all/conanfile.py
@@ -1,9 +1,12 @@
from conans import ConanFile, CMake, tools
import os

required_conan_version = ">=1.28.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I apply this to recipes that require 1.26 features? This feature is absolutely priceless. Can there be a hook for this?!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course! But it only works for Conan >=1.28.0. If you use with an older version, Conan will ignore it. However, it's supported in conan.conf since 1.27 (conan-io/conan#7183), but it's global.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A hook won't be used, we think we should not force this feature, we want to see the community adherence first. If in the future we see more and more people we can add a hook, or course.


class GeographiclibConan(ConanFile):
name = "geographiclib"
description = "Convert geographic units and solve geodesic problems"
topics = ("conan", "geographiclib", "geodesic")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://geographiclib.sourceforge.io"
license = "MIT"
Expand All @@ -17,33 +20,38 @@ class GeographiclibConan(ConanFile):
_cmake = None

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

def configure(self):
if self.options.shared:
del self.options.fPIC

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = "GeographicLib-" + self.version
os.rename(extracted_dir, self._source_subfolder)


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_LIB_TYPE"] = "SHARED" if self.options.shared else "STATIC"
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

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)", "")
tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
"add_subdirectory (js)", "")
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy(pattern="LICENSE.txt", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
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"]:
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")))
Expand All @@ -52,7 +60,10 @@ def package(self):
if not item.startswith("Geographic") or item.endswith(".pdb"):
os.remove(os.path.join(self.package_folder, "bin", item))


def package_info(self):
self.cpp_info.filenames["cmake_find_package"] = "geographiclib"
self.cpp_info.filenames["cmake_find_package_multi"] = "geographiclib"
self.cpp_info.names["cmake_find_package"] = "GeographicLib"
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"))
self.cpp_info.defines.append("GEOGRAPHICLIB_SHARED_LIB={}".format("1" if self.options.shared else "0"))
8 changes: 5 additions & 3 deletions recipes/geographiclib/all/test_package/CMakeLists.txt
@@ -1,8 +1,10 @@
cmake_minimum_required(VERSION 3.1)
project(PackageTest CXX)
project(test_package CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(example test_package.cpp)
target_link_libraries(example ${CONAN_LIBS})
find_package(geographiclib CONFIG REQUIRED)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} GeographicLib::GeographicLib)
6 changes: 3 additions & 3 deletions recipes/geographiclib/all/test_package/conanfile.py
@@ -1,9 +1,9 @@
import os
from conans import ConanFile, CMake, tools

class geographiclibTestConan(ConanFile):
class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
Expand All @@ -12,5 +12,5 @@ def build(self):

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "example")
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)