|
| 1 | +cmake_minimum_required(VERSION 3.10) |
| 2 | + |
| 3 | +project(SIMDCompressionAndIntersection |
| 4 | + VERSION 0.1.0 |
| 5 | + LANGUAGES C CXX) |
| 6 | + |
| 7 | +# --------------------------------------------------------------------------- |
| 8 | +# Standards |
| 9 | +# --------------------------------------------------------------------------- |
| 10 | +set(CMAKE_C_STANDARD 99) |
| 11 | +set(CMAKE_C_STANDARD_REQUIRED ON) |
| 12 | +set(CMAKE_CXX_STANDARD 11) |
| 13 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 14 | + |
| 15 | +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) |
| 16 | + set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE) |
| 17 | +endif() |
| 18 | + |
| 19 | +set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 20 | + |
| 21 | +# Is this the top-level project, or are we being added via add_subdirectory()? |
| 22 | +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
| 23 | + set(SIMDCOMP_IS_TOP_LEVEL ON) |
| 24 | +else() |
| 25 | + set(SIMDCOMP_IS_TOP_LEVEL OFF) |
| 26 | +endif() |
| 27 | + |
| 28 | +option(SIMDCOMP_BUILD_TESTS |
| 29 | + "Build the test, benchmark and example executables" ${SIMDCOMP_IS_TOP_LEVEL}) |
| 30 | +option(SIMDCOMP_INSTALL |
| 31 | + "Generate install rules for SIMDCompressionAndIntersection" ${SIMDCOMP_IS_TOP_LEVEL}) |
| 32 | + |
| 33 | +# Defines CMAKE_INSTALL_{LIB,INCLUDE,BIN}DIR; needed before they are referenced |
| 34 | +# in the library's INSTALL_INTERFACE include directories below. |
| 35 | +include(GNUInstallDirs) |
| 36 | + |
| 37 | +# Release builds define NDEBUG (disabling assertions), which is the CMake |
| 38 | +# default for the Release / RelWithDebInfo / MinSizeRel configurations. |
| 39 | + |
| 40 | +# --------------------------------------------------------------------------- |
| 41 | +# SIMD flags |
| 42 | +# |
| 43 | +# On x86/x64 the code is built for AVX (AVX itself is not required at runtime, |
| 44 | +# but the default build assumes it, matching the Makefile). On AArch64 the SSE |
| 45 | +# intrinsics are mapped to ARM NEON via include/neon_sse.h, and NEON is baseline |
| 46 | +# so no architecture flag is needed. |
| 47 | +# --------------------------------------------------------------------------- |
| 48 | +set(SIMD_FLAGS "") |
| 49 | +if(NOT MSVC) |
| 50 | + if(CMAKE_SYSTEM_PROCESSOR MATCHES "(^|;)(x86_64|amd64|AMD64|i.86|x86)$") |
| 51 | + set(SIMD_FLAGS -mavx) |
| 52 | + endif() |
| 53 | +endif() |
| 54 | + |
| 55 | +if(NOT MSVC) |
| 56 | + add_compile_options( |
| 57 | + ${SIMD_FLAGS} |
| 58 | + -Wall -Wextra -Wsign-compare -Wwrite-strings -Wpointer-arith |
| 59 | + -Winit-self -Wno-sign-conversion) |
| 60 | + # -Weffc++ and -pedantic only on the C++ sources (matches the Makefile). |
| 61 | + add_compile_options( |
| 62 | + $<$<COMPILE_LANGUAGE:CXX>:-Weffc++> |
| 63 | + $<$<COMPILE_LANGUAGE:CXX>:-pedantic> |
| 64 | + $<$<COMPILE_LANGUAGE:C>:-pedantic>) |
| 65 | +else() |
| 66 | + add_compile_options(/arch:AVX) |
| 67 | +endif() |
| 68 | + |
| 69 | +# --------------------------------------------------------------------------- |
| 70 | +# Library |
| 71 | +# --------------------------------------------------------------------------- |
| 72 | +set(SIMDCOMP_SOURCES |
| 73 | + src/codecfactory.cpp |
| 74 | + src/bitpacking.cpp |
| 75 | + src/integratedbitpacking.cpp |
| 76 | + src/simdbitpacking.cpp |
| 77 | + src/usimdbitpacking.cpp |
| 78 | + src/simdintegratedbitpacking.cpp |
| 79 | + src/intersection.cpp |
| 80 | + src/varintdecode.c |
| 81 | + src/streamvbyte.c |
| 82 | + src/simdpackedsearch.c |
| 83 | + src/simdpackedselect.c |
| 84 | + src/frameofreference.cpp |
| 85 | + src/for.c) |
| 86 | + |
| 87 | +add_library(SIMDCompressionAndIntersection STATIC ${SIMDCOMP_SOURCES}) |
| 88 | +# Same-name namespaced alias so consumers can use the identical target name |
| 89 | +# whether they add_subdirectory() this project or find_package() an install. |
| 90 | +add_library(SIMDCompressionAndIntersection::SIMDCompressionAndIntersection |
| 91 | + ALIAS SIMDCompressionAndIntersection) |
| 92 | +target_include_directories(SIMDCompressionAndIntersection PUBLIC |
| 93 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 94 | + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SIMDCompressionAndIntersection>) |
| 95 | + |
| 96 | +# --------------------------------------------------------------------------- |
| 97 | +# Test / benchmark / example executables (optional) |
| 98 | +# --------------------------------------------------------------------------- |
| 99 | +if(SIMDCOMP_BUILD_TESTS) |
| 100 | + foreach(prog unit testcodecs testintegration benchintersection benchsearch) |
| 101 | + add_executable(${prog} src/${prog}.cpp) |
| 102 | + target_link_libraries(${prog} PRIVATE SIMDCompressionAndIntersection) |
| 103 | + endforeach() |
| 104 | + |
| 105 | + add_executable(example example.cpp) |
| 106 | + target_link_libraries(example PRIVATE SIMDCompressionAndIntersection) |
| 107 | + |
| 108 | + # Advanced benchmarking tools |
| 109 | + foreach(prog simplesynth compress uncompress budgetedtest ramtocache entropy compflatstat) |
| 110 | + add_executable(${prog} advancedbenchmarking/src/${prog}.cpp) |
| 111 | + target_link_libraries(${prog} PRIVATE SIMDCompressionAndIntersection) |
| 112 | + target_include_directories(${prog} PRIVATE |
| 113 | + ${CMAKE_CURRENT_SOURCE_DIR}/advancedbenchmarking/include) |
| 114 | + endforeach() |
| 115 | + |
| 116 | + enable_testing() |
| 117 | + add_test(NAME unit COMMAND unit) |
| 118 | + add_test(NAME testintegration COMMAND testintegration) |
| 119 | +endif() |
| 120 | + |
| 121 | +# --------------------------------------------------------------------------- |
| 122 | +# Installation |
| 123 | +# --------------------------------------------------------------------------- |
| 124 | +if(SIMDCOMP_INSTALL) |
| 125 | + include(CMakePackageConfigHelpers) |
| 126 | + |
| 127 | + set(SIMDCOMP_INSTALL_CMAKEDIR |
| 128 | + "${CMAKE_INSTALL_LIBDIR}/cmake/SIMDCompressionAndIntersection" |
| 129 | + CACHE STRING "Path (relative to prefix) to install the CMake package config") |
| 130 | + |
| 131 | + # Library + export set. |
| 132 | + install(TARGETS SIMDCompressionAndIntersection |
| 133 | + EXPORT SIMDCompressionAndIntersectionTargets |
| 134 | + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 135 | + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 136 | + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") |
| 137 | + |
| 138 | + # Public headers (flat layout, matching the in-tree include/ directory). |
| 139 | + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" |
| 140 | + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/SIMDCompressionAndIntersection" |
| 141 | + FILES_MATCHING PATTERN "*.h") |
| 142 | + |
| 143 | + # Exported targets file -> SIMDCompressionAndIntersection::SIMDCompressionAndIntersection |
| 144 | + install(EXPORT SIMDCompressionAndIntersectionTargets |
| 145 | + FILE SIMDCompressionAndIntersectionTargets.cmake |
| 146 | + NAMESPACE SIMDCompressionAndIntersection:: |
| 147 | + DESTINATION "${SIMDCOMP_INSTALL_CMAKEDIR}") |
| 148 | + |
| 149 | + # Package config + version files, so find_package() works. |
| 150 | + configure_package_config_file( |
| 151 | + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/SIMDCompressionAndIntersectionConfig.cmake.in" |
| 152 | + "${CMAKE_CURRENT_BINARY_DIR}/SIMDCompressionAndIntersectionConfig.cmake" |
| 153 | + INSTALL_DESTINATION "${SIMDCOMP_INSTALL_CMAKEDIR}") |
| 154 | + |
| 155 | + write_basic_package_version_file( |
| 156 | + "${CMAKE_CURRENT_BINARY_DIR}/SIMDCompressionAndIntersectionConfigVersion.cmake" |
| 157 | + VERSION "${PROJECT_VERSION}" |
| 158 | + COMPATIBILITY SameMajorVersion) |
| 159 | + |
| 160 | + install(FILES |
| 161 | + "${CMAKE_CURRENT_BINARY_DIR}/SIMDCompressionAndIntersectionConfig.cmake" |
| 162 | + "${CMAKE_CURRENT_BINARY_DIR}/SIMDCompressionAndIntersectionConfigVersion.cmake" |
| 163 | + DESTINATION "${SIMDCOMP_INSTALL_CMAKEDIR}") |
| 164 | +endif() |
0 commit comments