Skip to content
Draft
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
39 changes: 19 additions & 20 deletions .github/workflows/code_testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ jobs:
matrix:
config:
- os: ubuntu-24.04
compiler: clang-18
compiler: llvm-19
- os: ubuntu-24.04
compiler: clang-19
- os: ubuntu-24.04
compiler: clang-20
compiler: llvm-20

- os: ubuntu-24.04
compiler: gcc-14
compiler: gcc-15
- os: ubuntu-24.04
compiler: gcc-16
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.compiler }})
defaults:
Expand All @@ -31,21 +31,23 @@ jobs:
- name: Add compiler repos
uses: dice-group/cpp-conan-release-reusable-workflow/.github/actions/setup_apt@main

- name: Install CMake
uses: lukka/get-cmake@latest
with:
cmakeVersion: 3.29.3

- name: Install compiler
id: install_cc
uses: rlalik/setup-cpp-compiler@v1.2
- name: Setup Cpp
uses: aminya/setup-cpp@v1
with:
compiler: ${{ matrix.config.compiler }}
vcvarsall: false

- name: Configure conan
uses: dice-group/cpp-conan-release-reusable-workflow/.github/actions/configure_conan@main
with:
conan-version: 2.21.0
cmake: 3.29.3
ninja: true
vcpkg: false
ccache: false
clangtidy: false
conan: 2.29.0

cppcheck: false

gcovr: false
opencppcoverage: false

- name: add conan user
run: |
Expand All @@ -65,9 +67,6 @@ jobs:

- name: Configure CMake
run: cmake -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined" -DCMAKE_BUILD_TYPE=Debug -DWITH_SVECTOR=ON -DWITH_BOOST=ON -DBUILD_TESTING=On -DBUILD_EXAMPLES=On -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake -G Ninja -B build .
env:
CC: ${{ steps.install_cc.outputs.cc }}
CXX: ${{ steps.install_cc.outputs.cxx }}

- name: Build tests and examples
working-directory: build
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ test_package/build/
test_package/CMakeUserPresets.json
/CMakeUserPresets.json
/conan_provider.cmake
include/dice/template-library/version.hpp
/include/dice/template-library/version.cppm

.clang-tidy
.clang-format
52 changes: 44 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.24)
cmake_minimum_required(VERSION 3.28)

project(
dice-template-library
Expand All @@ -8,7 +8,7 @@ project(
HOMEPAGE_URL "https://dice-research.org/")
set(POBR_VERSION 2) # Persisted Object Binary Representation

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/include/dice/template-library/version.hpp)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.cppm.in ${CMAKE_CURRENT_SOURCE_DIR}/src/dice/template-library/version.cppm)

option(BUILD_TESTING "build tests" OFF)
option(BUILD_EXAMPLES "build examples" OFF)
Expand Down Expand Up @@ -40,25 +40,60 @@ if (PROJECT_IS_TOP_LEVEL)
endif ()
endif ()

add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME} STATIC)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

target_include_directories(${PROJECT_NAME} INTERFACE
target_sources(${PROJECT_NAME} PUBLIC FILE_SET CXX_MODULES BASE_DIRS $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src> FILES
src/dice/template-library/dtl.cppm
src/dice/template-library/version.cppm
src/dice/template-library/channel.cppm
src/dice/template-library/flex_array.cppm
src/dice/template-library/fmt_join.cppm
src/dice/template-library/for.cppm
src/dice/template-library/format_to_ostream.cppm
src/dice/template-library/functional.cppm
src/dice/template-library/inplace_polymorphic.cppm
src/dice/template-library/integral_template_tuple.cppm
src/dice/template-library/integral_sequence.cppm
src/dice/template-library/integral_template_variant.cppm
src/dice/template-library/lazy_conditional.cppm
src/dice/template-library/limit_allocator.cppm
src/dice/template-library/mutex.cppm
src/dice/template-library/next_to_range.cppm
src/dice/template-library/opt_minmax.cppm
src/dice/template-library/ranges.cppm
src/dice/template-library/overloaded.cppm
src/dice/template-library/pointer_tag_pair.cppm
src/dice/template-library/polymorphic_allocator.cppm
src/dice/template-library/pool_allocator.cppm
src/dice/template-library/shared_mutex.cppm
src/dice/template-library/static_string.cppm
src/dice/template-library/stdint.cppm
src/dice/template-library/switch_cases.cppm

src/dice/template-library/standard_layout_tuple.cppm
src/dice/template-library/tuple_algorithm.cppm
src/dice/template-library/type_traits.cppm
src/dice/template-library/type_list.cppm
src/dice/template-library/variant2.cppm
)

target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

if (WITH_SVECTOR)
find_package(svector REQUIRED)

target_link_libraries(${PROJECT_NAME} INTERFACE
target_link_libraries(${PROJECT_NAME} PUBLIC
svector::svector
)
endif ()

if (WITH_BOOST)
find_package(Boost REQUIRED COMPONENTS)

target_link_libraries(${PROJECT_NAME} INTERFACE
target_link_libraries(${PROJECT_NAME} PUBLIC
Boost::headers
)
endif ()
Expand All @@ -68,9 +103,10 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23)

include(cmake/install_interface_library.cmake)
install_interface_library(${PROJECT_NAME} ${PROJECT_NAME} ${PROJECT_NAME} "include")
include(cmake/install_module_library.cmake)
install_module_library(${PROJECT_NAME} ${PROJECT_NAME} ${PROJECT_NAME} "include")

if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTING)
include(CTest)
Expand Down
40 changes: 0 additions & 40 deletions cmake/install_interface_library.cmake

This file was deleted.

44 changes: 44 additions & 0 deletions cmake/install_module_library.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

function(install_module_library TARGET_NAME NAMESPACE LIBRARY_NAME INCLUDE_PATH)

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

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

install(TARGETS ${TARGET_NAME} ${ARGN}
EXPORT ${TARGET_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILE_SET CXX_MODULES DESTINATION modules
)

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

configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/lib-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}-config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${TARGET_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 ${TARGET_NAME}-targets
FILE ${TARGET_NAME}-targets.cmake
NAMESPACE ${NAMESPACE}::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/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)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_PATH}/
DESTINATION include
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h")
endfunction()
9 changes: 3 additions & 6 deletions cmake/version.hpp.in → cmake/version.cppm.in
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#ifndef DICE_TEMPLATELIBRARY_VERSION_HPP
#define DICE_TEMPLATELIBRARY_VERSION_HPP

