Skip to content

Commit 0ad230c

Browse files
committed
[misc] add cmake stuff and version.hpp
1 parent 8dc2803 commit 0ad230c

File tree

9 files changed

+121
-83
lines changed

9 files changed

+121
-83
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## unreleased
8+
## [0.20.0] - 2025-08-03
9+
10+
First release. "Full C++20 equivalence."
911

1012
### Progress implementing std::views::X equivalents
1113

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cmake_minimum_required (VERSION 3.12)
2+
3+
project (radr LANGUAGES CXX
4+
DESCRIPTION "Range Adaptors Reimagined (radr)."
5+
HOMEPAGE_URL "https://github.com/h-2/radr")
6+
7+
message(STATUS "Loading the RADR library and implicitly calling find_package.")
8+
find_package (radr REQUIRED HINTS ${CMAKE_CURRENT_LIST_DIR}/cmake)
9+
message(STATUS "Add radr::radr to your program's target_link_libraries.")
10+
11+
message(STATUS "ATTENTION: Including the project root only includes the library.")
12+
message(STATUS "ATTENTION: To build unit tests, benchmarks or other utilitites, directly cmake one of the directories in tests/ .")

cmake/radr-config.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required (VERSION 3.12)
2+
3+
find_path (RADR_CLONE_DIR NAMES cmake/radr-config.cmake HINTS "${CMAKE_CURRENT_LIST_DIR}/..")
4+
find_path (RADR_INCLUDE_DIR NAMES radr/version.hpp HINTS "${RADR_CLONE_DIR}/include")
5+
6+
add_library (radr_radr INTERFACE)
7+
target_include_directories (radr_radr INTERFACE "${RADR_INCLUDE_DIR}")
8+
add_library (radr::radr ALIAS radr_radr)

include/radr/custom/tags.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#pragma once
1313

