Skip to content

Commit 9bbcd31

Browse files
authored
enable cmake import (#82)
1 parent 3d9f3b7 commit 9bbcd31

78 files changed

Lines changed: 288 additions & 376 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ out
1414
cygwin
1515
CMakeSettings.json
1616

17-
/cmake-build-debug/
17+
**/cmake-build-debug/

BUILD

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,30 @@ filegroup(
6969
name = "dot_clang_format",
7070
srcs = [".clang-format"],
7171
)
72+
73+
cc_library(
74+
name = "phtree",
75+
srcs = glob(
76+
include = [
77+
"include/**/*.h",
78+
],
79+
),
80+
hdrs = [
81+
"include/phtree/converter.h",
82+
"include/phtree/distance.h",
83+
"include/phtree/filter.h",
84+
"include/phtree/phtree.h",
85+
"include/phtree/phtree_multimap.h",
86+
],
87+
includes = [
88+
"include",
89+
],
90+
linkstatic = True,
91+
visibility = [
92+
"//visibility:public",
93+
],
94+
deps = [
95+
"//include/phtree/common",
96+
"//include/phtree/v16",
97+
],
98+
)

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88
### Added
9-
- Added build features:
9+
- Added build features: [#53](https://github.com/tzaeschke/phtree-cpp/issues/53)
1010
- linting for C++ and bazel files.
1111
- Added CI status badges.
1212
- Added test coverage
13-
[#53](https://github.com/tzaeschke/phtree-cpp/issues/53)
1413

1514
### Changed
1615
- Cleaned up build scripts. [#53](https://github.com/tzaeschke/phtree-cpp/issues/53)
1716
- Fixed code coverage + migrate to linux. [#80](https://github.com/tzaeschke/phtree-cpp/issues/80)
17+
- ***BREAKING CHANGE*** The project has been restructured to have a more "standard" directory structure.
18+
This affects how **bazel** dependencies work (use `deps = ["@phtree//:phtree",]`) and enables **cmake FetchContent_**.
19+
See README for details. [#75](https://github.com/tzaeschke/phtree-cpp/issues/75)
1820

1921
### Removed
2022
- Nothing.

CMakeLists.txt

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
cmake_minimum_required(VERSION 3.14)
22

3-
# set the project name
43
project(phtree VERSION 1.3.0
54
DESCRIPTION "PH-Tree C++"
5+
HOMEPAGE_URL "https://github.com/tzaeschke/phtree-cpp"
66
LANGUAGES CXX)
77

88

@@ -19,16 +19,13 @@ endif ()
1919
# ---------------------------------------------------------------------------------------
2020
# Build options
2121
# ---------------------------------------------------------------------------------------
22-
# example options
2322
option(PHTREE_BUILD_ALL "Build examples, tests and benchmarks" OFF)
2423

2524
# example options
2625
option(PHTREE_BUILD_EXAMPLES "Build examples" OFF)
27-
#option(PHTREE_BUILD_EXAMPLE_HO "Build header only example" OFF)
2826

2927
# testing options
3028
option(PHTREE_BUILD_TESTS "Build tests" OFF)
31-
#option(PHTREE_BUILD_TESTS_HO "Build tests using the header only version" OFF)
3229
option(PHTREE_CODE_COVERAGE "Collect coverage from test library" OFF)
3330
if (PHTREE_CODE_COVERAGE)
3431
set(PHTREE_BUILD_TESTS ON)
@@ -57,8 +54,7 @@ if (NOT CMAKE_CXX_STANDARD)
5754
endif ()
5855

5956
if (MSVC)
60-
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /Wall")
61-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
57+
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall")
6258
set(CMAKE_CXX_FLAGS_RELEASE "/O2")
6359

6460
if (PHTREE_BUILD_TESTS OR PHTREE_BUILD_ALL)
@@ -78,7 +74,7 @@ if (MSVC)
7874
# set(BENCHMARK_ENABLE_GTEST_TESTS OFF)
7975
endif ()
8076
else ()
81-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Werror")
77+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
8278
if (PHTREE_BUILD_BENCHMARKS)
8379
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -mavx -pthread")
8480
else ()
@@ -93,7 +89,17 @@ endif ()
9389
# ---------------------------------------------------------------------------------------
9490
# Build binaries
9591
# ---------------------------------------------------------------------------------------
96-
add_subdirectory(phtree)
92+
93+
# ---------------------------------------------------------------------------------------
94+
# Header only version
95+
# ---------------------------------------------------------------------------------------
96+
add_library(phtree INTERFACE)
97+
add_library(phtree::phtree ALIAS phtree)
98+
target_compile_features(phtree INTERFACE cxx_std_17)
99+
100+
target_include_directories(phtree INTERFACE
101+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
102+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
97103

98104
if (PHTREE_BUILD_EXAMPLES OR PHTREE_BUILD_ALL)
99105
message(STATUS "Generating examples")
@@ -107,26 +113,6 @@ endif ()
107113

108114
if (PHTREE_BUILD_TESTS OR PHTREE_BUILD_ALL)
109115
message(STATUS "Generating tests")
110-
if (FALSE)
111-
add_compile_definitions(GTEST_HAS_ABSL=0)
112-
add_compile_definitions(GTEST_OS_WINDOWS_MOBILE=0)
113-
if (MSVC)
114-
add_compile_definitions(GTEST_OS_WINDOWS_MINGW=0)
115-
endif ()
116-
add_compile_definitions(GTEST_OS_LINUX_ANDROID=0)
117-
if (LINUX)
118-
add_compile_definitions(GTEST_OS_LINUX=1)
119-
else ()
120-
add_compile_definitions(GTEST_OS_LINUX=0)
121-
endif ()
122-
add_compile_definitions(
123-
GTEST_OS_WINDOWS_MOBILE=0
124-
GTEST_OS_WINDOWS_PHONE=0
125-
GTEST_OS_WINDOWS_RT=0
126-
GTEST_OS_ESP8266=0
127-
GTEST_OS_XTENSA=0)
128-
endif ()
129-
130116
enable_testing()
131117
include(GoogleTest)
132118
add_subdirectory(test)

README.md

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,8 @@ There are numerous ways to improve performance. The following list gives an over
533533

534534
## Compiling the PH-Tree
535535

536-
The PH-Tree index itself is a *header only* library, it can be used by simply copying all headers in the `phtree`
537-
folder.
536+
The PH-Tree index itself is a *header only* library, it can be used by simply copying everything in the
537+
`include/phtree` folder.
538538
The examples, tests and benchmarks can be build with bazel or cmake.
539539

540540
<a id="build-system-and-dependencies"></a>
@@ -545,7 +545,7 @@ PH-Tree can be built with [Bazel](https://bazel.build) (primary build system) or
545545
[cmake](https://cmake.org/) *3.14*.
546546
All code is written in C++ targeting the C++17 standard.
547547
The code has been verified to compile on Linux with Clang 11 and GCC 9, and on Windows with Visual Studio 2019
548-
(except benchmarks, which don't work wi VS).
548+
(except benchmarks, which don't work with VS).
549549
The PH-tree makes use of vectorization, so suggested compilation options for clang/gcc are:
550550
```
551551
-O3 -mavx
@@ -555,6 +555,25 @@ The PH-tree makes use of vectorization, so suggested compilation options for cla
555555
<a id="bazel"></a>
556556

557557
### Bazel
558+
<!--
559+
`WORKSPACE` file:
560+
```
561+
http_archive(
562+
name = "phtree",
563+
strip_prefix = "phtree-cpp-v1.4.0",
564+
url = "https://github.com/tzaeschke/phtree-cpp",
565+
)
566+
```
567+
`BUILD` file:
568+
```
569+
cc_binary(
570+
...
571+
deps = [
572+
"@phtree//:phtree",
573+
],
574+
)
575+
```
576+
-->
558577

559578
Once you have set up your dependencies, you should be able to build the PH-Tree repository by running:
560579
```
@@ -575,6 +594,19 @@ bazel run //benchmark:update_mm_d_benchmark --config=benchmark -- --benchmark_c
575594
<a id="cmake"></a>
576595

577596
### cmake
597+
<!--With `FetchContent_...()`: ***NOTE This will only work once v1.4.0 has been released!***
598+
```
599+
include(FetchContent)
600+
FetchContent_Declare(
601+
phtree
602+
GIT_REPOSITORY https://github.com/tzaeschke/phtree-cpp.git
603+
#GIT_TAG v1.3.0
604+
GIT_TAG 9e81dd52560b346895379586d03ff4c51508d9d4
605+
)
606+
FetchContent_MakeAvailable(phtree)
607+
```
608+
-->
609+
578610
`cmake` uses `ccache` when available.
579611
```
580612
mkdir build
@@ -597,7 +629,8 @@ cmake --build .
597629
ctest
598630
```
599631
Next to example (`PHTREE_BUILD_EXAMPLES`) there are also tests (`PHTREE_BUILD_TESTS`) and
600-
benchmarks (`PHTREE_BUILD_BENCHMARKS`). To build all, use `PHTREE_BUILD_ALL`.
632+
benchmarks (`PHTREE_BUILD_BENCHMARKS`). To build all, use `PHTREE_BUILD_ALL`.
633+
**Note that the benchmarks currently don't work on Windows.**
601634

602635
## Further Resources
603636

WORKSPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ http_archive(
2828

2929
http_archive(
3030
name = "gtest",
31-
build_file = "@third_party//gtest:BUILD",
3231
sha256 = "b4870bf121ff7795ba20d20bcdd8627b8e088f2d1dab299a031c1034eddc93d5",
3332
strip_prefix = "googletest-release-1.11.0",
3433
url = "https://github.com/google/googletest/archive/release-1.11.0.tar.gz",

0 commit comments

Comments
 (0)