-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
165 lines (135 loc) · 4.36 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
cmake_minimum_required(VERSION 3.15...3.19)
#[[
-------------
Project Setup
-------------
]]
project(
hamarr
VERSION 1.3.0
DESCRIPTION "A C++ toolbox for data manipulation."
HOMEPAGE_URL "https://github.com/rufus-stone/hamarr"
LANGUAGES CXX)
include(cmake/PreventInSourceBuilds.cmake) # No in-source builds
include(GNUInstallDirs) # Provides default install locations
# Add the library and source files
add_library(
hamarr
src/format.cpp
include/hamarr/format.hpp
src/hex.cpp
include/hamarr/hex.hpp
src/binary.cpp
include/hamarr/binary.hpp
src/base64.cpp
include/hamarr/base64.hpp
src/url.cpp
include/hamarr/url.hpp
src/prng.cpp
include/hamarr/prng.hpp
src/bitwise.cpp
include/hamarr/bitwise.hpp
src/analysis.cpp
include/hamarr/analysis.hpp
src/pkcs7.cpp
include/hamarr/pkcs7.hpp
src/serialisation.cpp
include/hamarr/serialisation.hpp
src/uuid.cpp
include/hamarr/uuid.hpp
src/crypto.cpp
include/hamarr/crypto.hpp
include/hamarr/profiling.hpp
include/hamarr/exceptions.hpp)
# Add the library alias
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
# We require C++17
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
target_include_directories(
${PROJECT_NAME}
PUBLIC $<BUILD_INTERFACE:${${PROJECT_NAME}_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
# Check if Hamarr is being used as the main project vs. via sub_directory() or
# similar. We'll use this to enable or disable tests, installation, etc.
if(NOT DEFINED HAMARR_MAIN_PROJECT)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(HAMARR_MAIN_PROJECT ON)
else()
set(HAMARR_MAIN_PROJECT OFF)
endif()
endif()
#[[
option(ENABLE_CLANG_TIDY "Enable clang-tidy" ${HAMARR_MAIN_PROJECT})
if(ENABLE_CLANG_TIDY)
find_program(CLANGTIDY clang-tidy)
if(CLANGTIDY)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_CLANG_TIDY "${CLANGTIDY};--extra-arg-before=-std=c++17 -extra-arg=-Wno-unknown-warning-option")
else()
message(SEND_ERROR "clang-tidy requested but executable not found")
endif()
endif()
]]
#[[
------------
Dependencies
------------
]]
find_package(OpenSSL REQUIRED) # TODO: Make this optional
target_link_libraries(${PROJECT_NAME} PUBLIC OpenSSL::SSL)
#[[
------------------
Tests and Examples
------------------
]]
option(BUILD_HAMARR_TESTS "Build Hamarr tests" ${HAMARR_MAIN_PROJECT})
include(CTest) # Provides the BUILD_TESTING option (ON by default)
if(((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) OR BUILD_HAMARR_TESTS)
AND BUILD_TESTING)
message("Hamarr tests will be built...")
enable_testing()
add_subdirectory(test)
endif()
option(BUILD_HAMARR_EXAMPLES "Build Hamarr examples" ${HAMARR_MAIN_PROJECT})
if(BUILD_HAMARR_EXAMPLES)
message("Hamarr examples will be built...")
add_subdirectory(examples)
endif()
#[[
--------------------
Library Installation
--------------------
]]
option(INSTALL_HAMARR "Enable installation of Hamarr library"
${HAMARR_MAIN_PROJECT})
if(INSTALL_HAMARR)
message("Configuring library installation...")
# Install locations are provided by GNUInstallDirs
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}_Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(
EXPORT ${PROJECT_NAME}_Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/hamarr
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# TODO: Properly implement CPack stuff for package creation
# set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
# include(CPack)
endif()