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

cmake: add compiler + remove compiler.version to reduce number of builds #1783

Merged
merged 10 commits into from
Jul 2, 2020
11 changes: 0 additions & 11 deletions recipes/cmake/3.x.x/CMakeLists.txt

This file was deleted.

35 changes: 29 additions & 6 deletions recipes/cmake/3.x.x/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from conans import tools, ConanFile, CMake
from conans.tools import Version
from conans.errors import ConanInvalidConfiguration, ConanException


Expand All @@ -11,20 +10,36 @@ class CMakeConan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/Kitware/CMake"
license = "BSD-3-Clause"
exports_sources = ["CMakeLists.txt"]
generators = "cmake"
settings = "os", "arch", "build_type"
settings = "os", "arch", "compiler", "build_type"

options = {
"with_openssl": [True, False, "auto"],
}
default_options = {
"with_openssl": "auto",
}

_source_subfolder = "source_subfolder"
_cmake = None

def _minor_version(self):
return ".".join(str(self.version).split(".")[:2])

@property
def _with_openssl(self):
if self.options.with_openssl == "auto":
return self.settings.os != "Windows"
return self.options.with_openssl

def configure(self):
if self.settings.os == "Macos" and self.settings.arch == "x86":
raise ConanInvalidConfiguration("CMake does not support x86 for macOS")

def requirements(self):
if self._with_openssl:
self.requires("openssl/1.1.1g")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-" + self.version
Expand All @@ -35,12 +50,17 @@ def _configure_cmake(self):
self._cmake = CMake(self)
self._cmake.definitions["CMAKE_BOOTSTRAP"] = False
if self.settings.os == "Linux":
self._cmake.definitions["OPENSSL_USE_STATIC_LIBS"] = True
self._cmake.definitions["CMAKE_EXE_LINKER_FLAGS"] = "-lz"
self._cmake.configure(source_dir=self._source_subfolder)
self._cmake.definitions["CMAKE_USE_OPENSSL"] = self._with_openssl
if self._with_openssl:
self._cmake.definitions["OPENSSL_USE_STATIC_LIBS"] = not self.options["openssl"].shared
self._cmake.configure(source_folder=self._source_subfolder)
return self._cmake

def build(self):
tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
"project(CMake)",
"project(CMake)\ninclude(\"{}/conanbuildinfo.cmake\")\nconan_basic_setup()".format(
self.build_folder.replace("\\", "/")))
if self.settings.os == "Linux":
tools.replace_in_file(os.path.join(self._source_subfolder, "Utilities", "cmcurl", "CMakeLists.txt"),
"list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})",
Expand All @@ -54,6 +74,9 @@ def package(self):
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "doc"))

def package_id(self):
self.info.options.with_openssl = self._with_openssl
uilianries marked this conversation as resolved.
Show resolved Hide resolved

def package_info(self):
minor = self._minor_version()

Expand Down