|
| 1 | +cmake_minimum_required(VERSION 3.22) |
| 2 | + |
| 3 | +project(minisketch |
| 4 | + VERSION 0.0.1 |
| 5 | + DESCRIPTION "A library for BCH-based set reconciliation" |
| 6 | + HOMEPAGE_URL "http://github.com/sipa/minisketch/" |
| 7 | + LANGUAGES CXX |
| 8 | +) |
| 9 | + |
| 10 | +if(DEFINED CMAKE_CXX_STANDARD) |
| 11 | + if(CMAKE_CXX_STANDARD EQUAL 98 OR CMAKE_CXX_STANDARD LESS 11) |
| 12 | + message(FATAL_ERROR "This project requires at least C++11") |
| 13 | + endif() |
| 14 | +else() |
| 15 | + set(CMAKE_CXX_STANDARD 11) |
| 16 | +endif() |
| 17 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 18 | +if(NOT DEFINED CMAKE_CXX_EXTENSIONS) |
| 19 | + set(CMAKE_CXX_EXTENSIONS OFF) |
| 20 | +endif() |
| 21 | + |
| 22 | +option(MINISKETCH_TESTS "Build tests." ON) |
| 23 | +option(MINISKETCH_BENCHMARK "Build benchmark." OFF) |
| 24 | + |
| 25 | +set(supported_fields "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") |
| 26 | +set(MINISKETCH_FIELDS ${supported_fields} CACHE STRING "Comma-separated list of field sizes to build. Default=all. Available sizes: ${supported_fields}.") |
| 27 | +string(REPLACE "," ";" supported_field_list "${supported_fields}") |
| 28 | +string(REPLACE "," ";" provided_field_list "${MINISKETCH_FIELDS}") |
| 29 | +foreach(field IN LISTS supported_field_list) |
| 30 | + if(NOT field IN_LIST provided_field_list) |
| 31 | + set(have_disabled_fields TRUE) |
| 32 | + add_compile_definitions(DISABLE_FIELD_${field}) |
| 33 | + endif() |
| 34 | +endforeach() |
| 35 | + |
| 36 | +set(CMAKE_CXX_VISIBILITY_PRESET hidden) |
| 37 | +set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE) |
| 38 | + |
| 39 | +if(MSVC) |
| 40 | + add_compile_options(/Zc:__cplusplus /W4 /wd4060 /wd4065 /wd4100 /wd4127 /wd4146 /wd4244 /wd4267 /wd4310) |
| 41 | +else() |
| 42 | + add_compile_options(-Wall) |
| 43 | +endif() |
| 44 | + |
| 45 | +if(MINGW) |
| 46 | + add_link_options(-static) |
| 47 | +endif() |
| 48 | + |
| 49 | +add_subdirectory(src) |
| 50 | + |
| 51 | +message("\n") |
| 52 | +message("minisketch configure summary") |
| 53 | +message("============================") |
| 54 | +if(BUILD_SHARED_LIBS) |
| 55 | + set(library_type "Shared") |
| 56 | +else() |
| 57 | + set(library_type "Static") |
| 58 | +endif() |
| 59 | +message("Library type .......................... ${library_type}") |
| 60 | +message("Build options:") |
| 61 | +if(HAVE_CLMUL) |
| 62 | + set(clmul_status "ENABLED") |
| 63 | +else() |
| 64 | + set(clmul_status "DISABLED") |
| 65 | +endif() |
| 66 | +message(" clmul fields ........................ ${clmul_status}") |
| 67 | +if(CMAKE_CXX_STANDARD GREATER_EQUAL 20) |
| 68 | + set(clz_status "c++20") |
| 69 | +elseif(HAVE_CLZ) |
| 70 | + set(clz_status "compiler builtin") |
| 71 | +else() |
| 72 | + set(clz_status "default") |
| 73 | +endif() |
| 74 | +message(" clz implementation .................. ${clz_status}") |
| 75 | +message("Optional binaries:") |
| 76 | +message(" benchmark ........................... ${MINISKETCH_BENCHMARK}") |
| 77 | +message(" tests ............................... ${MINISKETCH_TESTS}") |
| 78 | +message("") |
| 79 | +if(CMAKE_CROSSCOMPILING) |
| 80 | + set(cross_status "TRUE, for ${CMAKE_SYSTEM_NAME}, ${CMAKE_SYSTEM_PROCESSOR}") |
| 81 | +else() |
| 82 | + set(cross_status "FALSE") |
| 83 | +endif() |
| 84 | +message("Cross compiling ....................... ${cross_status}") |
| 85 | +message("C++ compiler .......................... ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}, ${CMAKE_CXX_COMPILER}") |
| 86 | + |
| 87 | +get_directory_property(compile_options COMPILE_OPTIONS) |
| 88 | +string(REPLACE ";" " " compile_options "${compile_options}") |
| 89 | +macro(print_flags_per_config config indent dots) |
| 90 | + string(TOUPPER "${config}" config_uppercase) |
| 91 | + string(STRIP "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${config_uppercase}}" combined_cxx_flags) |
| 92 | + string(STRIP "${combined_cxx_flags} ${compile_options}" combined_cxx_flags) |
| 93 | + message("${indent}" "C++ flags ...........................${dots} ${combined_cxx_flags}") |
| 94 | +endmacro() |
| 95 | + |
| 96 | +get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) |
| 97 | +if(is_multi_config) |
| 98 | + list(JOIN CMAKE_CONFIGURATION_TYPES ", " configs) |
| 99 | + message("Available build configurations ........ ${configs}") |
| 100 | + if(CMAKE_GENERATOR MATCHES "Visual Studio") |
| 101 | + set(default_config "Debug") |
| 102 | + else() |
| 103 | + list(GET CMAKE_CONFIGURATION_TYPES 0 default_config) |
| 104 | + endif() |
| 105 | + message("Default build configuration ........... ${default_config}") |
| 106 | + foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES) |
| 107 | + message("'${config}' build configuration:") |
| 108 | + print_flags_per_config("${config}" " " "") |
| 109 | + endforeach() |
| 110 | +else() |
| 111 | + message("Build configuration ................... ${CMAKE_BUILD_TYPE}") |
| 112 | + print_flags_per_config("${CMAKE_BUILD_TYPE}" "" "..") |
| 113 | +endif() |
| 114 | + |
| 115 | +if(have_disabled_fields) |
| 116 | +message("") |
| 117 | +message(WARNING |
| 118 | + "Only compiling in support for field sizes: ${MINISKETCH_FIELDS}\n" |
| 119 | + "This means the library will lack support for other field sizes entirely.") |
| 120 | +endif() |
| 121 | +message("") |
0 commit comments