2022-09-30 22:36:59 -04:00
|
|
|
#[===================================================================[
|
|
|
|
|
parallel-hashmap library by Gregory Popovitch
|
|
|
|
|
|
|
|
|
|
CMake projects that wish to use this library may do
|
|
|
|
|
something like :
|
|
|
|
|
|
|
|
|
|
include(FetchContent)
|
|
|
|
|
FetchContent_Declare(
|
|
|
|
|
parallel-hashmap
|
|
|
|
|
GIT_REPOSITORY https://github.com/greg7mdp/parallel-hashmap.git
|
2025-01-21 10:50:42 -05:00
|
|
|
GIT_TAG v2.0.0 # adjust tag/branch/commit as needed
|
2022-09-30 22:36:59 -04:00
|
|
|
)
|
|
|
|
|
FetchContent_MakeAvailable(parallel-hashmap)
|
|
|
|
|
|
|
|
|
|
...
|
2023-01-19 16:24:50 -05:00
|
|
|
include_directories(${parallel-hashmap_SOURCE_DIR})
|
2022-09-30 22:36:59 -04:00
|
|
|
|
|
|
|
|
#]===================================================================]
|
|
|
|
|
|
2024-06-25 19:58:33 -04:00
|
|
|
cmake_minimum_required(VERSION 3.13)
|
2019-03-22 21:26:45 -04:00
|
|
|
|
2019-03-23 10:33:16 -04:00
|
|
|
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
|
|
|
|
|
|
|
|
|
include(DetectVersion)
|
|
|
|
|
|
2022-09-30 22:36:59 -04:00
|
|
|
if(NOT CMAKE_CXX_STANDARD)
|
|
|
|
|
set(CMAKE_CXX_STANDARD 11) ## compile with C++11 support
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(NOT CMAKE_CXX_STANDARD_REQUIRED)
|
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(NOT DEFINED PHMAP_MASTER_PROJECT)
|
|
|
|
|
set(PHMAP_MASTER_PROJECT OFF)
|
|
|
|
|
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
|
|
|
|
set(PHMAP_MASTER_PROJECT ON)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
2019-03-24 10:28:46 -04:00
|
|
|
|
2019-03-23 10:33:16 -04:00
|
|
|
project(phmap VERSION ${DETECTED_PHMAP_VERSION} LANGUAGES CXX)
|
|
|
|
|
|
2022-09-30 22:36:59 -04:00
|
|
|
## ----------------------------- options -----------------------------
|
|
|
|
|
option(PHMAP_INSTALL "Enable installation" ${PHMAP_MASTER_PROJECT})
|
|
|
|
|
|
|
|
|
|
|
2019-03-23 10:33:16 -04:00
|
|
|
set(PHMAP_DIR parallel_hashmap)
|
2024-06-25 19:58:33 -04:00
|
|
|
set(PHMAP_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/${PHMAP_DIR}/phmap.h
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/${PHMAP_DIR}/phmap_base.h
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/${PHMAP_DIR}/phmap_bits.h
|
2022-09-30 22:36:59 -04:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/${PHMAP_DIR}/phmap_config.h
|
2024-06-25 19:58:33 -04:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/${PHMAP_DIR}/phmap_dump.h
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/${PHMAP_DIR}/phmap_fwd_decl.h
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/${PHMAP_DIR}/phmap_utils.h
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/${PHMAP_DIR}/meminfo.h
|
2022-09-30 22:36:59 -04:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/${PHMAP_DIR}/btree.h)
|
2019-03-22 21:26:45 -04:00
|
|
|
|
2019-03-23 23:26:11 -04:00
|
|
|
include(helpers)
|
2019-03-22 21:26:45 -04:00
|
|
|
|
2019-03-23 10:33:16 -04:00
|
|
|
add_library(${PROJECT_NAME} INTERFACE)
|
2019-03-22 21:26:45 -04:00
|
|
|
|
2019-03-23 10:33:16 -04:00
|
|
|
target_sources(${PROJECT_NAME} INTERFACE ${PHMAP_HEADERS})
|
2019-03-22 21:26:45 -04:00
|
|
|
|
|
|
|
|
target_include_directories(
|
2019-03-23 10:33:16 -04:00
|
|
|
${PROJECT_NAME} INTERFACE
|
2019-03-26 08:35:11 -04:00
|
|
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
|
2019-03-23 10:33:16 -04:00
|
|
|
$<INSTALL_INTERFACE:include>)
|
|
|
|
|
|
2022-09-30 22:36:59 -04:00
|
|
|
if(PHMAP_INSTALL)
|
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
include(CMakePackageConfigHelpers)
|
2024-06-25 19:58:33 -04:00
|
|
|
|
2022-09-30 22:36:59 -04:00
|
|
|
install(
|
|
|
|
|
DIRECTORY ${PROJECT_SOURCE_DIR}/${PHMAP_DIR}/
|
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PHMAP_DIR})
|
2024-06-25 19:58:33 -04:00
|
|
|
|
2022-09-30 22:36:59 -04:00
|
|
|
install(TARGETS ${PROJECT_NAME}
|
|
|
|
|
EXPORT ${PROJECT_NAME}-targets)
|
2024-06-25 19:58:33 -04:00
|
|
|
|
2022-09-30 22:36:59 -04:00
|
|
|
export(EXPORT ${PROJECT_NAME}-targets
|
|
|
|
|
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
|
|
|
|
|
endif()
|
2019-03-23 10:33:16 -04:00
|
|
|
|
|
|
|
|
## ------------------------- building tests and examples -------------
|
2022-09-30 22:36:59 -04:00
|
|
|
option(PHMAP_BUILD_TESTS "Whether or not to build the tests" ${PHMAP_MASTER_PROJECT})
|
|
|
|
|
option(PHMAP_BUILD_EXAMPLES "Whether or not to build the examples" ${PHMAP_MASTER_PROJECT})
|
2025-10-15 22:49:31 -04:00
|
|
|
option(PHMAP_DOWNLOAD_GTEST "Whether to download gtest or use installed version" ON)
|
2019-03-23 10:33:16 -04:00
|
|
|
|
2019-03-27 20:37:51 -04:00
|
|
|
if(MSVC)
|
2024-06-25 19:58:33 -04:00
|
|
|
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/bigobj>")
|
2019-03-27 20:37:51 -04:00
|
|
|
endif()
|
|
|
|
|
|
2023-10-08 21:03:15 -04:00
|
|
|
if (PHMAP_BUILD_TESTS OR PHMAP_BUILD_EXAMPLES)
|
|
|
|
|
include_directories(${PROJECT_SOURCE_DIR})
|
|
|
|
|
endif()
|
2023-06-25 14:48:00 -04:00
|
|
|
|
2019-03-23 10:33:16 -04:00
|
|
|
if (PHMAP_BUILD_TESTS)
|
2022-09-30 22:36:59 -04:00
|
|
|
if (NOT PHMAP_GTEST_LIBS)
|
2025-10-15 22:49:31 -04:00
|
|
|
if (NOT PHMAP_DOWNLOAD_GTEST)
|
|
|
|
|
find_package(GTest CONFIG)
|
|
|
|
|
if (GTest_FOUND)
|
|
|
|
|
set(PHMAP_GTEST_LIBS GTest::gmock_main)
|
|
|
|
|
else()
|
|
|
|
|
set(PHMAP_DOWNLOAD_GTEST ON)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
if (PHMAP_DOWNLOAD_GTEST)
|
2025-10-16 06:31:01 +08:00
|
|
|
include(cmake/DownloadGTest.cmake)
|
|
|
|
|
|
|
|
|
|
check_target(gtest)
|
|
|
|
|
check_target(gtest_main)
|
|
|
|
|
check_target(gmock)
|
|
|
|
|
set(PHMAP_GTEST_LIBS gmock_main)
|
|
|
|
|
endif()
|
2022-09-30 22:36:59 -04:00
|
|
|
endif()
|
2019-03-23 23:26:11 -04:00
|
|
|
|
2019-03-26 09:00:55 -04:00
|
|
|
enable_testing()
|
|
|
|
|
|
2019-03-25 21:18:16 -04:00
|
|
|
## ---------------- regular hash maps ----------------------------
|
|
|
|
|
phmap_cc_test(NAME container_memory SRCS "tests/container_memory_test.cc"
|
2022-09-30 22:36:59 -04:00
|
|
|
DEPS ${PHMAP_GTEST_LIBS})
|
2019-03-23 23:26:11 -04:00
|
|
|
|
2019-03-25 21:18:16 -04:00
|
|
|
phmap_cc_test(NAME hash_policy_testing SRCS "tests/hash_policy_testing_test.cc"
|
2022-09-30 22:36:59 -04:00
|
|
|
DEPS ${PHMAP_GTEST_LIBS})
|
2019-03-24 18:10:20 -04:00
|
|
|
|
2019-03-25 21:18:16 -04:00
|
|
|
phmap_cc_test(NAME node_hash_policy SRCS "tests/node_hash_policy_test.cc"
|
2022-09-30 22:36:59 -04:00
|
|
|
DEPS ${PHMAP_GTEST_LIBS})
|
2019-03-24 18:10:20 -04:00
|
|
|
|
2019-03-25 21:18:16 -04:00
|
|
|
phmap_cc_test(NAME raw_hash_set SRCS "tests/raw_hash_set_test.cc"
|
2022-09-30 22:36:59 -04:00
|
|
|
DEPS ${PHMAP_GTEST_LIBS})
|
2019-03-25 21:18:16 -04:00
|
|
|
|
|
|
|
|
phmap_cc_test(NAME raw_hash_set_allocator SRCS "tests/raw_hash_set_allocator_test.cc"
|
2022-09-30 22:36:59 -04:00
|
|
|
DEPS ${PHMAP_GTEST_LIBS})
|
2019-03-25 21:18:16 -04:00
|
|
|
|
|
|
|
|
## ---------------- regular hash maps ----------------------------
|
|
|
|
|
phmap_cc_test(NAME flat_hash_set SRCS "tests/flat_hash_set_test.cc"
|
2022-09-30 22:36:59 -04:00
|
|
|
COPTS "-DUNORDERED_SET_CXX17" DEPS ${PHMAP_GTEST_LIBS})
|
2019-03-24 18:10:20 -04:00
|
|
|
|
2019-03-25 21:18:16 -04:00
|
|
|
phmap_cc_test(NAME flat_hash_map SRCS "tests/flat_hash_map_test.cc"
|
2022-09-30 22:36:59 -04:00
|
|
|
DEPS ${PHMAP_GTEST_LIBS})
|
2019-03-25 21:18:16 -04:00
|
|
|
|
2019-03-24 18:10:20 -04:00
|
|
|
phmap_cc_test(NAME node_hash_map SRCS "tests/node_hash_map_test.cc"
|
2022-09-30 22:36:59 -04:00
|
|
|
DEPS ${PHMAP_GTEST_LIBS})
|
2019-03-24 18:10:20 -04:00
|
|
|
|
|
|
|
|
phmap_cc_test(NAME node_hash_set SRCS "tests/node_hash_set_test.cc"
|
2022-09-30 22:36:59 -04:00
|
|
|
COPTS "-DUNORDERED_SET_CXX17" DEPS ${PHMAP_GTEST_LIBS})
|
2019-03-24 18:10:20 -04:00
|
|
|
|
2019-03-25 21:18:16 -04:00
|
|
|
## --------------- parallel hash maps -----------------------------------------------
|
|
|
|
|
phmap_cc_test(NAME parallel_flat_hash_map SRCS "tests/parallel_flat_hash_map_test.cc"
|
2022-09-30 22:36:59 -04:00
|
|
|
COPTS "-DUNORDERED_MAP_CXX17" DEPS ${PHMAP_GTEST_LIBS})
|
2019-03-25 21:18:16 -04:00
|
|
|
|
|
|
|
|
phmap_cc_test(NAME parallel_flat_hash_set SRCS "tests/parallel_flat_hash_set_test.cc"
|
2022-09-30 22:36:59 -04:00
|
|
|
COPTS "-DUNORDERED_SET_CXX17" DEPS ${PHMAP_GTEST_LIBS})
|
2019-03-25 21:18:16 -04:00
|
|
|
|
2019-03-25 07:58:34 -04:00
|
|
|
phmap_cc_test(NAME parallel_node_hash_map SRCS "tests/parallel_node_hash_map_test.cc"
|
2022-09-30 22:36:59 -04:00
|
|
|
DEPS ${PHMAP_GTEST_LIBS})
|
2019-03-25 07:58:34 -04:00
|
|
|
|
|
|
|
|
phmap_cc_test(NAME parallel_node_hash_set SRCS "tests/parallel_node_hash_set_test.cc"
|
2022-09-30 22:36:59 -04:00
|
|
|
COPTS "-DUNORDERED_SET_CXX17" DEPS ${PHMAP_GTEST_LIBS})
|
2019-03-25 07:58:34 -04:00
|
|
|
|
2019-04-07 09:19:04 -04:00
|
|
|
phmap_cc_test(NAME parallel_flat_hash_map_mutex SRCS "tests/parallel_flat_hash_map_mutex_test.cc"
|
2022-09-30 22:36:59 -04:00
|
|
|
COPTS "-DUNORDERED_MAP_CXX17" DEPS ${PHMAP_GTEST_LIBS})
|
2019-04-07 09:19:04 -04:00
|
|
|
|
2019-08-18 22:50:47 +08:00
|
|
|
phmap_cc_test(NAME dump_load SRCS "tests/dump_load_test.cc"
|
2022-09-30 22:36:59 -04:00
|
|
|
COPTS "-DUNORDERED_MAP_CXX17" DEPS ${PHMAP_GTEST_LIBS})
|
2019-12-30 13:42:48 -05:00
|
|
|
|
2022-05-07 10:12:35 -04:00
|
|
|
phmap_cc_test(NAME erase_if SRCS "tests/erase_if_test.cc"
|
2022-09-30 22:36:59 -04:00
|
|
|
COPTS "-DUNORDERED_MAP_CXX17" DEPS ${PHMAP_GTEST_LIBS})
|
2022-05-07 10:12:35 -04:00
|
|
|
|
2019-12-30 13:42:48 -05:00
|
|
|
## --------------- btree -----------------------------------------------
|
|
|
|
|
phmap_cc_test(NAME btree SRCS "tests/btree_test.cc"
|
2022-09-30 22:36:59 -04:00
|
|
|
DEPS ${PHMAP_GTEST_LIBS})
|
2019-08-18 22:50:47 +08:00
|
|
|
|
|
|
|
|
|
2019-03-23 10:33:16 -04:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if (PHMAP_BUILD_EXAMPLES)
|
2019-04-18 21:59:12 -04:00
|
|
|
if(NOT MSVC)
|
2024-06-25 19:58:33 -04:00
|
|
|
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-pedantic;-Wall;-Wextra;-Wcast-align;-Wcast-qual;-Wdisabled-optimization;-Winit-self;-Wlogical-op;-Wmissing-include-dirs;-Woverloaded-virtual;-Wredundant-decls;-Wshadow;-Wstrict-null-sentinel;-Wswitch-default;-Wno-unused>")
|
2023-06-25 14:48:00 -04:00
|
|
|
if (NOT CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0)
|
2024-06-25 19:58:33 -04:00
|
|
|
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-Wno-unknown-warning-option;-Wno-gnu-zero-variadic-macro-arguments>")
|
2023-06-25 14:48:00 -04:00
|
|
|
endif()
|
2019-12-31 14:21:24 -05:00
|
|
|
else()
|
2024-06-25 19:58:33 -04:00
|
|
|
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/W4;/Zc:__cplusplus>")
|
2019-04-18 21:59:12 -04:00
|
|
|
endif()
|
|
|
|
|
|
2019-04-07 21:44:55 -04:00
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
|
|
2019-06-15 19:50:43 -04:00
|
|
|
add_executable(ex_allmaps examples/allmaps.cc phmap.natvis)
|
|
|
|
|
add_executable(ex_basic examples/basic.cc phmap.natvis)
|
|
|
|
|
add_executable(ex_bench examples/bench.cc phmap.natvis)
|
|
|
|
|
add_executable(ex_emplace examples/emplace.cc phmap.natvis)
|
2022-06-20 19:54:26 -04:00
|
|
|
if (MSVC)
|
|
|
|
|
add_executable(ex_lazy_emplace_l examples/lazy_emplace_l.cc phmap.natvis)
|
|
|
|
|
endif()
|
2019-09-08 11:12:12 -04:00
|
|
|
add_executable(ex_serialize examples/serialize.cc phmap.natvis)
|
2023-06-11 10:02:00 -04:00
|
|
|
#target_include_directories(ex_serialize PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../cereal/include>)
|
2019-06-15 19:50:43 -04:00
|
|
|
add_executable(ex_hash_std examples/hash_std.cc phmap.natvis)
|
|
|
|
|
add_executable(ex_hash_value examples/hash_value.cc phmap.natvis)
|
2022-07-19 20:32:09 -04:00
|
|
|
add_executable(ex_hash examples/hash.cc phmap.natvis)
|
2019-06-15 19:50:43 -04:00
|
|
|
add_executable(ex_two_files examples/f1.cc examples/f2.cc phmap.natvis)
|
|
|
|
|
add_executable(ex_insert_bench examples/insert_bench.cc phmap.natvis)
|
|
|
|
|
add_executable(ex_knucleotide examples/knucleotide.cc phmap.natvis)
|
2019-08-13 22:42:37 +08:00
|
|
|
add_executable(ex_dump_load examples/dump_load.cc phmap.natvis)
|
2019-12-30 13:42:48 -05:00
|
|
|
add_executable(ex_btree examples/btree.cc phmap.natvis)
|
2023-06-25 21:36:38 -04:00
|
|
|
add_executable(ex_hash_bench examples/hash_bench.cc phmap.natvis)
|
2020-07-26 17:35:55 -04:00
|
|
|
add_executable(ex_matt examples/matt.cc phmap.natvis)
|
2023-04-09 18:48:26 -04:00
|
|
|
add_executable(ex_mt_word_counter examples/mt_word_counter.cc phmap.natvis)
|
2023-10-08 20:00:32 -04:00
|
|
|
add_executable(ex_p_bench examples/p_bench.cc phmap.natvis)
|
2019-08-13 22:42:37 +08:00
|
|
|
|
2024-03-31 18:34:50 -04:00
|
|
|
#set(Boost_INCLUDE_DIR /home/greg/dev/boost_1_82_0) # if boost installed in non-standard location
|
2024-06-25 19:58:33 -04:00
|
|
|
set(Boost_USE_STATIC_LIBS OFF)
|
|
|
|
|
set(Boost_USE_MULTITHREADED ON)
|
2024-03-31 18:03:39 -04:00
|
|
|
set(Boost_USE_STATIC_RUNTIME OFF)
|
|
|
|
|
|
2024-03-31 18:34:50 -04:00
|
|
|
# llil4map.cc - see https://www.perlmonks.com/?node_id=11149643
|
2024-03-31 18:03:39 -04:00
|
|
|
# -------------------------------------------------------------
|
2025-10-15 22:49:31 -04:00
|
|
|
if(POLICY CMP0167)
|
|
|
|
|
cmake_policy(SET CMP0167 NEW)
|
|
|
|
|
endif()
|
|
|
|
|
find_package(OpenMP QUIET)
|
|
|
|
|
find_package(Boost 1.70.0 QUIET)
|
2024-11-02 17:48:08 -04:00
|
|
|
if (OpenMP_FOUND AND Boost_FOUND AND "cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
|
2024-03-31 18:34:50 -04:00
|
|
|
add_executable(ex_llil4map examples/llil4map.cc phmap.natvis)
|
|
|
|
|
target_include_directories(ex_llil4map PRIVATE ${Boost_INCLUDE_DIRS})
|
|
|
|
|
target_compile_features(ex_llil4map PUBLIC cxx_std_20)
|
2024-05-26 03:54:24 +02:00
|
|
|
find_package(TBB COMPONENTS tbb)
|
|
|
|
|
if (TBB_FOUND)
|
|
|
|
|
target_link_libraries(ex_llil4map PRIVATE TBB::tbb)
|
|
|
|
|
endif()
|
2024-03-31 18:34:50 -04:00
|
|
|
target_link_libraries(ex_llil4map PRIVATE OpenMP::OpenMP_CXX)
|
|
|
|
|
target_compile_options(ex_llil4map PRIVATE "${OpenMP_CXX_FLAGS}")
|
2024-04-07 18:07:18 -04:00
|
|
|
|
2024-11-02 17:48:08 -04:00
|
|
|
file(COPY examples/llil_utils DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if (Boost_FOUND)
|
|
|
|
|
add_executable(ex_custom_pointer examples/custom_pointer.cc phmap.natvis)
|
|
|
|
|
target_include_directories(ex_custom_pointer PRIVATE ${Boost_INCLUDE_DIRS})
|
|
|
|
|
|
2024-04-07 18:07:18 -04:00
|
|
|
add_executable(ex_llil examples/llil.cc phmap.natvis)
|
|
|
|
|
target_include_directories(ex_llil PRIVATE ${Boost_INCLUDE_DIRS})
|
|
|
|
|
target_compile_features(ex_llil PUBLIC cxx_std_20)
|
2024-11-02 17:48:08 -04:00
|
|
|
target_link_libraries(ex_llil Threads::Threads)
|
2024-03-31 18:03:39 -04:00
|
|
|
endif()
|
2024-06-25 19:58:33 -04:00
|
|
|
|
2019-04-07 21:44:55 -04:00
|
|
|
target_link_libraries(ex_knucleotide Threads::Threads)
|
2019-04-11 19:02:35 -04:00
|
|
|
target_link_libraries(ex_bench Threads::Threads)
|
2019-03-23 10:33:16 -04:00
|
|
|
endif()
|