Skip to content

Commit

Permalink
(#13504) oatpp-sqlite: conan v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm authored Oct 17, 2022
1 parent c6b5db7 commit 3e2db9b
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 76 deletions.
7 changes: 0 additions & 7 deletions recipes/oatpp-sqlite/all/CMakeLists.txt

This file was deleted.

115 changes: 64 additions & 51 deletions recipes/oatpp-sqlite/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
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 copy, get, rmdir
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version
import os

required_conan_version = ">=1.43.0"
required_conan_version = ">=1.51.1"


class OatppsqliteConan(ConanFile):
Expand All @@ -12,82 +17,90 @@ class OatppsqliteConan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
description = "oat++ SQLite library"
topics = ("oat++", "oatpp", "sqlite")
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
generators = "cmake", "cmake_find_package"
exports_sources = "CMakeLists.txt"

_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
try:
del self.options.fPIC
except Exception:
pass

def validate(self):
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, 11)
def layout(self):
cmake_layout(self, src_folder="src")

if self.settings.os == "Windows" and self.options.shared:
raise ConanInvalidConfiguration("oatpp-sqlite can not be built as shared library on Windows")
def requirements(self):
self.requires(f"oatpp/{self.version}")
self.requires("sqlite3/3.39.4")

if self.settings.compiler == "gcc" and tools.Version(self.settings.compiler.version) < "5":
raise ConanInvalidConfiguration("oatpp-sqlite requires GCC >=5")
def validate(self):
if self.info.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 11)

def requirements(self):
self.requires("oatpp/" + self.version)
self.requires("sqlite3/3.37.0")
if is_msvc(self) and self.info.options.shared:
raise ConanInvalidConfiguration(f"{self.ref} can not be built as shared library with msvc")

def source(self):
tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True)
if self.info.settings.compiler == "gcc" and Version(self.info.settings.compiler.version) < "5":
raise ConanInvalidConfiguration(f"{self.ref} requires GCC >=5")

def _configure_cmake(self):
if self._cmake:
return self._cmake
def source(self):
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

self._cmake = CMake(self)
self._cmake.definitions["OATPP_BUILD_TESTS"] = False
self._cmake.definitions["OATPP_MODULES_LOCATION"] = "INSTALLED"
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
def generate(self):
tc = CMakeToolchain(self)
tc.variables["OATPP_BUILD_TESTS"] = False
tc.variables["OATPP_MODULES_LOCATION"] = "INSTALLED"
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def build(self):
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
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.filenames["cmake_find_package"] = "oatpp-sqlite"
self.cpp_info.filenames["cmake_find_package_multi"] = "oatpp-sqlite"
self.cpp_info.set_property("cmake_file_name", "oatpp-sqlite")
self.cpp_info.names["cmake_find_package"] = "oatpp"
self.cpp_info.names["cmake_find_package_multi"] = "oatpp"
self.cpp_info.set_property("cmake_target_name", "oatpp::oatpp-sqlite")
self.cpp_info.components["_oatpp-sqlite"].names["cmake_find_package"] = "oatpp-sqlite"
self.cpp_info.components["_oatpp-sqlite"].names["cmake_find_package_multi"] = "oatpp-sqlite"
self.cpp_info.components["_oatpp-sqlite"].set_property("cmake_target_name", "oatpp::oatpp-sqlite")
# TODO: back to global scope in conan v2 once legacy generators removed
self.cpp_info.components["_oatpp-sqlite"].includedirs = [
os.path.join("include", "oatpp-{}".format(self.version), "oatpp-sqlite")
os.path.join("include", f"oatpp-{self.version}", "oatpp-sqlite")
]
self.cpp_info.components["_oatpp-sqlite"].libdirs = [os.path.join("lib", "oatpp-{}".format(self.version))]
self.cpp_info.components["_oatpp-sqlite"].libdirs = [os.path.join("lib", f"oatpp-{self.version}")]
if self.settings.os == "Windows" and self.options.shared:
self.cpp_info.components["_oatpp-sqlite"].bindirs = [os.path.join("bin", f"oatpp-{self.version}")]
else:
self.cpp_info.components["_oatpp-sqlite"].bindirs = []
self.cpp_info.components["_oatpp-sqlite"].libs = ["oatpp-sqlite"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["_oatpp-sqlite"].system_libs = ["pthread"]

# TODO: to remove in conan v2 once legacy generators removed
self.cpp_info.filenames["cmake_find_package"] = "oatpp-sqlite"
self.cpp_info.filenames["cmake_find_package_multi"] = "oatpp-sqlite"
self.cpp_info.names["cmake_find_package"] = "oatpp"
self.cpp_info.names["cmake_find_package_multi"] = "oatpp"
self.cpp_info.components["_oatpp-sqlite"].names["cmake_find_package"] = "oatpp-sqlite"
self.cpp_info.components["_oatpp-sqlite"].names["cmake_find_package_multi"] = "oatpp-sqlite"
self.cpp_info.components["_oatpp-sqlite"].set_property("cmake_target_name", "oatpp::oatpp-sqlite")
self.cpp_info.components["_oatpp-sqlite"].requires = ["oatpp::oatpp", "sqlite3::sqlite3"]
12 changes: 4 additions & 8 deletions recipes/oatpp-sqlite/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package CXX)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(oatpp-sqlite REQUIRED)
find_package(oatpp-sqlite REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)

target_link_libraries(${PROJECT_NAME} PRIVATE oatpp::oatpp-sqlite)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
25 changes: 15 additions & 10 deletions recipes/oatpp-sqlite/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os

from conans import ConanFile, CMake, tools


class OatppSqliteTestConan(ConanFile):
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package"
generators = "CMakeToolchain", "CMakeDeps", "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)
# Current dir is "test_package/build/<build_id>" and CMakeLists.txt is
# in "test_package"
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
self.run(os.path.join("bin", "test_package"), 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")
11 changes: 11 additions & 0 deletions recipes/oatpp-sqlite/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(oatpp-sqlite REQUIRED CONFIG)

add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE oatpp::oatpp-sqlite)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
17 changes: 17 additions & 0 deletions recipes/oatpp-sqlite/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 3e2db9b

Please sign in to comment.