Skip to content

Commit

Permalink
sqlpp11-connector-sqlite3: migrate to Conan v2
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Oct 25, 2023
1 parent 448163e commit b2539bc
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 66 deletions.
7 changes: 0 additions & 7 deletions recipes/sqlpp11-connector-sqlite3/all/CMakeLists.txt

This file was deleted.

2 changes: 0 additions & 2 deletions recipes/sqlpp11-connector-sqlite3/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ sources:
patches:
"0.29":
- patch_file: "patches/cmake-dependencies.patch"

Check warning on line 10 in recipes/sqlpp11-connector-sqlite3/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/cmake-de ... ^ (line: 10)
base_path: "source_subfolder"
"0.30":
- patch_file: "patches/cmake-dependencies.patch"

Check warning on line 12 in recipes/sqlpp11-connector-sqlite3/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/cmake-de ... ^ (line: 12)
base_path: "source_subfolder"
96 changes: 55 additions & 41 deletions recipes/sqlpp11-connector-sqlite3/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,77 +1,91 @@
from conans import ConanFile, CMake, tools
import os

from conan import ConanFile
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file

required_conan_version = ">=1.53.0"


class sqlpp11Conan(ConanFile):
name = "sqlpp11-connector-sqlite3"
description = "A C++ wrapper for sqlite3 meant to be used in combination with sqlpp11."
topics = ("conan", "sqlpp11-connector-sqlite3", "sqlite3", "sqlpp11", "sql", "database")
settings = "os", "compiler", "build_type", "arch"
license = "BSD-2-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/rbock/sqlpp11-connector-sqlite3"
license = "BSD-2-Clause"
exports_sources = ["CMakeLists.txt", "patches/**"]
generators = "cmake"
options = {"shared": [True, False], "fPIC": [True, False], "with_sqlcipher": [True, False]}
default_options = {"shared": False, "fPIC": True, "with_sqlcipher": False}
short_paths = True

_cmake = None
topics = ("sqlite3", "sqlpp11", "sql", "database")

@property
def _source_subfolder(self):
return "source_subfolder"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_sqlcipher": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_sqlcipher": False,
}

@property
def _build_subfolder(self):
return "build_subfolder"
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:
del self.options.fPIC
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self, src_folder="src")

def validate(self):
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, 11)
check_min_cppstd(self, 11)

def requirements(self):
self.requires("sqlpp11/0.59")
self.requires("sqlpp11/0.60", transitive_headers=True, transitive_libs=True)
if self.options.with_sqlcipher:
self.requires("sqlcipher/4.4.0")
self.requires("sqlcipher/4.5.1", transitive_headers=True, transitive_libs=True)
else:
self.requires("sqlite3/3.32.3")
self.requires("sqlite3/3.43.2", transitive_headers=True, transitive_libs=True)

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["ENABLE_TESTS"] = False
self._cmake.definitions["SQLCIPHER"] = self.options.with_sqlcipher
self._cmake.definitions["SQLPP11_INCLUDE_DIR"] = self.deps_cpp_info["sqlpp11"].include_paths[0]
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["ENABLE_TESTS"] = False
tc.variables["SQLCIPHER"] = self.options.with_sqlcipher
tc.variables["SQLPP11_INCLUDE_DIR"] = self.dependencies["sqlpp11"].cpp_info.includedirs[0]
tc.generate()
tc = CMakeDeps(self)
tc.generate()

def _patch_sources(self):
apply_conandata_patches(self)
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "Sqlite3", "SQLite3")

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
self._patch_sources()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder)
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = ["sqlpp11-connector-sqlite3"]
if self.settings.os == "Linux":
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["m"]
if self.options.with_sqlcipher:
self.cpp_info.defines = ["SQLPP_USE_SQLCIPHER"]
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

@@ -58,14 +55,13 @@ endif()
@@ -58,14 +55,16 @@ endif()

if (SQLCIPHER)
target_compile_definitions(sqlpp11-connector-sqlite3 PUBLIC SQLPP_USE_SQLCIPHER)
- target_link_libraries(sqlpp11-connector-sqlite3 SQLCipher::SQLCipher)
target_link_libraries(sqlpp11-connector-sqlite3 SQLCipher::SQLCipher)
if (SQLPP_DYNAMIC_LOADING)
target_compile_definitions(sqlpp11-connector-sqlite3-dynamic PUBLIC SQLPP_USE_SQLCIPHER)
target_include_directories(sqlpp11-connector-sqlite3-dynamic PUBLIC ${SQLCIPHER_INCLUDE_DIRS})
endif()
else()
- target_link_libraries(sqlpp11-connector-sqlite3 ${SQLITE3_LIBRARIES})
+ target_link_libraries(sqlpp11-connector-sqlite3 SQLite::SQLite3)
endif()
+target_link_libraries(sqlpp11-connector-sqlite3 ${CONAN_LIBS})
+find_package(Sqlpp11 REQUIRED)
+target_link_libraries(sqlpp11-connector-sqlite3 sqlpp11::sqlpp11)

install(TARGETS sqlpp11-connector-sqlite3
ARCHIVE DESTINATION lib
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(sqlpp11-connector-sqlite3 REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE sqlpp11-connector-sqlite3::sqlpp11-connector-sqlite3)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
32 changes: 24 additions & 8 deletions recipes/sqlpp11-connector-sqlite3/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
from conans import ConanFile, CMake, tools
import os
import sqlite3

from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
from conan.tools.files import save, load


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def generate(self):
with_sqlcipher = bool(self.dependencies["sqlpp11-connector-sqlite3"].options.with_sqlcipher)
save(self, os.path.join(self.build_folder, "with_sqlcipher"), repr(with_sqlcipher))

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

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
with_sqlcipher = load(self, os.path.join(self.build_folder, "with_sqlcipher")) == "True"
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
# test that the database is encrypted when sqlcipher is used
con = sqlite3.connect("test.db")
cursor = con.cursor()
try:
cursor.execute("select * from tab_sample")
except sqlite3.DatabaseError:
assert self.options["sqlpp11-connector-sqlite3"].with_sqlcipher
assert with_sqlcipher
self.output.info("database is encrypted with sqlcipher")
return
assert not self.options["sqlpp11-connector-sqlite3"].with_sqlcipher
assert not with_sqlcipher
self.output.info("database is not encrypted")
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
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/)
29 changes: 29 additions & 0 deletions recipes/sqlpp11-connector-sqlite3/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from conans import ConanFile, CMake, tools
import os
import sqlite3


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
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.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
# test that the database is encrypted when sqlcipher is used
con = sqlite3.connect("test.db")
cursor = con.cursor()
try:
cursor.execute("select * from tab_sample")
except sqlite3.DatabaseError:
assert self.options["sqlpp11-connector-sqlite3"].with_sqlcipher
self.output.info("database is encrypted with sqlcipher")
return
assert not self.options["sqlpp11-connector-sqlite3"].with_sqlcipher
self.output.info("database is not encrypted")

0 comments on commit b2539bc

Please sign in to comment.