Skip to content
Permalink
Browse files
Merge pull request #245 from will-lauer/install
Updating cmake config to support publication and package building
  • Loading branch information
AlexanderSaydakov committed Oct 28, 2021
2 parents 68bbd1b + 6914292 commit 710ac0ac971bac8733afa5505eb4c8a5d57c2d34
Show file tree
Hide file tree
Showing 13 changed files with 225 additions and 253 deletions.
@@ -17,7 +17,7 @@

cmake_minimum_required(VERSION 3.12.0)
project(DataSketches
VERSION 0.12.0
VERSION 3.2.0
LANGUAGES CXX)

include(GNUInstallDirs)
@@ -126,11 +126,29 @@ endif()

# # Installation
install(TARGETS datasketches
EXPORT ${PROJCT_NAME}
EXPORT ${PROJECT_NAME}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/DataSketches
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/DataSketches
)

# Packaging
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/DataSketchesConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
cmake/DataSketchesConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/DataSketchesConfig.cmake"
INSTALL_DESTINATION lib/DataSketches/cmake
)
install(EXPORT ${PROJECT_NAME} DESTINATION lib/DataSketches/cmake)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/DataSketchesConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/DataSketchesConfig.cmake"
DESTINATION lib/DataSketches/cmake)


#set(CPACK_PROJECT_NAME ${PROJECT_NAME})
#set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
#include(CPack)
include(CPack)
@@ -9,11 +9,14 @@ global-exclude .git*

recursive-include python/pybind11 *

graft cmake
graft common
graft cpc
graft fi
graft hll
graft kll
graft req
graft theta
graft tuple
graft sampling
graft python
@@ -25,10 +25,8 @@ Installing the latest cmake on OSX: brew install cmake
Building and running unit tests using cmake for OSX and Linux:

```
$ cd build
$ cmake ..
$ make
$ make test
$ cmake -S . -B build/Release -DCMAKE_BUILD_TYPE=Release
$ cmake --build build/Release -t test
```

