Skip to content

Commit 0ad99d9

Browse files
Added support for Conan (#29)
1 parent db1b434 commit 0ad99d9

9 files changed

Lines changed: 236 additions & 7 deletions
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: linux-cxx20-conan
2+
3+
on: [push]
4+
5+
jobs:
6+
linux:
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
include:
11+
- compiler: llvm
12+
compiler-version: 16
13+
- compiler: llvm
14+
compiler-version: 18
15+
- compiler: gcc
16+
compiler-version: 11
17+
additional-dep: "g++-11"
18+
- compiler: gcc
19+
compiler-version: 12
20+
- compiler: gcc
21+
compiler-version: 14
22+
name: "${{ github.job }} (${{ matrix.compiler }}-${{ matrix.compiler-version }})"
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
with:
28+
submodules: recursive
29+
fetch-depth: 0
30+
- name: Install dependencies
31+
run: |
32+
sudo apt update
33+
sudo apt install -y ninja-build pipx ${{ matrix.additional-dep }}
34+
- name: Install Conan
35+
run: |
36+
pipx install conan
37+
conan profile detect
38+
- name: Compile
39+
run: |
40+
if [[ "${{ matrix.compiler }}" == "llvm" ]]; then
41+
export CC=clang-${{ matrix.compiler-version }}
42+
export CXX=clang++-${{ matrix.compiler-version }}
43+
elif [[ "${{ matrix.compiler }}" == "gcc" ]]; then
44+
export CC=gcc-${{ matrix.compiler-version }}
45+
export CXX=g++-${{ matrix.compiler-version }}
46+
fi
47+
sudo ln -s $(which ccache) /usr/local/bin/$CC
48+
sudo ln -s $(which ccache) /usr/local/bin/$CXX
49+
$CXX --version
50+
conan build . --build=missing -s compiler.cppstd=gnu20
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: linux-cxx20
1+
name: linux-cxx20-vcpkg
22

33
on: [push]
44

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: macos-cxx20-conan
2+
3+
on: [push]
4+
5+
jobs:
6+
macos-clang:
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
include:
11+
- os: "macos-latest"
12+
- os: "macos-13"
13+
name: "${{ github.job }} (${{ matrix.os }})"
14+
runs-on: ${{ matrix.os }}
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
submodules: recursive
20+
fetch-depth: 0
21+
- name: Install dependencies
22+
run: brew install ninja pipx
23+
- name: Install Conan
24+
run: |
25+
pipx install conan
26+
conan profile detect
27+
- name: Compile
28+
env:
29+
CC: clang
30+
CXX: clang++
31+
run: |
32+
$CXX --version
33+
conan build . --build=missing -s compiler.cppstd=gnu20
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: macos-cxx20
1+
name: macos-cxx20-vcpkg
22

33
on: [push]
44

.github/workflows/windows-cxx20.yaml renamed to .github/workflows/windows-cxx20-vcpkg.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: windows-cxx20
1+
name: windows-cxx20-vcpkg
22

33
on: [push]
44

CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,18 @@ endif()
6969

7070
if (SQLGEN_SQLITE3)
7171
list(APPEND SQLGEN_SOURCES src/sqlgen_sqlite.cpp)
72-
if (NOT TARGET unofficial-sqlite3)
73-
find_package(unofficial-sqlite3 CONFIG REQUIRED)
72+
73+
if (SQLGEN_USE_VCPKG)
74+
if (NOT TARGET unofficial-sqlite3)
75+
find_package(unofficial-sqlite3 CONFIG REQUIRED)
76+
endif()
77+
target_link_libraries(sqlgen PUBLIC unofficial::sqlite3::sqlite3)
78+
else()
79+
if (NOT TARGET unofficial-sqlite3)
80+
find_package(SQLite3 CONFIG REQUIRED)
81+
endif()
82+
target_link_libraries(sqlgen PUBLIC SQLite::SQLite3)
7483
endif()
75-
target_link_libraries(sqlgen PUBLIC unofficial::sqlite3::sqlite3)
7684
endif()
7785

7886
find_package(reflectcpp CONFIG REQUIRED)

CMakeUserPresets.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": 4,
3+
"vendor": {
4+
"conan": {}
5+
},
6+
"include": [
7+
"build/Release/generators/CMakePresets.json"
8+
]
9+
}

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Together, reflect-cpp and sqlgen enable reliable and efficient ETL pipelines.
2525

2626
## Quick Start
2727

28-
### Installation
28+
### Installation using vcpkg
2929

