Skip to content

Commit 12947aa

Browse files
authored
Merge b5565aa into 710ac0a
2 parents 710ac0a + b5565aa commit 12947aa

File tree

3 files changed

+50
-36
lines changed

3 files changed

+50
-36
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ configure_package_config_file(
142142
cmake/DataSketchesConfig.cmake.in
143143
"${CMAKE_CURRENT_BINARY_DIR}/DataSketchesConfig.cmake"
144144
INSTALL_DESTINATION lib/DataSketches/cmake
145+
PATH_VARS CMAKE_INSTALL_INCLUDEDIR
145146
)
146147
install(EXPORT ${PROJECT_NAME} DESTINATION lib/DataSketches/cmake)
147148
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/DataSketchesConfigVersion.cmake"

README.md

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ Installing the latest cmake on OSX: brew install cmake
2525
Building and running unit tests using cmake for OSX and Linux:
2626

2727
```
28-
$ cmake -S . -B build/Release -DCMAKE_BUILD_TYPE=Release
29-
$ cmake --build build/Release -t test
28+
$ cmake -S . -B build/Release -DCMAKE_BUILD_TYPE=Release
29+
$ cmake --build build/Release -t test
3030
```
3131

3232
Building and running unit tests using cmake for Windows from the command line:
3333

3434
```
35-
$ cd build
36-
$ cmake ..
37-
$ cd ..
38-
$ cmake --build build --config Release
39-
$ cmake --build build --config Release --target RUN_TESTS
35+
$ cd build
36+
$ cmake ..
37+
$ cd ..
38+
$ cmake --build build --config Release
39+
$ cmake --build build --config Release --target RUN_TESTS
4040
```
4141

4242
To install a local distribution (OSX and Linux), use the following command. The
@@ -46,8 +46,8 @@ the installation will be in /tmp/install/DataSketches (/tmp/install/DataSketches
4646
/tmp/install/DataSketches/lib, etc)
4747

4848
```
49-
$ cmake -S . -B build/Release -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/install/DataSketches
50-
$ cmake --build build/Release -t install
49+
$ cmake -S . -B build/Release -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/install/DataSketches
50+
$ cmake --build build/Release -t install
5151
```
5252

5353
To generate an installable package using cmake's built in cpack packaging tool,
@@ -56,44 +56,54 @@ variable (semi-colon separated list). Cmake usually supports packaging types suc
5656
DEB, STGZ, TGZ, TZ, ZIP, etc.
5757

5858
```
59-
$ cmake3 -S . -B build/Release -DCMAKE_BUILD_TYPE=Release -DCPACK_GENERATOR="RPM;STGZ;TGZ"
60-
$ cmake3 --build build/Release -t package
59+
$ cmake3 -S . -B build/Release -DCMAKE_BUILD_TYPE=Release -DCPACK_GENERATOR="RPM;STGZ;TGZ"
60+
$ cmake3 --build build/Release -t package
6161
```
6262

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

6767
```
68-
find_package(DataSketches 3.2 REQUIRED)
69-
target_link_library(my_dependent_target PUBLIC ${DATASKETCHES_LIB})
68+
find_package(DataSketches 3.2 REQUIRED)
69+
target_link_library(my_dependent_target PUBLIC ${DATASKETCHES_LIB})
7070
```
7171

72+
When used with find_package, DataSketches exports several variables, including
73+
74+
- `DATASKETCHES_VERSION`: The version number of the datasketches package that was imported.
75+
- `DATASKETCHES_INCLUDE_DIR`: The directory that should be added to access DataSketches include files.
76+
Because cmake automatically includes the interface directories for included target libraries when
77+
using `target_link_library`, under normal circumstances there will be no need to include this directly.
78+
- `DATASKETCHES_LIB`: The name of the DataSketches target to include as a dependency. Projects pulling
79+
in DataSketches should reference this with `target_link_library` in order to set up all the correct dependencies
80+
and include paths.
81+
7282
If you don't have DataSketches installed locally, dependent projects can pull it directly
7383
from GitHub using CMake's `ExternalProject` module. The code would look something like this:
7484

7585
```
76-
cmake_policy(SET CMP0097 NEW)
77-
include(ExternalProject)
78-
ExternalProject_Add(datasketches
79-
GIT_REPOSITORY https://github.com/apache/datasketches-cpp.git
80-
GIT_TAG 3.2.0
81-
GIT_SHALLOW true
82-
GIT_SUBMODULES ""
83-
INSTALL_DIR /tmp/datasketches-prefix
84-
CMAKE_ARGS -DBUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=/tmp/datasketches-prefix
85-
86-
# Override the install command to add DESTDIR
87-
# This is necessary to work around an oddity in the RPM (but not other) package
88-
# generation, as CMake otherwise picks up the Datasketch files when building
89-
# an RPM for a dependent package. (RPM scans the directory for files in addition to installing
90-
# those files referenced in an "install" rule in the cmake file)
91-
INSTALL_COMMAND env DESTDIR= ${CMAKE_COMMAND} --build . --target install
92-
)
93-
ExternalProject_Get_property(datasketches INSTALL_DIR)
94-
set(datasketches_INSTALL_DIR ${INSTALL_DIR})
95-
message("Source dir of datasketches = ${datasketches_INSTALL_DIR}")
96-
target_include_directories(my_dependent_target
97-
PRIVATE ${datasketches_INSTALL_DIR}/include/DataSketches)
98-
add_dependencies(my_dependent_target datasketches)
86+
cmake_policy(SET CMP0097 NEW)
87+
include(ExternalProject)
88+
ExternalProject_Add(datasketches
89+
GIT_REPOSITORY https://github.com/apache/datasketches-cpp.git
90+
GIT_TAG 3.2.0
91+
GIT_SHALLOW true
92+
GIT_SUBMODULES ""
93+
INSTALL_DIR /tmp/datasketches-prefix
94+
CMAKE_ARGS -DBUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=/tmp/datasketches-prefix
95+
96+
# Override the install command to add DESTDIR
97+
# This is necessary to work around an oddity in the RPM (but not other) package
98+
# generation, as CMake otherwise picks up the Datasketch files when building
99+
# an RPM for a dependent package. (RPM scans the directory for files in addition to installing
100+
# those files referenced in an "install" rule in the cmake file)
101+
INSTALL_COMMAND env DESTDIR= ${CMAKE_COMMAND} --build . --target install
102+
)
103+
ExternalProject_Get_property(datasketches INSTALL_DIR)
104+
set(datasketches_INSTALL_DIR ${INSTALL_DIR})
105+
message("Source dir of datasketches = ${datasketches_INSTALL_DIR}")
106+
target_include_directories(my_dependent_target
107+
PRIVATE ${datasketches_INSTALL_DIR}/include/DataSketches)
108+
add_dependencies(my_dependent_target datasketches)
99109
```

cmake/DataSketchesConfig.cmake.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
set(DATASKETCHES_VERSION "@PROJECT_VERSION@")
2+
13
@PACKAGE_INIT@
24

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

7+
set_and_check(DATASKETCHES_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@/DataSketches")
58
set(DATASKETCHES_LIB "datasketches")
69

710
check_required_components("@PROJECT_NAME@")

0 commit comments

Comments
 (0)