Skip to content

Commit

Permalink
Merge pull request #1783 from madebr/cmake_compiler
Browse files Browse the repository at this point in the history
cmake: add compiler + remove compiler.version to reduce number of builds
  • Loading branch information
danimtb authored Jul 2, 2020
2 parents 495fdb3 + d8e61fc commit 13adb10
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
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

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

Expand Down

0 comments on commit 13adb10

Please sign in to comment.