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

[c-ares] Fix cross building #4492

Merged
merged 2 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions recipes/c-ares/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ sources:
"1.14.0":
sha256: 62dd12f0557918f89ad6f5b759f0bf4727174ae9979499f5452c02be38d9d3e8
url: https://github.com/c-ares/c-ares/archive/cares-1_14_0.tar.gz
patches:
"1.14.0":
- patch_file: "patches/option-tools.patch"
base_path: "source_subfolder"
30 changes: 21 additions & 9 deletions recipes/c-ares/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@ class CAresConan(ConanFile):
topics = ("conan", "c-ares", "dns")
homepage = "https://c-ares.haxx.se/"
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
exports_sources = "CMakeLists.txt"
options = {
"shared": [True, False],
"fPIC": [True, False],
"tools": [True, False]
}
default_options = {
"shared": False,
"fPIC": True,
"tools": True
}
exports_sources = ["CMakeLists.txt", "patches/*"]
generators = "cmake"

_cmake = None
Expand Down Expand Up @@ -47,12 +55,15 @@ def _cmake_configure(self):
self._cmake = CMake(self)
self._cmake.definitions["CARES_STATIC"] = not self.options.shared
self._cmake.definitions["CARES_SHARED"] = self.options.shared
self._cmake.definitions["CARES_BUILD_TESTS"] = "OFF"
self._cmake.definitions["CARES_MSVC_STATIC_RUNTIME"] = "OFF"
self._cmake.definitions["CARES_BUILD_TESTS"] = False
self._cmake.definitions["CARES_MSVC_STATIC_RUNTIME"] = False
self._cmake.definitions["CARES_BUILD_TOOLS"] = self.options.tools
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._cmake_configure()
cmake.build()

Expand All @@ -77,9 +88,10 @@ def package_info(self):
self.cpp_info.components["cares"].system_libs.append("rt")
elif self.settings.os == "Windows":
self.cpp_info.components["cares"].system_libs.extend(["ws2_32", "Advapi32"])
elif self.settings.os == "Macos":
elif tools.is_apple_os(self.settings.os):
self.cpp_info.components["cares"].system_libs.append("resolv")

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)
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)
16 changes: 16 additions & 0 deletions recipes/c-ares/all/patches/option-tools.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -670,6 +670,8 @@ SET (CARES_FOUND 1 CACHE INTERNAL "CARES LIBRARY FOUND")
SET (CARES_LIBRARIES ${PROJECT_NAME}::cares CACHE INTERNAL "CARES LIBRARIES")


+OPTION (CARES_BUILD_TOOLS "Build tools" ON)
+IF(CARES_BUILD_TOOLS)
# Build ahost
ADD_EXECUTABLE (ahost ahost.c ${SAMPLESOURCES})
TARGET_COMPILE_DEFINITIONS (ahost PRIVATE HAVE_CONFIG_H=1)
@@ -695,3 +697,4 @@ TARGET_LINK_LIBRARIES (acountry PRIVATE ${PROJECT_NAME})
IF (CARES_INSTALL)
INSTALL (TARGETS acountry ${TARGETS_INST_DEST})
ENDIF ()
+ENDIF()