Files
parallel-hashmap/CMakeLists.txt
T

238 lines
9.6 KiB
CMake
Raw Normal View History

#[===================================================================[
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
)
FetchContent_MakeAvailable(parallel-hashmap)
...
include_directories(${parallel-hashmap_SOURCE_DIR})
#]===================================================================]
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)
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)
## ----------------------------- options -----------------------------
option(PHMAP_INSTALL "Enable installation" ${PHMAP_MASTER_PROJECT})
2019-03-23 10:33:16 -04:00
set(PHMAP_DIR parallel_hashmap)
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
${CMAKE_CURRENT_SOURCE_DIR}/${PHMAP_DIR}/phmap_config.h
${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
${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>)
if(PHMAP_INSTALL)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/${PHMAP_DIR}/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PHMAP_DIR})
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets)
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 -------------
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})
2019-03-23 10:33:16 -04:00
2019-03-27 20:37:51 -04:00
if(MSVC)
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()
2019-03-23 10:33:16 -04:00
if (PHMAP_BUILD_TESTS)
2019-03-24 18:44:50 -04:00
if (NOT PHMAP_GTEST_LIBS)
include(cmake/DownloadGTest.cmake)
check_target(gtest)
check_target(gtest_main)
check_target(gmock)
set(PHMAP_GTEST_LIBS gmock_main)
endif()
2019-03-23 23:26:11 -04:00
2019-03-26 09:00:55 -04:00
enable_testing()
## ---------------- regular hash maps ----------------------------
phmap_cc_test(NAME container_memory SRCS "tests/container_memory_test.cc"
DEPS ${PHMAP_GTEST_LIBS})
2019-03-23 23:26:11 -04:00
phmap_cc_test(NAME hash_policy_testing SRCS "tests/hash_policy_testing_test.cc"
DEPS ${PHMAP_GTEST_LIBS})
2019-03-24 18:10:20 -04:00
phmap_cc_test(NAME node_hash_policy SRCS "tests/node_hash_policy_test.cc"
DEPS ${PHMAP_GTEST_LIBS})
2019-03-24 18:10:20 -04:00
phmap_cc_test(NAME raw_hash_set SRCS "tests/raw_hash_set_test.cc"
DEPS ${PHMAP_GTEST_LIBS})
phmap_cc_test(NAME raw_hash_set_allocator SRCS "tests/raw_hash_set_allocator_test.cc"
DEPS ${PHMAP_GTEST_LIBS})
## ---------------- regular hash maps ----------------------------
phmap_cc_test(NAME flat_hash_set SRCS "tests/flat_hash_set_test.cc"
COPTS "-DUNORDERED_SET_CXX17" DEPS ${PHMAP_GTEST_LIBS})
2019-03-24 18:10:20 -04:00
phmap_cc_test(NAME flat_hash_map SRCS "tests/flat_hash_map_test.cc"
DEPS ${PHMAP_GTEST_LIBS})
2019-03-24 18:10:20 -04:00
phmap_cc_test(NAME node_hash_map SRCS "tests/node_hash_map_test.cc"
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"
COPTS "-DUNORDERED_SET_CXX17" DEPS ${PHMAP_GTEST_LIBS})
2019-03-24 18:10:20 -04:00
## --------------- parallel hash maps -----------------------------------------------
phmap_cc_test(NAME parallel_flat_hash_map SRCS "tests/parallel_flat_hash_map_test.cc"
COPTS "-DUNORDERED_MAP_CXX17" DEPS ${PHMAP_GTEST_LIBS})
phmap_cc_test(NAME parallel_flat_hash_set SRCS "tests/parallel_flat_hash_set_test.cc"
COPTS "-DUNORDERED_SET_CXX17" DEPS ${PHMAP_GTEST_LIBS})
2019-03-25 07:58:34 -04:00
phmap_cc_test(NAME parallel_node_hash_map SRCS "tests/parallel_node_hash_map_test.cc"
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"
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"
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"
COPTS "-DUNORDERED_MAP_CXX17" DEPS ${PHMAP_GTEST_LIBS})
phmap_cc_test(NAME erase_if SRCS "tests/erase_if_test.cc"
COPTS "-DUNORDERED_MAP_CXX17" DEPS ${PHMAP_GTEST_LIBS})
## --------------- btree -----------------------------------------------
phmap_cc_test(NAME btree SRCS "tests/btree_test.cc"
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)
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>")
if (NOT CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0)
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-Wno-unknown-warning-option;-Wno-gnu-zero-variadic-macro-arguments>")
endif()
else()
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)
if (MSVC)
add_executable(ex_lazy_emplace_l examples/lazy_emplace_l.cc phmap.natvis)
endif()
add_executable(ex_serialize examples/serialize.cc phmap.natvis)
#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)
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)
add_executable(ex_btree examples/btree.cc phmap.natvis)
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
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
2024-03-31 18:34:50 -04:00
# llil4map.cc - see https://www.perlmonks.com/?node_id=11149643
# -------------------------------------------------------------
find_package(OpenMP)
find_package(Boost 1.70.0)
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)
endif()
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()