Added support for Conan (#29)

This commit is contained in:
Dr. Patrick Urbanke (劉自成)
2025-07-18 22:31:19 +02:00
committed by GitHub
parent db1b434320
commit 0ad99d983a
9 changed files with 236 additions and 7 deletions

View File

@@ -0,0 +1,50 @@
name: linux-cxx20-conan
on: [push]
jobs:
linux:
strategy:
fail-fast: false
matrix:
include:
- compiler: llvm
compiler-version: 16
- compiler: llvm
compiler-version: 18
- compiler: gcc
compiler-version: 11
additional-dep: "g++-11"
- compiler: gcc
compiler-version: 12
- compiler: gcc
compiler-version: 14
name: "${{ github.job }} (${{ matrix.compiler }}-${{ matrix.compiler-version }})"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Install dependencies
run: |
sudo apt update
sudo apt install -y ninja-build pipx ${{ matrix.additional-dep }}
- name: Install Conan
run: |
pipx install conan
conan profile detect
- name: Compile
run: |
if [[ "${{ matrix.compiler }}" == "llvm" ]]; then
export CC=clang-${{ matrix.compiler-version }}
export CXX=clang++-${{ matrix.compiler-version }}
elif [[ "${{ matrix.compiler }}" == "gcc" ]]; then
export CC=gcc-${{ matrix.compiler-version }}
export CXX=g++-${{ matrix.compiler-version }}
fi
sudo ln -s $(which ccache) /usr/local/bin/$CC
sudo ln -s $(which ccache) /usr/local/bin/$CXX
$CXX --version
conan build . --build=missing -s compiler.cppstd=gnu20

View File

@@ -1,4 +1,4 @@
name: linux-cxx20
name: linux-cxx20-vcpkg
on: [push]

View File

@@ -0,0 +1,33 @@
name: macos-cxx20-conan
on: [push]
jobs:
macos-clang:
strategy:
fail-fast: false
matrix:
include:
- os: "macos-latest"
- os: "macos-13"
name: "${{ github.job }} (${{ matrix.os }})"
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Install dependencies
run: brew install ninja pipx
- name: Install Conan
run: |
pipx install conan
conan profile detect
- name: Compile
env:
CC: clang
CXX: clang++
run: |
$CXX --version
conan build . --build=missing -s compiler.cppstd=gnu20

View File

@@ -1,4 +1,4 @@
name: macos-cxx20
name: macos-cxx20-vcpkg
on: [push]

View File

@@ -1,4 +1,4 @@
name: windows-cxx20
name: windows-cxx20-vcpkg
on: [push]

View File

@@ -69,10 +69,18 @@ endif()
if (SQLGEN_SQLITE3)
list(APPEND SQLGEN_SOURCES src/sqlgen_sqlite.cpp)
if (NOT TARGET unofficial-sqlite3)
find_package(unofficial-sqlite3 CONFIG REQUIRED)
if (SQLGEN_USE_VCPKG)
if (NOT TARGET unofficial-sqlite3)
find_package(unofficial-sqlite3 CONFIG REQUIRED)
endif()
target_link_libraries(sqlgen PUBLIC unofficial::sqlite3::sqlite3)
else()
if (NOT TARGET unofficial-sqlite3)
find_package(SQLite3 CONFIG REQUIRED)
endif()
target_link_libraries(sqlgen PUBLIC SQLite::SQLite3)
endif()
target_link_libraries(sqlgen PUBLIC unofficial::sqlite3::sqlite3)
endif()
find_package(reflectcpp CONFIG REQUIRED)

9
CMakeUserPresets.json Normal file
View File

@@ -0,0 +1,9 @@
{
"version": 4,
"vendor": {
"conan": {}
},
"include": [
"build/Release/generators/CMakePresets.json"
]
}

View File

@@ -25,7 +25,7 @@ Together, reflect-cpp and sqlgen enable reliable and efficient ETL pipelines.
## Quick Start
### Installation
### Installation using vcpkg
1. Make sure you have the required dependencies installed (skip this step on Windows):
```bash
@@ -53,6 +53,25 @@ find_package(sqlgen REQUIRED)
target_link_libraries(your_target PRIVATE sqlgen::sqlgen)
```
### Installation using Conan
1. Install Conan (assuming you have Python and pipx installed):
```bash
pipx install conan
conan profile detect
```
For older versions of pip, you can also use `pip` instead of `pipx`.
2. Build the library:
```bash
conan build . --build=missing -s compiler.cppstd=gnu20
```
You can call `conan inspect .` to get an overview of the supported options.
## Usage Examples
### Hello World

110
conanfile.py Normal file
View File

@@ -0,0 +1,110 @@
from conan import ConanFile
from conan.tools.files import get, copy, rmdir
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
from conan.tools.env import VirtualBuildEnv
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.errors import ConanInvalidConfiguration
import os
required_conan_version = ">=2.18.1"
class SQLGenConan(ConanFile):
name = "sqlgen"
description = "sqlgen is an ORM and SQL query generator for C++-20, similar to Python's SQLAlchemy/SQLModel or Rust's Diesel."
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/getml/sqlgen"
topics = ("postgres", "sqlite", "orm")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_postgres": [True, False],
"with_sqlite3": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_postgres": True,
"with_sqlite3": True,
}
def config_options(self):
if self.settings.os == "Windows":
self.options.rm_safe("fPIC")
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
def requirements(self):
self.requires("reflect-cpp/0.19.0")
if self.options.with_postgres:
self.requires("libpq/17.5")
if self.options.with_sqlite3:
self.requires("sqlite3/3.49.1")
def build_requirements(self):
self.tool_requires("cmake/[>=3.23 <4]")
def validate(self):
if self.settings.get_safe("compiler.cppstd"):
check_min_cppstd(self, self._min_cppstd)
def layout(self):
cmake_layout(self, src_folder=".")
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def generate(self):
env = VirtualBuildEnv(self)
env.generate()
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.cache_variables["SQLGEN_BUILD_SHARED"] = self.options.shared
tc.cache_variables["SQLGEN_POSTGRES"] = self.options.with_postgres
tc.cache_variables["SQLGEN_SQLITE3"] = self.options.with_sqlite3
tc.cache_variables["SQLGEN_USE_VCPKG"] = False
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def package(self):
copy(
self,
pattern="LICENSE",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder,
)
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
def package_info(self):
self.cpp_info.libs = ["sqlgen"]
@property
def _min_cppstd(self):
return 20
@property
def _compilers_minimum_version(self):
return {
"Visual Studio": "17",
"msvc": "1938",
"gcc": "11",
"clang": "13",
"apple-clang": "15",
}