Building and running unit tests using cmake for Windows from the command line:
@@ -40,3 +38,62 @@ Building and running unit tests using cmake for Windows from the command line:
$ cmake --build build --config Release
$ cmake --build build --config Release --target RUN_TESTS
```

To install a local distribution (OSX and Linux), use the following command. The
CMAKE_INSTALL_PREFIX variable controls the destination. If not specified, it
defaults to installing in /usr (/usr/include, /usr/lib, etc). In the command below,
the installation will be in /tmp/install/DataSketches (/tmp/install/DataSketches/include,
/tmp/install/DataSketches/lib, etc)

```
$ cmake -S . -B build/Release -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/install/DataSketches
$ cmake --build build/Release -t install
```

To generate an installable package using cmake's built in cpack packaging tool,
use the following command. The type of packaging is controlled by the CPACK_GENERATOR
variable (semi-colon separated list). Cmake usually supports packaging types such as RPM,
DEB, STGZ, TGZ, TZ, ZIP, etc.

```
$ cmake3 -S . -B build/Release -DCMAKE_BUILD_TYPE=Release -DCPACK_GENERATOR="RPM;STGZ;TGZ"
$ cmake3 --build build/Release -t package
```

The DataSketches project can be included in other projects' CMakeLists.txt files in one of two ways.
If DataSketches has been installed on the host (using an RPM, DEB, "make install" into /usr/local, or some
way, then CMake's `find_package` command can be used like this:

```
find_package(DataSketches 3.2 REQUIRED)
target_link_library(my_dependent_target PUBLIC ${DATASKETCHES_LIB})
```

If you don't have DataSketches installed locally, dependent projects can pull it directly
from GitHub using CMake's `ExternalProject` module. The code would look something like this:

```
cmake_policy(SET CMP0097 NEW)
include(ExternalProject)
ExternalProject_Add(datasketches
GIT_REPOSITORY https://github.com/apache/datasketches-cpp.git
GIT_TAG 3.2.0
GIT_SHALLOW true
GIT_SUBMODULES ""
INSTALL_DIR /tmp/datasketches-prefix
CMAKE_ARGS -DBUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=/tmp/datasketches-prefix
# Override the install command to add DESTDIR
# This is necessary to work around an oddity in the RPM (but not other) package
# generation, as CMake otherwise picks up the Datasketch files when building
# an RPM for a dependent package. (RPM scans the directory for files in addition to installing
# those files referenced in an "install" rule in the cmake file)
INSTALL_COMMAND env DESTDIR= ${CMAKE_COMMAND} --build . --target install
)
ExternalProject_Get_property(datasketches INSTALL_DIR)
set(datasketches_INSTALL_DIR ${INSTALL_DIR})
message("Source dir of datasketches = ${datasketches_INSTALL_DIR}")
target_include_directories(my_dependent_target
PRIVATE ${datasketches_INSTALL_DIR}/include/DataSketches)
add_dependencies(my_dependent_target datasketches)
```
@@ -0,0 +1,7 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/DataSketches.cmake")

set(DATASKETCHES_LIB "datasketches")

check_required_components("@PROJECT_NAME@")
@@ -29,17 +29,18 @@ target_include_directories(common

target_compile_features(common INTERFACE cxx_std_11)

target_sources(common
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/include/common_defs.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/memory_operations.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/MurmurHash3.h
${CMAKE_CURRENT_SOURCE_DIR}/include/serde.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/count_zeros.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/inv_pow2_table.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/binomial_bounds.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/conditional_back_inserter.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/conditional_forward.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ceiling_power_of_2.hpp
)
install(TARGETS common EXPORT ${PROJECT_NAME})

install(FILES
include/common_defs.hpp
include/memory_operations.hpp
include/MurmurHash3.h
include/serde.hpp
include/count_zeros.hpp
include/inv_pow2_table.hpp
include/binomial_bounds.hpp
include/conditional_back_inserter.hpp
include/conditional_forward.hpp
include/ceiling_power_of_2.hpp
include/bounds_binomial_proportions.hpp
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/DataSketches")
@@ -32,43 +32,23 @@ target_include_directories(cpc
target_link_libraries(cpc INTERFACE common)
target_compile_features(cpc INTERFACE cxx_std_11)

set(cpc_HEADERS "")
list(APPEND cpc_HEADERS "include/compression_data.hpp")
list(APPEND cpc_HEADERS "include/cpc_common.hpp")
list(APPEND cpc_HEADERS "include/cpc_compressor.hpp")
list(APPEND cpc_HEADERS "include/cpc_compressor_impl.hpp")
list(APPEND cpc_HEADERS "include/cpc_confidence.hpp")
list(APPEND cpc_HEADERS "include/cpc_sketch.hpp")
list(APPEND cpc_HEADERS "include/cpc_sketch_impl.hpp")
list(APPEND cpc_HEADERS "include/cpc_union.hpp")
list(APPEND cpc_HEADERS "include/cpc_union_impl.hpp")
list(APPEND cpc_HEADERS "include/cpc_util.hpp")
list(APPEND cpc_HEADERS "include/icon_estimator.hpp")
list(APPEND cpc_HEADERS "include/kxp_byte_lookup.hpp")
list(APPEND cpc_HEADERS "include/u32_table.hpp")
list(APPEND cpc_HEADERS "include/u32_table_impl.hpp")

install(TARGETS cpc
EXPORT ${PROJECT_NAME}
)

install(FILES ${cpc_HEADERS}
install(FILES
include/compression_data.hpp
include/cpc_common.hpp
include/cpc_compressor.hpp
include/cpc_compressor_impl.hpp
include/cpc_confidence.hpp
include/cpc_sketch.hpp
include/cpc_sketch_impl.hpp
include/cpc_union.hpp
include/cpc_union_impl.hpp
include/cpc_util.hpp
include/icon_estimator.hpp
include/kxp_byte_lookup.hpp
include/u32_table.hpp
include/u32_table_impl.hpp
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/DataSketches")

target_sources(cpc
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/include/compression_data.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cpc_common.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cpc_compressor.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cpc_compressor_impl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cpc_confidence.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cpc_sketch.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cpc_sketch_impl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cpc_union.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cpc_union_impl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cpc_util.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/icon_estimator.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/kxp_byte_lookup.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/u32_table.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/u32_table_impl.hpp
)
@@ -32,23 +32,13 @@ target_include_directories(fi
target_link_libraries(fi INTERFACE common)
target_compile_features(fi INTERFACE cxx_std_11)

set(fi_HEADERS "")
list(APPEND fi_HEADERS "include/frequent_items_sketch.hpp")
list(APPEND fi_HEADERS "include/frequent_items_sketch_impl.hpp")
list(APPEND fi_HEADERS "include/reverse_purge_hash_map.hpp")
list(APPEND fi_HEADERS "include/reverse_purge_hash_map_impl.hpp")

install(TARGETS fi
EXPORT ${PROJECT_NAME}
)

install(FILES ${fi_HEADERS}
install(FILES
include/frequent_items_sketch.hpp
include/frequent_items_sketch_impl.hpp
include/reverse_purge_hash_map.hpp
include/reverse_purge_hash_map_impl.hpp
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/DataSketches")

target_sources(fi
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/include/frequent_items_sketch.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/frequent_items_sketch_impl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/reverse_purge_hash_map.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/reverse_purge_hash_map_impl.hpp
)
@@ -32,64 +32,41 @@ target_include_directories(hll
target_link_libraries(hll INTERFACE common)
target_compile_features(hll INTERFACE cxx_std_11)

# TODO: would be useful if this didn't need to be reproduced in target_sources(), too
set(hll_HEADERS "")
list(APPEND hll_HEADERS "include/hll.hpp;include/AuxHashMap.hpp;include/CompositeInterpolationXTable.hpp")
list(APPEND hll_HEADERS "include/hll.private.hpp;include/HllSketchImplFactory.hpp")
list(APPEND hll_HEADERS "include/CouponHashSet.hpp;include/CouponList.hpp")
list(APPEND hll_HEADERS "include/CubicInterpolation.hpp;include/HarmonicNumbers.hpp;include/Hll4Array.hpp")
list(APPEND hll_HEADERS "include/Hll6Array.hpp;include/Hll8Array.hpp;include/HllArray.hpp")
list(APPEND hll_HEADERS "include/HllSketchImpl.hpp")
list(APPEND hll_HEADERS "include/HllUtil.hpp;include/coupon_iterator.hpp")
list(APPEND hll_HEADERS "include/RelativeErrorTables.hpp;include/AuxHashMap-internal.hpp")
list(APPEND hll_HEADERS "include/CompositeInterpolationXTable-internal.hpp")
list(APPEND hll_HEADERS "include/CouponHashSet-internal.hpp;include/CouponList-internal.hpp")
list(APPEND hll_HEADERS "include/CubicInterpolation-internal.hpp;include/HarmonicNumbers-internal.hpp")
list(APPEND hll_HEADERS "include/Hll4Array-internal.hpp;include/Hll6Array-internal.hpp")
list(APPEND hll_HEADERS "include/Hll8Array-internal.hpp;include/HllArray-internal.hpp")
list(APPEND hll_HEADERS "include/HllSketch-internal.hpp")
list(APPEND hll_HEADERS "include/HllSketchImpl-internal.hpp;include/HllUnion-internal.hpp")
list(APPEND hll_HEADERS "include/coupon_iterator-internal.hpp;include/RelativeErrorTables-internal.hpp")

install(TARGETS hll
EXPORT ${PROJECT_NAME}
)

install(FILES ${hll_HEADERS}
install(FILES
include/hll.hpp
include/AuxHashMap.hpp
include/CompositeInterpolationXTable.hpp
include/hll.private.hpp
include/HllSketchImplFactory.hpp
include/CouponHashSet.hpp
include/CouponList.hpp
include/CubicInterpolation.hpp
include/HarmonicNumbers.hpp
include/Hll4Array.hpp
include/Hll6Array.hpp
include/Hll8Array.hpp
include/HllArray.hpp
include/HllSketchImpl.hpp
include/HllUtil.hpp
include/coupon_iterator.hpp
include/RelativeErrorTables.hpp
include/AuxHashMap-internal.hpp
include/CompositeInterpolationXTable-internal.hpp
include/CouponHashSet-internal.hpp
include/CouponList-internal.hpp
include/CubicInterpolation-internal.hpp
include/HarmonicNumbers-internal.hpp
include/Hll4Array-internal.hpp
include/Hll6Array-internal.hpp
include/Hll8Array-internal.hpp
include/HllArray-internal.hpp
include/HllSketch-internal.hpp
include/HllSketchImpl-internal.hpp
include/HllUnion-internal.hpp
include/coupon_iterator-internal.hpp
include/RelativeErrorTables-internal.hpp
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/DataSketches")

target_sources(hll
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/include/hll.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/hll.private.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/AuxHashMap.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/CompositeInterpolationXTable.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/CouponHashSet.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/CouponList.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/CubicInterpolation.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/HarmonicNumbers.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/Hll4Array.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/Hll6Array.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/Hll8Array.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/HllArray.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/HllSketchImpl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/HllSketchImplFactory.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/HllUtil.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/RelativeErrorTables.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/coupon_iterator.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/AuxHashMap-internal.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/CompositeInterpolationXTable-internal.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/CouponHashSet-internal.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/CouponList-internal.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/CubicInterpolation-internal.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/HarmonicNumbers-internal.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/Hll4Array-internal.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/Hll6Array-internal.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/Hll8Array-internal.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/HllArray-internal.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/HllSketch-internal.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/HllSketchImpl-internal.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/HllUnion-internal.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/RelativeErrorTables-internal.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/coupon_iterator-internal.hpp
)
@@ -32,27 +32,17 @@ target_include_directories(kll
target_link_libraries(kll INTERFACE common)
target_compile_features(kll INTERFACE cxx_std_11)

set(kll_HEADERS "")
list(APPEND kll_HEADERS "include/kll_sketch.hpp")
list(APPEND kll_HEADERS "include/kll_sketch_impl.hpp")
list(APPEND kll_HEADERS "include/kll_helper.hpp")
list(APPEND kll_HEADERS "include/kll_helper_impl.hpp")
list(APPEND kll_HEADERS "include/kll_quantile_calculator.hpp")
list(APPEND kll_HEADERS "include/kll_quantile_calculator_impl.hpp")

install(TARGETS kll
EXPORT ${PROJECT_NAME}
)

install(FILES ${kll_HEADERS}
install(FILES
include/kll_sketch.hpp
include/kll_sketch_impl.hpp
include/kll_helper.hpp
include/kll_helper_impl.hpp
include/kll_quantile_calculator.hpp
include/kll_quantile_calculator_impl.hpp
include/kolmogorov_smirnov.hpp
include/kolmogorov_smirnov_impl.hpp
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/DataSketches")

target_sources(kll
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/include/kll_helper.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/kll_helper_impl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/kll_sketch.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/kll_sketch_impl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/kll_quantile_calculator.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/kll_quantile_calculator_impl.hpp
)

0 comments on commit 710ac0a

Please sign in to comment.