-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
174 lines (145 loc) · 6.94 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
# -----------------------------------------------------------------------------
# @brief : Root cmake file.
# @author : Enrico Fraccaroli
# -----------------------------------------------------------------------------
# Set the minimum CMake version, the project name and default build type.
cmake_minimum_required(VERSION 3.1...3.18)
# Set the project name.
project(bvlib CXX)
# Set the default build type to Debug.
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Debug' as none was specified.")
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build." FORCE)
endif()
# -----------------------------------------------------------------------------
# ENABLE FETCH CONTENT
# -----------------------------------------------------------------------------
# We need this in order to import external projects.
include(FetchContent)
# Hide fetchcontent variables.
mark_as_advanced(FORCE
FETCHCONTENT_QUIET
FETCHCONTENT_BASE_DIR
FETCHCONTENT_FULLY_DISCONNECTED
FETCHCONTENT_UPDATES_DISCONNECTED
)
# -----------------------------------------------------------------------------
# OPTIONS
# -----------------------------------------------------------------------------
option(STRICT_WARNINGS "Enable strict compiler warnings" ON)
option(WARNINGS_AS_ERRORS "Treat all warnings as errors" OFF)
option(BUILD_EXAMPLES "Build examples" OFF)
option(BUILD_TESTS "Build tests" OFF)
# -----------------------------------------------------------------------------
# DEPENDENCIES
# -----------------------------------------------------------------------------
# We want doxygen for the documentation.
find_package(Doxygen)
# -----------------------------------------------------------------------------
# LIBRARY
# -----------------------------------------------------------------------------
# Add the C++ Library.
add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
# Inlcude header directories and set the library.
target_include_directories(${PROJECT_NAME} INTERFACE ${PROJECT_SOURCE_DIR}/include)
# Enalbe C++17.
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
# -----------------------------------------------------------------------------
# Set the compilation flags.
# -----------------------------------------------------------------------------
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# Disable warnings that suggest using MSVC-specific safe functions
target_compile_definitions(${PROJECT_NAME} INTERFACE _CRT_SECURE_NO_WARNINGS)
if(WARNINGS_AS_ERRORS)
target_compile_options(${PROJECT_NAME} INTERFACE /WX)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(WARNINGS_AS_ERRORS)
target_compile_options(${PROJECT_NAME} INTERFACE -Werror)
endif()
endif()
if(STRICT_WARNINGS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# Mark system headers as external for MSVC explicitly
# https://devblogs.microsoft.com/cppblog/broken-warnings-theory
target_compile_options(${PROJECT_NAME} INTERFACE /experimental:external)
target_compile_options(${PROJECT_NAME} INTERFACE /external:I ${CMAKE_BINARY_DIR})
target_compile_options(${PROJECT_NAME} INTERFACE /external:anglebrackets)
target_compile_options(${PROJECT_NAME} INTERFACE /external:W0)
target_compile_options(${PROJECT_NAME} INTERFACE /W4)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(${PROJECT_NAME} INTERFACE -Wall -Wextra -Wconversion -pedantic)
endif()
endif()
# -----------------------------------------------------------------------------
# EXAMPLES
# -----------------------------------------------------------------------------
if(BUILD_EXAMPLES)
# Add the example.
add_executable(${PROJECT_NAME}_example examples/example.cpp)
# Set the linked libraries.
target_link_libraries(${PROJECT_NAME}_example PUBLIC ${PROJECT_NAME})
endif()
# -----------------------------------------------------------------------------
# TESTS
# -----------------------------------------------------------------------------
if(BUILD_TESTS)
# CMake has support for adding tests to a project.
enable_testing()
# Add the test.
add_executable(${PROJECT_NAME}_test_operators ${PROJECT_SOURCE_DIR}/tests/test_operators.cpp)
# Liking for the test.
target_link_libraries(${PROJECT_NAME}_test_operators ${PROJECT_NAME})
# Add the test.
add_test(${PROJECT_NAME}_test_operators_run ${PROJECT_NAME}_test_operators)
# Add the test.
add_executable(${PROJECT_NAME}_test_comparison tests/test_comparison.cpp)
# Liking for the test.
target_link_libraries(${PROJECT_NAME}_test_comparison ${PROJECT_NAME})
# Add the test.
add_test(${PROJECT_NAME}_test_comparison_run ${PROJECT_NAME}_test_comparison)
endif()
# -----------------------------------------------------------------------------
# DOCUMENTATION
# -----------------------------------------------------------------------------
if(DOXYGEN_FOUND)
# Record the options that describe how to populate the specified content.
FetchContent_Declare(
doxygenawesome
GIT_REPOSITORY https://github.com/jothepro/doxygen-awesome-css
GIT_TAG 4cd62308d825fe0396d2f66ffbab45d0e247724c # 2.0.3
)
# Retrieve the properties related to the content.
FetchContent_GetProperties(doxygenawesome)
# If not populated, make the content available.
if(NOT doxygenawesome_POPULATED)
message(STATUS "Retrieving `doxygen-awesome-css`...")
# Ensures the named dependencies have been populated.
FetchContent_MakeAvailable(doxygenawesome)
# Hide fetchcontent variables, otherwise with ccmake it's a mess.
mark_as_advanced(FORCE
FETCHCONTENT_QUIET FETCHCONTENT_BASE_DIR FETCHCONTENT_FULLY_DISCONNECTED FETCHCONTENT_UPDATES_DISCONNECTED
FETCHCONTENT_UPDATES_DISCONNECTED_DOXYGENAWESOME FETCHCONTENT_SOURCE_DIR_DOXYGENAWESOME
)
endif()
# = CUSTOMIZATION =========================================================
set(DOXYGEN_PROJECT_NAME "Bitvector Library")
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE README.md)
set(DOXYGEN_SHOW_INCLUDE_FILES NO)
set(DOXYGEN_GENERATE_TREEVIEW YES)
set(DOXYGEN_HTML_HEADER ${doxygenawesome_SOURCE_DIR}/doxygen-custom/header.html)
set(DOXYGEN_HTML_EXTRA_STYLESHEET ${doxygenawesome_SOURCE_DIR}/doxygen-awesome.css)
set(DOXYGEN_HTML_EXTRA_FILES
${doxygenawesome_SOURCE_DIR}/doxygen-awesome-fragment-copy-button.js
${doxygenawesome_SOURCE_DIR}/doxygen-awesome-paragraph-link.js
${doxygenawesome_SOURCE_DIR}/doxygen-awesome-darkmode-toggle.js
)
doxygen_add_docs(
${PROJECT_NAME}_documentation
${PROJECT_SOURCE_DIR}/README.md
${PROJECT_SOURCE_DIR}/include/bvlib/bitvector.hpp
${PROJECT_SOURCE_DIR}/include/bvlib/math.hpp
${PROJECT_SOURCE_DIR}/include/bvlib/io.hpp
)
endif()