diff --git a/docs/package_templates/autotools_package/all/conandata.yml b/docs/package_templates/autotools_package/all/conandata.yml index 629a5640adc16..e11d72dbcdc2b 100644 --- a/docs/package_templates/autotools_package/all/conandata.yml +++ b/docs/package_templates/autotools_package/all/conandata.yml @@ -1,17 +1,13 @@ sources: - # Newer versions at the top "1.2.0": url: - "https://mirror1.net/package-1.2.0.tar.gz" - "https://mirror2.net/package-1.2.0.tar.gz" sha256: "________________________________________________________________" "1.1.0": - url: - - "https://mirror1.net/package-1.1.0.tar.gz" - - "https://mirror2.net/package-1.1.0.tar.gz" + url: "https://mirror2.net/package-1.1.0.tar.gz" sha256: "________________________________________________________________" patches: - # Newer versions at the top "1.1.0": - patch_file: "patches/0001-fix-cmake.patch" patch_description: "correct the order of cmake min and project" diff --git a/docs/package_templates/autotools_package/all/conanfile.py b/docs/package_templates/autotools_package/all/conanfile.py index 199bd122132bc..2e92117bd99d7 100644 --- a/docs/package_templates/autotools_package/all/conanfile.py +++ b/docs/package_templates/autotools_package/all/conanfile.py @@ -2,7 +2,7 @@ from conan.errors import ConanInvalidConfiguration from conan.tools.apple import fix_apple_shared_install_name from conan.tools.build import check_min_cppstd, cross_building -from conan.tools.env import Environment, VirtualBuildEnv, VirtualRunEnv +from conan.tools.env import Environment, VirtualRunEnv from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir from conan.tools.gnu import Autotools, AutotoolsDeps, AutotoolsToolchain, PkgConfigDeps from conan.tools.layout import basic_layout @@ -11,7 +11,7 @@ import os -required_conan_version = ">=1.54.0" +required_conan_version = ">=2.0.9" # # INFO: Please, remove all comments before pushing your PR! @@ -22,13 +22,13 @@ 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-" + # In case not listed there, use "DocumentRef-:LicenseRef-" 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 topics = ("topic1", "topic2", "topic3") - # package_type should usually be "library" (if there is shared option) + # package_type should usually be "library", "shared-library" or "static-library" package_type = "library" settings = "os", "arch", "compiler", "build_type" options = { @@ -41,65 +41,44 @@ class PackageConan(ConanFile): "fPIC": True, "with_foobar": True, } - - @property - def _min_cppstd(self): - return 14 - - # in case the project requires C++14/17/20/... the minimum compiler version should be listed - @property - def _compilers_minimum_version(self): - return { - "apple-clang": "10", - "clang": "7", - "gcc": "7", - "msvc": "191", - "Visual Studio": "15", - } + implements = ["auto_shared_fpic"] @property def _settings_build(self): return getattr(self, "settings_build", self.settings) # no exports_sources attribute, but export_sources(self) method instead - # this allows finer grain exportation of patches per version def export_sources(self): export_conandata_patches(self) - def config_options(self): - if self.settings.os == "Windows": - del self.options.fPIC - def configure(self): - if self.options.shared: - self.options.rm_safe("fPIC") - # for plain C projects only + # for plain C projects only. Otherwise, remove this method. self.settings.rm_safe("compiler.cppstd") self.settings.rm_safe("compiler.libcxx") def layout(self): - # src_folder must use the same source folder name the project basic_layout(self, src_folder="src") def requirements(self): - # prefer self.requires method instead of requires attribute + # Prefer self.requirements() method instead of self.requires attribute. self.requires("dependency/0.8.1") if self.options.with_foobar: + # INFO: used in foo/baz.hpp:34 self.requires("foobar/0.1.0") + # Some dependencies on CCI are allowed to use version ranges. + # See https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/dependencies.md#version-ranges + self.requires("openssl/[>=1.1 <4]") def validate(self): # validate the minimum cpp standard supported. Only for C++ projects - if self.settings.compiler.get_safe("cppstd"): - 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." - ) + check_min_cppstd(self, 14) + + # Always comment the reason including the upstream issue. + # INFO: Upstream only support Unix systems. See if self.settings.os not in ["Linux", "FreeBSD", "Macos"]: raise ConanInvalidConfiguration(f"{self.ref} is not supported on {self.settings.os}.") - # if another tool than the compiler or autotools is required to build the project (pkgconf, bison, flex etc) + # if a tool other than the compiler or autotools is required to build the project (pkgconf, bison, flex etc) def build_requirements(self): # only if we have to call autoreconf self.tool_requires("libtool/x.y.z") @@ -118,17 +97,16 @@ def build_requirements(self): def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) + # apply patches listed in conandata.yml + # Using patches is always the last resort to fix issues. If possible, try to fix the issue in the upstream project. + apply_conandata_patches(self) def generate(self): - # inject tool_requires env vars in build scope (not needed if there is no tool_requires) - env = VirtualBuildEnv(self) - env.generate() - # inject requires env vars in build scope + # inject required env vars into the build scope # it's required in case of native build when there is AutotoolsDeps & at least one dependency which might be shared, because configure tries to run a test executable if not cross_building(self): - env = VirtualRunEnv(self) - env.generate(scope="build") - # --fpic is automatically managed when 'fPIC'option is declared + VirtualRunEnv(self).generate(scope="build") + # --fpic is automatically managed when 'fPIC' option is declared # --enable/disable-shared is automatically managed when 'shared' option is declared tc = AutotoolsToolchain(self) # autotools usually uses 'yes' and 'no' to enable/disable options @@ -143,8 +121,10 @@ def yes_no(v): return "yes" if v else "no" tc = PkgConfigDeps(self) tc.generate() # generate dependencies for autotools - tc = AutotoolsDeps(self) - tc.generate() + # some recipes might require a workaround for MSVC (https://github.com/conan-io/conan/issues/12784): + # https://github.com/conan-io/conan-center-index/blob/00ce907b910d0d772f1c73bb699971c141c423c1/recipes/xapian-core/all/conanfile.py#L106-L135 + deps = AutotoolsDeps(self) + deps.generate() # If Visual Studio is supported if is_msvc(self): @@ -158,7 +138,7 @@ def yes_no(v): return "yes" if v else "no" env.define("CC", f"{compile_wrapper} cl -nologo") env.define("CXX", f"{compile_wrapper} cl -nologo") env.define("LD", "link -nologo") - env.define("AR", f"{ar_wrapper} \"lib -nologo\"") + env.define("AR", f"{ar_wrapper} lib") env.define("NM", "dumpbin -symbols") env.define("OBJDUMP", ":") env.define("RANLIB", ":") @@ -166,8 +146,7 @@ def yes_no(v): return "yes" if v else "no" env.vars(self).save_script("conanbuild_msvc") def build(self): - # apply patches listed in conandata.yml - apply_conandata_patches(self) + autotools = Autotools(self) # (optional) run autoreconf to regenerate configure file (libtool should be in tool_requires) autotools.autoreconf() @@ -180,8 +159,9 @@ def package(self): autotools = Autotools(self) autotools.install() - # some files extensions and folders are not allowed. Please, read the FAQs to get informed. + # Some files extensions and folders are not allowed. Please, read the FAQs to get informed. rm(self, "*.la", os.path.join(self.package_folder, "lib")) + # Consider disabling these at first to verify that the package_info() output matches the info exported by the project. rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) rmdir(self, os.path.join(self.package_folder, "share")) @@ -191,7 +171,7 @@ def package(self): def package_info(self): self.cpp_info.libs = ["package_lib"] - # if package provides a pkgconfig file (package.pc, usually installed in /lib/pkgconfig/) + # if the package provides a pkgconfig file (package.pc, usually installed in /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 diff --git a/docs/package_templates/autotools_package/all/test_package/CMakeLists.txt b/docs/package_templates/autotools_package/all/test_package/CMakeLists.txt index 006bc198df7b0..c16ec6d748476 100644 --- a/docs/package_templates/autotools_package/all/test_package/CMakeLists.txt +++ b/docs/package_templates/autotools_package/all/test_package/CMakeLists.txt @@ -1,11 +1,7 @@ cmake_minimum_required(VERSION 3.15) -project(test_package LANGUAGES C) # if the project is pure C -# project(test_package LANGUAGES CXX) # if the project uses c++ +project(test_package LANGUAGES CXX) find_package(package REQUIRED CONFIG) -add_executable(${PROJECT_NAME} test_package.c) -# don't link to ${CONAN_LIBS} or CONAN_PKG::package +add_executable(${PROJECT_NAME} test_package.cpp) target_link_libraries(${PROJECT_NAME} PRIVATE package::package) -# In case the target project need a specific C++ standard -# target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) diff --git a/docs/package_templates/autotools_package/all/test_package/conanfile.py b/docs/package_templates/autotools_package/all/test_package/conanfile.py index 0a808db45f245..2e77b4246fa81 100644 --- a/docs/package_templates/autotools_package/all/test_package/conanfile.py +++ b/docs/package_templates/autotools_package/all/test_package/conanfile.py @@ -4,11 +4,9 @@ import os -# It will become the standard on Conan 2.x class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" - test_type = "explicit" + generators = "CMakeDeps", "CMakeToolchain" def layout(self): cmake_layout(self) diff --git a/docs/package_templates/autotools_package/all/test_package/test_package.c b/docs/package_templates/autotools_package/all/test_package/test_package.c deleted file mode 100644 index f949b7f4a20f4..0000000000000 --- a/docs/package_templates/autotools_package/all/test_package/test_package.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include "package/foobar.h" // Make sure includes work as expected - - -int main(void) { - printf("Create a minimal usage for the target project here.\n"); - printf("Avoid big examples, bigger than 100 lines\n"); - printf("Avoid networking connections.\n"); - printf("Avoid background apps or servers.\n"); - printf("The propose is testing the generated artifacts only.\n"); - - foobar_print_version(); // Make sure to call something that will require linkage for compiled libraries - - return EXIT_SUCCESS; -} diff --git a/docs/package_templates/autotools_package/all/test_package/test_package.cpp b/docs/package_templates/autotools_package/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..2746a345c92f8 --- /dev/null +++ b/docs/package_templates/autotools_package/all/test_package/test_package.cpp @@ -0,0 +1,21 @@ +#include +#include "package/foobar.h" + + +int main(void) { + /* + * TODO: Remove this comment before pushing the testing code; + * + * Create a minimal usage for the target project here; + * Avoid upstream full examples, or code bigger than 15 lines; + * Avoid networking connections; + * Avoid background apps or servers; + * Avoid GUI apps; + * Avoid extra files like images, sounds and other binaries; + * The propose is testing the generated artifacts ONLY; + */ + + foobar_print_version(); // Make sure to call something that will require linkage for compiled libraries + + return EXIT_SUCCESS; +} diff --git a/docs/package_templates/cmake_package/all/conandata.yml b/docs/package_templates/cmake_package/all/conandata.yml index 629a5640adc16..dacc527595b61 100644 --- a/docs/package_templates/cmake_package/all/conandata.yml +++ b/docs/package_templates/cmake_package/all/conandata.yml @@ -1,17 +1,13 @@ sources: - # Newer versions at the top "1.2.0": url: - "https://mirror1.net/package-1.2.0.tar.gz" - "https://mirror2.net/package-1.2.0.tar.gz" sha256: "________________________________________________________________" "1.1.0": - url: - - "https://mirror1.net/package-1.1.0.tar.gz" - - "https://mirror2.net/package-1.1.0.tar.gz" + url: "https://mirror1.net/package-1.1.0.tar.gz" sha256: "________________________________________________________________" patches: - # Newer versions at the top "1.1.0": - patch_file: "patches/0001-fix-cmake.patch" patch_description: "correct the order of cmake min and project" diff --git a/docs/package_templates/cmake_package/all/conanfile.py b/docs/package_templates/cmake_package/all/conanfile.py index 9635abc398ca9..e9c4c869882aa 100644 --- a/docs/package_templates/cmake_package/all/conanfile.py +++ b/docs/package_templates/cmake_package/all/conanfile.py @@ -2,14 +2,12 @@ from conan.errors import ConanInvalidConfiguration from conan.tools.build import check_min_cppstd from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout -from conan.tools.env import VirtualBuildEnv -from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rm, rmdir -from conan.tools.microsoft import check_min_vs, is_msvc, is_msvc_static_runtime -from conan.tools.scm import Version +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir +from conan.tools.microsoft import is_msvc, is_msvc_static_runtime import os -required_conan_version = ">=1.53.0" +required_conan_version = ">=2.0.9" # # INFO: Please, remove all comments before pushing your PR! @@ -20,13 +18,13 @@ 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-" + # In case not listed there, use "DocumentRef-:LicenseRef-" 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 topics = ("topic1", "topic2", "topic3") - # package_type should usually be "library" (if there is shared option) + # package_type should usually be "library", "shared-library" or "static-library" package_type = "library" settings = "os", "arch", "compiler", "build_type" options = { @@ -37,95 +35,64 @@ class PackageConan(ConanFile): "shared": False, "fPIC": True, } - - @property - def _min_cppstd(self): - return 14 - - # in case the project requires C++14/17/20/... the minimum compiler version should be listed - @property - def _compilers_minimum_version(self): - return { - "apple-clang": "10", - "clang": "7", - "gcc": "7", - "msvc": "191", - "Visual Studio": "15", - } + implements = ["auto_shared_fpic"] # no exports_sources attribute, but export_sources(self) method instead - # this allows finer grain exportation of patches per version def export_sources(self): export_conandata_patches(self) - def config_options(self): - if self.settings.os == "Windows": - del self.options.fPIC - def configure(self): - if self.options.shared: - self.options.rm_safe("fPIC") # for plain C projects only self.settings.rm_safe("compiler.cppstd") self.settings.rm_safe("compiler.libcxx") def layout(self): - # src_folder must use the same source folder name the project cmake_layout(self, src_folder="src") def requirements(self): - # prefer self.requires method instead of requires attribute + # Always prefer self.requirements() method instead of self.requires attribute. self.requires("dependency/0.8.1") + if self.options.with_foobar: + # INFO: used in foo/baz.hpp:34 + self.requires("foobar/0.1.0", transitive_headers=True, transitive_libs=True) + # Some dependencies on CCI are allowed to use version ranges. + # See https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/dependencies.md#version-ranges + self.requires("openssl/[>=1.1 <4]") def validate(self): - # validate the minimum cpp standard supported. For C++ projects only - if self.settings.compiler.cppstd: - 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 + # validate the minimum cpp standard supported. For C++ projects only. + check_min_cppstd(self, 14) + # in case it does not work in another configuration, it should be validated here. Always comment the reason including the upstream issue. + # INFO: Upstream does not support DLL: See if is_msvc(self) and self.options.shared: raise ConanInvalidConfiguration(f"{self.ref} can not be built as shared on Visual Studio and msvc.") - # if another tool than the compiler or CMake is required to build the project (pkgconf, bison, flex etc) + # if a tool other than the compiler or CMake newer than 3.15 is required to build the project (pkgconf, bison, flex etc) def build_requirements(self): - self.tool_requires("tool/x.y.z") + self.tool_requires("cmake/[>=3.16 <4]") def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) + # Using patches is always the last resort to fix issues. If possible, try to fix the issue in the upstream project. + apply_conandata_patches(self) def generate(self): - # BUILD_SHARED_LIBS and POSITION_INDEPENDENT_CODE are automatically parsed when self.options.shared or self.options.fPIC exist + # BUILD_SHARED_LIBS and POSITION_INDEPENDENT_CODE are set automatically as tc.variables when self.options.shared or self.options.fPIC exist tc = CMakeToolchain(self) # Boolean values are preferred instead of "ON"/"OFF" - tc.variables["PACKAGE_CUSTOM_DEFINITION"] = True + tc.cache_variables["PACKAGE_BUILD_TESTS"] = False if is_msvc(self): - # don't use self.settings.compiler.runtime - tc.variables["USE_MSVC_RUNTIME_LIBRARY_DLL"] = not is_msvc_static_runtime(self) - # deps_cpp_info, deps_env_info and deps_user_info are no longer used - if self.dependencies["dependency"].options.foobar: - tc.variables["DEPENDENCY_LIBPATH"] = self.dependencies["dependency"].cpp_info.libdirs - # cache_variables should be used sparingly, example setting cmake policies - tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW" - tc.generate() - # In case there are dependencies listed on requirements, CMakeDeps should be used - tc = CMakeDeps(self) + tc.cache_variables["USE_MSVC_RUNTIME_LIBRARY_DLL"] = not is_msvc_static_runtime(self) tc.generate() - # In case there are dependencies listed on build_requirements, VirtualBuildEnv should be used - tc = VirtualBuildEnv(self) - tc.generate(scope="build") - def _patch_sources(self): - apply_conandata_patches(self) - # remove bundled xxhash - rm(self, "whateer.*", os.path.join(self.source_folder, "lib")) - replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "...", "") + # In case there are dependencies listed under requirements, CMakeDeps should be used + deps = CMakeDeps(self) + # You can override the CMake package and target names if they don't match the names used in the project + deps.set_property("fontconfig", "cmake_file_name", "Fontconfig") + deps.set_property("fontconfig", "cmake_target_name", "Fontconfig::Fontconfig") + deps.generate() def build(self): - self._patch_sources() # It can be apply_conandata_patches(self) only in case no more patches are needed cmake = CMake(self) cmake.configure() cmake.build() @@ -135,17 +102,16 @@ def package(self): cmake = CMake(self) cmake.install() - # some files extensions and folders are not allowed. Please, read the FAQs to get informed. + # Some files extensions and folders are not allowed. Please, read the FAQs to get informed. + # Consider disabling these at first to verify that the package_info() output matches the info exported by the project. rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) rmdir(self, os.path.join(self.package_folder, "share")) - rm(self, "*.la", os.path.join(self.package_folder, "lib")) - rm(self, "*.pdb", os.path.join(self.package_folder, "lib")) - rm(self, "*.pdb", os.path.join(self.package_folder, "bin")) + rm(self, "*.pdb", self.package_folder, recursive=True) def package_info(self): + # library name to be packaged self.cpp_info.libs = ["package_lib"] - # if 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") @@ -161,9 +127,3 @@ def package_info(self): self.cpp_info.system_libs.append("m") self.cpp_info.system_libs.append("pthread") self.cpp_info.system_libs.append("dl") - - # TODO: to remove in conan v2 once cmake_find_package_* generators removed - self.cpp_info.filenames["cmake_find_package"] = "PACKAGE" - self.cpp_info.filenames["cmake_find_package_multi"] = "package" - self.cpp_info.names["cmake_find_package"] = "PACKAGE" - self.cpp_info.names["cmake_find_package_multi"] = "package" diff --git a/docs/package_templates/cmake_package/all/test_package/CMakeLists.txt b/docs/package_templates/cmake_package/all/test_package/CMakeLists.txt index b1b30db795a84..c16ec6d748476 100644 --- a/docs/package_templates/cmake_package/all/test_package/CMakeLists.txt +++ b/docs/package_templates/cmake_package/all/test_package/CMakeLists.txt @@ -1,12 +1,7 @@ cmake_minimum_required(VERSION 3.15) - -project(test_package LANGUAGES C) # if the project is pure C -# project(test_package LANGUAGES CXX) # if the project uses c++ +project(test_package LANGUAGES CXX) find_package(package REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) -# don't link to ${CONAN_LIBS} or CONAN_PKG::package target_link_libraries(${PROJECT_NAME} PRIVATE package::package) -# In case the target project need a specific C++ standard -target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) diff --git a/docs/package_templates/cmake_package/all/test_package/conanfile.py b/docs/package_templates/cmake_package/all/test_package/conanfile.py index 02eb5ce439fb4..2e77b4246fa81 100644 --- a/docs/package_templates/cmake_package/all/test_package/conanfile.py +++ b/docs/package_templates/cmake_package/all/test_package/conanfile.py @@ -4,18 +4,16 @@ import os -# It will become the standard on Conan 2.x class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" - test_type = "explicit" - - def requirements(self): - self.requires(self.tested_reference_str) + generators = "CMakeDeps", "CMakeToolchain" def layout(self): cmake_layout(self) + def requirements(self): + self.requires(self.tested_reference_str) + def build(self): cmake = CMake(self) cmake.configure() diff --git a/docs/package_templates/cmake_package/config.yml b/docs/package_templates/cmake_package/all/test_package/config.yml similarity index 68% rename from docs/package_templates/cmake_package/config.yml rename to docs/package_templates/cmake_package/all/test_package/config.yml index a885cbf942a74..d07c95e596619 100644 --- a/docs/package_templates/cmake_package/config.yml +++ b/docs/package_templates/cmake_package/all/test_package/config.yml @@ -1,5 +1,4 @@ versions: - # Newer versions at the top "1.2.0": folder: all "1.1.0": diff --git a/docs/package_templates/cmake_package/all/test_package/test_package.cpp b/docs/package_templates/cmake_package/all/test_package/test_package.cpp index 8e653f30a5476..7480c357a3b18 100644 --- a/docs/package_templates/cmake_package/all/test_package/test_package.cpp +++ b/docs/package_templates/cmake_package/all/test_package/test_package.cpp @@ -1,14 +1,19 @@ #include -#include #include "package/foobar.hpp" int main(void) { - std::cout << "Create a minimal usage for the target project here." << std::endl; - std::cout << "Avoid big examples, bigger than 100 lines" << std::endl; - std::cout << "Avoid networking connections." << std::endl; - std::cout << "Avoid background apps or servers." << std::endl; - std::cout << "The propose is testing the generated artifacts only." << std::endl; + /* + * TODO: Remove this comment before pushing the testing code; + * + * Create a minimal usage for the target project here; + * Avoid upstream full examples, or code bigger than 15 lines; + * Avoid networking connections; + * Avoid background apps or servers; + * Avoid GUI apps; + * Avoid extra files like images, sounds and other binaries; + * The propose is testing the generated artifacts ONLY; + */ foobar.print_version(); diff --git a/docs/package_templates/header_only/all/conandata.yml b/docs/package_templates/header_only/all/conandata.yml index 629a5640adc16..e11d72dbcdc2b 100644 --- a/docs/package_templates/header_only/all/conandata.yml +++ b/docs/package_templates/header_only/all/conandata.yml @@ -1,17 +1,13 @@ sources: - # Newer versions at the top "1.2.0": url: - "https://mirror1.net/package-1.2.0.tar.gz" - "https://mirror2.net/package-1.2.0.tar.gz" sha256: "________________________________________________________________" "1.1.0": - url: - - "https://mirror1.net/package-1.1.0.tar.gz" - - "https://mirror2.net/package-1.1.0.tar.gz" + url: "https://mirror2.net/package-1.1.0.tar.gz" sha256: "________________________________________________________________" patches: - # Newer versions at the top "1.1.0": - patch_file: "patches/0001-fix-cmake.patch" patch_description: "correct the order of cmake min and project" diff --git a/docs/package_templates/header_only/all/conanfile.py b/docs/package_templates/header_only/all/conanfile.py index 6e443b6024963..6615ea677d66a 100644 --- a/docs/package_templates/header_only/all/conanfile.py +++ b/docs/package_templates/header_only/all/conanfile.py @@ -3,101 +3,73 @@ from conan.tools.build import check_min_cppstd from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get from conan.tools.layout import basic_layout -from conan.tools.scm import Version import os -required_conan_version = ">=1.52.0" +required_conan_version = ">=2.0" class PackageConan(ConanFile): name = "package" description = "short description" # Use short name only, conform to SPDX License List: https://spdx.org/licenses/ - # In case it's not listed there, use "LicenseRef-" + # In case it's not listed there, use "DocumentRef-:LicenseRef-" license = "" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/project/package" # Do not put "conan" nor the project name in topics. Use topics from the upstream listed on GH - # Keep 'header-only' as topic + # Include 'header-only' as a topic topics = ("topic1", "topic2", "topic3", "header-only") package_type = "header-library" - # 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 - @property - def _compilers_minimum_version(self): - return { - "apple-clang": "10", - "clang": "7", - "gcc": "7", - "msvc": "191", - "Visual Studio": "15", - } - # 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 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 - self.requires("dependency/0.8.1", transitive_headers=True) + self.requires("dependency/0.8.1") + # Some dependencies on CCI are allowed to use version ranges. + # See https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/dependencies.md#version-ranges + self.requires("openssl/[>=1.1 <4]") # same package ID for any package def package_id(self): self.info.clear() def validate(self): - if self.settings.compiler.get_safe("cppstd"): - # 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 this library does not work in some another configuration, it should be validated here too + # Validate the minimum cpp standard supported when installing the package. For C++ projects only + check_min_cppstd(self, 14) + # in case it does not work in another configuration, it should be validated here. Always comment the reason including the upstream issue. + # INFO: Upstream does not support DLL: See 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 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 - def build(self): # The attribute no_copy_source should not be used when applying patches in build + # Using patches is always the last resort to fix issues. If possible, try to fix the issue in the upstream project. apply_conandata_patches(self) + # Suppress warning message about missing build() method when running Conan + def build(self): + pass + # Copy all files to the package folder def package(self): copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) - copy( - self, - "*.h", - os.path.join(self.source_folder, "include"), - os.path.join(self.package_folder, "include"), - ) + # Prefer CMake.install() or similar in case the upstream offers an official method to install the headers. + copy(self, "*.h", os.path.join(self.source_folder, "include"), os.path.join(self.package_folder, "include")) def package_info(self): - # Folders not used for header-only - self.cpp_info.bindirs = [] - self.cpp_info.libdirs = [] - # 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... @@ -111,12 +83,10 @@ def package_info(self): # (package.pc, usually installed in /lib/pkgconfig/) self.cpp_info.set_property("pkg_config_name", "package") + # Folders not used for header-only + self.cpp_info.bindirs = [] + self.cpp_info.libdirs = [] + # 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"]) - - # TODO: to remove in conan v2 once cmake_find_package_* generators removed - self.cpp_info.filenames["cmake_find_package"] = "PACKAGE" - self.cpp_info.filenames["cmake_find_package_multi"] = "package" - self.cpp_info.names["cmake_find_package"] = "PACKAGE" - self.cpp_info.names["cmake_find_package_multi"] = "package" diff --git a/docs/package_templates/header_only/all/test_package/CMakeLists.txt b/docs/package_templates/header_only/all/test_package/CMakeLists.txt index eaac388e85a10..c16ec6d748476 100644 --- a/docs/package_templates/header_only/all/test_package/CMakeLists.txt +++ b/docs/package_templates/header_only/all/test_package/CMakeLists.txt @@ -1,11 +1,7 @@ cmake_minimum_required(VERSION 3.15) -project(test_package LANGUAGES C) # if the project is pure C -# project(test_package LANGUAGES CXX) # if the project uses c++ +project(test_package LANGUAGES CXX) find_package(package REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) -# don't link to ${CONAN_LIBS} or CONAN_PKG::package target_link_libraries(${PROJECT_NAME} PRIVATE package::package) -# In case the target project need a specific C++ standard -target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) diff --git a/docs/package_templates/header_only/all/test_package/conanfile.py b/docs/package_templates/header_only/all/test_package/conanfile.py index 0a808db45f245..2e77b4246fa81 100644 --- a/docs/package_templates/header_only/all/test_package/conanfile.py +++ b/docs/package_templates/header_only/all/test_package/conanfile.py @@ -4,11 +4,9 @@ import os -# It will become the standard on Conan 2.x class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" - test_type = "explicit" + generators = "CMakeDeps", "CMakeToolchain" def layout(self): cmake_layout(self) diff --git a/docs/package_templates/header_only/all/test_package/test_package.cpp b/docs/package_templates/header_only/all/test_package/test_package.cpp index 8e653f30a5476..7480c357a3b18 100644 --- a/docs/package_templates/header_only/all/test_package/test_package.cpp +++ b/docs/package_templates/header_only/all/test_package/test_package.cpp @@ -1,14 +1,19 @@ #include -#include #include "package/foobar.hpp" int main(void) { - std::cout << "Create a minimal usage for the target project here." << std::endl; - std::cout << "Avoid big examples, bigger than 100 lines" << std::endl; - std::cout << "Avoid networking connections." << std::endl; - std::cout << "Avoid background apps or servers." << std::endl; - std::cout << "The propose is testing the generated artifacts only." << std::endl; + /* + * TODO: Remove this comment before pushing the testing code; + * + * Create a minimal usage for the target project here; + * Avoid upstream full examples, or code bigger than 15 lines; + * Avoid networking connections; + * Avoid background apps or servers; + * Avoid GUI apps; + * Avoid extra files like images, sounds and other binaries; + * The propose is testing the generated artifacts ONLY; + */ foobar.print_version(); diff --git a/docs/package_templates/header_only/config.yml b/docs/package_templates/header_only/config.yml index a885cbf942a74..d07c95e596619 100644 --- a/docs/package_templates/header_only/config.yml +++ b/docs/package_templates/header_only/config.yml @@ -1,5 +1,4 @@ versions: - # Newer versions at the top "1.2.0": folder: all "1.1.0": diff --git a/docs/package_templates/meson_package/all/conandata.yml b/docs/package_templates/meson_package/all/conandata.yml index 629a5640adc16..e11d72dbcdc2b 100644 --- a/docs/package_templates/meson_package/all/conandata.yml +++ b/docs/package_templates/meson_package/all/conandata.yml @@ -1,17 +1,13 @@ sources: - # Newer versions at the top "1.2.0": url: - "https://mirror1.net/package-1.2.0.tar.gz" - "https://mirror2.net/package-1.2.0.tar.gz" sha256: "________________________________________________________________" "1.1.0": - url: - - "https://mirror1.net/package-1.1.0.tar.gz" - - "https://mirror2.net/package-1.1.0.tar.gz" + url: "https://mirror2.net/package-1.1.0.tar.gz" sha256: "________________________________________________________________" patches: - # Newer versions at the top "1.1.0": - patch_file: "patches/0001-fix-cmake.patch" patch_description: "correct the order of cmake min and project" diff --git a/docs/package_templates/meson_package/all/conanfile.py b/docs/package_templates/meson_package/all/conanfile.py index 172c9c688ab22..19ae7296e875f 100644 --- a/docs/package_templates/meson_package/all/conanfile.py +++ b/docs/package_templates/meson_package/all/conanfile.py @@ -2,8 +2,7 @@ from conan.errors import ConanInvalidConfiguration from conan.tools.apple import fix_apple_shared_install_name from conan.tools.build import check_min_cppstd -from conan.tools.env import VirtualBuildEnv -from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rm, rmdir +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir from conan.tools.gnu import PkgConfigDeps from conan.tools.layout import basic_layout from conan.tools.meson import Meson, MesonToolchain @@ -12,7 +11,7 @@ import os -required_conan_version = ">=1.53.0" +required_conan_version = ">=2.0" # # INFO: Please, remove all comments before pushing your PR! @@ -23,13 +22,13 @@ 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-" + # In case not listed there, use "DocumentRef-:LicenseRef-" 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 topics = ("topic1", "topic2", "topic3") - # package_type should usually be "library" (if there is shared option) + # package_type should usually be "library", "shared-library" or "static-library" package_type = "library" settings = "os", "arch", "compiler", "build_type" options = { @@ -42,56 +41,36 @@ class PackageConan(ConanFile): "fPIC": True, "feature": True, } - - @property - def _min_cppstd(self): - return 14 - - # in case the project requires C++14/17/20/... the minimum compiler version should be listed - @property - def _compilers_minimum_version(self): - return { - "apple-clang": "10", - "clang": "7", - "gcc": "7", - "msvc": "191", - "Visual Studio": "15", - } + implements = ["auto_shared_fpic"] # no exports_sources attribute, but export_sources(self) method instead - # this allows finer grain exportation of patches per version def export_sources(self): export_conandata_patches(self) - def config_options(self): - if self.settings.os == "Windows": - del self.options.fPIC - def configure(self): - if self.options.shared: - self.options.rm_safe("fPIC") - # for plain C projects only + # for plain C projects only. Otherwise, remove this method. self.settings.rm_safe("compiler.cppstd") self.settings.rm_safe("compiler.libcxx") def layout(self): - # src_folder must use the same source folder name the project basic_layout(self, src_folder="src") def requirements(self): - # prefer self.requires method instead of requires attribute + # Prefer self.requirements() method instead of self.requires attribute. self.requires("dependency/0.8.1") + if self.options.with_foobar: + # INFO: used in foo/baz.hpp:34 + self.requires("foobar/0.1.0") + # Some dependencies on CCI are allowed to use version ranges. + # See https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/dependencies.md#version-ranges + self.requires("openssl/[>=1.1 <4]") def validate(self): # validate the minimum cpp standard supported. For C++ projects only - if self.settings.compiler.get_safe("cppstd"): - 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 + check_min_cppstd(self, 14) + # in case it does not work in another configuration, it should be validated here too + # Always comment the reason including the upstream issue. + # INFO: Upstream does not support DLL: See if is_msvc(self) and self.info.options.shared: raise ConanInvalidConfiguration(f"{self.ref} can not be built as shared on Visual Studio and msvc.") @@ -105,12 +84,14 @@ def build_requirements(self): def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) + # apply patches listed in conandata.yml + # Using patches is always the last resort to fix issues. If possible, try to fix the issue in the upstream project. + apply_conandata_patches(self) def generate(self): # Meson feature options must be set to "enabled" or "disabled" - feature = lambda option: "enabled" if option else "disabled" - - # default_library and b_staticpic are automatically parsed when self.options.shared and self.options.fpic exist + def feature(v): return "enabled" if v else "disabled" + # default_library and static and fpic are automatically parsed when self.options.shared and self.options.fpic exist # buildtype is automatically parsed for self.settings tc = MesonToolchain(self) # In case need to pass definitions directly to the compiler @@ -122,21 +103,11 @@ def generate(self): # Meson project options may vary their types tc.project_options["tests"] = False tc.generate() - # In case there are dependencies listed on requirements, PkgConfigDeps should be used - tc = PkgConfigDeps(self) - tc.generate() - # In case there are dependencies listed on build_requirements, VirtualBuildEnv should be used - tc = VirtualBuildEnv(self) - tc.generate() - - def _patch_sources(self): - apply_conandata_patches(self) - # remove bundled xxhash - rm(self, "whateer.*", os.path.join(self.source_folder, "lib")) - replace_in_file(self, os.path.join(self.source_folder, "meson.build"), "...", "") + # In case there are dependencies listed under requirements, PkgConfigDeps should be used + deps = PkgConfigDeps(self) + deps.generate() def build(self): - self._patch_sources() # It can be apply_conandata_patches(self) only in case no more patches are needed meson = Meson(self) meson.configure() meson.build() @@ -146,11 +117,11 @@ def package(self): meson = Meson(self) meson.install() - # some files extensions and folders are not allowed. Please, read the FAQs to get informed. + # Some files extensions and folders are not allowed. Please, read the FAQs to get informed. + # Consider disabling these at first to verify that the package_info() output matches the info exported by the project. rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) rmdir(self, os.path.join(self.package_folder, "share")) - rm(self, "*.pdb", os.path.join(self.package_folder, "lib")) - rm(self, "*.pdb", os.path.join(self.package_folder, "bin")) + rm(self, "*.pdb", self.package_folder, recursive=True) # In shared lib/executable files, meson set install_name (macOS) to lib dir absolute path instead of @rpath, it's not relocatable, so fix it fix_apple_shared_install_name(self) diff --git a/docs/package_templates/meson_package/all/test_package/conanfile.py b/docs/package_templates/meson_package/all/test_package/conanfile.py index 3064d349d2d58..577771653eaef 100644 --- a/docs/package_templates/meson_package/all/test_package/conanfile.py +++ b/docs/package_templates/meson_package/all/test_package/conanfile.py @@ -5,11 +5,9 @@ import os -# It will become the standard on Conan 2.x class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "PkgConfigDeps", "MesonToolchain", "VirtualRunEnv", "VirtualBuildEnv" - test_type = "explicit" + generators = "PkgConfigDeps", "MesonToolchain" def layout(self): basic_layout(self) diff --git a/docs/package_templates/meson_package/all/test_package/test_package.cpp b/docs/package_templates/meson_package/all/test_package/test_package.cpp index 315875d954777..7480c357a3b18 100644 --- a/docs/package_templates/meson_package/all/test_package/test_package.cpp +++ b/docs/package_templates/meson_package/all/test_package/test_package.cpp @@ -1,16 +1,19 @@ #include -#include #include "package/foobar.hpp" int main(void) { /* - * Create a minimal usage for the target project here. - * Avoid big examples, bigger than 100 lines. - * Avoid networking connections. - * Avoid background apps or servers. - * The propose is testing the generated artifacts only. - */ + * TODO: Remove this comment before pushing the testing code; + * + * Create a minimal usage for the target project here; + * Avoid upstream full examples, or code bigger than 15 lines; + * Avoid networking connections; + * Avoid background apps or servers; + * Avoid GUI apps; + * Avoid extra files like images, sounds and other binaries; + * The propose is testing the generated artifacts ONLY; + */ foobar.print_version(); diff --git a/docs/package_templates/meson_package/config.yml b/docs/package_templates/meson_package/config.yml index a885cbf942a74..d07c95e596619 100644 --- a/docs/package_templates/meson_package/config.yml +++ b/docs/package_templates/meson_package/config.yml @@ -1,5 +1,4 @@ versions: - # Newer versions at the top "1.2.0": folder: all "1.1.0": diff --git a/docs/package_templates/msbuild_package/all/conandata.yml b/docs/package_templates/msbuild_package/all/conandata.yml index 629a5640adc16..5f2e653489b97 100644 --- a/docs/package_templates/msbuild_package/all/conandata.yml +++ b/docs/package_templates/msbuild_package/all/conandata.yml @@ -1,5 +1,4 @@ sources: - # Newer versions at the top "1.2.0": url: - "https://mirror1.net/package-1.2.0.tar.gz" @@ -11,7 +10,6 @@ sources: - "https://mirror2.net/package-1.1.0.tar.gz" sha256: "________________________________________________________________" patches: - # Newer versions at the top "1.1.0": - patch_file: "patches/0001-fix-cmake.patch" patch_description: "correct the order of cmake min and project" diff --git a/docs/package_templates/msbuild_package/all/conanfile.py b/docs/package_templates/msbuild_package/all/conanfile.py index ca164fc1620f8..900972af0dc8f 100644 --- a/docs/package_templates/msbuild_package/all/conanfile.py +++ b/docs/package_templates/msbuild_package/all/conanfile.py @@ -6,20 +6,20 @@ import os -required_conan_version = ">=1.53.0" +required_conan_version = ">=2.0" 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-" + # In case not listed there, use "DocumentRef-:LicenseRef-" 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 topics = ("topic1", "topic2", "topic3") - # package_type should usually be "library" (if there is shared option) + # package_type should usually be "library", "shared-library" or "static-library" package_type = "library" settings = "os", "arch", "compiler", "build_type" options = { @@ -30,20 +30,14 @@ class PackageConan(ConanFile): "shared": False, "fPIC": True, } + implements = ["auto_shared_fpic"] # no exports_sources attribute, but export_sources(self) method instead - # this allows finer grain exportation of patches per version def export_sources(self): export_conandata_patches(self) - def config_options(self): - if self.settings.os == "Windows": - del self.options.fPIC - def configure(self): - if self.options.shared: - self.options.rm_safe("fPIC") - # for plain C projects only + # for plain C projects only. Otherwise, this method is not needed self.settings.rm_safe("compiler.cppstd") self.settings.rm_safe("compiler.libcxx") @@ -51,11 +45,19 @@ def layout(self): basic_layout(self, src_folder="src") def requirements(self): - # prefer self.requires method instead of requires attribute + # Prefer self.requirements() method instead of self.requires attribute. self.requires("dependency/0.8.1") + if self.options.with_foobar: + # used in foo/baz.hpp:34 + self.requires("foobar/0.1.0") + # A small number of dependencies on CCI are allowed to use version ranges. + # See https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/dependencies.md#version-ranges + self.requires("openssl/[>=1.1 <4]") def validate(self): - # in case it does not work in another configuration, it should validated here too + # in case it does not work in another configuration, it should be validated here too + # Always comment the reason including the upstream issue. + # INFO: Upstream does not support DLL: See if not is_msvc(self): raise ConanInvalidConfiguration(f"{self.ref} can be built only by Visual Studio and msvc.") @@ -65,6 +67,9 @@ def build_requirements(self): def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) + # apply patches listed in conandata.yml + # Using patches is always the last resort to fix issues. If possible, try to fix the issue in the upstream project. + apply_conandata_patches(self) @property def _msbuild_configuration(self): @@ -88,37 +93,7 @@ def generate(self): deps.configuration = self._msbuild_configuration deps.generate() - def _patch_sources(self): - apply_conandata_patches(self) - # remove bundled xxhash - rm(self, "whateer.*", os.path.join(self.source_folder, "lib")) - replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "...", "") - - # Allows to inject platform toolset, and props file generated by MSBuildToolchain & MSBuildDeps - # TODO: to remove once https://github.com/conan-io/conan/pull/12817 available in conan client - vcxproj_files = ["path/to/vcxproj_file1", "path/to/vcxproj_file2", "..."] - platform_toolset = MSBuildToolchain(self).toolset - import_conan_generators = "" - for props_file in ["conantoolchain.props", "conandeps.props"]: - props_path = os.path.join(self.generators_folder, props_file) - if os.path.exists(props_path): - import_conan_generators += f"" - for vcxproj_file in vcxproj_files: - replace_in_file( - self, vcxproj_file, - # change this v142 value depending on actual value in vcxproj file - "v142", - f"{platform_toolset}", - ) - if props_path: - replace_in_file( - self, vcxproj_file, - "", - f"{import_conan_generators}", - ) - def build(self): - self._patch_sources() # It can be apply_conandata_patches(self) only in case no more patches are needed msbuild = MSBuild(self) msbuild.build_type = self._msbuild_configuration # customize according the solution file and compiler version diff --git a/docs/package_templates/msbuild_package/all/test_package/CMakeLists.txt b/docs/package_templates/msbuild_package/all/test_package/CMakeLists.txt index 69086f9b189e8..c16ec6d748476 100644 --- a/docs/package_templates/msbuild_package/all/test_package/CMakeLists.txt +++ b/docs/package_templates/msbuild_package/all/test_package/CMakeLists.txt @@ -1,10 +1,7 @@ cmake_minimum_required(VERSION 3.15) - -project(test_package LANGUAGES C) # if the project is pure C -# project(test_package LANGUAGES CXX) # if the project uses C++ +project(test_package LANGUAGES CXX) find_package(package REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) -# don't link to ${CONAN_LIBS} or CONAN_PKG::package target_link_libraries(${PROJECT_NAME} PRIVATE package::package) diff --git a/docs/package_templates/msbuild_package/all/test_package/conanfile.py b/docs/package_templates/msbuild_package/all/test_package/conanfile.py index 02eb5ce439fb4..2e77b4246fa81 100644 --- a/docs/package_templates/msbuild_package/all/test_package/conanfile.py +++ b/docs/package_templates/msbuild_package/all/test_package/conanfile.py @@ -4,18 +4,16 @@ import os -# It will become the standard on Conan 2.x class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" - test_type = "explicit" - - def requirements(self): - self.requires(self.tested_reference_str) + generators = "CMakeDeps", "CMakeToolchain" def layout(self): cmake_layout(self) + def requirements(self): + self.requires(self.tested_reference_str) + def build(self): cmake = CMake(self) cmake.configure() diff --git a/docs/package_templates/msbuild_package/all/test_package/test_package.cpp b/docs/package_templates/msbuild_package/all/test_package/test_package.cpp index 8e653f30a5476..7480c357a3b18 100644 --- a/docs/package_templates/msbuild_package/all/test_package/test_package.cpp +++ b/docs/package_templates/msbuild_package/all/test_package/test_package.cpp @@ -1,14 +1,19 @@ #include -#include #include "package/foobar.hpp" int main(void) { - std::cout << "Create a minimal usage for the target project here." << std::endl; - std::cout << "Avoid big examples, bigger than 100 lines" << std::endl; - std::cout << "Avoid networking connections." << std::endl; - std::cout << "Avoid background apps or servers." << std::endl; - std::cout << "The propose is testing the generated artifacts only." << std::endl; + /* + * TODO: Remove this comment before pushing the testing code; + * + * Create a minimal usage for the target project here; + * Avoid upstream full examples, or code bigger than 15 lines; + * Avoid networking connections; + * Avoid background apps or servers; + * Avoid GUI apps; + * Avoid extra files like images, sounds and other binaries; + * The propose is testing the generated artifacts ONLY; + */ foobar.print_version(); diff --git a/docs/package_templates/msbuild_package/config.yml b/docs/package_templates/msbuild_package/config.yml index a885cbf942a74..d07c95e596619 100644 --- a/docs/package_templates/msbuild_package/config.yml +++ b/docs/package_templates/msbuild_package/config.yml @@ -1,5 +1,4 @@ versions: - # Newer versions at the top "1.2.0": folder: all "1.1.0": diff --git a/docs/package_templates/prebuilt_tool_package/all/conandata.yml b/docs/package_templates/prebuilt_tool_package/all/conandata.yml index efcc89654623a..b9d6d85ec79e3 100644 --- a/docs/package_templates/prebuilt_tool_package/all/conandata.yml +++ b/docs/package_templates/prebuilt_tool_package/all/conandata.yml @@ -1,5 +1,4 @@ sources: - # Newer versions at the top "1.2.0": "Windows": "x86_64": diff --git a/docs/package_templates/prebuilt_tool_package/all/conanfile.py b/docs/package_templates/prebuilt_tool_package/all/conanfile.py index aa042fd087498..eb1d1e11e7805 100644 --- a/docs/package_templates/prebuilt_tool_package/all/conanfile.py +++ b/docs/package_templates/prebuilt_tool_package/all/conanfile.py @@ -5,7 +5,7 @@ import os -required_conan_version = ">=1.47.0" +required_conan_version = ">=2.0" class PackageConan(ConanFile): @@ -19,7 +19,7 @@ class PackageConan(ConanFile): package_type = "application" settings = "os", "arch", "compiler", "build_type" # even for pre-built executables - # not needed but supress warning message from conan commands + # not needed but suppress warning message from conan commands def layout(self): pass @@ -37,7 +37,7 @@ def validate(self): def source(self): pass - # download the source here, than copy to package folder + # download the source here, then copy to package folder def build(self): get( self, @@ -58,7 +58,3 @@ def package_info(self): self.cpp_info.libdirs = [] self.cpp_info.resdirs = [] self.cpp_info.includedirs = [] - - # TODO: Legacy, to be removed on Conan 2.0 - bin_folder = os.path.join(self.package_folder, "bin") - self.env_info.PATH.append(bin_folder) diff --git a/docs/package_templates/prebuilt_tool_package/all/test_package/conanfile.py b/docs/package_templates/prebuilt_tool_package/all/test_package/conanfile.py index b3a58664b7d6b..0358d4cb99039 100644 --- a/docs/package_templates/prebuilt_tool_package/all/test_package/conanfile.py +++ b/docs/package_templates/prebuilt_tool_package/all/test_package/conanfile.py @@ -1,12 +1,12 @@ from conan import ConanFile -from conan.tools.build import can_run +from conan.tools.layout import basic_layout -# It will become the standard on Conan 2.x class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "VirtualBuildEnv" - test_type = "explicit" + + def layout(self): + basic_layout(self) def build_requirements(self): self.tool_requires(self.tested_reference_str) diff --git a/docs/package_templates/prebuilt_tool_package/config.yml b/docs/package_templates/prebuilt_tool_package/config.yml index a885cbf942a74..d07c95e596619 100644 --- a/docs/package_templates/prebuilt_tool_package/config.yml +++ b/docs/package_templates/prebuilt_tool_package/config.yml @@ -1,5 +1,4 @@ versions: - # Newer versions at the top "1.2.0": folder: all "1.1.0":