-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
147 lines (125 loc) · 4.81 KB
/
CMakeLists.txt
File metadata and controls
147 lines (125 loc) · 4.81 KB
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
cmake_minimum_required(VERSION 3.5)
project(hmac_cpp VERSION 0.5.0 LANGUAGES CXX)
option(HMACCPP_BUILD_EXAMPLES "Build the example program" OFF)
option(HMACCPP_BUILD_TESTS "Build the test suite" OFF)
option(HMACCPP_BUILD_BENCH "Build benchmarks" OFF)
option(HMACCPP_BUILD_SHARED "Build hmac_cpp as a shared library" OFF)
option(HMACCPP_ENABLE_MLOCK "Pin secret buffers in RAM using mlock/VirtualLock" ON)
include(CheckSymbolExists)
check_symbol_exists(explicit_bzero "strings.h" HAVE_EXPLICIT_BZERO)
if(HMACCPP_BUILD_SHARED)
set(BUILD_SHARED_LIBS ON)
endif()
set(HMAC_SOURCES
src/sha1.cpp
src/sha256.cpp
src/sha512.cpp
src/hmac.cpp
src/hmac_utils.cpp
src/encoding.cpp
src/memlock.cpp
)
set(HMAC_HEADERS
include/hmac_cpp/api.hpp
include/hmac_cpp/hmac.hpp
include/hmac_cpp/hmac_utils.hpp
include/hmac_cpp/sha1.hpp
include/hmac_cpp/sha256.hpp
include/hmac_cpp/sha512.hpp
include/hmac_cpp/secure_buffer.hpp
include/hmac_cpp/memlock.hpp
include/hmac_cpp/secret_string.hpp
include/hmac_cpp/encoding.hpp
include/hmac_cpp/version.hpp
)
add_library(hmac_cpp ${HMAC_SOURCES})
target_compile_features(hmac_cpp PUBLIC cxx_std_11)
target_include_directories(hmac_cpp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
if(BUILD_SHARED_LIBS)
target_compile_definitions(hmac_cpp PRIVATE HMAC_CPP_BUILD)
else()
target_compile_definitions(hmac_cpp PUBLIC HMAC_CPP_STATIC)
endif()
if(HMACCPP_ENABLE_MLOCK)
target_compile_definitions(hmac_cpp PUBLIC HMAC_CPP_ENABLE_MLOCK)
endif()
if(HAVE_EXPLICIT_BZERO)
target_compile_definitions(hmac_cpp PUBLIC HAVE_EXPLICIT_BZERO)
endif()
if(MSVC)
target_compile_options(hmac_cpp PRIVATE /wd4251)
else()
target_compile_options(hmac_cpp PRIVATE -fvisibility=hidden)
endif()
if(NOT TARGET hmac_cpp::hmac_cpp)
add_library(hmac_cpp::hmac_cpp ALIAS hmac_cpp)
endif()
if(HMACCPP_BUILD_EXAMPLES)
add_executable(example example.cpp)
target_link_libraries(example PRIVATE hmac_cpp)
target_include_directories(example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_executable(example_streaming example_streaming.cpp)
target_link_libraries(example_streaming PRIVATE hmac_cpp)
target_include_directories(example_streaming PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_executable(example_pbkdf2 example_pbkdf2.cpp)
target_link_libraries(example_pbkdf2 PRIVATE hmac_cpp)
target_include_directories(example_pbkdf2 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_executable(example_encoding example_encoding.cpp)
target_link_libraries(example_encoding PRIVATE hmac_cpp)
target_include_directories(example_encoding PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_executable(example_secret example_secret.cpp)
target_link_libraries(example_secret PRIVATE hmac_cpp)
target_include_directories(example_secret PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
endif()
include(CMakePackageConfigHelpers)
install(TARGETS hmac_cpp EXPORT hmac_cppTargets DESTINATION lib)
install(FILES ${HMAC_HEADERS} DESTINATION include/hmac_cpp)
install(EXPORT hmac_cppTargets
FILE hmac_cppTargets.cmake
NAMESPACE hmac_cpp::
DESTINATION lib/cmake/hmac_cpp
)
configure_package_config_file(
cmake/hmac_cppConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/hmac_cppConfig.cmake"
INSTALL_DESTINATION lib/cmake/hmac_cpp
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/hmac_cppConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/hmac_cppConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/hmac_cppConfigVersion.cmake"
DESTINATION lib/cmake/hmac_cpp
)
configure_file(cmake/hmac_cpp.pc.in "${CMAKE_CURRENT_BINARY_DIR}/hmac_cpp.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/hmac_cpp.pc" DESTINATION lib/pkgconfig)
if(HMACCPP_BUILD_TESTS)
enable_testing()
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
FetchContent_MakeAvailable(googletest)
find_package(OpenSSL REQUIRED)
add_executable(test_all test_all.cpp)
target_link_libraries(test_all PRIVATE hmac_cpp gtest_main OpenSSL::Crypto)
target_include_directories(test_all PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_test(NAME test_all COMMAND test_all)
add_executable(test_totp test_totp.cpp)
target_link_libraries(test_totp PRIVATE hmac_cpp gtest_main)
target_include_directories(test_totp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_test(NAME test_totp COMMAND test_totp)
endif()
export(EXPORT hmac_cppTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/hmac_cppTargets.cmake"
NAMESPACE hmac_cpp::
)