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 Conan 2.0 compatibility #13739

Merged
merged 41 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8014395
CMake Conan 2.0 compatibility
System-Arch Oct 25, 2022
3279e24
Fix lint errors
System-Arch Oct 25, 2022
312df47
Avoid lint error with Conan 2.0 argument name
System-Arch Oct 25, 2022
3498d3f
Avoid lint error with Conan 2.0 argument name
System-Arch Oct 25, 2022
bb9383d
Removed unused imports
System-Arch Oct 25, 2022
31ab1a3
Handle Conan version disparities
System-Arch Oct 25, 2022
05f13da
Use basic_layout with Autotools
System-Arch Oct 25, 2022
5769d2c
Call AutotoolsDeps generate
System-Arch Oct 25, 2022
b00e0bd
Call CMakeDeps generate
System-Arch Oct 25, 2022
520b6e1
Update imports per suggestioned changes
System-Arch Oct 25, 2022
4be0900
Removed extra space
System-Arch Oct 25, 2022
8a86742
Remove extraneous items
System-Arch Oct 26, 2022
cb56f47
Determine require_version in a version-agnostic manner
System-Arch Nov 2, 2022
fe4cb86
Use Conan 1.53
System-Arch Nov 2, 2022
8154df4
Handle @ in ref
System-Arch Nov 3, 2022
887635c
Fix lint errors
System-Arch Nov 3, 2022
a4b5d3a
Bigger hammer
System-Arch Nov 3, 2022
cede0fe
Remove PATH addition in package_id
System-Arch Nov 3, 2022
b6accd3
Use validate_build instead of validate
System-Arch Nov 3, 2022
8c33609
Moved Mac x86 check to validate() method.
System-Arch Nov 14, 2022
f0fea9e
Bump openssl version
System-Arch Nov 14, 2022
2e008ee
Merge branch 'master' into System-Arch-cmake-1
System-Arch Nov 15, 2022
ed5ef30
Add blank line to trigger CI build
System-Arch Nov 15, 2022
0485ca3
Eliminate use of validate_build()
System-Arch Nov 18, 2022
4713991
Restore use of validate_build()
System-Arch Nov 18, 2022
4354d5e
Merge branch 'master' into System-Arch-cmake-1
System-Arch Nov 28, 2022
e582a53
Removed blank line to trigger CI
System-Arch Nov 29, 2022
be5ffcf
Add blank line to trigger CI
System-Arch Dec 1, 2022
568f04c
Added boostrap options and removed unneeded env. vars
System-Arch Dec 3, 2022
5836bfc
Deal with Conan 1.x vs 2.0 inconsistencies
System-Arch Dec 3, 2022
19f2c05
Fixed lint issue
System-Arch Dec 3, 2022
dd2bdee
Placate linter
System-Arch Dec 3, 2022
58ff30a
Apply suggestions from code review
System-Arch Dec 6, 2022
c9345af
Use save & load for bootstrap args; Use tool_requires in test packages
System-Arch Dec 7, 2022
bb59eb4
Eliminate use of validate_build; Add more settings to test recipes
System-Arch Dec 7, 2022
6b5e6e2
Set PATH in package_info() for v1.x; Lower req. ver. to 1.50
System-Arch Dec 7, 2022
b100df8
Apply suggestions from code review
System-Arch Dec 8, 2022
7fa560a
Added AutotoolsDeps generator; Eliminated can_run() from tests
System-Arch Dec 9, 2022
3bf716f
Correct msvc version
System-Arch Dec 12, 2022
8fa91ae
Use f-strings
System-Arch Dec 12, 2022
182c7d4
Replace VirtualRunEnv with VirtualBuildEnv
System-Arch Jan 11, 2023
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
114 changes: 59 additions & 55 deletions recipes/cmake/3.x.x/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import os
from conan import ConanFile
from conan import ConanFile, conan_version
from conan.tools.files import chdir, copy, rmdir, get, replace_in_file
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
from conan.tools.gnu import AutotoolsToolchain, Autotools
from conan.tools.build import build_jobs, cross_building, check_min_cppstd
from conan.tools.scm import Version
from conan.tools.files import rmdir, get
from conans import tools, AutoToolsBuildEnvironment, CMake
from conan.errors import ConanInvalidConfiguration, ConanException
from conan.errors import ConanInvalidConfiguration
from conan.errors import ConanException
import os

