Skip to content
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ubuntu22.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ jobs:
cmake .. -DSTREAMVBYTE_SANITIZE_UNDEFINED=ON -DCMAKE_BUILD_TYPE=buildundefsani -DSTREAMVBYTE_ENABLE_EXAMPLES=ON -DSTREAMVBYTE_ENABLE_TESTS=ON &&
cmake --build . &&
ctest --output-on-failure

- name: Install sreamvbyte
run: |
cd buildrelease
sudo cmake --install .

- name: Check cmake target installation
run: cmake --find-package -DNAME=streamvbyte -DCOMPILER_ID=GNU -DLANGUAGE=C -DMODE=EXIST
140 changes: 90 additions & 50 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
cmake_minimum_required(VERSION 3.3)
cmake_minimum_required(VERSION 3.12)

set(CMAKE_MACOSX_RPATH OFF)
project(STREAMVBYTE VERSION "1.0.0")
project(streamvbyte VERSION "0.5.3" LANGUAGES C)

set(STREAMVBYTE_LIB_VERSION "1.0.0" CACHE STRING "streamvbyte library version")
set(STREAMVBYTE_LIB_VERSION "0.5.3" CACHE STRING "streamvbyte library version")
set(STREAMVBYTE_LIB_SOVERSION "1" CACHE STRING "streamvbyte library soversion")

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
# Create target
add_library(
streamvbyte
src/streamvbyte_encode.c
src/streamvbyte_decode.c
src/streamvbyte_zigzag.c
src/streamvbytedelta_encode.c
src/streamvbytedelta_decode.c
src/streamvbyte_0124_encode.c
src/streamvbyte_0124_decode.c
)

# Add alias
add_library(streamvbyte::streamvbyte ALIAS streamvbyte)

# Set C standard
target_compile_features(streamvbyte PUBLIC c_std_99)
set_target_properties(streamvbyte PROPERTIES C_STANDARD_REQUIRED ON)

# Set fPIC
set_target_properties(streamvbyte PROPERTIES POSITION_INDEPENDENT_CODE ON)

option(STREAMVBYTE_SANITIZE "Sanitize addresses" OFF)

# Set CMAKE_BUILD_TYPE
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected")
if(STREAMVBYTE_SANITIZE)
Expand All @@ -35,33 +55,25 @@ if(STREAMVBYTE_SANITIZE)
-fno-omit-frame-pointer
-fno-sanitize-recover=all
)
add_compile_definitions(ASAN_OPTIONS=detect_leaks=1)
add_compile_definitions("ASAN_OPTIONS=detect_leaks=1")
endif()

option(STREAMVBYTE_SANITIZE_UNDEFINED "Sanitize undefined behavior" OFF)
if(STREAMVBYTE_SANITIZE_UNDEFINED)
add_compile_options(-fsanitize=undefined -fno-sanitize-recover=all)
add_link_options(-fsanitize=undefined -fno-sanitize-recover=all)
endif()

if(MSVC)
add_definitions("-D__restrict__=__restrict")
target_compile_definitions(streamvbyte PRIVATE "__restrict__=__restrict")
endif()

# test for arm
# Add Neon support flag
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
set(BASE_FLAGS ${BASE_FLAGS} "-D__ARM_NEON__")
add_compile_definitions("__ARM_NEON__")
endif()

set(STREAMVBYTE_SRCS
${PROJECT_SOURCE_DIR}/src/streamvbyte_encode.c
${PROJECT_SOURCE_DIR}/src/streamvbyte_decode.c
${PROJECT_SOURCE_DIR}/src/streamvbyte_zigzag.c
${PROJECT_SOURCE_DIR}/src/streamvbytedelta_encode.c
${PROJECT_SOURCE_DIR}/src/streamvbytedelta_decode.c
${PROJECT_SOURCE_DIR}/src/streamvbyte_0124_encode.c
${PROJECT_SOURCE_DIR}/src/streamvbyte_0124_decode.c
)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

add_library(streamvbyte "${STREAMVBYTE_SRCS}")
target_link_libraries(streamvbyte ${BASE_FLAGS})

