This repository has been archived by the owner on Sep 29, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
433 lines (327 loc) · 14.1 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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
#
# Format convention
# - command (lower case)
# - VARIABLE (upper case)
# (http://www.cmake.org/cmake/help/v2.8.10/cmake.html)
#
cmake_minimum_required(VERSION 2.8./ FATAL_ERROR)
project(PGROUTING)
#set(CMAKE_VERBOSE_MAKEFILE 1)
# Configure options
option(WITH_DOC
"Set ON|OFF (default=OFF) to build Documentation library tree" OFF)
option(BUILD_LATEX
"Set ON|OFF (default=OFF) to build Documentation library tree as PDF" OFF)
option(BUILD_HTML
"Set ON|OFF (default=ON) to build Documentation library tree as HTML" ON)
option(BUILD_MAN
"Set ON|OFF (default=ON) to build Documentation library tree as MAN page" OFF)
SET(POSTGRESQL_BIN "" CACHE STRING "Define optional path to PostgreSQL binaries an a non-standard location.")
#-----------------------------------------------------------------------------
# PGROUTING version number.
set(PGROUTING_VERSION_MAJOR "2")
set(PGROUTING_VERSION_MINOR "2")
set(PGROUTING_VERSION_PATCH "3")
set(PGROUTING_VERSION_STRING "${PGROUTING_VERSION_MAJOR}.${PGROUTING_VERSION_MINOR}.${PGROUTING_VERSION_PATCH}")
set(PGROUTING_VERSION "${PGROUTING_VERSION_MAJOR}.${PGROUTING_VERSION_MINOR}")
set(POSTGRESQL_MINIMUM_VERSION "9.1.0")
set(POSTGIS_MINIMUM_VERSION "2.0.0")
file(STRINGS "${PGROUTING_SOURCE_DIR}/VERSION" PGROUTING_BUILD_STRING)
set(PGROUTING_GIT_TAG "pgrouting-2.2.3")
#string(REGEX REPLACE "^(.+)-([0-9]+)-g([0-9a-f]+) (.*)$" "\\1" PGROUTING_GIT_TAG ${PGROUTING_BUILD_STRING})
string(REGEX REPLACE "^(.+)-([^-]+)-[0-9]+-g([0-9a-f]+) (.*)$" "\\2" PGROUTING_GIT_BUILD ${PGROUTING_BUILD_STRING})
string(REGEX REPLACE "^(.+)-([0-9]+)-g([0-9a-f]+) (.*)$" "\\3" PGROUTING_GIT_HASH ${PGROUTING_BUILD_STRING})
string(REGEX REPLACE "^(.+)-([0-9]+)-g([0-9a-f]+) (.*)$" "\\4" PGROUTING_GIT_BRANCH ${PGROUTING_BUILD_STRING})
set(PGROUTING_VERSION_REVISION_NAME "${PGROUTING_GIT_HASH} ${PGROUTING_GIT_BRANCH}")
set(PGROUTING_VERSION_REVISION_HASH "${PGROUTING_GIT_HASH}")
message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}")
message(STATUS "PGROUTING_GIT_TAG: ${PGROUTING_GIT_TAG}")
message(STATUS "PGROUTING_GIT_BUILD: ${PGROUTING_GIT_BUILD}")
message(STATUS "PGROUTING_GIT_HASH: ${PGROUTING_GIT_HASH}")
message(STATUS "PGROUTING_GIT_BRANCH: ${PGROUTING_GIT_BRANCH}")
message(STATUS "PGROUTING_VERSION_REVISION_NAME: ${PGROUTING_VERSION_REVISION_NAME}")
message(STATUS "PGROUTING_SOURCE_DIR: ${PGROUTING_SOURCE_DIR}")
message(STATUS "CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}")
message(STATUS "PGROUTING_VERSION_REVISION_HASH: ${PGROUTING_VERSION_REVISION_HASH}")
message(STATUS "POSTGRESQL_BIN: ${POSTGRESQL_BIN}")
#-----------------------------------------------------------------------------
# CMAKE configuration
# This is for my mingw64 environment, it should go away
set(CMAKE_PREFIX_PATH /usr:/usr/local)
set(CMAKE_INCLUDE_PATH /usr:/usr/local)
set(CMAKE_LIBRARY_PATH /usr:/usr/local)
add_subdirectory(cmake)
set(CMAKE_MODULE_PATH "${PGROUTING_SOURCE_DIR}/cmake")
include(MacroLibrary)
include(TargetDistclean)
message(STATUS "UNIX=${UNIX}")
message(STATUS "WIN32=${WIN32}")
if(WIN32)
set(OS_BUILD $ENV{OS_BUILD})
if(NOT OS_BUILD)
set(OS_BUILD "64")
endif(NOT OS_BUILD)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}:/c/ming${OS_BUILD}/projects/pgx${OS_BUILD}/pg92)
if (NOT BOOST_ROOT)
set(BOOST_ROOT c:/ming${OS_BUILD}/msys/local)
endif(NOT BOOST_ROOT)
if (NOT CGAL_ROOT)
set(CGAL_ROOT c:/ming${OS_BUILD}/msys/local)
endif(NOT CGAL_ROOT)
if (NOT GMP_ROOT)
set(GMP_ROOT c:/ming${OS_BUILD}/mingw${OS_BUILD})
endif(NOT GMP_ROOT)
message(STATUS "OS_BUILD=${OS_BUILD}")
message(STATUS "CGAL_ROOT=${CGAL_ROOT}")
message(STATUS "GMP_ROOT=${GMP_ROOT}")
message(STATUS "BOOST_ROOT=${BOOST_ROOT}")
message(STATUS "CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}")
endif(WIN32)
include(FindPerl)
if(NOT PERL_EXECUTABLE)
message(FATAL_ERROR " Please check your Perl installation.")
endif(NOT PERL_EXECUTABLE)
find_package(PostgreSQL)
if(NOT POSTGRESQL_FOUND)
message(FATAL_ERROR " Please check your PostgreSQL installation.")
endif(NOT POSTGRESQL_FOUND)
#set(Boost_DEBUG ON)
find_package(Boost)
if(Boost_INCLUDE_DIRS)
message(STATUS "Boost headers were found here: ${Boost_INCLUDE_DIR}")
else(Boost_INCLUDE_DIRS)
message(FATAL_ERROR " Please check your Boost installation ")
endif(Boost_INCLUDE_DIRS)
find_package(CGAL)
if(NOT CGAL_FOUND)
message(FATAL_ERROR " Please check your CGAL installation, or set correct path to CGAL_INCLUDE_DIR and CGAL_LIBRARIES.")
endif(NOT CGAL_FOUND)
if(NOT POSTGRESQL_VERSION_STRING)
message(FATAL_ERROR "pg_config was not found. Please check your PostgreSQL installation!")
endif(NOT POSTGRESQL_VERSION_STRING)
message(STATUS "POSTGRESQL_VERSION_STRING is ${POSTGRESQL_VERSION_STRING}")
string(SUBSTRING "${POSTGRESQL_VERSION_STRING}" 11 -1 POSTGRESQL_VERSION)
message(STATUS "POSTGRESQL_VERSION is ${POSTGRESQL_VERSION}")
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*" "\\1\\2" PGSQL_VERSION ${POSTGRESQL_VERSION})
message(STATUS "PGSQL_VERSION is ${PGSQL_VERSION}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPGSQL_VERSION=${PGSQL_VERSION}")
if("${POSTGRESQL_VERSION}" VERSION_LESS "${POSTGRESQL_MINIMUM_VERSION}")
message(FATAL_ERROR " PostgreSQL ${POSTGRESQL_MINIMUM_VERSION} or greater is required.")
endif("${POSTGRESQL_VERSION}" VERSION_LESS "${POSTGRESQL_MINIMUM_VERSION}")
execute_process(
COMMAND ${POSTGRESQL_PG_CONFIG} --pkglibdir
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE LIB_DIR)
if(LIB_DIR)
message(STATUS "Install directory for libraries is set to ${LIB_DIR}")
else(LIB_DIR)
message(FATAL_ERROR "pg_config --pkglibdir failed to return a value. Please check your PostgreSQL installation!")
endif(LIB_DIR)
set(LIBRARY_INSTALL_PATH ${LIB_DIR})
execute_process(
COMMAND ${POSTGRESQL_PG_CONFIG} --sharedir
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE SHARE_DIR)
if(SHARE_DIR)
set(SHARE_DIR "${SHARE_DIR}/extension")
message(STATUS "Extension directory for SQL files is set to ${SHARE_DIR}")
else(SHARE_DIR)
message(FATAL_ERROR "pg_config --sharedir failed to return a value. Please check your PostgreSQL installation!")
endif(SHARE_DIR)
# Handles documentation
add_subdirectory(doc)
#include directories: files in alphabetical order
set(PGROUTING_INCLUDE_DIRECTORIES
${PGROUTING_SOURCE_DIR}/src/apsp_johnson/src
${PGROUTING_SOURCE_DIR}/src/apsp_warshall/src
${PGROUTING_SOURCE_DIR}/src/allpairs/src
${PGROUTING_SOURCE_DIR}/src/astar/src
${PGROUTING_SOURCE_DIR}/src/bd_astar/src
${PGROUTING_SOURCE_DIR}/src/bd_dijkstra/src
${PGROUTING_SOURCE_DIR}/src/common/src
${PGROUTING_SOURCE_DIR}/src/dijkstra/src
${PGROUTING_SOURCE_DIR}/src/driving_distance/src
${PGROUTING_SOURCE_DIR}/src/kdijkstra/src
${PGROUTING_SOURCE_DIR}/src/ksp/src
${PGROUTING_SOURCE_DIR}/src/trsp/src
${PGROUTING_SOURCE_DIR}/src/tsp/src
${PGROUTING_SOURCE_DIR}/src/vrp_basic/src
${PGROUTING_SOURCE_DIR}/src/vrppdtw/src
# not using C/C++
${PGROUTING_SOURCE_DIR}/src/label_graph/src
#not suported but directory exists
# ${PGROUTING_SOURCE_DIR}/src/shooting_star/src
)
include_directories(${PGROUTING_INCLUDE_DIRECTORIES} ${POSTGRESQL_INCLUDE_DIR} ${Boost_INCLUDE_DIRS})
if(WIN32)
include_directories(${POSTGRESQL_INCLUDE_DIR}/port/win32)
endif(WIN32)
# we need link libpostgres.a on win32 env
if(WIN32)
message(STATUS "LINK_DIRECTORIES = ${POSTGRESQL_LIBRARIES}")
link_directories(${POSTGRESQL_LIBRARIES} ${LIB_DIR})
link_libraries(postgres)
endif(WIN32)
# TODO default compilation with -dNDEBUG
#compiler directives
if(APPLE)
# support GNU(Xcode<4) and Clang(Xcode>=4)
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -O2 -g -frounding-math")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -O2 -g")
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -O2 -g -frounding-math -Wno-deprecated")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -O2 -std=c++0x -g -Wno-deprecated")
endif()
elseif(UNIX) # UNIX system variable include UNIX like system(i.e. APPLE and CYGWIN)
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -fPIC -O2 -g -Wall -Wconversion -pedantic -fmax-errors=10 -Wmissing-prototypes -frounding-math")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -fPIC -O2 -g -Wall -Wconversion -pedantic -fmax-errors=10 -Wextra -frounding-math -Wno-deprecated")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -O2 -g -frounding-math")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -O2 -g -std=c++0x -frounding-math -Wno-deprecated")
elseif(WIN32)
# currently, support MinGW only
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -frounding-math")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -std=c++0x -frounding-math -Wno-deprecated")
endif()
# List variable to collect module SQL file names
set(PACKAGE_SQL_FILES "")
set(L_PACKAGE_SQL_FILES "")
#==========================
# PgRouting_SOURCE_NAMES
#==========================
set(PgRouting_SOURCE_NAMES
"common"
#to be deprecated
"kdijkstra"
"dijkstra"
"driving_distance"
"ksp"
"allpairs"
"withPoints"
#"funnyDijkstra"
"alpha_shape"
"astar" "bd_astar"
"bd_dijkstra"
"trsp" #2.0
"tsp"
"vrp_basic"
"vrppdtw"
)
#-------------------
# add the subdirectories that have the C/C++ code
#-------------------
foreach (subdir ${PgRouting_SOURCE_NAMES})
add_subdirectory("${PGROUTING_SOURCE_DIR}/src/${subdir}/src")
endforeach()
#-----------------------------------------------------------------------------
# List variable to collect module SQL file names
#-----------------------------------------------------------------------------
set(PgRouting_SQL_DIRECTORIES ${PgRouting_SOURCE_NAMES}
"apsp_johnson" #V2.0
"apsp_warshall" #V2.0
"convinience"
"topology"
"label_graph")
set(PACKAGE_SQL_FILES "")
set(LIST_PACKAGE_SQL_FILES "")
foreach (subdir ${PgRouting_SQL_DIRECTORIES})
add_subdirectory("${PGROUTING_SOURCE_DIR}/src/${subdir}/sql")
endforeach()
list(APPEND LIST_PACKAGE_SQL_FILES "${PACKAGE_SQL_FILES}")
#if (CDEBUG)
foreach (files ${LIST_PACKAGE_SQL_FILES})
message("${files}")
endforeach()
#endif()
#add_subdirectory(src)
#list(APPEND L_PACKAGE_SQL_FILES "${PACKAGE_SQL_FILES}")
# assemble the object files from the src functions into
# a single library librouting.so
set(LIBRARY_OUTPUT_PATH lib)
if(APPLE)
set(LIBRARY_MODE_TARGET "MODULE")
else(APPLE)
set(LIBRARY_MODE_TARGET "SHARED")
endif(APPLE)
LINK_LIBRARIES(${CGAL_LIBRARIES} ${GMP_LIBRARIES} ${BOOST_THREAD_LIBRARIES})
#-------------------
# pgRouting objects to be linked
#-------------------
foreach (subdir ${PgRouting_SOURCE_NAMES} )
set(PGROUTING_OBJECTS ${PGROUTING_OBJECTS} "$<TARGET_OBJECTS:${subdir}>")
endforeach()
#-----------------------------------------------------------------------------
# PGROUTING Library names
#-----------------------------------------------------------------------------
message("Building the library names")
#----------------------
# PGROUTING installation files names have the following name
#----------------------
set(PGROUTING_LIB_NAME "pgrouting-${PGROUTING_VERSION}")
#----------------------
# PGROUTING library name used in the pgr_functions
# '$libdir/${PGROUTING_LIBRARY_NAME}'
#----------------------
set(PGROUTING_LIBRARY_NAME "libpgrouting-${PGROUTING_VERSION}")
add_library(${PGROUTING_LIB_NAME}
${LIBRARY_MODE_TARGET}
${PGROUTING_OBJECTS})
install(TARGETS ${PGROUTING_LIB_NAME} DESTINATION ${LIBRARY_INSTALL_PATH})
if(APPLE)
set_target_properties(${PGROUTING_LIB_NAME}
PROPERTIES
LINK_FLAGS "-bundle_loader ${POSTGRESQL_EXECUTABLE} -bundle")
endif(APPLE)
file(WRITE "${CMAKE_BINARY_DIR}/lib/pgrouting--${PGROUTING_VERSION_STRING}.sql.in"
"-- pgRouting version '${PGROUTING_VERSION_STRING}' extension for postgresql\n")
file(APPEND "${CMAKE_BINARY_DIR}/lib/pgrouting--${PGROUTING_VERSION_STRING}.sql.in"
"-- Complain if script is sourced in pgsql, rather than CREATE EXTENSION\n")
#file(APPEND "${CMAKE_BINARY_DIR}/lib/pgrouting--${PGROUTING_VERSION_STRING}.sql.in"
# "\\echo Use \"CREATE EXTENSION pgrouting\" to load this file. \\quit")
foreach(PACKAGE_SQL_FILE ${LIST_PACKAGE_SQL_FILES})
cat(${PACKAGE_SQL_FILE} "${CMAKE_BINARY_DIR}/lib/pgrouting--${PGROUTING_VERSION_STRING}.sql.in")
endforeach()
# copy our temporary file into a final file
# this extra set will allow us to place variables in the sql file
# that will get substituted in this step before they are installed
configure_file("${CMAKE_BINARY_DIR}/lib/pgrouting--${PGROUTING_VERSION_STRING}.sql.in"
"${CMAKE_BINARY_DIR}/lib/pgrouting--${PGROUTING_VERSION_STRING}.sql")
configure_file("${PGROUTING_SOURCE_DIR}/src/common/sql/pgrouting.control.in"
"${CMAKE_BINARY_DIR}/lib/pgrouting.control")
# create the signature file for this release
message(STATUS "Creating lib/pgrouting--${PGROUTING_VERSION_STRING}.sig")
execute_process(
COMMAND ${PERL_EXECUTABLE} ${PGROUTING_SOURCE_DIR}/tools/mk-signature-file ${PGROUTING_VERSION_STRING}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
RESULT_VARIABLE SIG_RESULT
)
if(SIG_RESULT)
message(FATAL_ERROR " SIG_RESULT: ${SIG_RESULT}")
endif(SIG_RESULT)
# create the extension update scripts
execute_process(
COMMAND ${PERL_EXECUTABLE} ${PGROUTING_SOURCE_DIR}/tools/build-extension-update-files ${PGROUTING_VERSION_STRING} ${PGROUTING_SOURCE_DIR}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
RESULT_VARIABLE UPDATE_RESULT
)
if(UPDATE_RESULT)
message(FATAL_ERROR " UPDATE_RESULT: ${UPDATE_RESULT}")
endif(UPDATE_RESULT)
# make a list of the files we need to install for version updates
file(GLOB VERSION_UPDATE_FILES "${CMAKE_BINARY_DIR}/lib/pgrouting--*--*.sql")
# this will create the commands in the makefile under the install target
if(UNIX)
file(GLOB_RECURSE LIBS_TO_INSTALL "${CMAKE_BINARY_DIR}/lib/*.so")
else(UNIX)
file(GLOB_RECURSE LIBS_TO_INSTALL "${CMAKE_BINARY_DIR}/lib/*.dll")
endif(UNIX)
message(STATUS "LIBS_TO_INSTALL=${LIBS_TO_INSTALL}")
install(FILES ${LIBS_TO_INSTALL} DESTINATION ${LIB_DIR})
install(FILES
"${CMAKE_BINARY_DIR}/lib/pgrouting--${PGROUTING_VERSION_STRING}.sql"
"${CMAKE_BINARY_DIR}/lib/pgrouting.control"
${VERSION_UPDATE_FILES}
DESTINATION "${SHARE_DIR}")