-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCMakeLists.txt
110 lines (89 loc) · 3.61 KB
/
CMakeLists.txt
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(DBICPP CXX C)
LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/lib)
SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules modules)
FIND_PACKAGE(uuid REQUIRED)
FIND_PACKAGE(pcre REQUIRED)
FIND_PACKAGE(pq)
FIND_PACKAGE(mysql)
FIND_PACKAGE(sqlite3)
INCLUDE_DIRECTORIES(inc ${UUID_INCLUDE_DIRS} ${PCRE_INCLUDE_DIRS})
INCLUDE (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
CHECK_FUNCTION_EXISTS(getline HAS_GETLINE)
IF (HAS_GETLINE)
ADD_DEFINITIONS(-DHAS_GETLINE)
ENDIF()
IF (APPLE)
FILE(GLOB SOURCES "src/*.cc" "src/bsd/getline.cc")
ELSE ()
FILE(GLOB SOURCES "src/*.cc")
ENDIF ()
ADD_LIBRARY(dbic++ STATIC ${SOURCES})
SET(CMAKE_INSTALL_LIBDIR lib CACHE PATH "Output directory for libraries")
# TODO including container.cc and error.cc is a workaround to address
# dynamic symbol resolution problems. need to change the way linking works.
IF (PQ_FOUND)
INCLUDE_DIRECTORIES(${PQ_INCLUDE_DIRS})
FILE(GLOB PGSOURCES "src/drivers/pg/*.cc")
ADD_LIBRARY(dbdpg SHARED ${PGSOURCES} src/container.cc src/error.cc)
IF (APPLE)
TARGET_LINK_LIBRARIES(dbdpg dbic++ ${PQ_LIBRARIES} ${UUID_LIBRARIES} ${PCRE_LIBRARIES})
ELSE ()
TARGET_LINK_LIBRARIES(dbdpg ${PQ_LIBRARIES})
ENDIF()
SET_TARGET_PROPERTIES(dbdpg PROPERTIES VERSION ${CMAKE_PG_VERSION} SOVERSION 1)
INSTALL(TARGETS dbdpg
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/dbic++
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/dbic++)
ENDIF()
IF (MYSQL_FOUND)
INCLUDE_DIRECTORIES(${MYSQL_INCLUDE_DIRS})
FILE(GLOB MYSQLSOURCES "src/drivers/mysql/*.cc")
ADD_LIBRARY(dbdmysql SHARED ${MYSQLSOURCES} src/container.cc src/error.cc)
IF (APPLE)
TARGET_LINK_LIBRARIES(dbdmysql dbic++ ${MYSQL_LIBRARIES} ${UUID_LIBRARIES} ${PCRE_LIBRARIES})
ELSE()
TARGET_LINK_LIBRARIES(dbdmysql ${MYSQL_LIBRARIES})
ENDIF()
SET_TARGET_PROPERTIES(dbdmysql PROPERTIES VERSION ${CMAKE_MYSQL_VERSION} SOVERSION 1)
INSTALL(TARGETS dbdmysql
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/dbic++
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/dbic++)
ENDIF()
IF (SQLITE3_FOUND)
INCLUDE_DIRECTORIES(${SQLITE3_INCLUDE_DIRS})
FILE(GLOB SQLITE3SOURCES "src/drivers/sqlite3/*.cc")
ADD_LIBRARY(dbdsqlite3 SHARED ${SQLITE3SOURCES} src/container.cc src/error.cc)
IF (APPLE)
TARGET_LINK_LIBRARIES(dbdsqlite3 dbic++ ${SQLITE3_LIBRARIES} ${UUID_LIBRARIES} ${PCRE_LIBRARIES})
ELSE()
TARGET_LINK_LIBRARIES(dbdsqlite3 ${SQLITE3_LIBRARIES})
ENDIF()
SET_TARGET_PROPERTIES(dbdsqlite3 PROPERTIES VERSION ${CMAKE_SQLITE3_VERSION} SOVERSION 1)
INSTALL(TARGETS dbdsqlite3
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/dbic++
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/dbic++)
ENDIF()
ADD_EXECUTABLE(demo/demo src/examples/demo.cc)
TARGET_LINK_LIBRARIES(demo/demo dbic++ dl ${UUID_LIBRARIES} ${PCRE_LIBRARIES})
ADD_EXECUTABLE(demo/async src/examples/async.cc)
TARGET_LINK_LIBRARIES(demo/async dbic++ dl ${UUID_LIBRARIES} ${PCRE_LIBRARIES})
ADD_DEFINITIONS(-Wall -Wno-sign-compare -rdynamic -fPIC -O3 -Wno-non-virtual-dtor)
ADD_DEFINITIONS(${UUID_DEFINITIONS} ${PCRE_DEFINITIONS})
# Use -DCMAKE_INSTALL_PREFIX:PATH=<path> to override /usr/local
# SET(CMAKE_INSTALL_PREFIX /usr CACHE INTERNAL "")
INSTALL(DIRECTORY DESTINATION ${CMAKE_INSTALL_LIBDIR}/dbic++)
INSTALL(TARGETS dbic++
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
INSTALL(DIRECTORY inc/
DESTINATION include
FILES_MATCHING
PATTERN "*.h")
IF (APPLE)
INSTALL(FILES pkgconfig/macosx/dbic++.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
ELSE()
INSTALL(FILES pkgconfig/dbic++.pc
DESTINATION lib/pkgconfig)
ENDIF()