# Set version
set_target_properties(
streamvbyte
PROPERTIES
Expand All @@ -70,64 +82,92 @@ set_target_properties(
WINDOWS_EXPORT_ALL_SYMBOLS YES
)

# Add root include directory
target_include_directories(
streamvbyte
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/include>
)

install(
FILES
${PROJECT_SOURCE_DIR}/include/streamvbyte.h
${PROJECT_SOURCE_DIR}/include/streamvbytedelta.h
${PROJECT_SOURCE_DIR}/include/streamvbyte_zigzag.h
DESTINATION include
)
install(TARGETS streamvbyte DESTINATION lib)

option(STREAMVBYTE_SANITIZE_UNDEFINED "Sanitize undefined behavior" OFF)
if(STREAMVBYTE_SANITIZE_UNDEFINED)
add_compile_options(-fsanitize=undefined -fno-sanitize-recover=all)
add_link_options(-fsanitize=undefined -fno-sanitize-recover=all)
endif()

# Print info
message(STATUS "CMAKE_SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR})
message(STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE}) # this tends to be "sticky" so you can remain unknowingly in debug mode
message(STATUS "CMAKE_C_COMPILER: " ${CMAKE_C_COMPILER}) # important to know which compiler is used
message(STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS}) # important to know the flags
message(STATUS "CMAKE_C_FLAGS_DEBUG: " ${CMAKE_C_FLAGS_DEBUG})
message(STATUS "CMAKE_C_FLAGS_RELEASE: " ${CMAKE_C_FLAGS_RELEASE})

# build programs

# example
# Example
option(STREAMVBYTE_ENABLE_EXAMPLES "Enable examples for streamvbyte" OFF)
if(STREAMVBYTE_ENABLE_EXAMPLES)
add_executable(example ${PROJECT_SOURCE_DIR}/examples/example.c)
add_executable(example examples/example.c)
target_link_libraries(example streamvbyte)
endif()

# Tests
option(STREAMVBYTE_ENABLE_TESTS "Enable unit tests for streamvbyte" OFF)
if(STREAMVBYTE_ENABLE_TESTS)
if(NOT MSVC)
# perf
add_executable(perf ${PROJECT_SOURCE_DIR}/tests/perf.c)
# Perf
add_executable(perf tests/perf.c)
target_link_libraries(perf streamvbyte)
target_link_libraries(perf m)
endif()

# writeseq
add_executable(writeseq ${PROJECT_SOURCE_DIR}/tests/writeseq.c)
# Writeseq
add_executable(writeseq tests/writeseq.c)
target_link_libraries(writeseq streamvbyte)

# unit
add_executable(unit ${PROJECT_SOURCE_DIR}/tests/unit.c)
# Unit
add_executable(unit tests/unit.c)
target_link_libraries(unit streamvbyte)

enable_testing()

# add unit tests
# Add unit tests
add_test(NAME unit COMMAND unit)
add_custom_target(check COMMAND ctest --output-on-failure DEPENDS unit)
endif()

# Install
include(GNUInstallDirs)

install(TARGETS streamvbyte EXPORT streamvbyte-target)
install(
EXPORT streamvbyte-target
FILE streamvbyte-targets.cmake
NAMESPACE streamvbyte::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake
)

include(CMakePackageConfigHelpers)

# Create package config file
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/streamvbyte-config.cmake.in"
"streamvbyte-config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake
)

# Create package version file
write_basic_package_version_file(
streamvbyte-config-version.cmake
COMPATIBILITY SameMajorVersion
)

# Install cmake files
install(
FILES
"${PROJECT_BINARY_DIR}/streamvbyte-config.cmake"
"${PROJECT_BINARY_DIR}/streamvbyte-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake
)

install(
FILES
${PROJECT_SOURCE_DIR}/include/streamvbyte.h
${PROJECT_SOURCE_DIR}/include/streamvbytedelta.h
${PROJECT_SOURCE_DIR}/include/streamvbyte_zigzag.h
DESTINATION include
)
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ zigzag_encode(mysignedints, myunsignedints, number); // mysignedints => myunsign
zigzag_decode(myunsignedints, mysignedints, number); // myunsignedints => mysignedints
```

Installation (CMake)
----------------

```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing "mkdir build?". Note that you can do cmake -B build ....

cmake -DCMAKE_BUILD_TYPE=Release ..
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We default on release.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still good to spell it out because under Windows, it must be spelt out.

cmake --build .
sudo cmake --install .
```

Installation
----------------

Expand Down
1 change: 1 addition & 0 deletions cmake/streamvbyte-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@PACKAGE_INIT@