-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
200 lines (183 loc) · 7.26 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
message(STATUS "CMake version: ${CMAKE_VERSION}")
cmake_minimum_required(VERSION 3.5)
# Choose new behaviour for CMP0048
# See https://cmake.org/cmake/help/v3.0/policy/CMP0048.html for more details
if(POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif()
##
## CONFIGURATION
##
set(LIBRARY_NAME "Graph")
set(LIBRARY_SOURCE_DIR "single_include/")
set(LIBRARY_DEV_DIR "src/")
set(LIBRARY_CONFIG_INSTALL_DIR "lib/cmake/${LIBRARY_NAME}")
set(LIBRARY_INCLUDE_INSTALL_DIR "include")
set(LIBRARY_HEADER_INSTALL_DIR "${LIBRARY_INCLUDE_INSTALL_DIR}/${LIBRARY_NAME}")
set(LIBRARY_TARGETS_EXPORT_NAME "${LIBRARY_NAME}Targets")
set(LIBRARY_CMAKE_CONFIG_TEMPLATE "cmake/config.cmake.in")
set(LIBRARY_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}/cmake_config")
set(LIBRARY_CMAKE_VERSION_CONFIG_FILE "${LIBRARY_CMAKE_CONFIG_DIR}/${LIBRARY_NAME}ConfigVersion.cmake")
set(LIBRARY_CMAKE_PROJECT_CONFIG_FILE "${LIBRARY_CMAKE_CONFIG_DIR}/${LIBRARY_NAME}Config.cmake")
##
## PROJECT
##
project(${LIBRARY_NAME} LANGUAGES CXX VERSION 1.1.2)
##
## OPTIONS
##
option(ENABLE_EXAMPLES "Build examples." ON)
option(ENABLE_TESTING "Build the unit tests." ON)
option(ENABLE_BENCHMARKING "Build benchmarks suite" OFF)
##
## TARGET
## create target and add include path
##
add_library(${LIBRARY_NAME} INTERFACE)
#single_include/graph.hpp)
target_include_directories(
${LIBRARY_NAME}
INTERFACE $<INSTALL_INTERFACE:single_include/>
)
# set the Standard version
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++17" COMPILER_SUPPORTS_CXX17)
check_cxx_compiler_flag("-std=c++14" COMPILER_SUPPORTS_CXX14)
check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11)
#check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if (COMPILER_SUPPORTS_CXX17)
add_definitions(-std=c++17)
if(CMAKE_VERSION VERSION_GREATER 3.8.1)
set(CMAKE_CXX_STANDARD 17)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -std=gnu++17")
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} supports C++17")
elseif (COMPILER_SUPPORTS_CXX14)
add_definitions(-std=c++14)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -std=gnu++14")
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} supports C++14")
elseif (COMPILER_SUPPORTS_CXX11)
add_definitions(-std=c++11)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -std=gnu++11")
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} supports C++11")
#elseif (COMPILER_SUPPORTS_CXX0X)
# add_definitions(-std=c++0x)
# message(STATUS "The compiler ${CMAKE_CXX_COMPILER} supports C++0x")
else ()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif ()
find_package(nlohmann_json QUIET)
if(NOT nlohmann_json_FOUND)
message(STATUS "")
message(WARNING "Library nlohmann_json is not installed, you should include third-party/json/single_include/nlohmann/json.hpp file in your project")
message(WARNING "To install this library and guarantee the portability of your project, please run `make install_json`")
add_definitions(-DINCLUDE_JSON_FILE)
# Update of json Git submodule
execute_process(
COMMAND git submodule update --init --quiet ${Graph_SOURCE_DIR}/third-party/json
WORKING_DIRECTORY ${Graph_SOURCE_DIR}
)
execute_process(
COMMAND git checkout develop --force --quiet
WORKING_DIRECTORY ${Graph_SOURCE_DIR}/third-party/json
)
# Target to install the json library
file(MAKE_DIRECTORY ${Graph_SOURCE_DIR}/third-party/json/build)
add_custom_target(install_json
COMMAND cmake ..
COMMAND sudo make install -j 4
WORKING_DIRECTORY ${Graph_SOURCE_DIR}/third-party/json/build)
endif()
function(enable_all_warnings TARGET)
if("$CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
target_compile_options(${TARGET} PRIVATE
-Weverything
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-padded
-Wno-shadow
-Wno-weak-vtables
-pedantic
-pedantic-errors)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
elseif(NOT MSVC)
set_target_properties(${TARGET} PROPERTIES
COMPILE_FLAGS "-Wall"
COMPILE_FLAGS "-Wextra"
COMPILE_FLAGS "-Waddress"
COMPILE_FLAGS "-Wbuiltin-macro-redefined"
COMPILE_FLAGS "-Wconversion"
COMPILE_FLAGS "-Winit-self"
COMPILE_FLAGS "-Wnon-virtual-dtor"
COMPILE_FLAGS "-Wold-style-cast"
COMPILE_FLAGS "-Woverloaded-virtual"
COMPILE_FLAGS "-Wsuggest-attribute=const"
COMPILE_FLAGS "-Wsuggest-attribute=noreturn"
COMPILE_FLAGS "-Wsuggest-attribute=pure"
COMPILE_FLAGS "-Wswitch"
COMPILE_FLAGS "-Wunreachable-code"
COMPILE_FLAGS "-pedantic"
)
endif()
if(NOT COMPILER_SUPPORTS_CXX17 OR CMAKE_VERSION VERSION_GREATER 3.8.1)
set_target_properties(${TARGET} PROPERTIES
CXX_STANDARD ${CMAKE_CXX_STANDARD}
CXX_STANDARD_REQUIRED ON)
else()
set_target_properties(${TARGET} PROPERTIES
CXX_STANDARD_REQUIRED ON)
endif()
endfunction()
if(ENABLE_EXAMPLES)
include_directories(${LIBRARY_SOURCE_DIR})
add_subdirectory(doc/examples)
endif()
##
## TESTS
## create and configure the unit test target
##
if(ENABLE_TESTING)
enable_testing()
include_directories(${LIBRARY_DEV_DIR})
add_subdirectory(test)
endif()
##
## BENCHMARKS
## create and configure the benchmark target
##
if(ENABLE_BENCHMARKING)
include_directories(${LIBRARY_SOURCE_DIR})
add_subdirectory(benchmarks)
endif()
##
## INSTALLATION
## install header files, generate and install cmake config for find_package()
##
#include(CMakePackageConfigHelpers)
#write_basic_package_version_file(
# ${LIBRARY_CMAKE_VERSION_CONFIG_FILE} COMPATIBILITY SameMajorVersion
#)
#configure_package_config_file(
# ${LIBRARY_CMAKE_CONFIG_TEMPLATE}
# ${LIBRARY_CMAKE_PROJECT_CONFIG_FILE}
# INSTALL_DESTINATION ${LIBRARY_CONFIG_INSTALL_DIR}
#)
#install(
# DIRECTORY ${LIBRARY_SOURCE_DIR}
# DESTINATION ${LIBRARY_HEADER_INSTALL_DIR}
#)
#install(
# FILES ${LIBRARY_CMAKE_PROJECT_CONFIG_FILE} ${LIBRARY_CMAKE_VERSION_CONFIG_FILE}
# DESTINATION ${LIBRARY_CONFIG_INSTALL_DIR}
#)
#install(
# TARGETS ${LIBRARY_NAME}
# EXPORT ${LIBRARY_TARGETS_EXPORT_NAME}
# INCLUDES DESTINATION ${LIBRARY_INCLUDE_INSTALL_DIR}
#)
#install(
# EXPORT ${LIBRARY_TARGETS_EXPORT_NAME}
# DESTINATION ${LIBRARY_CONFIG_INSTALL_DIR}
#)