-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
314 lines (268 loc) · 10.7 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
cmake_minimum_required(VERSION 3.13.0 FATAL_ERROR)
project(Graphviz)
include(FeatureSummary)
# =============================== Build options ================================
option(enable_ltdl "Support on-demand plugin loading" ON)
option(with_expat "Support HTML-like labels through expat" ON )
option(with_digcola "DIGCOLA features in neato layout engine" ON )
option(with_gvedit "GVEdit interactive graph editor" ON)
option(with_ipsepcola "IPSEPCOLA features in neato layout engine (disabled by default - C++ portability issues)." OFF )
option(with_ortho "ORTHO features in neato layout engine." ON )
option(with_sfdp "sfdp layout engine." ON )
option(with_smyrna "SMYRNA large graph viewer (disabled by default - experimental)" OFF)
option(with_zlib "Support raster image compression through zlib" ON)
option(use_coverage "enables analyzing code coverage" OFF)
option(with_cxx_api "enables building the C++ API" OFF)
option(with_cxx_tests "enables building the C++ tests" OFF)
option(use_win_pre_inst_libs "enables building using pre-installed Windows libraries" ON)
if(WIN32)
# Build dynamic-link libraries on Windows, including MinGW. The
# CMake build system does not currently support building static
# libraries, so the GVDLL symbol can be unconditionally set until
# such support is introduced.
add_definitions(-DGVDLL)
option(install_win_dependency_dlls "Install 3rd party dependencies" ON)
endif()
if(with_digcola)
add_definitions(-DDIGCOLA)
endif()
if(with_ipsepcola)
add_definitions(-DIPSEPCOLA)
endif()
if(with_ortho)
add_definitions(-DORTHO)
endif()
if(with_sfdp)
add_definitions(-DSFDP)
endif()
# ===================== Append local CMake module directory ====================
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# ============================= Build dependencies =============================
find_package(BISON 3.0 REQUIRED)
find_package(FLEX REQUIRED)
find_program(GIT git)
if(NOT GIT)
message(FATAL_ERROR "git not found")
endif()
find_program(GZIP gzip)
# ================== Convenient values for CMake configuration =================
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
include(GNUInstallDirs)
set(BINARY_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}")
set(LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}")
set(HEADER_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/graphviz")
set(MAN_INSTALL_DIR "${CMAKE_INSTALL_MANDIR}")
set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
set(DATA_INSTALL_DIR "${CMAKE_INSTALL_DATAROOTDIR}")
else()
set(BINARY_INSTALL_DIR bin)
set(LIBRARY_INSTALL_DIR lib)
set(HEADER_INSTALL_DIR include/graphviz)
set(MAN_INSTALL_DIR share/man)
set(libdir "${CMAKE_INSTALL_PREFIX}/${LIBRARY_INSTALL_DIR}")
set(includedir "${CMAKE_INSTALL_PREFIX}/include")
set(DATA_INSTALL_DIR share)
endif()
set(PLUGIN_INSTALL_DIR ${LIBRARY_INSTALL_DIR}/graphviz)
set(PKGCONFIG_DIR ${LIBRARY_INSTALL_DIR}/pkgconfig)
# TODO: Find a way to check for groff and ps2pdf for manpage pdf generation
# set(MAN_PDF_INSTALL_DIR share/graphviz/doc/pdf)
set(WINDOWS_DEPENDENCY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/windows/dependencies/libraries")
set(WINDOWS_DEPENDENCY_VCPKG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/windows/dependencies/libraries/vcpkg/installed")
if(CMAKE_CL_64)
set(WINDOWS_DEPENDENCY_DIR "${WINDOWS_DEPENDENCY_DIR}/x64")
set(WINDOWS_DEPENDENCY_VCPKG_DIR "${WINDOWS_DEPENDENCY_VCPKG_DIR}/x64-windows")
else()
set(WINDOWS_DEPENDENCY_DIR "${WINDOWS_DEPENDENCY_DIR}/x86")
set(WINDOWS_DEPENDENCY_VCPKG_DIR "${WINDOWS_DEPENDENCY_VCPKG_DIR}/x86-windows")
endif()
set(GRAPHVIZ_PLUGIN_VERSION 6)
# Name of the config file used by Graphviz
set(GVPLUGIN_CONFIG_FILE config${GRAPHVIZ_PLUGIN_VERSION})
# ============================ Library dependencies ============================
if(WIN32)
if(use_win_pre_inst_libs)
list(APPEND CMAKE_PREFIX_PATH ${WINDOWS_DEPENDENCY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${WINDOWS_DEPENDENCY_VCPKG_DIR})
endif()
if(MINGW)
list(APPEND CMAKE_PREFIX_PATH $ENV{MSYSTEM_PREFIX})
endif()
endif()
find_package(ANN)
find_package(CAIRO)
if(with_expat)
find_package(EXPAT)
endif()
find_package(GD)
find_package(GS)
find_package(GTS)
if(enable_ltdl)
find_package(LTDL)
if(LTDL_FOUND)
add_definitions(-DENABLE_LTDL)
endif()
endif()
find_package(PANGOCAIRO)
find_package(PkgConfig)
if(PkgConfig_FOUND)
pkg_check_modules(POPPLER poppler-glib)
pkg_check_modules(RSVG librsvg-2.0)
pkg_check_modules(WEBP libwebp)
else()
set(POPPLER_FOUND 0)
set(RSVG_FOUND 0)
set(WEBP_FOUND 0)
endif()
if(with_zlib)
find_package(ZLIB)
endif()
if(UNIX)
find_library(MATH_LIB m)
link_libraries(${MATH_LIB})
endif()
if(WIN32)
# Find Windows specific dependencies
# Find DLLs on Windows
find_program(EXPAT_RUNTIME_LIBRARIES NAMES libexpat.dll expat.dll msys-expat-1.dll)
if(CMAKE_CL_64)
find_program(MSYS_RUNTIME_LIBRARIES NAMES msys-2.0.dll)
endif()
endif()
# ============================ Set Graphviz version ============================
find_package(Python3 REQUIRED COMPONENTS Interpreter)
if(DEFINED VERSION)
set(GRAPHVIZ_VERSION_STRING "${VERSION}")
else()
execute_process(
COMMAND ${Python3_EXECUTABLE} gen_version.py
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE gen_version_result
OUTPUT_VARIABLE GRAPHVIZ_VERSION_STRING
ERROR_VARIABLE gen_version_error
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if(NOT gen_version_result EQUAL 0)
message(FATAL_ERROR "Failed to set version: ${gen_version_error}")
endif()
endif()
# Set GRAPHVIZ_VERSION_BUILD to time of last commit, or to 0 if that fails.
execute_process(
COMMAND ${Python3_EXECUTABLE} gen_version.py --committer-date-graphviz
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE gen_date_result
OUTPUT_VARIABLE GRAPHVIZ_VERSION_BUILD
ERROR_VARIABLE gen_date_error
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if(NOT gen_date_result EQUAL 0)
message(FATAL_ERROR "Failed to set date: ${gen_date_error}")
endif()
string(REGEX REPLACE "\\..*"
"" GRAPHVIZ_VERSION_MAJOR
${GRAPHVIZ_VERSION_STRING})
string(REGEX REPLACE "[^.]*\\.([^.]*)\\..*"
"\\1" GRAPHVIZ_VERSION_MINOR
${GRAPHVIZ_VERSION_STRING})
string(REGEX REPLACE "[^.]*\\.[^.]*\\.(.*)$"
"\\1" GRAPHVIZ_VERSION_PATCH
${GRAPHVIZ_VERSION_STRING})
set(GRAPHVIZ_VERSION_FULL "${GRAPHVIZ_VERSION_STRING}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/builddate.h "#define BUILDDATE \"${GRAPHVIZ_VERSION_BUILD}\"")
configure_file(graphviz_version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/graphviz_version.h @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/graphviz_version.h DESTINATION ${HEADER_INSTALL_DIR})
message(STATUS "Graphviz version: ${GRAPHVIZ_VERSION_FULL}")
include(config_checks)
if(NOT HAVE_GETOPT_H)
find_package(GETOPT REQUIRED)
endif()
include_directories(${CMAKE_CURRENT_BINARY_DIR})
# ==================== Custom target for `make uninstall` ======================
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
# =========================== Compiler configuration ===========================
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# enable LTO in release builds
include(CheckIPOSupported)
check_ipo_supported(RESULT HAVE_IPO)
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR
CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
if(HAVE_IPO)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
endif()
endif()
if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
# MSVC warning C4996 mostly fires on completely valid code. The changes
# proposed in the warning text often seriously compromise the code
# portability, while they never substantially improve the code quality. Thus
# we suppress this warning.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996")
else()
# Enable common warnings flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
endif()
include(CheckCCompilerFlag)
check_c_compiler_flag(-Wformat-overflow=2 HAVE_C_WFORMAT_OVERFLOW_2)
if(HAVE_C_WFORMAT_OVERFLOW_2)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat-overflow=2")
endif()
check_c_compiler_flag(-Wshadow HAVE_C_WSHADOW)
if(HAVE_C_WSHADOW)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
endif()
check_c_compiler_flag(-Wundef HAVE_C_WUNDEF)
if(HAVE_C_WUNDEF)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wundef")
endif()
if(use_coverage)
add_compile_options("-coverage")
add_link_options("-coverage")
endif()
# ============================ Packaging information ===========================
include(InstallRequiredSystemLibraries)
include(package_info)
include(CPack)
# ==================================== Test ====================================
include(CTest)
# ======================= Specify subdirectories to build ======================
add_subdirectory(contrib/diffimg)
add_subdirectory(contrib/prune)
add_subdirectory(graphs)
add_subdirectory(lib)
add_subdirectory(plugin)
add_subdirectory(cmd)
add_subdirectory(share)
if(with_cxx_tests)
add_subdirectory(tests)
endif()
MATH(EXPR GRAPHVIZ_PLUGIN_VERSION "${GRAPHVIZ_PLUGIN_VERSION}+1")
set(GVPLUGIN_VERSION "${GRAPHVIZ_PLUGIN_VERSION}")
set(VERSION "${GRAPHVIZ_VERSION_STRING}")
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "${CMAKE_INSTALL_PREFIX}")
set(PACKAGE "graphviz")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lib/cdt/libcdt.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libcdt.pc @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lib/cgraph/libcgraph.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libcgraph.pc @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lib/gvc/libgvc.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libgvc.pc @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lib/gvpr/libgvpr.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libgvpr.pc @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lib/edgepaint/liblab_gamut.pc.in ${CMAKE_CURRENT_BINARY_DIR}/liblab_gamut.pc @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lib/pathplan/libpathplan.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libpathplan.pc @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lib/xdot/libxdot.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libxdot.pc @ONLY)
file(GLOB pcfiles "${CMAKE_CURRENT_BINARY_DIR}/*.pc")
foreach(file "${pcfiles}")
install(FILES ${file} DESTINATION "${PKGCONFIG_DIR}")
endforeach(file)
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)