-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
What is your suggestion?
Right now, when a package wants to generate extra variables for its consumers, it needs to do something like:
diff --git a/recipes/eigen/all/conanfile.py b/recipes/eigen/all/conanfile.py
index c97c160c2..8c9feea21 100644
--- a/recipes/eigen/all/conanfile.py
+++ b/recipes/eigen/all/conanfile.py
@@ -1,6 +1,7 @@
from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout, CMakeToolchain
-from conan.tools.files import apply_conandata_patches, export_conandata_patches, copy, get, rmdir
+from conan.tools.files import apply_conandata_patches, export_conandata_patches, copy, get, rmdir, save
+from conan.tools.scm import Version
import os
required_conan_version = ">=1.52.0"
@@ -59,10 +60,26 @@ class EigenConan(ConanFile):
copy(self, "COPYING.*", self.source_folder, os.path.join(self.package_folder, "licenses"))
rmdir(self, os.path.join(self.package_folder, "share"))
+ save(self, os.path.join(self.package_folder, self._extra_variables_file_rel_path), self._extra_variables_file_content())
+
+ def _extra_variables_file_content(self):
+ version = Version(self.version)
+ return f"""\
+ set (EIGEN3_VERSION_STRING "{self.version}")
+ set (EIGEN3_VERSION_MAJOR "{version.major}")
+ set (EIGEN3_VERSION_MINOR "{version.minor}")
+ set (EIGEN3_VERSION_PATCH "{version.patch}")
+ """
+
+ @property
+ def _extra_variables_file_rel_path(self):
+ return os.path.join("lib", "cmake", f"conan-official-{self.name}-variables.cmake")
+
def package_info(self):
self.cpp_info.set_property("cmake_file_name", "Eigen3")
self.cpp_info.set_property("cmake_target_name", "Eigen3::Eigen")
self.cpp_info.set_property("pkg_config_name", "eigen3")
+ self.cpp_info.set_property("cmake_build_modules", [self._extra_variables_file_rel_path])
# TODO: back to global scope once cmake_find_package* generators removed
self.cpp_info.components["eigen3"].bindirs = []
self.cpp_info.components["eigen3"].libdirs = []
We should think if it makes sense for recipes to be able to specify the variables directly from a property, without needing to use cmake_build_modules
Have you read the CONTRIBUTING guide?
- I've read the CONTRIBUTING guide