-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
112 lines (98 loc) · 3.98 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
cmake_minimum_required(VERSION 3.10)
project(multihash VERSION 1.0 LANGUAGES CXX)
option(BUILD_TESTING "Build unit tests" ON)
find_package(cryptopp CONFIG REQUIRED)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(HEADER_FILES
multihash/algorithm.h;
multihash/algorithm_identifier.h
multihash/algorithm_factory.h
multihash/algorithm_registry.h
multihash/multihash.h;)
add_library(libmultihash
multihash/algorithm.cpp
multihash/algorithm_identifier.cpp
multihash/algorithm_factory.cpp
multihash/algorithm_registry.cpp
multihash/detail/cryptopp_impl.h
multihash/multihash.cpp
${HEADER_FILES})
target_include_directories(libmultihash PUBLIC
$<BUILD_INTERFACE:${multihash_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)
set_target_properties(libmultihash PROPERTIES OUTPUT_NAME multihash)
target_link_libraries(libmultihash PUBLIC cryptopp-static)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${multihash_BINARY_DIR}/multihashConfigVersion.cmake"
VERSION ${PACKAGE_VERSION}
COMPATIBILITY AnyNewerVersion)
install(TARGETS libmultihash
EXPORT multihashTargets
INCLUDES DESTINATION include
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(FILES ${HEADER_FILES} DESTINATION include/multihash)
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${multihash_SOURCE_DIR}/cmake/multihashConfig.cmake"
"${multihash_BINARY_DIR}/multihashConfig.cmake"
INSTALL_DESTINATION share/cmake/multihash
)
install(EXPORT multihashTargets DESTINATION share/cmake/multihash)
install(FILES "${multihash_BINARY_DIR}/multihashConfigVersion.cmake"
"${multihash_BINARY_DIR}/multihashConfig.cmake"
DESTINATION share/cmake/multihash)
if (MSVC)
target_compile_options(libmultihash PRIVATE /W4 /WX /MP)
else ()
if (BUILD_COVERAGE)
set(COVERAGE_FLAGS "--coverage")
endif ()
target_compile_options(libmultihash PRIVATE -Wall -Wextra -pedantic -Werror
${COVERAGE_FLAGS})
target_link_options(libmultihash PRIVATE ${COVERAGE_FLAGS})
endif ()
if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-DNDEBUG)
endif ()
if (BUILD_TESTING)
enable_testing()
find_package(GTest MODULE REQUIRED)
add_executable(multihash_test
test/multihash_test.cpp
test/algorithm_registry_test.cpp
test/main.cpp
multihash/detail/cryptopp_impl.cpp test/algorithm_test.cpp test/multihash_test.h)
target_link_libraries(multihash_test PRIVATE libmultihash GTest::GTest GTest::Main)
gtest_discover_tests(multihash_test)
if (MSVC)
target_compile_options(multihash_test PRIVATE /W4 /WX /MP)
else ()
target_compile_options(multihash_test PRIVATE -Wall -Wextra -pedantic
-Werror ${COVERAGE_FLAGS})
target_link_options(multihash_test PRIVATE ${COVERAGE_FLAGS})
target_link_libraries(multihash_test PRIVATE ${COVERAGE_FLAGS})
endif ()
if (NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
target_compile_options(libmultihash PRIVATE -Wall -Werror -pedantic -Wextra)
# Binary depends on getopt which is unavailable in Windows
add_executable(multihash multihash/main.cpp)
target_link_libraries(multihash libmultihash)
target_link_options(multihash PRIVATE ${COVERAGE_FLAGS})
# Component test for whole executable
add_test(
NAME multihash_bin_test WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
COMMAND multihash --hash-type sha1 ${CMAKE_CURRENT_SOURCE_DIR}/test/foo
)
set_tests_properties(
multihash_bin_test PROPERTIES PASS_REGULAR_EXPRESSION
"1114f1d2d2f924e986ac86fdf7b36c94bcdf32beec15"
TIMEOUT 1
)
endif()
endif()