Skip to content
Merged
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
30 changes: 20 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
cmake_minimum_required(VERSION 3.5)
project(hmac_cpp VERSION 0.2.0 LANGUAGES CXX)

if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(BUILD_EXAMPLE "Build the example program" ON)
option(BUILD_TESTS "Build the test suite" OFF)
option(HMACCPP_BUILD_EXAMPLES "Build the example program" OFF)
option(HMACCPP_BUILD_TESTS "Build the test suite" OFF)
option(HMACCPP_BUILD_BENCH "Build benchmarks" OFF)

set(HMAC_SOURCES
src/sha1.cpp
Expand All @@ -27,12 +23,17 @@ set(HMAC_HEADERS
)

add_library(hmac_cpp STATIC ${HMAC_SOURCES})
target_compile_features(hmac_cpp PUBLIC cxx_std_11)
target_include_directories(hmac_cpp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

if(BUILD_EXAMPLE)
if(NOT TARGET hmac_cpp::hmac_cpp)
add_library(hmac_cpp::hmac_cpp ALIAS hmac_cpp)
endif()

if(HMACCPP_BUILD_EXAMPLES)
add_executable(example example.cpp)
target_link_libraries(example PRIVATE hmac_cpp)
target_include_directories(example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
Expand All @@ -41,7 +42,11 @@ endif()
include(CMakePackageConfigHelpers)
install(TARGETS hmac_cpp EXPORT hmac_cppTargets DESTINATION lib)
install(FILES ${HMAC_HEADERS} DESTINATION include/hmac_cpp)
install(EXPORT hmac_cppTargets NAMESPACE hmac_cpp:: DESTINATION lib/cmake/hmac_cpp)
install(EXPORT hmac_cppTargets
FILE hmac_cppTargets.cmake
NAMESPACE hmac_cpp::
DESTINATION lib/cmake/hmac_cpp
)

configure_package_config_file(
cmake/hmac_cppConfig.cmake.in
Expand All @@ -59,7 +64,7 @@ install(FILES
DESTINATION lib/cmake/hmac_cpp
)

if(BUILD_TESTS)
if(HMACCPP_BUILD_TESTS)
enable_testing()
include(FetchContent)
FetchContent_Declare(
Expand All @@ -80,3 +85,8 @@ if(BUILD_TESTS)
target_include_directories(test_totp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_test(NAME test_totp COMMAND test_totp)
endif()

export(EXPORT hmac_cppTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/hmac_cppTargets.cmake"
NAMESPACE hmac_cpp::
)
7 changes: 5 additions & 2 deletions README-RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@

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

По умолчанию примеры, тесты и бенчмарки не собираются. Включите их с помощью
`HMACCPP_BUILD_EXAMPLES`, `HMACCPP_BUILD_TESTS` и `HMACCPP_BUILD_BENCH`.

Для сборки используйте CMake:

```bash
cmake -B build -DBUILD_EXAMPLE=ON
cmake -B build -DHMACCPP_BUILD_EXAMPLES=ON
cmake --build build
```

Expand Down Expand Up @@ -237,7 +240,7 @@ try {

## 📄 Пример

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

```cpp
#include <iostream>
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ A lightweight `C++11` library for computing `HMAC` (hash-based message authentic

## 🔧 Build and Installation

Examples, tests, and benchmarks are disabled by default. Enable them with
`HMACCPP_BUILD_EXAMPLES`, `HMACCPP_BUILD_TESTS`, and `HMACCPP_BUILD_BENCH`.

Use CMake to build:

```bash
cmake -B build -DBUILD_EXAMPLE=ON
cmake -B build -DHMACCPP_BUILD_EXAMPLES=ON
cmake --build build
```

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

```bash
cmake -B build -DBUILD_TESTS=ON
cmake -B build -DHMACCPP_BUILD_TESTS=ON
cmake --build build
cd build
ctest --output-on-failure
Expand Down Expand Up @@ -277,7 +280,7 @@ This is useful for stateless authentication, API protection, and one-time tokens

## 📄 Example

The example is in `example.cpp` and is built automatically when `BUILD_EXAMPLE=ON`.
The example is in `example.cpp` and builds when `HMACCPP_BUILD_EXAMPLES=ON`.

```cpp
#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion build_lib_mingw.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
cmake -G "MinGW Makefiles" -B build -DBUILD_EXAMPLE=OFF
cmake -G "MinGW Makefiles" -B build -DHMACCPP_BUILD_EXAMPLES=OFF
cmake --build build
pause
3 changes: 2 additions & 1 deletion scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
set -e
cmake -S . -B build -DBUILD_TESTS=ON -DCMAKE_CXX_STANDARD=${CXX_STANDARD:-11}
# Configure and run tests
cmake -S . -B build -DHMACCPP_BUILD_TESTS=ON
cmake --build build --target test_all test_totp
cd build
ctest --output-on-failure
Loading