required_conan_version = ">=1.49.0"
required_conan_version = ">=1.52.0"

class CMakeConan(ConanFile):
name = "cmake"
package_type = "application"
System-Arch marked this conversation as resolved.
Show resolved Hide resolved
description = "Conan installer for CMake"
topics = ("cmake", "build", "installer")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/Kitware/CMake"
license = "BSD-3-Clause"
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"

options = {
Expand All @@ -26,9 +29,6 @@ class CMakeConan(ConanFile):
"bootstrap": False,
}

_source_subfolder = "source_subfolder"
_cmake = None

def config_options(self):
if self.settings.os == "Windows":
self.options.with_openssl = False
Expand All @@ -38,15 +38,15 @@ def requirements(self):
self.requires("openssl/1.1.1q")
System-Arch marked this conversation as resolved.
Show resolved Hide resolved

def validate(self):
if self.settings.os == "Macos" and self.settings.arch == "x86":
if self.info.settings.os == "Macos" and self.info.settings.arch == "x86":
System-Arch marked this conversation as resolved.
Show resolved Hide resolved
raise ConanInvalidConfiguration("CMake does not support x86 for macOS")

if self.settings.os == "Windows" and self.options.bootstrap:
if self.info.settings.os == "Windows" and self.info.options.bootstrap:
raise ConanInvalidConfiguration("CMake does not support bootstrapping on Windows")

minimal_cpp_standard = "11"
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, minimal_cpp_standard)
if self.info.settings.get_safe("compiler.cppstd"):
check_min_cppstd(self, minimal_cpp_standard)

minimal_version = {
"gcc": "4.8",
Expand All @@ -55,85 +55,89 @@ def validate(self):
"Visual Studio": "14",
}

compiler = str(self.settings.compiler)
compiler = str(self.info.settings.compiler)
if compiler not in minimal_version:
self.output.warn(
self.output.warning(
"{} recipe lacks information about the {} compiler standard version support".format(self.name, compiler))
System-Arch marked this conversation as resolved.
Show resolved Hide resolved
self.output.warn(
self.output.warning(
"{} requires a compiler that supports at least C++{}".format(self.name, minimal_cpp_standard))
return

version = Version(self.settings.compiler.version)
version = Version(self.info.settings.compiler.version)
if version < minimal_version[compiler]:
raise ConanInvalidConfiguration(
"{} requires a compiler that supports at least C++{}".format(self.name, minimal_cpp_standard))

def layout(self):
cmake_layout(self, src_folder="src")
System-Arch marked this conversation as resolved.
Show resolved Hide resolved

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def _configure_cmake(self):
if not self._cmake:
self._cmake = CMake(self)
def generate(self):
if self.info.options.bootstrap:
tc = AutotoolsToolchain(self)
tc.generate()
System-Arch marked this conversation as resolved.
Show resolved Hide resolved
else:
tc = CMakeToolchain(self)
if not self.settings.compiler.cppstd:
self._cmake.definitions["CMAKE_CXX_STANDARD"] = 11
self._cmake.definitions["CMAKE_BOOTSTRAP"] = False
tc.variables["CMAKE_CXX_STANDARD"] = 11
tc.variables["CMAKE_BOOTSTRAP"] = False
if self.settings.os == "Linux":
self._cmake.definitions["CMAKE_USE_OPENSSL"] = self.options.with_openssl
tc.variables["CMAKE_USE_OPENSSL"] = self.options.with_openssl
if self.options.with_openssl:
self._cmake.definitions["OPENSSL_USE_STATIC_LIBS"] = not self.options["openssl"].shared
if tools.cross_building(self):
self._cmake.definitions["HAVE_POLL_FINE_EXITCODE"] = ''
self._cmake.definitions["HAVE_POLL_FINE_EXITCODE__TRYRUN_OUTPUT"] = ''
self._cmake.configure(source_folder=self._source_subfolder)

return self._cmake
openssl = self.dependencies["openssl"]
tc.variables["OPENSSL_USE_STATIC_LIBS"] = not openssl.options.shared
if cross_building(self):
tc.variables["HAVE_POLL_FINE_EXITCODE"] = ''
tc.variables["HAVE_POLL_FINE_EXITCODE__TRYRUN_OUTPUT"] = ''
tc.generate()
System-Arch marked this conversation as resolved.
Show resolved Hide resolved

def build(self):
if self.options.bootstrap:
with tools.chdir(self._source_subfolder):
self.run(['./bootstrap', '--prefix={}'.format(self.package_folder), '--parallel={}'.format(tools.cpu_count())])
autotools = AutoToolsBuildEnvironment(self)
if self.info.options.bootstrap:
with chdir(self, self.source_folder):
self.run('./bootstrap --prefix="" --parallel={}'.format(build_jobs(self)))
autotools = Autotools(self)
autotools.make()
else:
tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
"project(CMake)",
"project(CMake)\ninclude(\"{}/conanbuildinfo.cmake\")\nconan_basic_setup(NO_OUTPUT_DIRS)".format(
self.install_folder.replace("\\", "/")))
if self.settings.os == "Linux":
tools.replace_in_file(os.path.join(self._source_subfolder, "Utilities", "cmcurl", "CMakeLists.txt"),
replace_in_file(self, os.path.join(self.source_folder, "Utilities", "cmcurl", "CMakeLists.txt"),
"list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})",
"list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES} ${CMAKE_DL_LIBS} pthread)")

cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("Copyright.txt", dst="licenses", src=self._source_subfolder)
copy(self, "Copyright.txt", self.source_folder, os.path.join(self.package_folder, "licenses"), keep_path=False)
if self.options.bootstrap:
with tools.chdir(self._source_subfolder):
autotools = AutoToolsBuildEnvironment(self)
with chdir(self, self.source_folder):
autotools = Autotools(self)
autotools.install()
else:
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
System-Arch marked this conversation as resolved.
Show resolved Hide resolved
cmake.install()
rmdir(self, os.path.join(self.package_folder, "doc"))

def package_id(self):
del self.info.settings.compiler

def package_info(self):
module_version = "{}.{}".format(Version(self.version).major, Version(self.version).minor)

bindir = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bindir))
self.env_info.PATH.append(bindir)
System-Arch marked this conversation as resolved.
Show resolved Hide resolved