module;
#include <array>
export module dice.template_library:version;

namespace dice::template_library {
export namespace dice::template_library {
inline constexpr char name[] = "@PROJECT_NAME@";
inline constexpr char version[] = "@PROJECT_VERSION@";
inline constexpr std::array<int, 3> version_tuple = {@PROJECT_VERSION_MAJOR@, @PROJECT_VERSION_MINOR@, @PROJECT_VERSION_PATCH@};
inline constexpr int pobr_version = @POBR_VERSION@; ///< persisted object binary representation version
} // namespace dice::template_library

#endif // DICE_TEMPLATELIBRARY_VERSION_HPP
13 changes: 5 additions & 8 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DiceTemplateLibrary(ConanFile):
topics = "template", "template-library", "compile-time", "switch", "integral-tuple"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain"
exports_sources = "include/*", "CMakeLists.txt", "cmake/*", "LICENSE"
exports_sources = "include/*", "CMakeLists.txt", "cmake/*", "LICENSE", "src/*"
options = {
"with_test_deps": [True, False],
"with_svector": [True, False],
Expand Down Expand Up @@ -70,18 +70,15 @@ def package_id(self):
def package(self):
self._configure_cmake().install()

for dir in ("lib", "res", "share"):
rmdir(self, os.path.join(self.package_folder, dir))

copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))

def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.set_property("cmake_target_name", f"{self.name}::{self.name}")
self.cpp_info.set_property("cmake_file_name", self.name)

self.cpp_info.libs = ["dice-template-library"]
self.cpp_info.set_property("cmake_find_mode", "none")
self.cpp_info.builddirs = ["."]

if self.options.with_svector:
self.cpp_info.requires += ["svector::svector"]
Expand Down
4 changes: 2 additions & 2 deletions examples/example_channel.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <dice/template-library/channel.hpp>

#include <algorithm>
#include <iostream>
#include <thread>
#include <vector>
#include <cassert>

import dice.template_library;

int main() {
dice::template_library::channel<int> chan{8};
Expand Down
4 changes: 2 additions & 2 deletions examples/example_flex_array.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <dice/template-library/flex_array.hpp>

#include <cstddef>
#include <iostream>
#include <variant>

import dice.template_library;

using namespace dice::template_library;

// multidimensional-shape polymorphism without heap allocation
Expand Down
6 changes: 3 additions & 3 deletions examples/example_format_to_ostream.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Include the overload that makes it ostreamable.
#include <dice/template-library/format_to_ostream.hpp>

#include <format>
#include <iostream>
#include <sstream>
#include <string>

// Import the overload that makes it ostreamable.
import dice.template_library;

// A type that has no std::ostream operator<< defined
struct not_ostreamable {
int value;
Expand Down
4 changes: 2 additions & 2 deletions examples/example_inplace_polymorphic.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <dice/template-library/inplace_polymorphic.hpp>

#include <iostream>
#include <string>

import dice.template_library;

namespace dtl = dice::template_library;

struct animal {
Expand Down
4 changes: 2 additions & 2 deletions examples/example_integral_sequence.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <dice/template-library/integral_sequence.hpp>

#include <array>
#include <iostream>
#include <variant>

import dice.template_library;

using namespace dice::template_library;

// Example template that takes an integral value
Expand Down
4 changes: 2 additions & 2 deletions examples/example_limit_allocator.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <dice/template-library/limit_allocator.hpp>

#include <cassert>
#include <vector>
#include <typeinfo>

import dice.template_library;

int main() {
std::vector<int, dice::template_library::limit_allocator<int>> vec{dice::template_library::limit_allocator<int>{3 * sizeof(int)}};
Expand Down
4 changes: 2 additions & 2 deletions examples/example_mutex.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <dice/template-library/mutex.hpp>

#include <cassert>
#include <thread>

import dice.template_library;

int main() {
dice::template_library::mutex<int> mut{0};

Expand Down
Loading
Loading