Skip to content

Commit 2f092d1

Browse files
committed
chore(test): clarify run script
Add comment describing the test runner.
1 parent baa5d59 commit 2f092d1

5 files changed

Lines changed: 34 additions & 17 deletions

File tree

CMakeLists.txt

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
cmake_minimum_required(VERSION 3.5)
22
project(hmac_cpp VERSION 0.2.0 LANGUAGES CXX)
33

4-
if(NOT DEFINED CMAKE_CXX_STANDARD)
5-
set(CMAKE_CXX_STANDARD 11)
6-
endif()
7-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
8-
9-
option(BUILD_EXAMPLE "Build the example program" ON)
10-
option(BUILD_TESTS "Build the test suite" OFF)
4+
option(HMACCPP_BUILD_EXAMPLES "Build the example program" OFF)
5+
option(HMACCPP_BUILD_TESTS "Build the test suite" OFF)
6+
option(HMACCPP_BUILD_BENCH "Build benchmarks" OFF)
117

128
set(HMAC_SOURCES
139
src/sha1.cpp
@@ -27,12 +23,17 @@ set(HMAC_HEADERS
2723
)
2824

2925
add_library(hmac_cpp STATIC ${HMAC_SOURCES})
26+
target_compile_features(hmac_cpp PUBLIC cxx_std_11)
3027
target_include_directories(hmac_cpp PUBLIC
3128
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
3229
$<INSTALL_INTERFACE:include>
3330
)
3431

35-
if(BUILD_EXAMPLE)
32+
if(NOT TARGET hmac_cpp::hmac_cpp)
33+
add_library(hmac_cpp::hmac_cpp ALIAS hmac_cpp)
34+
endif()
35+
36+
if(HMACCPP_BUILD_EXAMPLES)
3637
add_executable(example example.cpp)
3738
target_link_libraries(example PRIVATE hmac_cpp)
3839
target_include_directories(example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
@@ -41,7 +42,11 @@ endif()
4142
include(CMakePackageConfigHelpers)
4243
install(TARGETS hmac_cpp EXPORT hmac_cppTargets DESTINATION lib)
4344
install(FILES ${HMAC_HEADERS} DESTINATION include/hmac_cpp)
44-
install(EXPORT hmac_cppTargets NAMESPACE hmac_cpp:: DESTINATION lib/cmake/hmac_cpp)
45+
install(EXPORT hmac_cppTargets
46+
FILE hmac_cppTargets.cmake
47+
NAMESPACE hmac_cpp::
48+
DESTINATION lib/cmake/hmac_cpp
49+
)
4550

4651
configure_package_config_file(
4752
cmake/hmac_cppConfig.cmake.in
@@ -59,7 +64,7 @@ install(FILES
5964
DESTINATION lib/cmake/hmac_cpp
6065
)
6166

62-
if(BUILD_TESTS)
67+
if(HMACCPP_BUILD_TESTS)
6368
enable_testing()
6469
include(FetchContent)
6570
FetchContent_Declare(
@@ -80,3 +85,8 @@ if(BUILD_TESTS)
8085
target_include_directories(test_totp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
8186
add_test(NAME test_totp COMMAND test_totp)
8287
endif()
88+
89+
export(EXPORT hmac_cppTargets
90+
FILE "${CMAKE_CURRENT_BINARY_DIR}/hmac_cppTargets.cmake"
91+
NAMESPACE hmac_cpp::
92+
)

README-RU.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@
2222

2323
## 🔧 Установка и сборка
2424

25+
По умолчанию примеры, тесты и бенчмарки не собираются. Включите их с помощью
26+
`HMACCPP_BUILD_EXAMPLES`, `HMACCPP_BUILD_TESTS` и `HMACCPP_BUILD_BENCH`.
27+
2528
Для сборки используйте CMake:
2629

2730
```bash
28-
cmake -B build -DBUILD_EXAMPLE=ON
31+
cmake -B build -DHMACCPP_BUILD_EXAMPLES=ON
2932
cmake --build build
3033
```
3134

@@ -237,7 +240,7 @@ try {
237240

238241
## 📄 Пример
239242

240-
Пример находится в `example.cpp`, автоматически собирается при `BUILD_EXAMPLE=ON`.
243+
Пример находится в `example.cpp` и собирается при `HMACCPP_BUILD_EXAMPLES=ON`.
241244

242245
```cpp
243246
#include <iostream>

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ A lightweight `C++11` library for computing `HMAC` (hash-based message authentic
2222

2323
## 🔧 Build and Installation
2424

25+
Examples, tests, and benchmarks are disabled by default. Enable them with
26+
`HMACCPP_BUILD_EXAMPLES`, `HMACCPP_BUILD_TESTS`, and `HMACCPP_BUILD_BENCH`.
27+
2528
Use CMake to build:
2629

2730
```bash
28-
cmake -B build -DBUILD_EXAMPLE=ON
31+
cmake -B build -DHMACCPP_BUILD_EXAMPLES=ON
2932
cmake --build build
3033
```
3134

@@ -63,7 +66,7 @@ target_link_libraries(my_app PRIVATE hmac_cpp::hmac_cpp)
6366
Enable tests during configuration and run them with CTest:
6467

6568
```bash
66-
cmake -B build -DBUILD_TESTS=ON
69+
cmake -B build -DHMACCPP_BUILD_TESTS=ON
6770
cmake --build build
6871
cd build
6972
ctest --output-on-failure
@@ -277,7 +280,7 @@ This is useful for stateless authentication, API protection, and one-time tokens
277280

278281
## 📄 Example
279282

280-
The example is in `example.cpp` and is built automatically when `BUILD_EXAMPLE=ON`.
283+
The example is in `example.cpp` and builds when `HMACCPP_BUILD_EXAMPLES=ON`.
281284

282285
```cpp
283286
#include <iostream>

build_lib_mingw.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
cmake -G "MinGW Makefiles" -B build -DBUILD_EXAMPLE=OFF
1+
cmake -G "MinGW Makefiles" -B build -DHMACCPP_BUILD_EXAMPLES=OFF
22
cmake --build build
33
pause

scripts/run_tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bash
22
set -e
3-
cmake -S . -B build -DBUILD_TESTS=ON -DCMAKE_CXX_STANDARD=${CXX_STANDARD:-11}
3+
# Configure and run tests
4+
cmake -S . -B build -DHMACCPP_BUILD_TESTS=ON
45
cmake --build build --target test_all test_totp
56
cd build
67
ctest --output-on-failure

0 commit comments

Comments
 (0)