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

Improve the comments in the header-only template #14875

Merged
Changes from all commits
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
48 changes: 27 additions & 21 deletions docs/package_templates/header_only/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@ class PackageConan(ConanFile):
name = "package"
description = "short description"
# Use short name only, conform to SPDX License List: https://spdx.org/licenses/
# In case not listed there, use "LicenseRef-<license-file-name>"
# In case it's not listed there, use "LicenseRef-<license-file-name>"
license = ""
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/project/package"
# no "conan" and project name in topics. Use topics from the upstream listed on GH
# Keep 'hearder-only' as topic
# Do not put "conan" nor the project name in topics. Use topics from the upstream listed on GH
# Keep 'header-only' as topic
topics = ("topic1", "topic2", "topic3", "header-only")
settings = "os", "arch", "compiler", "build_type" # even for header only
no_copy_source = True # do not copy sources to build folder for header only projects, unless, need to apply patches
# Keep these or explain why it's not required for this particular case
settings = "os", "arch", "compiler", "build_type"
# Do not copy sources to build folder for header only projects, unless you need to apply patches
no_copy_source = True

@property
def _min_cppstd(self):
return 14

# in case the project requires C++14/17/20/... the minimum compiler version should be listed
# In case the project requires C++14/17/20/... the minimum compiler version should be listed
@property
def _compilers_minimum_version(self):
return {
Expand All @@ -39,18 +41,18 @@ def _compilers_minimum_version(self):
"apple-clang": "5.1",
}

# no exports_sources attribute, but export_sources(self) method instead
# this allows finer grain exportation of patches per version
# Use the export_sources(self) method instead of the exports_sources attribute.
# This allows finer grain exportation of patches per version
def export_sources(self):
export_conandata_patches(self)

def layout(self):
# src_folder must use the same source folder name the project
# src_folder must use the same source folder name than the project
basic_layout(self, src_folder="src")

def requirements(self):
# prefer self.requires method instead of requires attribute
# direct dependencies of header only libs are always transitive since they are included in public headers
# Prefer self.requires method instead of requires attribute
# Direct dependencies of header only libs are always transitive since they are included in public headers
self.requires("dependency/0.8.1", transitive_headers=True)

# same package ID for any package
Expand All @@ -59,27 +61,28 @@ def package_id(self):

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
# validate the minimum cpp standard supported when installing the package. For C++ projects only
# Validate the minimum cpp standard supported when installing the package. For C++ projects only
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)
# in case it does not work in another configuration, it should validated here too

# In case this library does not work in some another configuration, it should be validated here too
if self.settings.os == "Windows":
raise ConanInvalidConfiguration(f"{self.ref} can not be used on Windows.")

def source(self):
# download source package and extract to source folder
# Download source package and extract to source folder
get(self, **self.conan_data["sources"][self.version], strip_root=True)

# not mandatory when there is no patch, but will suppress warning message about missing build() method
# Not mandatory when there is no patch, but will suppress warning message about missing build() method
def build(self):
# The attribute no_copy_source should not be used when applying patches in build
apply_conandata_patches(self)

# copy all files to the package folder
# Copy all files to the package folder
def package(self):
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
copy(
Expand All @@ -90,21 +93,24 @@ def package(self):
)

def package_info(self):
# folders not used for header-only
# Folders not used for header-only
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []

# if package has an official FindPACKAGE.cmake listed in https://cmake.org/cmake/help/latest/manual/cmake-modules.7.html#find-modules
# Set these to the appropriate values if the package has an official FindPACKAGE.cmake
# listed in https://cmake.org/cmake/help/latest/manual/cmake-modules.7.html#find-modules
# examples: bzip2, freetype, gdal, icu, libcurl, libjpeg, libpng, libtiff, openssl, sqlite3, zlib...
self.cpp_info.set_property("cmake_module_file_name", "PACKAGE")
self.cpp_info.set_property("cmake_module_target_name", "PACKAGE::PACKAGE")
# if package provides a CMake config file (package-config.cmake or packageConfig.cmake, with package::package target, usually installed in <prefix>/lib/cmake/<package>/)
# Set these to the appropriate values if package provides a CMake config file
# (package-config.cmake or packageConfig.cmake, with package::package target, usually installed in <prefix>/lib/cmake/<package>/)
self.cpp_info.set_property("cmake_file_name", "package")
self.cpp_info.set_property("cmake_target_name", "package::package")
# if package provides a pkgconfig file (package.pc, usually installed in <prefix>/lib/pkgconfig/)
# Set this to the appropriate value if the package provides a pkgconfig file
# (package.pc, usually installed in <prefix>/lib/pkgconfig/)
self.cpp_info.set_property("pkg_config_name", "package")

# If they are needed on Linux, m, pthread and dl are usually needed on FreeBSD too
# Add m, pthread and dl if needed in Linux/FreeBSD
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.extend(["dl", "m", "pthread"])

Expand Down