-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
241 lines (206 loc) · 10.9 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
cmake_minimum_required(VERSION 3.10)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
###########################################################################
# Package Properties
###########################################################################
file(READ "VERSION" PROJECT_VERSION)
string(STRIP "${PROJECT_VERSION}" PROJECT_VERSION) # remove the newline
project(GraphCanon VERSION ${PROJECT_VERSION})
set(GraphCanon_VERSION ${PROJECT_VERSION} CACHE INTERNAL "" FORCE)
set(PNAME_FILE graph-canon) # how the project name should be written in file names
set(CPACK_PACKAGE_CONTACT "Jakob Lykke Andersen <jlandersen@imada.sdu.dk>")
set(CMAKE_CXX_FLAGS_OPTDEBUG "-g -O3")
set(CMAKE_C_FLAGS_OPTDEBUG "-g -O3")
set(CMAKE_EXE_LINKER_FLAGS_OPTDEBUG "")
set(CMAKE_SHARED_LINKER_FLAGS_OPTDEBUG "")
mark_as_advanced(CMAKE_CXX_FLAGS_OPTDEBUG CMAKE_C_FLAGS_OPTDEBUG CMAKE_EXE_LINKER_FLAGS_OPTDEBUG CMAKE_SHARED_LINKER_FLAGS_OPTDEBUG)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel OptDebug."
FORCE)
endif()
###########################################################################
# Options
###########################################################################
option(BUILD_BIN "Enable building of any command line tools." ON)
option(BUILD_BIN_BENCHMARK "Enable building of the benchmark version of the selected algorithm configurations." OFF)
option(BUILD_BIN_ALL_ALG "Enable building of all algorithm configurations of otherwise selected command line tools." OFF)
option(BUILD_DOC "Enable documentation building." ON)
option(BUILD_EXAMPLES "Enable example building." OFF)
option(BUILD_TESTING "Enable test building." OFF)
option(BUILD_TESTING_SANITIZERS "Compile tests with sanitizers." ON)
enable_testing() # should be included here to add the targets in the top-level folder
option(USE_NESTED_PERM_GROUP "Use the PermGroup version in external/perm_group." ON)
get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
set(BUILD_BIN 0)
set(BUILD_DOC 0)
set(BUILD_EXAMPLES 0)
set(BUILD_TESTING 0)
endif()
###########################################################################
# Individual checks
###########################################################################
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
set(graph_canon_config_dependencies "")
set(graph_canon_config_find_files "")
# Boost
# -------------------------------------------------------------------------
set(v 1.67.0)
if(BUILD_BIN)
find_package(Boost ${v} REQUIRED COMPONENTS program_options)
else()
find_package(Boost ${v} REQUIRED)
endif()
if(BUILD_TESTING)
find_package(Boost ${v} REQUIRED COMPONENTS unit_test_framework)
endif()
message(STATUS "(Boost include dir is ${Boost_INCLUDE_DIRS})")
string(APPEND graph_canon_config_dependencies "set(BOOST_FOUND 0)\n") # TODO: remove when CMake 3.15 is required https://gitlab.kitware.com/cmake/cmake/issues/18590
string(APPEND graph_canon_config_dependencies "find_dependency(Boost ${v})\n")
# PermGroup
# -------------------------------------------------------------------------
set(v 0.5)
if(USE_NESTED_PERM_GROUP)
message(STATUS "PermGroup: using external/perm_group")
add_subdirectory(external/perm_group)
if(PermGroup_VERSION VERSION_LESS v)
message(FATAL_ERROR "Nested PermGroup version not new enough: is ${PermGroup_VERSION}, needs ${v}."
" Try again after 'git submodule update --init --recursive; ./bootstrap.sh'."
" Otherwise please report as bug.")
endif()
else()
find_package(PermGroup ${v} REQUIRED)
string(APPEND graph_canon_config_dependencies "find_dependency(PermGroup ${v})\n")
message(STATUS "PermGroup version: ${PermGroup_VERSION}")
endif()
# Sphinx
# -------------------------------------------------------------------------
if(BUILD_DOC)
find_program(SPHINX NAMES sphinx-build sphinx-build3 sphinx-build-3 sphinx-build2)
if(SPHINX)
message(STATUS "Sphinx: ${SPHINX}")
else()
message(FATAL_ERROR "Sphinx not found, required for building the documentation. Use --DBUILD_DOC=off to disable.")
endif()
endif()
###########################################################################
# Targets and Artefacts
###########################################################################
include(CMakeFiles.txt)
include(GNUInstallDirs)
if(NOT hasParent)
set(CMAKE_NO_BUILTIN_CHRPATH TRUE) #
# https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling
set(CMAKE_SKIP_BUILD_RPATH FALSE) # use RPATH in the build tree
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) # but not the RPATH used in installation
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}") # there, add this one
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # in addition to those deduced automatically
endif()
# libgraph_canon (header-only)
# -------------------------------------------------------------------------
# TODO: the files are ${graph_canon_INCLUDE_FILES}, but should they be put somewhere?
add_library(graph_canon INTERFACE)
add_library(GraphCanon::graph_canon ALIAS graph_canon)
target_include_directories(graph_canon
INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>)
target_link_libraries(graph_canon INTERFACE PermGroup::perm_group Boost::boost)
#target_compile_options(graph_canon INTERFACE -Wall -Wextra)
install(TARGETS graph_canon
EXPORT PROJECT_exports
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT GraphCanon_lib
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT GraphCanon_lib
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT GraphCanon_lib)
install(DIRECTORY include/graph_canon
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT GraphCanon_dev
FILES_MATCHING PATTERN "*.hpp")
# config.hpp
# -------------------------------------------------------------------------
configure_file(config.hpp.in include/graph_canon/config.hpp @ONLY)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/graph_canon
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT GraphCanon_dev)
# Subdirs
# -------------------------------------------------------------------------
add_subdirectory(bin)
add_subdirectory(doc)
add_subdirectory(test)
add_subdirectory(examples)
# CMake Package Support
# -------------------------------------------------------------------------
include(CMakePackageConfigHelpers)
# due to the stupid restrictive version formatting we change it
set(exportDir ${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/${PROJECT_NAME})
configure_file(${PROJECT_NAME}Config.cmake ${exportDir}/${PROJECT_NAME}Config.cmake @ONLY)
foreach(f ${graph_canon_config_find_files})
configure_file(${PROJECT_SOURCE_DIR}/cmake/${f} ${exportDir}/${f} COPYONLY)
endforeach()
write_basic_package_version_file(
${exportDir}/${PROJECT_NAME}Config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
install(EXPORT PROJECT_exports
NAMESPACE ${PROJECT_NAME}::
DESTINATION lib/cmake/${PROJECT_NAME}
FILE ${PROJECT_NAME}Targets.cmake)
install(DIRECTORY ${exportDir}
DESTINATION lib/cmake
COMPONENT GraphCanon_dev)
# Packaging
# -------------------------------------------------------------------------
string(TOUPPER ${PROJECT_NAME} PNAME_UPPER)
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) # because the default doesn't include the tweak number
set(CPACK_GENERATOR "DEB")
#set(CPACK_GENERATOR "DEB" "RPM")
set(CPACK_DEB_COMPONENT_INSTALL ON)
#set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS ON)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
# we use CACHE INTERNAL to make it work when in a subproject
set(CPACK_DEBIAN_${PNAME_UPPER}_RUN_PACKAGE_SHLIBDEPS ON CACHE INTERNAL "")
set(CPACK_DEBIAN_${PNAME_UPPER}_LIB_PACKAGE_SHLIBDEPS ON CACHE INTERNAL "")
set(CPACK_DEBIAN_${PNAME_UPPER}_DEV_PACKAGE_SHLIBDEPS ON CACHE INTERNAL "")
set(CPACK_DEBIAN_${PNAME_UPPER}_DOC_PACKAGE_SHLIBDEPS ON CACHE INTERNAL "")
set(CPACK_COMPONENT_${PNAME_UPPER}_RUN_DEPENDS ${PNAME_UPPER}_LIB CACHE INTERNAL "")
set(CPACK_COMPONENT_${PNAME_UPPER}_DEV_DEPENDS ${PNAME_UPPER}_LIB CACHE INTERNAL "")
set(CPACK_DEBIAN_${PNAME_UPPER}_RUN_PACKAGE_NAME "${PNAME_FILE}" CACHE INTERNAL "")
set(CPACK_DEBIAN_${PNAME_UPPER}_LIB_PACKAGE_NAME "lib${PNAME_FILE}" CACHE INTERNAL "")
set(CPACK_DEBIAN_${PNAME_UPPER}_DEV_PACKAGE_NAME "lib${PNAME_FILE}-dev" CACHE INTERNAL "")
set(CPACK_DEBIAN_${PNAME_UPPER}_DOC_PACKAGE_NAME "${PNAME_FILE}-doc" CACHE INTERNAL "")
set(CPACK_DEBIAN_${PNAME_UPPER}_RUN_FILE_NAME "${PNAME_FILE}_${PROJECT_VERSION}.deb" CACHE INTERNAL "")
set(CPACK_DEBIAN_${PNAME_UPPER}_LIB_FILE_NAME "lib${PNAME_FILE}_${PROJECT_VERSION}.deb" CACHE INTERNAL "")
set(CPACK_DEBIAN_${PNAME_UPPER}_DEV_FILE_NAME "lib${PNAME_FILE}-dev_${PROJECT_VERSION}.deb" CACHE INTERNAL "")
set(CPACK_DEBIAN_${PNAME_UPPER}_DOC_FILE_NAME "${PNAME_FILE}-doc_${PROJECT_VERSION}.deb" CACHE INTERNAL "")
#set(CPACK_RPM_${PNAME_UPPER}_RUN_PACKAGE_NAME "${PNAME_FILE}" CACHE INTERNAL "")
#set(CPACK_RPM_${PNAME_UPPER}_LIB_PACKAGE_NAME "lib${PNAME_FILE}" CACHE INTERNAL "")
#set(CPACK_RPM_${PNAME_UPPER}_DEV_PACKAGE_NAME "lib${PNAME_FILE}-devel" CACHE INTERNAL "")
#set(CPACK_RPM_${PNAME_UPPER}_DOC_PACKAGE_NAME "${PNAME_FILE}-doc" CACHE INTERNAL "")
#set(CPACK_RPM_${PNAME_UPPER}_RUN_FILE_NAME "${PNAME_FILE}-${PROJECT_VERSION}.rpm" CACHE INTERNAL "")
#set(CPACK_RPM_${PNAME_UPPER}_LIB_FILE_NAME "lib${PNAME_FILE}-${PROJECT_VERSION}.rpm" CACHE INTERNAL "")
#set(CPACK_RPM_${PNAME_UPPER}_DEV_FILE_NAME "lib${PNAME_FILE}-devel-${PROJECT_VERSION}.rpm" CACHE INTERNAL "")
#set(CPACK_RPM_${PNAME_UPPER}_DOC_FILE_NAME "${PNAME_FILE}-doc-${PROJECT_VERSION}.rpm" CACHE INTERNAL "")
if(NOT hasParent)
set(CPACK_SOURCE_PACKAGE_FILE_NAME
"${PNAME_FILE}-${CPACK_PACKAGE_VERSION}")
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_IGNORE_FILES
".swp$"
"~$"
"__pycache__"
*.pyc
"/.git"
"/.idea"
"/build"
"/stage"
"/bootstrap.sh"
"external")
add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
include(CPack)
endif()