Skip to content

Commit

Permalink
Merge pull request #145 from tcbrindle/pr/cmake_module
Browse files Browse the repository at this point in the history
Use CMake modules support
  • Loading branch information
tcbrindle authored Jan 10, 2024
2 parents c3e04d5 + f57cad5 commit b4a5919
Show file tree
Hide file tree
Showing 84 changed files with 233 additions and 480 deletions.
1 change: 0 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ jobs:
run: |
cmake -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DFLUX_BUILD_BENCHMARKS=${{matrix.build_type == 'Release'}} \
-DFLUX_BUILD_MODULE=On \
-A ${{matrix.platform}} \
$GITHUB_WORKSPACE
Expand Down
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ option(FLUX_BUILD_TESTS "Build Flux tests" ${PROJECT_IS_TOP_LEVEL})
option(FLUX_BUILD_BENCHMARKS "Build Flux benchmarks" Off)
option(FLUX_BUILD_TOOLS "Build single-header generator tool" Off)
option(FLUX_BUILD_MODULE "Build C++20 module (experimental)" Off)
option(FLUX_BUILD_TESTS_USING_MODULE "Build tests using modules (experimental)" Off)
option(FLUX_ENABLE_ASAN "Enable Address Sanitizer for tests" Off)
option(FLUX_ENABLE_UBSAN "Enable Undefined Behaviour Sanitizer for tests" Off)

Expand All @@ -76,7 +77,11 @@ if (FLUX_BUILD_TOOLS)
endif()

if (FLUX_BUILD_MODULE)
add_subdirectory(module)
if(CMAKE_VERSION VERSION_LESS "3.28.0")
message(FATAL_ERROR "Modules support requires CMake v3.28 or later (currently v${CMAKE_VERSION})")
else()
add_subdirectory(module)
endif()
endif()

set(FLUX_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/flux)
Expand Down
223 changes: 0 additions & 223 deletions cmake/modules.cmake

This file was deleted.

1 change: 1 addition & 0 deletions include/flux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include <flux/op/zip_algorithms.hpp>

