Skip to content

Commit

Permalink
changed cmake, package and namespace layout (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigerl authored Jun 14, 2022
1 parent caf2f66 commit 23878ee
Show file tree
Hide file tree
Showing 25 changed files with 355 additions and 364 deletions.
21 changes: 10 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
cmake_minimum_required(VERSION 3.18)
project(dice-sparse-map
VERSION 0.1.0
VERSION 0.2.0
DESCRIPTION "C++ implementation of a memory efficient hash map and hash set based on [tsl::sparse_map](https://github.com/Tessil/sparse-map). We added support for fancy pointers.")

include(cmake/boilerplate_init.cmake)
boilerplate_init()

find_package(Boost REQUIRED)

add_library(dice-sparse-map INTERFACE)
# Use Dice::sparse_map as target, more consistent with other libraries conventions (Boost, Qt, ...)
add_library(dice-sparse-map::dice-sparse-map ALIAS dice-sparse-map)
add_library(Dice::sparse-map ALIAS dice-sparse-map)
add_library(${PROJECT_NAME} INTERFACE)
# Use dice::sparse_map as target, more consistent with other libraries conventions (Boost, Qt, ...)
add_library("${PROJECT_NAME}::${PROJECT_NAME}" ALIAS "${PROJECT_NAME}")

target_include_directories(
dice-sparse-map INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
target_include_directories(${PROJECT_NAME}
INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")

target_link_libraries(dice-sparse-map INTERFACE
target_link_libraries(${PROJECT_NAME} INTERFACE
Boost::headers
)

set_target_properties(dice-sparse-map PROPERTIES
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 20
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON)

if(MSVC)
target_sources(sparse_map INTERFACE
target_sources(${PROJECT_NAME} INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tsl-sparse-map.natvis>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_DATAROOTDIR}/tsl-sparse-map.natvis>")
endif()

if (IS_TOP_LEVEL)
include(cmake/install_interface_library.cmake)
install_interface_library(dice-sparse-map include)
install_interface_library("${PROJECT_NAME}" "${PROJECT_NAME}" "${PROJECT_NAME}" "include")
endif ()


24 changes: 0 additions & 24 deletions LICENSE → LICENSE-dice-sparse-map
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
License for the original code:

MIT License

Copyright (c) 2017 Thibaut Goetghebuer-Planchon <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

License for changes from the original code:

MIT License
Expand Down
23 changes: 23 additions & 0 deletions LICENSE-tsl-sparse-map
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
License for the original code:

MIT License

Copyright (c) 2017 Thibaut Goetghebuer-Planchon <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
62 changes: 31 additions & 31 deletions README.md

Large diffs are not rendered by default.

40 changes: 16 additions & 24 deletions cmake/install_interface_library.cmake
Original file line number Diff line number Diff line change
@@ -1,48 +1,40 @@
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

function(install_interface_library TARGET_NAME INCLUDE_PATH)
if (NOT ${ARGC} EQUAL 2)
message(
FATAL_ERROR
"you did not specify the target and the include path in the parameter!")
endif ()
function(install_interface_library TARGET_NAME NAMESPACE LIBRARY_NAME INCLUDE_PATH)

target_include_directories(
${TARGET_NAME} INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

install(TARGETS ${TARGET_NAME}
set_property(TARGET ${TARGET_NAME} PROPERTY EXPORT_NAME ${LIBRARY_NAME})

install(
TARGETS ${TARGET_NAME}
EXPORT ${TARGET_NAME}-targets
# ARCHIVE, LIBRARY and RUNTIME are provided here only for completeness. They are not really need for the interface library.
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

write_basic_package_version_file("${TARGET_NAME}-config-version.cmake"

write_basic_package_version_file(
"${TARGET_NAME}-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)

configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/lib-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
"${PROJECT_BINARY_DIR}/${TARGET_NAME}-config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
# here we have two possibilities: either CMAKE_INSTALL_DATAROOTDIR (share) or CMAKE_INSTALL_LIBDIR (lib/lib64)
# we just have to be consistent for one target

install(
EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}-targets.cmake
NAMESPACE ${PROJECT_NAME}::
EXPORT ${TARGET_NAME}-targets
FILE ${TARGET_NAME}-targets.cmake
NAMESPACE ${NAMESPACE}::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)

install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
install(FILES "${PROJECT_BINARY_DIR}/${TARGET_NAME}-config.cmake"
"${PROJECT_BINARY_DIR}/${TARGET_NAME}-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)

message("files installed: ${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_PATH}/")
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_PATH}/
DESTINATION include
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h")
install(DIRECTORY ${PROJECT_SOURCE_DIR}/${INCLUDE_PATH}/ DESTINATION include)
endfunction()
2 changes: 1 addition & 1 deletion cmake/lib-config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake")
check_required_components("@PROJECT_NAME@")
18 changes: 11 additions & 7 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class ProjectConanFile(ConanFile):

# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True, "boost:header_only": True}
exports_sources = "include/*", "CMakeLists.txt", "cmake/*"
options = {"shared": [True, False], "fPIC": [True, False]} # todo: remove when the boost dependency is not needed anymore
default_options = {"shared": False, "fPIC": True, "boost:header_only": True} # todo: remove when the boost dependency is not needed anymore
exports_sources = "include/*", "CMakeLists.txt", "cmake/*", "LICENSE*"
requires = "boost/1.69.0"

generators = ("CMakeDeps", "CMakeToolchain")
Expand All @@ -36,7 +36,7 @@ def set_version(self):
self.description = re.search(r"project\([^)]*DESCRIPTION\s+\"([^\"]+)\"[^)]*\)", cmake_file).group(1)


def config_options(self):
def config_options(self): # todo: remove when the boost dependency is not needed anymore
if self.settings.os == "Windows":
del self.options.fPIC

Expand All @@ -58,7 +58,11 @@ def build(self):

def package(self):
self._configure_cmake().install()
rmdir(os.path.join(self.package_folder, "cmake"))
for file in os.listdir(self.folders.package_folder):
if file != "include":
rmdir(os.path.join(self.package_folder, file))
self.copy(pattern="LICENSE*", dst="licenses", src=self.folders.source_folder)

def package_id(self):
self.info.header_only()

def package_info(self):
self.cpp_info.set_property("cmake_target_aliases", ["Dice::sparse-map"])
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef DICE_SPARSE_MAP_BOOST_OFFSET_POINTER_HPP
#define DICE_SPARSE_MAP_BOOST_OFFSET_POINTER_HPP

#include "Dice/sparse-map/sparse_hash.hpp" //needed, so the basic template is already included
#include "dice/sparse-map/sparse_hash.hpp" //needed, so the basic template is already included
#include <boost/interprocess/offset_ptr.hpp>

namespace Dice::sparse_map {
namespace dice::sparse_map {
/* Template specialisation for a "const_cast" of a boost offset_ptr.
* @tparam PT PointedType
* @tparam DT DifferenceType
Expand All @@ -19,6 +19,6 @@ struct Remove_Const<boost::interprocess::offset_ptr<PT, DT, OT, OA>> {
return boost::interprocess::const_pointer_cast<PT, DT, OT, OA>(const_iter);
}
};
} // namespace Dice
} // namespace dice

#endif // DICE_SPARSE_MAP_BOOST_OFFSET_POINTER_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <ratio>
#include <stdexcept>

namespace Dice::sparse_map::sh {
namespace dice::sparse_map::sh {

/**
* Grow the hash table by a factor of GrowthFactor keeping the bucket count to a
Expand Down Expand Up @@ -192,7 +192,7 @@ class mod_growth_policy {

/**
* Grow the hash table by using prime numbers as bucket count. Slower than
* Dice::sh::power_of_two_growth_policy in general but will probably distribute
* dice::sh::power_of_two_growth_policy in general but will probably distribute
* the values around better in the buckets with a poor hash function.
*
* To allow the compiler to optimize the modulo operation, a lookup table is
Expand Down Expand Up @@ -294,6 +294,6 @@ class prime_growth_policy {
unsigned int m_iprime;
};

} // namespace Dice
} // namespace dice

#endif
Loading

0 comments on commit 23878ee

Please sign in to comment.