-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sqlpp11-connector-sqlite3: migrate to Conan v2
- Loading branch information
Showing
8 changed files
with
125 additions
and
66 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 GitHub Actions / Lint changed files (YAML files)conandata.yml schema warning
|
||
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 GitHub Actions / Lint changed files (YAML files)conandata.yml schema warning
|
||
base_path: "source_subfolder" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 4 additions & 5 deletions
9
recipes/sqlpp11-connector-sqlite3/all/test_package/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
recipes/sqlpp11-connector-sqlite3/all/test_package/conanfile.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
8 changes: 8 additions & 0 deletions
8
recipes/sqlpp11-connector-sqlite3/all/test_v1_package/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
recipes/sqlpp11-connector-sqlite3/all/test_v1_package/conanfile.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |