-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
165 lines (143 loc) · 4.53 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Apache 2 Licensed
# Code modified from:
# TimescaleDB (https://www.timescale.com/)
cmake_minimum_required(VERSION 3.4)
set(PROJECT_NAME demopgextension)
set(PROEJCT_VERSION "0.0.1")
project(${PROJECT_NAME} VERSION ${VERSION} LANGUAGES C)
if (NOT CMAKE_BUILD_TYPE)
# Default to Release builds
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel" FORCE)
endif ()
message(STATUS "Build type is ${CMAKE_BUILD_TYPE}")
# Search paths for Postgres binaries
if (WIN32)
find_path(PG_PATH
bin/postgres
HINTS
"C:/PostgreSQL"
"C:/Program Files/PostgreSQL"
PATH_SUFFIXES
bin
10/bin
96/bin
pg96/bin
DOC
"The path to a PostgreSQL installation")
endif (WIN32)
if (UNIX)
find_path(PG_PATH
bin/postgres
HINTS
$ENV{HOME}
/opt/local/pgsql
/usr/local/pgsql
/usr/lib/postgresql
PATH_SUFFIXES
bin
10/bin
9.6/bin
96/bin
pg96/bin
DOC
"The path to a PostgreSQL installation")
endif (UNIX)
find_program(PG_CONFIG pg_config
HINTS
${PG_PATH}
PATH_SUFFIXES
bin
DOC
"The path to the pg_config of the PostgreSQL version to compile against"
REQUIRED)
if (NOT PG_CONFIG)
message(FATAL_ERROR "Unable to find 'pg_config'")
endif ()
find_package(Git)
message(STATUS "Using pg_config ${PG_CONFIG}")
# Check PostgreSQL version
execute_process(
COMMAND ${PG_CONFIG} --version
OUTPUT_VARIABLE PG_VERSION_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT ${PG_VERSION_STRING} MATCHES "^PostgreSQL[ ]+([0-9]+)\\.([0-9]+)(\\.([0-9]+))*$")
message(FATAL_ERROR "Could not parse PostgreSQL version ${PG_VERSION}")
endif ()
set(PG_VERSION_MAJOR ${CMAKE_MATCH_1})
set(PG_VERSION_MINOR ${CMAKE_MATCH_2})
set(PG_VERSION_PATCH ${CMAKE_MATCH_4})
if (NOT ${PG_VERSION_PATCH} OR ${PG_VERSION_PATCH} EQUAL "")
set(PG_VERSION "${PG_VERSION_MAJOR}.${PG_VERSION_MINOR}")
else ()
set(PG_VERSION "${PG_VERSION_MAJOR}.${PG_VERSION_MINOR}.${PG_VERSION_PATCH}")
endif ()
message(STATUS "Compiling against PostgreSQL version ${PG_VERSION}")
if ((${PG_VERSION} VERSION_LESS "9.6")
OR (${PG_VERSION} VERSION_EQUAL "11")
OR (${PG_VERSION} VERSION_GREATER "11"))
endif ()
# Get PostgreSQL configuration from pg_config
execute_process(
COMMAND ${PG_CONFIG} --includedir
OUTPUT_VARIABLE PG_INCLUDEDIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${PG_CONFIG} --includedir-server
OUTPUT_VARIABLE PG_INCLUDEDIR_SERVER
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${PG_CONFIG} --libdir
OUTPUT_VARIABLE PG_LIBDIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${PG_CONFIG} --pkglibdir
OUTPUT_VARIABLE PG_PKGLIBDIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${PG_CONFIG} --sharedir
OUTPUT_VARIABLE PG_SHAREDIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${PG_CONFIG} --bindir
OUTPUT_VARIABLE PG_BINDIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${PG_CONFIG} --cppflags
OUTPUT_VARIABLE PG_CPPFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${PG_CONFIG} --cflags
OUTPUT_VARIABLE PG_CFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${PG_CONFIG} --ldflags
OUTPUT_VARIABLE PG_LDFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${PG_CONFIG} --libs
OUTPUT_VARIABLE PG_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE)
find_path(PG_SOURCE_DIR
src/include/pg_config.h.in
HINTS
$ENV{HOME}
$ENV{HOME}/projects
$ENV{HOME}/Projects
$ENV{HOME}/development
$ENV{HOME}/Development
PATH_SUFFIXES
postgres
postgresql
pgsql
DOC
"The path to the PostgreSQL source tree")
if (PG_SOURCE_DIR)
message(STATUS "Found PostgreSQL source in ${PG_SOURCE_DIR}")
endif (PG_SOURCE_DIR)
add_subdirectory(sql)
add_subdirectory(src)
set(EXT_CONTROL_FILE ${PROJECT_NAME}.control)
configure_file(${EXT_CONTROL_FILE} ${EXT_CONTROL_FILE})
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXT_CONTROL_FILE}
DESTINATION "${PG_SHAREDIR}/extension")