-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
112 lines (93 loc) · 3.46 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.14)
project(hyperloglog LANGUAGES CXX VERSION 1.0.0)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
get_directory_property(is_subproject PARENT_DIRECTORY)
if(NOT is_subproject)
set(is_standalone YES)
else()
set(is_standalone NO)
endif()
include(GNUInstallDirs)
add_library(${PROJECT_NAME} src/murmurhash.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${${PROJECT_NAME}_SOURCE_DIR}>/include/
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION})
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE
/W4)
else()
target_compile_options(${PROJECT_NAME} PRIVATE
-Werror -Wall -Wextra -Wconversion -Wsign-conversion
-Wno-implicit-fallthrough)
endif()
if (is_standalone)
add_executable(estimate_distribution
EXCLUDE_FROM_ALL
src/estimate_distribution.cpp)
target_link_libraries(estimate_distribution PRIVATE ${PROJECT_NAME})
add_executable(record_biases
EXCLUDE_FROM_ALL
src/record_biases.cpp)
target_link_libraries(record_biases PRIVATE ${PROJECT_NAME})
Include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.7.1)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
add_executable(${PROJECT_NAME}_tests EXCLUDE_FROM_ALL src/tests.cpp)
target_link_libraries(${PROJECT_NAME}_tests PRIVATE
${PROJECT_NAME} Catch2::Catch2WithMain)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(${PROJECT_NAME}_tests PRIVATE
/W4 /permissive- /w14242 /w14254 /w14263 /w14265 /w14287 /we4289 /w14296
/w14311 /w14545 /w14546 /w14547 /w14549 /w14555 /w14619 /w14640 /w14826
/w14905 /w14906 /w14928)
else()
target_compile_options(${PROJECT_NAME}_tests PRIVATE
-Werror -Wall -Wextra -Wconversion -Wsign-conversion -Wnull-dereference
-Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused
-Woverloaded-virtual -Wpedantic -Wimplicit-fallthrough)
target_link_options(${PROJECT_NAME}_tests PRIVATE
-fsanitize=address,undefined)
endif()
include(CTest)
include(Catch)
catch_discover_tests(${PROJECT_NAME}_tests)
endif()
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}-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
if(NOT INCLUDE_INSTALL_DIR)
set(INCLUDE_INSTALL_DIR include/)
endif()
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
PATH_VARS INCLUDE_INSTALL_DIR)
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}-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})