diff --git a/recipes/taocpp-taopq/all/CMakeLists.txt b/recipes/taocpp-taopq/all/CMakeLists.txt deleted file mode 100644 index 7d5ba25565b0ab..00000000000000 --- a/recipes/taocpp-taopq/all/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -cmake_minimum_required(VERSION 3.4) -project(cmake_wrapper) - -include(conanbuildinfo.cmake) -conan_basic_setup(KEEP_RPATHS) - -set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) - -add_subdirectory(source_subfolder) diff --git a/recipes/taocpp-taopq/all/conandata.yml b/recipes/taocpp-taopq/all/conandata.yml index 0019bb42bc62ce..b825cbd0e993fd 100644 --- a/recipes/taocpp-taopq/all/conandata.yml +++ b/recipes/taocpp-taopq/all/conandata.yml @@ -1,7 +1,7 @@ sources: "cci.20210727": - sha256: 7d5b801984f71140a8579989e29b746d56167eccb710d821b2336eac723b51a3 - url: https://github.com/taocpp/taopq/archive/3212b6eb74637277b40095d2ab2db872a76c6d9f.tar.gz + url: "https://github.com/taocpp/taopq/archive/3212b6eb74637277b40095d2ab2db872a76c6d9f.tar.gz" + sha256: "7d5b801984f71140a8579989e29b746d56167eccb710d821b2336eac723b51a3" "cci.20200222": - sha256: d10d29dace4d752484c3174bf07903b471c8746d06e9ca0e3e85c4bed676edaa - url: https://github.com/taocpp/taopq/archive/b7f66c8dbe993cba250c8e9f0878128b1ad74ff9.tar.gz + url: "https://github.com/taocpp/taopq/archive/b7f66c8dbe993cba250c8e9f0878128b1ad74ff9.tar.gz" + sha256: "d10d29dace4d752484c3174bf07903b471c8746d06e9ca0e3e85c4bed676edaa" diff --git a/recipes/taocpp-taopq/all/conanfile.py b/recipes/taocpp-taopq/all/conanfile.py index 29a15d8a468764..4cf5de4b292312 100644 --- a/recipes/taocpp-taopq/all/conanfile.py +++ b/recipes/taocpp-taopq/all/conanfile.py @@ -1,9 +1,12 @@ -from conans import ConanFile, CMake, tools -from conans.errors import ConanInvalidConfiguration -import functools +from conan import ConanFile +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.files import get, rmdir +from conan.tools.scm import Version import os -required_conan_version = ">=1.43.0" +required_conan_version = ">=1.53.0" class TaoCPPTaopqConan(ConanFile): @@ -14,7 +17,7 @@ class TaoCPPTaopqConan(ConanFile): description = "C++ client library for PostgreSQL" topics = ("cpp17", "postgresql", "libpq", "data-base", "sql") - settings = "os", "build_type", "compiler", "arch" + settings = "os", "arch", "build_type", "compiler" options = { "shared": [True, False], "fPIC": [True, False], @@ -24,24 +27,18 @@ class TaoCPPTaopqConan(ConanFile): "fPIC": True, } - exports_sources = "CMakeLists.txt" - generators = "cmake", "cmake_find_package" - - @property - def _source_subfolder(self): - return "source_subfolder" - @property - def _build_subfolder(self): - return "build_subfolder" + def _min_cppstd(self): + return "17" @property - def _min_compilers_version(self): + def _compilers_minimum_version(self): return { "gcc": "7", "clang": "6", "apple-clang": "10", - "Visual Studio": "15" + "Visual Studio": "15", + "msvc": "191", } def config_options(self): @@ -50,48 +47,55 @@ def config_options(self): def configure(self): if self.options.shared: - del self.options.fPIC + self.options.rm_safe("fPIC") + + def layout(self): + cmake_layout(self, src_folder="src") def requirements(self): - self.requires("libpq/14.2") + self.requires("libpq/14.5") def validate(self): if self.settings.compiler.get_safe("cppstd"): - tools.check_min_cppstd(self, "17") - min_compiler_version = self._min_compilers_version.get(str(self.settings.compiler), False) - if min_compiler_version: - if tools.Version(self.settings.compiler.version) < min_compiler_version: - raise ConanInvalidConfiguration("taocpp-taopq requires C++17, which your compiler does not support.") - else: - self.output.warn("taocpp-taopq requires C++17. Your compiler is unknown. Assuming it supports C++17.") + 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." + ) def source(self): - tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) + get(self, **self.conan_data["sources"][self.version], strip_root=True) - @functools.lru_cache(1) - def _configure_cmake(self): - cmake = CMake(self) - cmake.definitions["TAOPQ_BUILD_TESTS"] = False - cmake.definitions["TAOPQ_INSTALL_DOC_DIR"] = "licenses" - cmake.configure(build_folder=self._build_subfolder) - return cmake + def generate(self): + tc = CMakeToolchain(self) + tc.variables["TAOPQ_BUILD_TESTS"] = False + tc.variables["TAOPQ_INSTALL_DOC_DIR"] = "licenses" + tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True + tc.generate() + deps = CMakeDeps(self) + deps.generate() def build(self): - cmake = self._configure_cmake() + cmake = CMake(self) + cmake.configure() cmake.build() def package(self): - cmake = self._configure_cmake() + cmake = CMake(self) cmake.install() - tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) def package_info(self): self.cpp_info.set_property("cmake_file_name", "taopq") self.cpp_info.set_property("cmake_target_name", "taocpp::taopq") # TODO: back to global scope in conan v2 once cmake_find_package_* generators removed self.cpp_info.components["_taocpp-taopq"].libs = ["taopq"] - if self.settings.os == "Windows": - self.cpp_info.components["_taocpp-taopq"].system_libs = ["Ws2_32"] + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.components["_taocpp-taopq"].system_libs.append("m") + elif self.settings.os == "Windows": + self.cpp_info.components["_taocpp-taopq"].system_libs.append("ws2_32") # TODO: to remove in conan v2 once cmake_find_package_* generators removed self.cpp_info.filenames["cmake_find_package"] = "taopq" diff --git a/recipes/taocpp-taopq/all/test_package/CMakeLists.txt b/recipes/taocpp-taopq/all/test_package/CMakeLists.txt index 670b0751cce41e..6e73a15321e7c8 100644 --- a/recipes/taocpp-taopq/all/test_package/CMakeLists.txt +++ b/recipes/taocpp-taopq/all/test_package/CMakeLists.txt @@ -1,11 +1,8 @@ cmake_minimum_required(VERSION 3.8) -project(test_package CXX) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) +project(test_package LANGUAGES CXX) find_package(taopq REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) -target_link_libraries(${PROJECT_NAME} taocpp::taopq) -set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17) +target_link_libraries(${PROJECT_NAME} PRIVATE taocpp::taopq) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) diff --git a/recipes/taocpp-taopq/all/test_package/conanfile.py b/recipes/taocpp-taopq/all/test_package/conanfile.py index 38f4483872d47f..98ab55852ad565 100644 --- a/recipes/taocpp-taopq/all/test_package/conanfile.py +++ b/recipes/taocpp-taopq/all/test_package/conanfile.py @@ -1,10 +1,19 @@ -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout import os class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "cmake", "cmake_find_package_multi" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) def build(self): cmake = CMake(self) @@ -12,6 +21,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - bin_path = os.path.join("bin", "test_package") - self.run(bin_path, run_environment=True) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/taocpp-taopq/all/test_v1_package/CMakeLists.txt b/recipes/taocpp-taopq/all/test_v1_package/CMakeLists.txt new file mode 100644 index 00000000000000..0d20897301b68b --- /dev/null +++ b/recipes/taocpp-taopq/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.1) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package + ${CMAKE_CURRENT_BINARY_DIR}/test_package) diff --git a/recipes/taocpp-taopq/all/test_v1_package/conanfile.py b/recipes/taocpp-taopq/all/test_v1_package/conanfile.py new file mode 100644 index 00000000000000..38f4483872d47f --- /dev/null +++ b/recipes/taocpp-taopq/all/test_v1_package/conanfile.py @@ -0,0 +1,17 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True)