-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
248 lines (222 loc) · 8.81 KB
/
Copy pathCMakeLists.txt
File metadata and controls
248 lines (222 loc) · 8.81 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
set(INSTALL_FILE ${PROJECT_NAME}--${PROJECT_VERSION_MOD}.sql)
include(ScriptFiles)
# These files represent the modifications that happen in each version, excluding
# new objects or updates to functions. We use them to build a path (update
# script) from every historical version to the current version. Note that not
# all of these files may exist on disk, in case they would have no contents.
# There still needs to be an entry here to build an update script for that
# version. Thus, for every new release, an entry should be added here.
set(MOD_FILES
updates/2.9.0--2.9.1.sql
updates/2.9.1--2.9.2.sql
updates/2.9.2--2.9.3.sql
updates/2.9.3--2.10.0.sql
updates/2.10.0--2.10.1.sql
updates/2.10.1--2.10.2.sql
updates/2.10.2--2.10.3.sql
updates/2.10.3--2.11.0.sql
updates/2.11.0--2.11.1.sql
updates/2.11.1--2.11.2.sql
updates/2.11.2--2.12.0.sql
updates/2.12.0--2.12.1.sql
updates/2.12.1--2.12.2.sql
updates/2.12.2--2.13.0.sql
updates/2.13.0--2.13.1.sql
updates/2.13.1--2.14.0.sql
updates/2.14.0--2.14.1.sql
updates/2.14.1--2.14.2.sql
updates/2.14.2--2.15.0.sql
updates/2.15.0--2.15.1.sql
updates/2.15.1--2.15.2.sql
updates/2.15.2--2.15.3.sql
updates/2.15.3--2.16.0.sql
updates/2.16.0--2.16.1.sql
updates/2.16.1--2.17.0.sql
updates/2.17.0--2.17.1.sql
updates/2.17.1--2.17.2.sql
updates/2.17.2--2.18.0.sql
updates/2.18.0--2.18.1.sql
updates/2.18.1--2.18.2.sql
updates/2.18.2--2.19.0.sql
updates/2.19.0--2.19.1.sql
updates/2.19.1--2.19.2.sql
updates/2.19.2--2.19.3.sql
updates/2.19.3--2.20.0.sql
updates/2.20.0--2.20.1.sql
updates/2.20.1--2.20.2.sql
updates/2.20.2--2.20.3.sql
updates/2.20.3--2.21.0.sql
updates/2.21.0--2.21.1.sql
updates/2.21.1--2.21.2.sql
updates/2.21.2--2.21.3.sql
updates/2.21.3--2.21.4.sql
updates/2.21.4--2.22.0.sql
updates/2.22.0--2.22.1.sql
updates/2.22.1--2.23.0.sql
updates/2.23.0--2.23.1.sql
updates/2.23.1--2.24.0.sql
updates/2.24.0--2.25.0.sql
updates/2.25.0--2.25.1.sql
updates/2.25.1--2.25.2.sql
updates/2.25.2--2.26.0.sql
updates/2.26.0--2.26.1.sql
updates/2.26.1--2.26.2.sql
updates/2.26.2--2.26.3.sql
updates/2.26.3--2.26.4.sql
updates/2.26.4--2.27.0.sql
updates/2.27.0--2.27.1.sql)
# The downgrade file to generate a downgrade script for the current version, as
# specified in version.config
set(CURRENT_REV_FILE reverse-dev.sql)
set(MODULE_PATHNAME "$libdir/timescaledb-${PROJECT_VERSION_MOD}")
set(LOADER_PATHNAME "$libdir/timescaledb")
set(TS_MODULE_PATHNAME
${MODULE_PATHNAME}
PARENT_SCOPE)
set(TSL_MODULE_PATHNAME
"$libdir/timescaledb-tsl-${PROJECT_VERSION_MOD}"
PARENT_SCOPE)
if(NOT GENERATE_DOWNGRADE_SCRIPT)
message(
STATUS "Not generating downgrade script: downgrade generation disabled.")
elseif(NOT GIT_FOUND)
message(STATUS "Not generating downgrade script: Git not available.")
else()
generate_downgrade_script(
SOURCE_VERSION
${PROJECT_VERSION_MOD}
TARGET_VERSION
${PREVIOUS_VERSION}
INPUT_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/updates
FILES
${CURRENT_REV_FILE})
endif()
# Function to replace @VARIABLE@ in source files, producing output files in the
# build dir. When SUFFIX is provided, it is appended to each output filename
# (used for version-specific copies like version_check.sql).
function(version_files SRC_FILE_LIST OUTPUT_FILE_LIST)
cmake_parse_arguments(_vf "" "SUFFIX" "" ${ARGN})
set(result "")
foreach(unversioned_file ${SRC_FILE_LIST})
set(versioned_file ${unversioned_file}${_vf_SUFFIX})
list(APPEND result ${CMAKE_CURRENT_BINARY_DIR}/${versioned_file})
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${unversioned_file})
configure_file(${unversioned_file} ${versioned_file} @ONLY)
endif()
endforeach(unversioned_file)
set(${OUTPUT_FILE_LIST}
"${result}"
PARENT_SCOPE)
endfunction()
# Create versioned files (replacing MODULE_PATHNAME) in the build directory of
# all our source files
version_files("${PRE_UPDATE_FILES}" PRE_UPDATE_FILES_VERSIONED)
version_files("${POST_UPDATE_FILES}" POST_UPDATE_FILES_VERSIONED)
version_files("${PRE_INSTALL_SOURCE_FILES}" PRE_INSTALL_SOURCE_FILES_VERSIONED)
version_files("${PRE_INSTALL_FUNCTION_FILES}"
PRE_INSTALL_FUNCTION_FILES_VERSIONED)
version_files("${SOURCE_FILES}" SOURCE_FILES_VERSIONED)
version_files("${MOD_FILES}" MOD_FILES_VERSIONED)
version_files("updates/latest-dev.sql" LASTEST_MOD_VERSIONED)
version_files("notice.sql" NOTICE_FILE)
# Function to concatenate all files in SRC_FILE_LIST into file OUTPUT_FILE. When
# STRIP_REPLACE is set, strips `OR REPLACE` from the output to prevent privilege
# escalation attacks in CREATE scripts.
function(cat_files SRC_FILE_LIST OUTPUT_FILE)
if(WIN32)
set("SRC_ARG" "-DSRC_FILE_LIST=${SRC_FILE_LIST}")
else()
set("SRC_ARG" "'-DSRC_FILE_LIST=${SRC_FILE_LIST}'")
endif()
set(_extra_args)
if(STRIP_REPLACE)
list(APPEND _extra_args "-DSTRIP_REPLACE=ON")
endif()
add_custom_command(
OUTPUT ${OUTPUT_FILE}
DEPENDS ${SRC_FILE_LIST}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} "${SRC_ARG}" "-DOUTPUT_FILE=${OUTPUT_FILE}"
${_extra_args} -P cat.cmake
COMMENT "Generating ${OUTPUT_FILE}")
endfunction()
# Generate the extension file used with CREATE EXTENSION
set(STRIP_REPLACE ON)
cat_files(
"${PRE_INSTALL_SOURCE_FILES_VERSIONED};${SOURCE_FILES_VERSIONED};${NOTICE_FILE}"
${CMAKE_CURRENT_BINARY_DIR}/${INSTALL_FILE})
set(STRIP_REPLACE OFF)
add_custom_target(sqlfile ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${INSTALL_FILE})
# Generate the update files used with ALTER EXTENSION <name> UPDATE
set(MOD_FILE_REGEX
"([0-9]+\\.[0-9]+\\.*[0-9]+[-a-z0-9]*)--([0-9]+\\.[0-9]+\\.*[0-9]+[-a-z0-9]*).sql"
)
# We'd like to process the updates in reverse (descending) order
if(EXISTS
"${CMAKE_CURRENT_SOURCE_DIR}/updates/${PREVIOUS_VERSION}--${PROJECT_VERSION_MOD}.sql"
)
set(MOD_FILES_LIST ${MOD_FILES_VERSIONED})
else()
set(MOD_FILES_LIST
"${MOD_FILES_VERSIONED};updates/${PREVIOUS_VERSION}--${PROJECT_VERSION_MOD}.sql"
)
endif()
list(REVERSE MOD_FILES_LIST)
# Variable that will hold the list of update scripts from every previous version
# to the current version
set(UPDATE_SCRIPTS "")
# A list of current modfiles. We append to this list for every previous version
# that moves us further away from the current version, thus making the update
# path longer as we move back in history
set(CURR_MOD_FILES "${LASTEST_MOD_VERSIONED}")
# Generate the post-update file once (same for all update scripts)
set(POST_FILES_PROCESSED ${POST_UPDATE_FILES_VERSIONED}.processed)
cat_files("${POST_UPDATE_FILES_VERSIONED}" ${POST_FILES_PROCESSED})
# Now loop through the modfiles and generate the update files
foreach(transition_mod_file ${MOD_FILES_LIST})
if(NOT (${transition_mod_file} MATCHES ${MOD_FILE_REGEX}))
message(FATAL_ERROR "Cannot parse update file name ${transition_mod_file}")
endif()
set(START_VERSION ${CMAKE_MATCH_1})
set(END_VERSION ${CMAKE_MATCH_2})
set(PRE_FILES ${PRE_UPDATE_FILES_VERSIONED})
# 2.24.0 was last time we changed view signatures any version past that we can
# support extension updates while user view dependencies exist
if(START_VERSION VERSION_GREATER "2.24.0")
set(PRE_FILES ${PRE_FILES};views_detached.sql)
endif()
# Check for version-specific update code with fixes
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/updates/${START_VERSION}.sql)
version_files("updates/${START_VERSION}.sql" ORIGIN_MOD_FILE)
list(APPEND PRE_FILES ${ORIGIN_MOD_FILE})
endif()
version_files("updates/version_check.sql" VERSION_CHECK_VERSIONED SUFFIX
-${START_VERSION})
list(PREPEND PRE_FILES "header.sql;${VERSION_CHECK_VERSIONED}")
# There might not have been any changes in the modfile, in which case the
# modfile need not be present
if(EXISTS ${transition_mod_file})
# Prepend the modfile as we are moving through the versions in descending
# order
list(INSERT CURR_MOD_FILES 0 ${transition_mod_file})
endif()
set(UPDATE_SCRIPT
${CMAKE_CURRENT_BINARY_DIR}/timescaledb--${START_VERSION}--${PROJECT_VERSION_MOD}.sql
)
list(APPEND UPDATE_SCRIPTS ${UPDATE_SCRIPT})
if(CURR_MOD_FILES)
cat_files(
"${PRE_FILES};${CURR_MOD_FILES};${PRE_INSTALL_FUNCTION_FILES_VERSIONED};${SOURCE_FILES_VERSIONED};${POST_FILES_PROCESSED}"
${UPDATE_SCRIPT})
else()
cat_files(
"${PRE_FILES};${PRE_INSTALL_FUNCTION_FILES_VERSIONED};${SOURCE_FILES_VERSIONED};${POST_FILES_PROCESSED}"
${UPDATE_SCRIPT})
endif()
endforeach(transition_mod_file)
add_custom_target(sqlupdatescripts ALL DEPENDS ${UPDATE_SCRIPTS})
# Install target for the extension file and update scripts
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${INSTALL_FILE} ${UPDATE_SCRIPTS}
DESTINATION "${PG_SHAREDIR}/extension")