3030
1. Make sure you have the required dependencies installed (skip this step on Windows):
3131
```bash
@@ -53,6 +53,25 @@ find_package(sqlgen REQUIRED)
5353
target_link_libraries(your_target PRIVATE sqlgen::sqlgen)
5454
```
5555

56+
### Installation using Conan
57+
58+
1. Install Conan (assuming you have Python and pipx installed):
59+
60+
```bash
61+
pipx install conan
62+
conan profile detect
63+
```
64+
65+
For older versions of pip, you can also use `pip` instead of `pipx`.
66+
67+
2. Build the library:
68+
69+
```bash
70+
conan build . --build=missing -s compiler.cppstd=gnu20
71+
```
72+
73+
You can call `conan inspect .` to get an overview of the supported options.
74+
5675
## Usage Examples
5776

5877
### Hello World

conanfile.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
from conan import ConanFile
2+
from conan.tools.files import get, copy, rmdir
3+
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
4+
5+
6+
from conan.tools.env import VirtualBuildEnv
7+
from conan.tools.build import check_min_cppstd
8+
from conan.tools.scm import Version
9+
from conan.errors import ConanInvalidConfiguration
10+
11+
import os
12+
13+
required_conan_version = ">=2.18.1"
14+
15+
16+
class SQLGenConan(ConanFile):
17+
name = "sqlgen"
18+
description = "sqlgen is an ORM and SQL query generator for C++-20, similar to Python's SQLAlchemy/SQLModel or Rust's Diesel."
19+
license = "MIT"
20+
url = "https://github.com/conan-io/conan-center-index"
21+
homepage = "https://github.com/getml/sqlgen"
22+
topics = ("postgres", "sqlite", "orm")
23+
package_type = "library"
24+
settings = "os", "arch", "compiler", "build_type"
25+
26+
options = {
27+
"shared": [True, False],
28+
"fPIC": [True, False],
29+
"with_postgres": [True, False],
30+
"with_sqlite3": [True, False],
31+
}
32+
default_options = {
33+
"shared": False,
34+
"fPIC": True,
35+
"with_postgres": True,
36+
"with_sqlite3": True,
37+
}
38+
39+
def config_options(self):
40+
if self.settings.os == "Windows":
41+
self.options.rm_safe("fPIC")
42+
43+
def configure(self):
44+
if self.options.shared:
45+
self.options.rm_safe("fPIC")
46+
47+
def requirements(self):
48+
self.requires("reflect-cpp/0.19.0")
49+
if self.options.with_postgres:
50+
self.requires("libpq/17.5")
51+
if self.options.with_sqlite3:
52+
self.requires("sqlite3/3.49.1")
53+
54+
def build_requirements(self):
55+
self.tool_requires("cmake/[>=3.23 <4]")
56+
57+
def validate(self):
58+
if self.settings.get_safe("compiler.cppstd"):
59+
check_min_cppstd(self, self._min_cppstd)
60+
61+
def layout(self):
62+
cmake_layout(self, src_folder=".")
63+
64+
def source(self):
65+
get(self, **self.conan_data["sources"][self.version], strip_root=True)
66+
67+
def generate(self):
68+
env = VirtualBuildEnv(self)
69+
env.generate()
70+
deps = CMakeDeps(self)
71+
deps.generate()
72+
tc = CMakeToolchain(self)
73+
tc.cache_variables["SQLGEN_BUILD_SHARED"] = self.options.shared
74+
tc.cache_variables["SQLGEN_POSTGRES"] = self.options.with_postgres
75+
tc.cache_variables["SQLGEN_SQLITE3"] = self.options.with_sqlite3
76+
tc.cache_variables["SQLGEN_USE_VCPKG"] = False
77+
tc.generate()
78+
79+
def build(self):
80+
cmake = CMake(self)
81+
cmake.configure()
82+
cmake.build()
83+
84+
def package(self):
85+
copy(
86+
self,
87+
pattern="LICENSE",
88+
dst=os.path.join(self.package_folder, "licenses"),
89+
src=self.source_folder,
90+
)
91+
cmake = CMake(self)
92+
cmake.install()
93+
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
94+
95+
def package_info(self):
96+
self.cpp_info.libs = ["sqlgen"]
97+
98+
@property
99+
def _min_cppstd(self):
100+
return 20
101+
102+
@property
103+
def _compilers_minimum_version(self):
104+
return {
105+
"Visual Studio": "17",
106+
"msvc": "1938",
107+
"gcc": "11",
108+
"clang": "13",
109+
"apple-clang": "15",
110+
}

0 commit comments

Comments
 (0)