CMakeLists.txt raw
1 cmake_minimum_required(VERSION 3.22)
2
3 #=============================
4 # Project / Package Metadata
5 #=============================
6 project(minisketch
7 VERSION 0.0.1
8 DESCRIPTION "A library for BCH-based set reconciliation"
9 HOMEPAGE_URL "https://github.com/bitcoin-core/minisketch"
10 LANGUAGES CXX
11 )
12
13 # ============================================================
14 # Project Initialization
15 # ============================================================
16 enable_testing()
17 include(CTestUseLaunchers)
18
19 list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
20
21 if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
22 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
23 endif()
24 if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
25 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
26 endif()
27 if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
28 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
29 endif()
30
31 # Prevent include directories from parent project from leaking into this one.
32 set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES "")
33
34 #=============================
35 # Language Setup
36 #=============================
37 if(DEFINED CMAKE_CXX_STANDARD)
38 if(CMAKE_CXX_STANDARD EQUAL 98 OR CMAKE_CXX_STANDARD LESS 11)
39 message(FATAL_ERROR "This project requires at least C++11")
40 endif()
41 else()
42 set(CMAKE_CXX_STANDARD 11)
43 endif()
44 set(CMAKE_CXX_STANDARD_REQUIRED ON)
45 if(NOT DEFINED CMAKE_CXX_EXTENSIONS)
46 set(CMAKE_CXX_EXTENSIONS OFF)
47 endif()
48
49 #=============================
50 # Configurable Options
51 #=============================
52 option(MINISKETCH_INSTALL "Enable installation." ${PROJECT_IS_TOP_LEVEL})
53 if(NOT PROJECT_IS_TOP_LEVEL)
54 mark_as_advanced(MINISKETCH_INSTALL)
55 endif()
56
57 option(MINISKETCH_BUILD_TESTS "Build tests." ON)
58 option(MINISKETCH_BUILD_BENCHMARK "Build benchmark." OFF)
59
60 set(supported_fields "")
61 set(have_enabled_fields NO)
62 set(have_disabled_fields NO)
63 foreach(i RANGE 2 64)
64 list(APPEND supported_fields ${i})
65 endforeach()
66 if(NOT DEFINED MINISKETCH_FIELDS)
67 set(MINISKETCH_FIELDS ${supported_fields} CACHE STRING "Semicolon-separated list of field sizes to build. Default=all. Available sizes: ${supported_fields}.")
68 endif()
69 foreach(field IN LISTS supported_fields)
70 if(field IN_LIST MINISKETCH_FIELDS)
71 set(have_enabled_fields YES)
72 else()
73 set(have_disabled_fields YES)
74 add_compile_definitions(DISABLE_FIELD_${field})
75 endif()
76 endforeach()
77 if(NOT have_enabled_fields)
78 message(FATAL_ERROR "No field sizes are enabled.")
79 endif()
80 unset(have_enabled_fields)
81 unset(supported_fields)
82
83 #=============================
84 # Build Options
85 #=============================
86 set(CMAKE_CXX_VISIBILITY_PRESET hidden)
87
88 if(MSVC)
89 add_compile_options(/Zc:__cplusplus)
90 endif()
91
92 if(MINGW)
93 add_link_options(-static)
94 endif()
95
96 #=============================
97 # Diagnostics Options
98 #=============================
99 if(MSVC)
100 # For both MSVC's cl.exe and clang-cl compilers.
101 add_compile_options(/W3) # Production quality warning level. Enables -Wall Clang's core option.
102 else()
103 add_compile_options(-Wall)
104 endif()
105
106 if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
107 add_compile_options(/wd4060) # Disable warning C4060 "switch statement contains no 'case' or 'default' labels".
108 add_compile_options(/wd4065) # Disable warning C4065 "switch statement contains 'default' but no 'case' labels".
109 add_compile_options(/wd4146) # Disable warning C4146 "unary minus operator applied to unsigned type, result still unsigned".
110 add_compile_options(/wd4244) # Disable warning C4244 "conversion from 'type1' to 'type2', possible loss of data".
111 else()
112 add_compile_options(-Wundef)
113 endif()
114
115 #=============================
116 # Main Processing
117 #=============================
118 include(SystemIntrospection)
119 add_subdirectory(src)
120
121 include(PrintConfigureSummary)
122 print_configure_summary()
123