14+
#include "radr/version.hpp"
15+
1416
namespace radr::custom
1517
{
1618

include/radr/detail/detail.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <iterator>
1717
#include <ranges>
1818

19+
#include "../version.hpp"
1920
#include "bind_back.hpp"
2021
#include "fwd.hpp"
2122

include/radr/version.hpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Copyright (c) 2023-2025 Hannes Hauswedell
5+
//
6+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
7+
// See the LICENSE file for details.
8+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9+
//
10+
//===----------------------------------------------------------------------===//
11+
12+
#pragma once
13+
14+
#include <cinttypes>
15+
#include <ciso646> // makes _LIBCPP_VERSION available
16+
#include <cstddef> // makes __GLIBCXX__ available
17+
18+
// ============================================================================
19+
// C++ standard and features
20+
// ============================================================================
21+
22+
// C++ standard [required]
23+
#ifdef __cplusplus
24+
static_assert(__cplusplus >= 201709, "RADR requires C++20 or later, make sure that you have set -std=c++20.");
25+
#else
26+
# error "This is not a C++ compiler."
27+
#endif
28+
29+
#if __has_include(<version>)
30+
# include <version>
31+
#endif
32+
33+
// ============================================================================
34+
// Compilers
35+
// ============================================================================
36+
37+
#if !(defined(__clang_major__) && (__clang_major__ >= 16)) && !(defined(__GNUC__) && (__GNUC__ >= 11))
38+
# pragma GCC warning "Only Clang >= 16 and GCC >= 11 are officially supported."
39+
#endif
40+
41+
// ============================================================================
42+
// Version
43+
// ============================================================================
44+
45+
#define RADR_VERSION_MAJOR 0
46+
#define RADR_VERSION_MINOR 20
47+
#define RADR_VERSION_PATCH 0

tests/benchmark/CMakeLists.txt

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
cmake_minimum_required (VERSION 3.7)
2-
project (radr_benchmark CXX)
1+
cmake_minimum_required (VERSION 3.12)
2+
project (radr_test_benchmark CXX)
33

44
include(FetchContent)
55

@@ -8,14 +8,12 @@ include(FetchContent)
88
# ----------------------------------------------------------------------------
99

1010
message(STATUS "Beginning to configure RADR micro benchmarks...")
11+
include (../radr-test.cmake)
1112

1213
if (CMAKE_BUILD_TYPE AND NOT ("${CMAKE_BUILD_TYPE}" STREQUAL "Release"))
1314
message (WARNING "Benchmarks should typically be built in Release mode! [build type = ${CMAKE_BUILD_TYPE}]")
1415
endif ()
1516

16-
set(CMAKE_CXX_STANDARD 20)
17-
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
18-
1917
# ----------------------------------------------------------------------------
2018
# Options
2119
# ----------------------------------------------------------------------------
@@ -26,12 +24,7 @@ option(RADR_BENCHMARK_ALIGN_LOOPS "Pass -falign-loops=32 to the benchmark builds
2624
# Paths to folders.
2725
# ----------------------------------------------------------------------------
2826

29-
find_path (RADR_BASE_DIR
30-
NAMES include/radr/rad/as_const.hpp
31-
HINTS "${CMAKE_CURRENT_LIST_DIR}/../../")
32-
set (RADR_INCLUDE_DIR "${RADR_BASE_DIR}/include/")
33-
set (RADR_TEST_INCLUDE_DIR "${RADR_BASE_DIR}/tests/include/")
34-
set (RADR_UNIT_TESTS_SRC "${RADR_BASE_DIR}/tests/benchmark/")
27+
set (RADR_BENCHMARKS_DIR "${RADR_CLONE_DIR}/tests/benchmark/")
3528

3629
# ----------------------------------------------------------------------------
3730
# Components and dependencies
@@ -54,47 +47,26 @@ FetchContent_MakeAvailable(googlebenchmark)
5447
# ----------------------------------------------------------------------------
5548

5649
add_library (radr_benchmark INTERFACE)
57-
target_compile_options (radr_benchmark INTERFACE "-pedantic" "-Wall" "-Wextra" "-Werror")
5850
target_link_libraries (radr_benchmark INTERFACE "pthread" benchmark::benchmark_main)
59-
target_include_directories (radr_benchmark INTERFACE "${RADR_INCLUDE_DIR}" "${RADR_TEST_INCLUDE_DIR}")
6051
add_library (radr::test::benchmark ALIAS radr_benchmark)
6152

6253
if (RADR_BENCHMARK_ALIGN_LOOPS)
6354
target_compile_options (radr_benchmark INTERFACE "-falign-loops=32")
6455
endif ()
6556

66-
# ----------------------------------------------------------------------------
67-
# Test target macro
68-
# ----------------------------------------------------------------------------
69-
70-
macro (radr_test unit_test_cpp)
71-
get_filename_component (target_dir "${unit_test_cpp}" DIRECTORY)
72-
get_filename_component (target "${unit_test_cpp}" NAME_WLE)
73-
74-
add_executable (${target} "${RADR_UNIT_TESTS_SRC}/${unit_test_cpp}")
75-
target_link_libraries (${target} radr::test::benchmark)
76-
77-
file (MAKE_DIRECTORY ${target_dir})
78-
set_target_properties(${target} PROPERTIES
79-
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${target_dir}")
80-
81-
add_test (NAME "${target_dir}/${target}" COMMAND "${target_dir}/${target}")
82-
83-
unset (target)
84-
unset (target_dir)
85-
endmacro ()
86-
8757
# ----------------------------------------------------------------------------
8858
# Start generating tests
8959
# ----------------------------------------------------------------------------
9060

9161
file (GLOB_RECURSE ENTRIES
92-
RELATIVE ${RADR_BASE_DIR}/tests/benchmark
93-
"${RADR_UNIT_TESTS_SRC}/[!.]*cpp")
62+
RELATIVE ${RADR_BENCHMARKS_DIR}
63+
"${RADR_BENCHMARKS_DIR}/[!.]*cpp")
9464

9565
foreach (ENTRY ${ENTRIES})
96-
message(STATUS ${ENTRY})
97-
radr_test(${ENTRY})
66+
radr_add_test(${ENTRY})
67+
get_filename_component (target "${ENTRY}" NAME_WLE)
68+
message(STATUS "Adding benchmark target '${target}' for file ${ENTRY}")
69+
target_link_libraries (${target} radr::test::benchmark)
9870
endforeach ()
9971

10072
message(STATUS "Configuring RADR micro benchmarks DONE.")

tests/radr-test.cmake

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
# -*- CMake -*-
22
#===----------------------------------------------------------------------===//
33
#
4-
# Copyright (c) 2023 Hannes Hauswedell
4+
# Copyright (c) 2023-2025 Hannes Hauswedell
55
#
66
# Licensed under the Apache License v2.0 with LLVM Exceptions.
77
# See the LICENSE file for details.
88
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
99
#
1010
#===----------------------------------------------------------------------===//
1111

12-
cmake_minimum_required (VERSION 3.10)
12+
cmake_minimum_required (VERSION 3.12)
1313

1414
# ----------------------------------------------------------------------------
1515
# RADR SETUP
1616
# ----------------------------------------------------------------------------
1717

18-
find_path (RADR_INCLUDE_DIR NAMES radr/rad/as_const.hpp HINTS "${CMAKE_CURRENT_SOURCE_DIR}/../../include/" REQUIRED)
19-
find_path (RADR_TEST_INCLUDE_DIR NAMES radr/test/gtest_helpers.hpp HINTS "${CMAKE_CURRENT_SOURCE_DIR}/../include/" REQUIRED)
18+
find_package(radr REQUIRED HINTS "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/")
19+
20+
find_path (RADR_TEST_INCLUDE_DIR NAMES radr/test/gtest_helpers.hpp HINTS "${RADR_CLONE_DIR}/tests/include/" REQUIRED)
2021

2122
# ----------------------------------------------------------------------------
2223
# GoogleTest
@@ -35,31 +36,29 @@ FetchContent_MakeAvailable(googletest)
3536
# Pseudo library to ease target definition
3637
# ----------------------------------------------------------------------------
3738

38-
add_library (radr_test_unit INTERFACE)
39-
target_link_libraries (radr_test_unit INTERFACE gtest_main gtest pthread)
40-
target_include_directories (radr_test_unit INTERFACE "${RADR_INCLUDE_DIR}" "${RADR_TEST_INCLUDE_DIR}")
41-
target_compile_options (radr_test_unit INTERFACE -pedantic -Wall -Wextra -Werror)
42-
add_library (radr::test::unit ALIAS radr_test_unit)
39+
add_library (radr_test_base INTERFACE)
40+
target_link_libraries (radr_test_base INTERFACE radr::radr gtest_main gtest pthread)
41+
target_include_directories (radr_test_base INTERFACE "${RADR_TEST_INCLUDE_DIR}")
42+
target_compile_options (radr_test_base INTERFACE -pedantic -Wall -Wextra -Werror)
43+
add_library (radr::test::base ALIAS radr_test_base)
4344

4445
# ----------------------------------------------------------------------------
45-
# add_subdirectories
46+
# radr_add_test macro
4647
# ----------------------------------------------------------------------------
4748

48-
macro (add_subdirectories_of directory)
49-
file (GLOB ENTRIES
50-
RELATIVE ${directory}
51-
${directory}/[!.]*)
49+
macro (radr_add_test unit_test_cpp)
50+
get_filename_component (target_dir "${unit_test_cpp}" DIRECTORY)
51+
get_filename_component (target "${unit_test_cpp}" NAME_WLE)
5252

53-
foreach (ENTRY ${ENTRIES})
54-
if (IS_DIRECTORY ${directory}/${ENTRY})
55-
if (EXISTS ${directory}/${ENTRY}/CMakeLists.txt)
56-
add_subdirectory (${directory}/${ENTRY} ${CMAKE_CURRENT_BINARY_DIR}/${ENTRY})
57-
endif ()
58-
endif ()
59-
endforeach ()
60-
unset (ENTRIES)
61-
endmacro ()
53+
add_executable (${target} "${unit_test_cpp}")
54+
target_link_libraries (${target} radr::test::base)
55+
56+
file (MAKE_DIRECTORY ${target_dir})
57+
set_target_properties(${target} PROPERTIES
58+
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${target_dir}")
59+
60+
add_test (NAME "${target_dir}/${target}" COMMAND "${target_dir}/${target}")
6261

63-
macro (add_subdirectories)
64-
add_subdirectories_of(${CMAKE_CURRENT_SOURCE_DIR})
62+
unset (target)
63+
unset (target_dir)
6564
endmacro ()

tests/unit/CMakeLists.txt

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
1-
cmake_minimum_required (VERSION 3.10)
1+
cmake_minimum_required (VERSION 3.12)
22
project (radr_test_unit CXX)
33

4-
include (../radr-test.cmake)
4+
message(STATUS "Beginning to configure RADR unit tests...")
55

6-
option (RADR_VERBOSE_TESTS "Run each test case individually" OFF)
6+
include (../radr-test.cmake)
77

8-
function (radr_unit_test test_name)
9-
file (RELATIVE_PATH file_name "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_LIST_DIR}/${test_name}.cpp")
10-
set(target_name ${test_name})
8+
enable_testing()
119

12-
add_executable (${target_name} ${test_name}.cpp)
13-
target_link_libraries (${target_name} radr::test::unit)
14-
if (RADR_VERBOSE_TESTS)
15-
gtest_discover_tests(${file_name} TEST_PREFIX "${target_name}::" PROPERTIES TIMEOUT "30")
16-
else ()
17-
add_test (NAME "${file_name}" COMMAND ${target_name})
18-
endif ()
10+
set (RADR_UNIT_TESTS_SRC "${RADR_CLONE_DIR}/tests/unit/")
1911

20-
unset (unit_test)
21-
unset (target_name)
22-
unset (file_name)
23-
endfunction ()
12+
file (GLOB_RECURSE ENTRIES
13+
RELATIVE ${RADR_UNIT_TESTS_SRC}
14+
"${RADR_UNIT_TESTS_SRC}/[!.]*cpp")
2415

25-
enable_testing()
16+
foreach (ENTRY ${ENTRIES})
17+
radr_add_test(${ENTRY})
18+
get_filename_component (target "${ENTRY}" NAME_WLE)
19+
message(STATUS "Adding unit-test target '${target}' for file ${ENTRY}")
20+
endforeach ()
2621

27-
add_subdirectories ()
22+
message(STATUS "Configuring RADR unit tests done.")

0 commit comments

Comments
 (0)