Skip to content

Commit

Permalink
Formatted CMake and Markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickroberts committed Jan 29, 2025
1 parent ba321f0 commit d01f7ea
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 74 deletions.
157 changes: 88 additions & 69 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
cmake_minimum_required(VERSION 3.25)

project(
beman.any_view
DESCRIPTION "A generalized type-erased view with customizable properties"
LANGUAGES CXX)
beman.any_view
DESCRIPTION "A generalized type-erased view with customizable properties"
LANGUAGES CXX
)

# [CMAKE.SKIP_TESTS]
option(
BEMAN_ANY_VIEW_BUILD_TESTS
"Enable building tests and test infrastructure. Default: ON. Values: { ON, OFF }."
${PROJECT_IS_TOP_LEVEL})
BEMAN_ANY_VIEW_BUILD_TESTS
"Enable building tests and test infrastructure. Default: ON. Values: { ON, OFF }."
${PROJECT_IS_TOP_LEVEL}
)

# [CPP.NO_FLAG_FORKING]
set(BEMAN_ANY_VIEW_DESIGN
"FLAGS"
CACHE
STRING
"Enable alternative design for any_view_options. Default: FLAGS. Values: { FLAGS, TRAITS, NAMED }."
CACHE STRING
"Enable alternative design for any_view_options. Default: FLAGS. Values: { FLAGS, TRAITS, NAMED }."
)

set(BEMAN_ANY_VIEW_OPTION
"COPYABLE"
CACHE
STRING
"Enable opt-in option for any_view. Default: COPYABLE. Values: { COPYABLE, MOVE_ONLY }."
CACHE STRING
"Enable opt-in option for any_view. Default: COPYABLE. Values: { COPYABLE, MOVE_ONLY }."
)

set(BEMAN_ANY_VIEW_USE_FLAGS OFF)
Expand All @@ -35,33 +35,36 @@ set(BEMAN_ANY_VIEW_USE_COPYABLE OFF)
set(BEMAN_ANY_VIEW_USE_MOVE_ONLY OFF)

if(BEMAN_ANY_VIEW_DESIGN STREQUAL "FLAGS")
set(BEMAN_ANY_VIEW_USE_FLAGS ON)
set(BEMAN_ANY_VIEW_USE_FLAGS ON)
elseif(BEMAN_ANY_VIEW_DESIGN STREQUAL "TRAITS")
set(BEMAN_ANY_VIEW_USE_TRAITS ON)
set(BEMAN_ANY_VIEW_USE_TRAITS ON)
elseif(BEMAN_ANY_VIEW_DESIGN STREQUAL "NAMED")
set(BEMAN_ANY_VIEW_USE_NAMED ON)
set(BEMAN_ANY_VIEW_USE_NAMED ON)
else()
message(
FATAL_ERROR
"BEMAN_ANY_VIEW_DESIGN must be one of { FLAGS, TRAITS, NAMED }; got ${BEMAN_ANY_VIEW_DESIGN}"
)
message(
FATAL_ERROR
"BEMAN_ANY_VIEW_DESIGN must be one of { FLAGS, TRAITS, NAMED }; got ${BEMAN_ANY_VIEW_DESIGN}"
)
endif()

if(BEMAN_ANY_VIEW_OPTION STREQUAL "COPYABLE")
set(BEMAN_ANY_VIEW_USE_COPYABLE ON)
set(BEMAN_ANY_VIEW_USE_COPYABLE ON)
elseif(BEMAN_ANY_VIEW_OPTION STREQUAL "MOVE_ONLY")
set(BEMAN_ANY_VIEW_USE_MOVE_ONLY ON)
set(BEMAN_ANY_VIEW_USE_MOVE_ONLY ON)
else()
message(
FATAL_ERROR
"BEMAN_ANY_VIEW_OPTION must be one of { COPYABLE, MOVE_ONLY }; got ${BEMAN_ANY_VIEW_OPTION}"
)
message(
FATAL_ERROR
"BEMAN_ANY_VIEW_OPTION must be one of { COPYABLE, MOVE_ONLY }; got ${BEMAN_ANY_VIEW_OPTION}"
)
endif()

string(TOLOWER "${BEMAN_ANY_VIEW_OPTION}" BEMAN_ANY_VIEW_OPTION)

configure_file("${PROJECT_SOURCE_DIR}/include/beman/any_view/config.hpp.in"
"${PROJECT_BINARY_DIR}/include/beman/any_view/config.hpp" @ONLY)
configure_file(
"${PROJECT_SOURCE_DIR}/include/beman/any_view/config.hpp.in"
"${PROJECT_BINARY_DIR}/include/beman/any_view/config.hpp"
@ONLY
)

