Skip to content

Commit

Permalink
(conan-io#15433) taocpp-taopq: conan v2 support
Browse files Browse the repository at this point in the history
* conan v2 support

* add libm to system libs
  • Loading branch information
SpaceIm authored and StellaSmith committed Feb 2, 2023
1 parent f5d40ed commit a0fa711
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 62 deletions.
9 changes: 0 additions & 9 deletions recipes/taocpp-taopq/all/CMakeLists.txt

This file was deleted.

8 changes: 4 additions & 4 deletions recipes/taocpp-taopq/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -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"
80 changes: 42 additions & 38 deletions recipes/taocpp-taopq/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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],
Expand All @@ -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):
Expand All @@ -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"
Expand Down
9 changes: 3 additions & 6 deletions recipes/taocpp-taopq/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 14 additions & 5 deletions recipes/taocpp-taopq/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
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)
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)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/taocpp-taopq/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions recipes/taocpp-taopq/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit a0fa711

Please sign in to comment.