forked from valsydalv/conan-sqlpp11-connector-postgresql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconanfile.py
70 lines (60 loc) · 3.49 KB
/
conanfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import subprocess
import os
from conans import ConanFile, CMake, tools
class Sqlpp11connectorpostgresqlConan(ConanFile):
name = "sqlpp11-connector-postgresql"
version = "0.2"
license = "MIT"
url = "https://github.com/StiventoUser/conan-sqlpp11-connector-postgresql"
description = "A connector for sqlpp11 library."
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False] }
default_options = "shared=False"
generators = "cmake"
requires = (
"sqlpp11/0.54@vkrapivin/testing",
"boost/1.66.0@conan/stable") # Change in a future to Boost.Lexical_Cast/1.66.0@bincrafters/stable # Boost/1.64.0@bincrafters/stable
def getPostgreSQLIncludeDir(self):
return subprocess.check_output(r"pg_config --includedir | tr -d '\n'", shell=True)
def getPostgreSQLLibDir(self):
return subprocess.check_output(r"pg_config --libdir | tr -d '\n'", shell=True)
def source(self):
self.run("git clone https://github.com/StiventoUser/sqlpp11-connector-postgresql.git")
with tools.chdir("sqlpp11-connector-postgresql"):
self.run("git checkout %s" % "package-version") # TODO update to version checkout
# This small hack might be useful to guarantee proper /MT /MD linkage in MSVC
# if the packaged project doesn't have variables to set it properly
tools.replace_in_file("CMakeLists.txt", "project(sqlpp11-connector-postgresql VERSION 0.1 LANGUAGES CXX)", '''project(sqlpp11-connector-postgresql VERSION 0.1 LANGUAGES CXX)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()''')
def build(self):
cmake = CMake(self)
if self.settings.os == "Windows":
pg_root = os.getenv("PostgreSQL_ROOT")
if not pg_root:
raise ValueError('PostgreSQL_ROOT must be set in the environment variables.')
cmake.definitions["POSTGRESQL_ROOT_DIR"] = pg_root
else:
cmake.definitions["PostgreSQL_ROOT_DIRECTORIES"] = "%s %s" % (self.getPostgreSQLIncludeDir(), self.getPostgreSQLLibDir())
cmake.definitions["sqlpp11_ROOT_DIR"] = self.deps_cpp_info["sqlpp11"].rootpath
cmake.definitions["CMAKE_MODULE_PATH"] = ("%s;%s/lib/cmake/Sqlpp11" % (cmake.definitions.get("CMAKE_MODULE_PATH", ""), self.deps_cpp_info["sqlpp11"].rootpath)).replace('\\', '/')
cmake.definitions["CMAKE_PREFIX_PATH"] = "%s/lib/cmake/Sqlpp11" % self.deps_cpp_info["sqlpp11"].rootpath
cmake.configure(source_folder="sqlpp11-connector-postgresql")
cmake.build()
# Explicit way:
# self.run('cmake %s/hello %s' % (self.source_folder, cmake.command_line))
# self.run("cmake --build . %s" % cmake.build_config)
def package(self):
self.copy("*.h", dst="include", src="sqlpp11-connector-postgresql/include")
self.copy("*.py", dst="scripts", src="sqlpp11-connector-postgresql/scripts", keep_path=False)
self.copy("*.lib", dst="lib", keep_path=False)
self.copy("*.dll", dst="bin", keep_path=False)
self.copy("*.so", dst="lib", keep_path=False)
self.copy("*.dylib", dst="lib", keep_path=False)
self.copy("*.a", dst="lib", keep_path=False)
def package_info(self):
if self.options.shared == "True":
self.cpp_info.libs = ["sqlpp11-connector-postgresql-dynamic"]
else:
self.cpp_info.libs = ['sqlpp11-connector-postgresql']
self.user_info.DDL2CPP = os.path.join(self.package_folder, "scripts", "ddl2cpp.py")