#include <flux/source/array_ptr.hpp>
#include <flux/source/bitset.hpp>
#include <flux/source/empty.hpp>
#include <flux/source/generator.hpp>
#include <flux/source/getlines.hpp>
Expand Down
1 change: 0 additions & 1 deletion include/flux/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <flux/core/default_impls.hpp>
#include <flux/core/functional.hpp>
#include <flux/core/inline_sequence_base.hpp>
#include <flux/core/macros.hpp>
#include <flux/core/optional.hpp>
#include <flux/core/sequence_access.hpp>
#include <flux/core/simple_sequence_base.hpp>
Expand Down
8 changes: 2 additions & 6 deletions include/flux/core/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ namespace detail {

struct runtime_error_fn {
[[noreturn]]
inline void operator()(char const* msg,
std::source_location loc = std::source_location::current()) const
void operator()(char const* msg,
std::source_location loc = std::source_location::current()) const
{
if constexpr (config::on_error == error_policy::unwind) {
char buf[1024];
Expand Down Expand Up @@ -100,10 +100,6 @@ FLUX_EXPORT inline constexpr auto assert_ = detail::assert_fn{};
FLUX_EXPORT inline constexpr auto bounds_check = detail::bounds_check_fn{};
FLUX_EXPORT inline constexpr auto indexed_bounds_check = detail::indexed_bounds_check_fn{};

#define FLUX_ASSERT(cond) (::flux::assert_(cond, "assertion '" #cond "' failed"))

#define FLUX_DEBUG_ASSERT(cond) (::flux::assert_(!::flux::config::enable_debug_asserts || (cond), "assertion '" #cond "' failed"));

} // namespace flux

#endif // FLUX_CORE_ASSERT_HPP_INCLUDED
2 changes: 1 addition & 1 deletion include/flux/core/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#ifndef FLUX_CORE_CONCEPTS_HPP_INCLUDED
#define FLUX_CORE_CONCEPTS_HPP_INCLUDED

#include <flux/core/macros.hpp>
#include <flux/core/utils.hpp>

#include <compare>
Expand Down Expand Up @@ -322,6 +321,7 @@ concept adaptable_sequence =
detail::trivially_copyable_sequence<std::decay_t<Seq>>)) &&
!detail::is_ilist<Seq>;

FLUX_EXPORT
template <typename D>
struct inline_sequence_base;

Expand Down
2 changes: 1 addition & 1 deletion include/flux/core/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef FLUX_CORE_CONFIG_HPP_INCLUDED
#define FLUX_CORE_CONFIG_HPP_INCLUDED

#include <flux/core/macros.hpp>
#include <flux/macros.hpp>

#include <concepts>
#include <cstddef>
Expand Down
5 changes: 4 additions & 1 deletion include/flux/core/functional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef FLUX_CORE_FUNCTIONAL_HPP_INCLUDED
#define FLUX_CORE_FUNCTIONAL_HPP_INCLUDED

#include <flux/core/macros.hpp>
#include <flux/macros.hpp>

#include <functional>
#include <type_traits>
Expand Down Expand Up @@ -174,18 +174,21 @@ FLUX_EXPORT inline constexpr auto either = [](auto&& p, auto&& or_) {

namespace detail {

FLUX_EXPORT
template <typename P>
constexpr auto operator!(detail::predicate<P> pred)
{
return not_(std::move(pred));
}

FLUX_EXPORT
template <typename L, typename R>
constexpr auto operator&&(detail::predicate<L> lhs, detail::predicate<R> rhs)
{
return both(std::move(lhs), std::move(rhs));
}

FLUX_EXPORT
template <typename L, typename R>
constexpr auto operator||(detail::predicate<L> lhs, detail::predicate<R> rhs)
{
Expand Down
4 changes: 4 additions & 0 deletions include/flux/core/macros.hpp → include/flux/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
::flux::inc(_flux_seq_, _flux_cur_)) \
if (_flux_var_decl_ = ::flux::read_at(_flux_seq_, _flux_cur_); true)

#define FLUX_ASSERT(cond) (::flux::assert_(cond, "assertion '" #cond "' failed"))

#define FLUX_DEBUG_ASSERT(cond) (::flux::assert_(!::flux::config::enable_debug_asserts || (cond), "assertion '" #cond "' failed"));

#ifdef FLUX_MODULE_INTERFACE
#define FLUX_EXPORT export
#else
Expand Down
3 changes: 2 additions & 1 deletion include/flux/op/to.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

namespace flux {

FLUX_EXPORT
struct from_sequence_t {
explicit from_sequence_t() = default;
};

inline constexpr auto from_sequence = from_sequence_t{};
FLUX_EXPORT inline constexpr auto from_sequence = from_sequence_t{};

namespace detail {

Expand Down
19 changes: 16 additions & 3 deletions module/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@

include(modules)
add_library(flux-mod)
add_library(flux::module ALIAS flux-mod)

add_module_library(flux-mod flux.cpp)
target_link_libraries(flux-mod PUBLIC flux)
target_sources(flux-mod PUBLIC
FILE_SET CXX_MODULES
BASE_DIRS ${PROJECT_SOURCE_DIR}/module
FILES flux.cpp
)

target_sources(flux-mod PUBLIC
FILE_SET HEADERS
BASE_DIRS ${PROJECT_SOURCE_DIR}/include
FILES ${PROJECT_SOURCE_DIR}/include/flux/macros.hpp
)

target_link_libraries(flux-mod PRIVATE flux)
target_compile_features(flux-mod PUBLIC $<IF:$<CXX_COMPILER_ID:MSVC>,cxx_std_23,cxx_std_20>)
set_target_properties(flux-mod PROPERTIES CXX_EXTENSIONS Off)

# Squish MSVC warning when building the module, hopefully we're not actually doing anything wrong
Expand Down
Loading

0 comments on commit b4a5919

Please sign in to comment.