Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 93 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ project(
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()

message(VERBOSE "*")
message(VERBOSE "* ${PROJECT_NAME} v${PROJECT_VERSION} (${CMAKE_BUILD_TYPE})")
message(VERBOSE "* Copyright (c) 2017-2025 Michele Caini <[email protected]>")
Expand All @@ -37,6 +37,13 @@ list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
option(ENTT_USE_LIBCPP "Use libc++ by adding -stdlib=libc++ flag if available." OFF)
option(ENTT_USE_SANITIZER "Enable sanitizers by adding -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined flags if available." OFF)
option(ENTT_USE_CLANG_TIDY "Enable static analysis with clang-tidy" OFF)
option(ENTT_MODULE "Build EnTT module instead of a regular header-only library." OFF)

set(ENTT_USER_CONFIG "" CACHE FILEPATH "Path to a file containing user EnTT configuration.")

if (NOT ENTT_MODULE AND ENTT_USER_CONFIG)
message(FATAL_ERROR "The option ENTT_USER_CONFIG can be used only when ENTT_MODULE is ON")
endif()

if(ENTT_USE_LIBCPP)
if(NOT WIN32)
Expand Down Expand Up @@ -83,25 +90,56 @@ endif()

include(GNUInstallDirs)

add_library(EnTT INTERFACE)
if (ENTT_MODULE)
if (CMAKE_VERSION VERSION_LESS 3.28)
message(FATAL_ERROR "CMake >= 3.28 is required to build EnTT as a module")
endif()

set(ENTT_LIBRARY_TYPE STATIC)
set(ENTT_SCOPE PUBLIC)
set(ENTT_CXX_STD cxx_std_20)
else()
set(ENTT_LIBRARY_TYPE INTERFACE)
set(ENTT_SCOPE INTERFACE)
set(ENTT_CXX_STD cxx_std_17)
endif()

add_library(EnTT ${ENTT_LIBRARY_TYPE})
add_library(EnTT::EnTT ALIAS EnTT)

target_include_directories(
EnTT
INTERFACE
${ENTT_SCOPE}
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

target_compile_features(EnTT INTERFACE cxx_std_17)
target_compile_features(EnTT ${ENTT_SCOPE} ${ENTT_CXX_STD})

if(ENTT_HAS_LIBCPP)
target_compile_options(EnTT BEFORE INTERFACE -stdlib=libc++)
target_compile_options(EnTT BEFORE ${ENTT_SCOPE} -stdlib=libc++)
if(ENTT_MODULE)
target_link_options(EnTT ${ENTT_SCOPE} -stdlib=libc++)
endif()
endif()

if(ENTT_HAS_SANITIZER)
target_compile_options(EnTT INTERFACE $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined>)
target_link_libraries(EnTT INTERFACE $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined>)
target_compile_options(EnTT ${ENTT_SCOPE} $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined>)
target_link_options(EnTT ${ENTT_SCOPE} $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined>)
endif()

if (ENTT_USER_CONFIG)
target_compile_definitions(EnTT ${ENTT_SCOPE} ENTT_USER_CONFIG=\"${ENTT_USER_CONFIG}\")
endif()

if (ENTT_MODULE)
target_sources(EnTT
PUBLIC
FILE_SET cxx_modules TYPE CXX_MODULES
BASE_DIRS ${EnTT_SOURCE_DIR}/src/entt
FILES
${EnTT_SOURCE_DIR}/src/entt/entt.ixx
)
endif()

if(ENTT_CLANG_TIDY_EXECUTABLE)
Expand Down Expand Up @@ -268,11 +306,22 @@ if(ENTT_INSTALL)

include(CMakePackageConfigHelpers)

install(
TARGETS EnTT
EXPORT EnTTTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
if(ENTT_MODULE)
install(
TARGETS EnTT
EXPORT EnTTTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILE_SET cxx_modules DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/entt
)
else()
install(
TARGETS EnTT
EXPORT EnTTTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()

write_basic_package_version_file(
EnTTConfigVersion.cmake
Expand All @@ -286,18 +335,37 @@ if(ENTT_INSTALL)
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake
)

export(
EXPORT EnTTTargets
FILE ${CMAKE_CURRENT_BINARY_DIR}/EnTTTargets.cmake
NAMESPACE EnTT::
)
if(ENTT_MODULE)
export(
TARGETS EnTT
FILE "${CMAKE_CURRENT_BINARY_DIR}/EnTTTargets.cmake"
NAMESPACE EnTT::
CXX_MODULES_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/cxx-modules"
)
else()
export(
TARGETS EnTT
FILE "${CMAKE_CURRENT_BINARY_DIR}/EnTTTargets.cmake"
NAMESPACE EnTT::
)
endif()

install(
EXPORT EnTTTargets
FILE EnTTTargets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake
NAMESPACE EnTT::
)
if(ENTT_MODULE)
install(
EXPORT EnTTTargets
FILE EnTTTargets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake
NAMESPACE EnTT::
CXX_MODULES_DIRECTORY ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake/cxx-modules
)
else()
install(
EXPORT EnTTTargets
FILE EnTTTargets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/EnTT/cmake
NAMESPACE EnTT::
)
endif()

install(
FILES
Expand Down Expand Up @@ -330,12 +398,12 @@ if(ENTT_BUILD_TESTING OR ENTT_BUILD_TESTBED)
# Tests and tesetbed do not work together because SDL gets confused with EnTT tests
if(ENTT_BUILD_TESTING)
option(ENTT_FIND_GTEST_PACKAGE "Enable finding gtest package." OFF)

option(ENTT_BUILD_BENCHMARK "Build benchmark." OFF)
option(ENTT_BUILD_EXAMPLE "Build examples." OFF)
option(ENTT_BUILD_LIB "Build lib tests." OFF)
option(ENTT_BUILD_SNAPSHOT "Build snapshot test with Cereal." OFF)

include(CTest)
enable_testing()
add_subdirectory(test)
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ mind.

```cpp
#include <entt/entt.hpp>
// or import entt;
// See Integration > CMake for details.

struct position {
float x;
Expand Down Expand Up @@ -246,6 +248,9 @@ using `EnTT` as a submodule without conflicting with user logic.<br/>
It is therefore necessary to set the option to true to take advantage of the
installation logic provided by this library.

Note that `EnTT` can be consumed also as a C++ module. To enable module support,
the `ENTT_MODULE` option has to be set to `ON` in `CMake`.

## Natvis support

When using `CMake`, just enable the option `ENTT_INCLUDE_NATVIS` and enjoy
Expand Down
16 changes: 16 additions & 0 deletions src/entt/config/module.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef ENTT_MODULE_H
#define ENTT_MODULE_H

#ifndef ENTT_MODULE_EXPORT
# define ENTT_MODULE_EXPORT
#endif // ENTT_MODULE_EXPORT

#ifndef ENTT_MODULE_EXPORT_BEGIN
# define ENTT_MODULE_EXPORT_BEGIN
#endif // ENTT_MODULE_EXPORT_BEGIN

#ifndef ENTT_MODULE_EXPORT_END
# define ENTT_MODULE_EXPORT_END
#endif // ENTT_MODULE_EXPORT_END

#endif // ENTT_MODULE_H
54 changes: 35 additions & 19 deletions src/entt/container/dense_map.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
#ifndef ENTT_CONTAINER_DENSE_MAP_HPP
#define ENTT_CONTAINER_DENSE_MAP_HPP

#include <cmath>
#include <cstddef>
#include <functional>
#include <iterator>
#include <limits>
#include <memory>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#include "../config/config.h"
#include "../core/bit.hpp"
#include "../core/compressed_pair.hpp"
#include "../core/iterator.hpp"
#include "../core/memory.hpp"
#include "../core/type_traits.hpp"
#include "fwd.hpp"
#include "../config/module.h"

#ifndef ENTT_MODULE
# include <cmath>
# include <cstddef>
# include <functional>
# include <iterator>
# include <limits>
# include <memory>
# include <tuple>
# include <type_traits>
# include <utility>
# include <vector>
# include "../config/config.h"
# include "../core/bit.hpp"
# include "../core/compressed_pair.hpp"
# include "../core/iterator.hpp"
# include "../core/memory.hpp"
# include "../core/type_traits.hpp"
# include "fwd.hpp"
#endif // ENTT_MODULE

namespace entt {

Expand Down Expand Up @@ -55,7 +59,7 @@ struct dense_map_node final {
template<typename It>
class dense_map_iterator final {
template<typename>
friend class dense_map_iterator;
friend class internal::dense_map_iterator;

using first_type = decltype(std::as_const(std::declval<It>()->element.first));
using second_type = decltype((std::declval<It>()->element.second));
Expand Down Expand Up @@ -139,6 +143,8 @@ class dense_map_iterator final {
It it;
};

ENTT_MODULE_EXPORT_BEGIN

template<typename Lhs, typename Rhs>
[[nodiscard]] constexpr std::ptrdiff_t operator-(const dense_map_iterator<Lhs> &lhs, const dense_map_iterator<Rhs> &rhs) noexcept {
return lhs.it - rhs.it;
Expand Down Expand Up @@ -174,10 +180,12 @@ template<typename Lhs, typename Rhs>
return !(lhs < rhs);
}

ENTT_MODULE_EXPORT_END

template<typename It>
class dense_map_local_iterator final {
template<typename>
friend class dense_map_local_iterator;
friend class internal::dense_map_local_iterator;

using first_type = decltype(std::as_const(std::declval<It>()->element.first));
using second_type = decltype((std::declval<It>()->element.second));
Expand Down Expand Up @@ -230,6 +238,8 @@ class dense_map_local_iterator final {
std::size_t offset;
};

ENTT_MODULE_EXPORT_BEGIN

template<typename Lhs, typename Rhs>
[[nodiscard]] constexpr bool operator==(const dense_map_local_iterator<Lhs> &lhs, const dense_map_local_iterator<Rhs> &rhs) noexcept {
return lhs.index() == rhs.index();
Expand All @@ -240,9 +250,13 @@ template<typename Lhs, typename Rhs>
return !(lhs == rhs);
}

ENTT_MODULE_EXPORT_END

} // namespace internal
/*! @endcond */

ENTT_MODULE_EXPORT_BEGIN

/**
* @brief Associative container for key-value pairs with unique keys.
*
Expand Down Expand Up @@ -1055,6 +1069,8 @@ class dense_map {
float threshold{default_threshold};
};

ENTT_MODULE_EXPORT_END

} // namespace entt

/*! @cond TURN_OFF_DOXYGEN */
Expand Down
Loading
Loading