self.buildenv_info.prepend_path("CMAKE_ROOT", self.package_folder)
self.env_info.CMAKE_ROOT = self.package_folder
self.runenv_info.define_path("CMAKE_ROOT", self.package_folder)
module_version = "{}.{}".format(Version(self.version).major, Version(self.version).minor)
mod_path = os.path.join(self.package_folder, "share", f"cmake-{module_version}", "Modules")
self.buildenv_info.prepend_path("CMAKE_MODULE_PATH", mod_path)
self.env_info.CMAKE_MODULE_PATH = mod_path
self.runenv_info.define_path("CMAKE_MODULE_PATH", mod_path)
if not os.path.exists(mod_path):
raise ConanException("Module path not found: %s" % mod_path)

self.cpp_info.includedirs = []
System-Arch marked this conversation as resolved.
Show resolved Hide resolved

# TODO remove once conan v2 is the only support and recipes have been migrated
if Version(conan_version).major < 2:
bindir = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bindir))
self.runenv_info.append_path("PATH", bindir)
System-Arch marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 8 additions & 4 deletions recipes/cmake/3.x.x/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from six import StringIO
from conan import ConanFile
from conan import ConanFile, conan_version
from conan.tools.build import can_run
from conan.tools.scm import Version


class TestPackageConan(ConanFile):
Expand All @@ -14,10 +14,14 @@ def requirements(self):
def test(self):
if can_run(self):
System-Arch marked this conversation as resolved.
Show resolved Hide resolved
System-Arch marked this conversation as resolved.
Show resolved Hide resolved
output = StringIO()
self.run("cmake --version", env="conanrun", output=output)
# Third arg to self.run renamed "stdout" in Conan 2.0 but 1.x linter doesn't like it
self.run("cmake --version", output, env="conanrun")
output_str = str(output.getvalue())
self.output.info("Installed version: {}".format(output_str))
require_version = str(self.deps_cpp_info["cmake"].version)
if Version(conan_version).major < 2:
System-Arch marked this conversation as resolved.
Show resolved Hide resolved
require_version = str(self.deps_cpp_info["cmake"].version)
else:
require_version = str(self.dependencies["cmake"].ref.version)
self.output.info("Expected version: {}".format(require_version))
assert_cmake_version = "cmake version %s" % require_version
assert(assert_cmake_version in output_str)