include(FetchContent)
include(GNUInstallDirs)
Expand All @@ -70,56 +73,72 @@ add_library(beman.any_view INTERFACE)
add_library(beman::any_view ALIAS beman.any_view)
# TODO: implement non-template friend function and remove this suppression
target_compile_options(
beman.any_view INTERFACE $<$<CXX_COMPILER_ID:GNU>:-Wno-non-template-friend>)
beman.any_view
INTERFACE $<$<CXX_COMPILER_ID:GNU>:-Wno-non-template-friend>
)
target_include_directories(
beman.any_view
INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>)
beman.any_view
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)

install(
TARGETS beman.any_view
EXPORT ${TARGETS_EXPORT_NAME}
DESTINATION $<$<CONFIG:Debug>:debug/>${CMAKE_INSTALL_LIBDIR})
TARGETS beman.any_view
EXPORT ${TARGETS_EXPORT_NAME}
DESTINATION
$<$<CONFIG:Debug>:debug/>${CMAKE_INSTALL_LIBDIR}
)

install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME}
FILES_MATCHING
PATTERN "${CMAKE_CURRENT_SOURCE_DIR}/include/beman/any_view/*.hpp")
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME}
FILES_MATCHING
PATTERN "${CMAKE_CURRENT_SOURCE_DIR}/include/beman/any_view/*.hpp"
)

macro(beman_add_executable)
set(options)
set(oneValueArgs CATEGORY TARGET)
set(multiValueArgs SOURCES LIBRARIES)

cmake_parse_arguments(beman_executable "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN})

set(target
"beman.any_view.${beman_executable_CATEGORY}.${beman_executable_TARGET}")

if(NOT beman_executable_SOURCES)
set(beman_executable_SOURCES "${beman_executable_TARGET}.cpp")
endif()

add_executable(${target})
target_sources(${target} PRIVATE ${beman_executable_SOURCES})
target_link_libraries(${target} PRIVATE beman::any_view
${beman_executable_LIBRARIES})
set(options)
set(oneValueArgs CATEGORY TARGET)
set(multiValueArgs SOURCES LIBRARIES)

cmake_parse_arguments(
beman_executable
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)

set(target
"beman.any_view.${beman_executable_CATEGORY}.${beman_executable_TARGET}"
)

if(NOT beman_executable_SOURCES)
set(beman_executable_SOURCES "${beman_executable_TARGET}.cpp")
endif()

add_executable(${target})
target_sources(${target} PRIVATE ${beman_executable_SOURCES})
target_link_libraries(
${target}
PRIVATE beman::any_view ${beman_executable_LIBRARIES}
)
endmacro()

if(BEMAN_ANY_VIEW_BUILD_TESTS)
enable_testing()

# Fetch GoogleTest
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
EXCLUDE_FROM_ALL)
set(INSTALL_GTEST OFF) # Disable GoogleTest installation
FetchContent_MakeAvailable(googletest)

add_subdirectory(tests/beman/any_view)
enable_testing()

# Fetch GoogleTest
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
EXCLUDE_FROM_ALL
)
set(INSTALL_GTEST OFF) # Disable GoogleTest installation
FetchContent_MakeAvailable(googletest)

add_subdirectory(tests/beman/any_view)
endif()
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

## Usage

`std::ranges::any_view` is a class template that provides a type-erased interface for `std::ranges::view`. It may additionally model other concepts like `std::ranges::contiguous_range`, `std::ranges::sized_range`, `std::ranges::borrowed_range`, and `std::copyable` depending on the instantiation.
`std::ranges::any_view` is a class template that provides a type-erased interface for `std::ranges::view`.
It may additionally model other concepts like `std::ranges::contiguous_range`, `std::ranges::sized_range`,
`std::ranges::borrowed_range`, and `std::copyable` depending on the instantiation.

## Integrate beman.any_view into your project

Expand All @@ -34,7 +36,8 @@ FetchContent_Declare(
FetchContent_MakeAvailable(beman.any_view)
```

You will also need to add `beman::any_view` to the link libraries of any targets that include `beman/any_view/*.hpp` in their source or header files:
You will also need to add `beman::any_view` to the link libraries of any targets that include `beman/any_view/*.hpp` in
their source or header files:

```cmake
target_link_libraries(yourlib PUBLIC beman::any_view)
Expand Down
7 changes: 4 additions & 3 deletions tests/beman/any_view/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
include(GoogleTest)

function(beman_add_test)
beman_add_executable(${ARGN} CATEGORY tests LIBRARIES GTest::gtest
GTest::gtest_main)
gtest_discover_tests(${target})
beman_add_executable(${ARGN} CATEGORY tests LIBRARIES GTest::gtest
GTest::gtest_main
)
gtest_discover_tests(${target})
endfunction()

beman_add_test(TARGET concepts SOURCES concepts.test.cpp)

0 comments on commit d01f7ea

Please sign in to comment.