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