Skip to content

Commit 0935cfe

Browse files
authored
cmake full build and VS 19 (#71)
1 parent 91b99f4 commit 0935cfe

22 files changed

Lines changed: 413 additions & 112 deletions

.bazelignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ignore typical cmake build folders
2+
build
3+
out
4+
cmake-build-debug

.github/workflows/cmake-windows.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
- name: Configure CMake
2121
working-directory: ${{github.workspace}}\out
22-
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -S ${{github.workspace}} -B ${{github.workspace}}\out
22+
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -S ${{github.workspace}} -B ${{github.workspace}}\out -DPHTREE_BUILD_EXAMPLES=ON -DPHTREE_BUILD_TESTS=ON
2323

2424
- name: Build
2525
working-directory: ${{github.workspace}}\out
@@ -30,5 +30,4 @@ jobs:
3030
working-directory: ${{github.workspace}}\out
3131
# Execute tests defined by the CMake configuration.
3232
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
33-
# TODO Currently tests are run via bazel only.
3433
run: ctest -C ${env:BUILD_TYPE}

.github/workflows/cmake.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
# Note the current convention is to use the -S and -B options here to specify source
2424
# and build directories, but this is only available with CMake 3.13 and higher.
2525
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
26-
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
26+
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DPHTREE_BUILD_ALL=ON
2727

2828
- name: Build
2929
working-directory: ${{github.workspace}}/build
@@ -38,3 +38,8 @@ jobs:
3838
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
3939
# TODO Currently tests are run via bazel only.
4040
run: ctest -C $BUILD_TYPE
41+
42+
- name: Example
43+
working-directory: ${{github.workspace}}/build
44+
shell: bash
45+
run: examples/Example

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ bazel-*
1010
compile_commands.json
1111
perf.data*
1212
build
13+
out
14+
CMakeSettings.json
1315

1416
/cmake-build-debug/

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4040
and function signatures than normal `PhTree` filters. [#26](https://github.com/tzaeschke/phtree-cpp/issues/26)
4141

4242
### Fixed
43+
- Fixed cmake to work with Visual Studio 2019. Added tests and benchmarks to cmake.
44+
(benchmarks still do not work with VS at the moment).
45+
[#62](https://github.com/tzaeschke/phtree-cpp/issues/62)
4346
- Fixed two compilation problems and a memory leak when compiling with Visual Studio 2019.
4447
(also added `msan` support). [#64](https://github.com/tzaeschke/phtree-cpp/pull/64)
4548

CMakeLists.txt

Lines changed: 98 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,110 @@
11
cmake_minimum_required(VERSION 3.14)
22

33
# set the project name
4-
project(PH_Tree_Main VERSION 1.2.0
4+
project(phtree VERSION 1.2.0
55
DESCRIPTION "PH-Tree C++"
66
LANGUAGES CXX)
77

8-
if(NOT CMAKE_BUILD_TYPE)
9-
set(CMAKE_BUILD_TYPE Release)
10-
endif()
8+
# ---------------------------------------------------------------------------------------
9+
# Set default build to release
10+
# ---------------------------------------------------------------------------------------
11+
if (NOT CMAKE_BUILD_TYPE)
12+
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
13+
endif ()
14+
15+
# ---------------------------------------------------------------------------------------
16+
# Build options
17+
# ---------------------------------------------------------------------------------------
18+
# example options
19+
option(PHTREE_BUILD_ALL "Build examples, tests and benchmarks" OFF)
20+
21+
# example options
22+
option(PHTREE_BUILD_EXAMPLES "Build examples" OFF)
23+
#option(PHTREE_BUILD_EXAMPLE_HO "Build header only example" OFF)
24+
25+
# testing options
26+
option(PHTREE_BUILD_TESTS "Build tests" OFF)
27+
#option(PHTREE_BUILD_TESTS_HO "Build tests using the header only version" OFF)
28+
29+
# bench options
30+
option(PHTREE_BUILD_BENCHMARKS "Build benchmarks (Requires https://github.com/google/benchmark.git to be installed)" OFF)
31+
32+
# ---------------------------------------------------------------------------------------
33+
# Compiler config
34+
# ---------------------------------------------------------------------------------------
35+
find_program(CCACHE_FOUND ccache)
36+
if(CCACHE_FOUND)
37+
message("CCACHE is found")
38+
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
39+
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
40+
else(CCACHE_FOUND)
41+
message("CCACHE is NOT found")
42+
endif(CCACHE_FOUND)
1143

1244
# specify the C++ standard
13-
set(CMAKE_CXX_STANDARD 17)
14-
set(CMAKE_CXX_STANDARD_REQUIRED True)
15-
if(WIN32)
16-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /Wall")
45+
if (NOT CMAKE_CXX_STANDARD)
46+
set(CMAKE_CXX_STANDARD 17)
47+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
48+
endif ()
49+
50+
if (MSVC)
51+
#set(CMAKE_CXX_FLAGS_RELEASE "/MT")
52+
#set(CMAKE_CXX_FLAGS_DEBUG "/MTd")
53+
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /Wall")
54+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
1755
set(CMAKE_CXX_FLAGS_RELEASE "/O2")
18-
else()
56+
57+
# set(CMAKE_CXX_FLAGS "-DNOMINMAX ${CMAKE_CXX_FLAGS}") # exclude M$ min/max macros
58+
# set(CMAKE_CXX_FLAGS "/wd4996 ${CMAKE_CXX_FLAGS}") # don't warn about use of plain C functions without (non-portable) "_s" suffix
59+
# set(CMAKE_EXE_LINKER_FLAGS "/WX:NO ${CMAKE_EXE_LINKER_FLAGS}" ) # don't treat warnings as compile errors--gtest doesn't build
60+
# #set(CMAKE_CXX_FLAGS_DEBUG "/analyze ${CMAKE_CXX_FLAGS_DEBUG}")
61+
else ()
1962
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Werror")
20-
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
21-
endif()
63+
if (PHTREE_BUILD_BENCHMARKS)
64+
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -mavx -pthread")
65+
else ()
66+
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -mavx")
67+
endif ()
68+
endif ()
2269

70+
# ---------------------------------------------------------------------------------------
71+
# Build binaries
72+
# ---------------------------------------------------------------------------------------
2373
add_subdirectory(phtree)
24-
add_subdirectory(examples)
74+
75+
if (PHTREE_BUILD_EXAMPLES OR PHTREE_BUILD_ALL)
76+
message(STATUS "Generating examples")
77+
add_subdirectory(examples)
78+
endif ()
79+
80+
if (PHTREE_BUILD_BENCHMARKS OR PHTREE_BUILD_ALL)
81+
message(STATUS "Generating benchmarks")
82+
add_subdirectory(benchmark)
83+
endif ()
84+
85+
if (PHTREE_BUILD_TESTS OR PHTREE_BUILD_ALL)
86+
message(STATUS "Generating tests")
87+
if (FALSE)
88+
add_compile_definitions(GTEST_HAS_ABSL=0)
89+
add_compile_definitions(GTEST_OS_WINDOWS_MOBILE=0)
90+
if (MSVC)
91+
add_compile_definitions(GTEST_OS_WINDOWS_MINGW=0)
92+
endif ()
93+
add_compile_definitions(GTEST_OS_LINUX_ANDROID=0)
94+
if (LINUX)
95+
add_compile_definitions(GTEST_OS_LINUX=1)
96+
else ()
97+
add_compile_definitions(GTEST_OS_LINUX=0)
98+
endif ()
99+
add_compile_definitions(
100+
GTEST_OS_WINDOWS_MOBILE=0
101+
GTEST_OS_WINDOWS_PHONE=0
102+
GTEST_OS_WINDOWS_RT=0
103+
GTEST_OS_ESP8266=0
104+
GTEST_OS_XTENSA=0)
105+
endif ()
106+
107+
enable_testing()
108+
include(GoogleTest)
109+
add_subdirectory(test)
110+
endif ()

README.md

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -538,67 +538,72 @@ There are numerous ways to improve performance. The following list gives an over
538538

539539
## Compiling the PH-Tree
540540

541-
This section will guide you through the initial build system and IDE you need to go through in order to build and run
542-
custom versions of the PH-Tree on your machine.
541+
The PH-Tree index itself is a *header only* library, it can be used by simply copying all headers in the `phtree`
542+
folder.
543+
The examples, tests and benchmarks can be build with bazel or cmake.
543544

544545
<a id="build-system-and-dependencies"></a>
545546

546547
### Build system & dependencies
547548

548-
PH-Tree can be built with *cmake 3.14* or [Bazel](https://bazel.build) as build system. All code is written in C++
549-
targeting the C++17 standard. The code has been verified to compile on Linux with Clang 9, 10, 11, 12, and GCC 9, 10,
550-
11, and on Windows with Visual Studio 2019.
551-
552-
#### Ubuntu Linux
553-
554-
* Installing [clang](https://apt.llvm.org/)
555-
556-
* Installing [bazel](https://docs.bazel.build/versions/main/install-ubuntu.html)
557-
558-
* To install [cmake](https://launchpad.net/~hnakamur/+archive/ubuntu/cmake):
559-
549+
PH-Tree can be built with [Bazel](https://bazel.build) (primary build system) or with
550+
[cmake](https://cmake.org/) *3.14*.
551+
All code is written in C++ targeting the C++17 standard.
552+
The code has been verified to compile on Linux with Clang 11 and GCC 9, and on Windows with Visual Studio 2019
553+
(except benchmarks, which don't work wi VS).
554+
The PH-tree makes use of vectorization, so suggested compilation options for clang/gcc are:
560555
```
561-
sudo add-apt-repository ppa:hnakamur/libarchive
562-
sudo add-apt-repository ppa:hnakamur/libzstd
563-
sudo add-apt-repository ppa:hnakamur/cmake
564-
sudo apt update
565-
sudo apt install cmake
556+
-O3 -mavx
566557
```
567558

568-
#### Windows
569-
570-
To build on Windows, you'll need to have a version of Visual Studio 2019 installed (likely Professional), in addition to
571-
[Bazel](https://docs.bazel.build/versions/master/windows.html) or
572-
[cmake](https://cmake.org/download/).
573559

574560
<a id="bazel"></a>
575561

576562
### Bazel
577563

578564
Once you have set up your dependencies, you should be able to build the PH-Tree repository by running:
579-
580565
```
581566
bazel build ...
582567
```
583568

584569
Similarly, you can run all unit tests with:
585-
586570
```
587571
bazel test ...
588572
```
589573

574+
Benchmarks:
575+
```
576+
bazel run //benchmark:update_mm_d_benchmark --config=benchmark -- --benchmark_counters_tabular=true
577+
```
578+
579+
590580
<a id="cmake"></a>
591581

592582
### cmake
593-
583+
`cmake` uses `ccache` when available.
594584
```
595585
mkdir build
596586
cd build
597587
cmake ..
598588
cmake --build .
589+
```
590+
591+
Run example:
592+
```
593+
cmake .. -DPHTREE_BUILD_EXAMPLES=ON
594+
cmake --build .
599595
./example/Example
600596
```
601597

598+
Run tests:
599+
```
600+
cmake .. -DPHTREE_BUILD_TESTS=ON
601+
cmake --build .
602+
ctest
603+
```
604+
Next to example (`PHTREE_BUILD_EXAMPLES`) there are also tests (`PHTREE_BUILD_TESTS`) and
605+
benchmarks (`PHTREE_BUILD_BENCHMARKS`). To build all, use `PHTREE_BUILD_ALL`.
606+
602607
## Further Resources
603608

604609
<a id="theory"></a>

benchmark/BUILD

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ package(default_visibility = ["//visibility:private"])
33
cc_library(
44
name = "benchmark",
55
testonly = True,
6-
srcs = [
7-
"logging.cc",
8-
],
96
hdrs = [
107
"benchmark_util.h",
118
"logging.h",

benchmark/CMakeLists.txt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(phtree-benchmarks)
3+
4+
set(BENCHMARK_ENABLE_TESTING OFF)
5+
6+
include(FetchContent)
7+
8+
FetchContent_Declare(
9+
googlebenchmark
10+
GIT_REPOSITORY https://github.com/google/benchmark.git
11+
GIT_TAG v1.7.0
12+
)
13+
FetchContent_MakeAvailable(googlebenchmark)
14+
15+
FetchContent_Declare(
16+
spdlog
17+
GIT_REPOSITORY https://github.com/gabime/spdlog.git
18+
GIT_TAG v1.10.0
19+
)
20+
FetchContent_MakeAvailable(spdlog)
21+
22+
set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/phtree)
23+
set(INCLUDE_FILES ${INCLUDE_DIR}/phtree.h ${INCLUDE_DIR}/phtree_multimap.h benchmark_util.h logging.h)
24+
25+
macro(package_add_benchmark TESTNAME)
26+
add_executable(${TESTNAME} ${ARGN} ${INCLUDE_FILES})
27+
target_link_libraries(${TESTNAME} PRIVATE benchmark::benchmark)
28+
target_link_libraries(${TESTNAME} PRIVATE spdlog::spdlog)
29+
target_include_directories(${TESTNAME} PRIVATE ${PROJECT_SOURCE_DIR}/..)
30+
endmacro()
31+
32+
add_compile_definitions(RUN_HAVE_STD_REGEX=0 RUN_HAVE_POSIX_REGEX=0 COMPILE_HAVE_GNU_POSIX_REGEX=0)
33+
34+
package_add_benchmark(count_mm_d_benchmark count_mm_d_benchmark.cc)
35+
package_add_benchmark(erase_benchmark erase_benchmark.cc)
36+
package_add_benchmark(erase_d_benchmark erase_d_benchmark.cc)
37+
package_add_benchmark(extent_benchmark extent_benchmark.cc)
38+
package_add_benchmark(extent_benchmark_weird extent_benchmark_weird.cc)
39+
package_add_benchmark(find_benchmark find_benchmark.cc)
40+
package_add_benchmark(hd_erase_d_benchmark hd_erase_d_benchmark.cc)
41+
package_add_benchmark(hd_insert_d_benchmark hd_insert_d_benchmark.cc)
42+
package_add_benchmark(hd_knn_d_benchmark hd_knn_d_benchmark.cc)
43+
package_add_benchmark(hd_query_d_benchmark hd_query_d_benchmark.cc)
44+
package_add_benchmark(insert_benchmark insert_benchmark.cc)
45+
package_add_benchmark(insert_box_d_benchmark insert_box_d_benchmark.cc)
46+
package_add_benchmark(insert_d_benchmark insert_d_benchmark.cc)
47+
package_add_benchmark(knn_d_benchmark knn_d_benchmark.cc)
48+
package_add_benchmark(query_benchmark query_benchmark.cc)
49+
package_add_benchmark(query_box_d_benchmark query_box_d_benchmark.cc)
50+
package_add_benchmark(query_d_benchmark query_d_benchmark.cc)
51+
package_add_benchmark(query_mm_box_d_benchmark query_mm_box_d_benchmark.cc)
52+
package_add_benchmark(query_mm_d_benchmark query_mm_d_benchmark.cc)
53+
package_add_benchmark(query_mm_d_filter_benchmark query_mm_d_filter_benchmark.cc)
54+
package_add_benchmark(update_box_d_benchmark update_box_d_benchmark.cc)
55+
package_add_benchmark(update_d_benchmark update_d_benchmark.cc)
56+
package_add_benchmark(update_mm_box_d_benchmark update_mm_box_d_benchmark.cc)
57+
package_add_benchmark(update_mm_d_benchmark update_mm_d_benchmark.cc)

benchmark/logging.cc

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)