Skip to content

Commit 3e567bd

Browse files
authored
Conan v2 (#7)
Updated to Conan V2 usage Upgraded OpenSSL to 3.x Upgraded Doctest to 2.4.11
1 parent d9f108c commit 3e567bd

File tree

6 files changed

+40
-35
lines changed

6 files changed

+40
-35
lines changed

.github/workflows/build-shared.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
os: [ubuntu-20.04, macos-latest, windows-latest]
12+
os: [ubuntu-latest, macos-latest, windows-latest]
1313

1414
runs-on: ${{ matrix.os }}
1515

@@ -20,38 +20,38 @@ jobs:
2020

2121
steps:
2222
- name: Perform checkout
23-
uses: actions/checkout@v2
23+
uses: actions/checkout@v3
2424

2525
- name: Install Python environment
26-
uses: actions/setup-python@v2
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: '3.10'
2729

2830
- name: Install conan
2931
run: |
3032
pip install conan --upgrade
31-
conan profile new default --detect
33+
conan profile detect --force
3234
3335
- name: Linux build
3436
if: matrix.os == 'ubuntu-20.04'
3537
run: |
36-
conan profile update settings.compiler.libcxx=libstdc++11 default
3738
mkdir -p build && cd build
38-
conan install .. --build=missing
39+
conan install .. --output-folder=. --build=missing
3940
cmake .. -DBUILD_TESTING=TRUE -DBUILD_SHARED_LIBS=TRUE -DCMAKE_BUILD_TYPE=Release
4041
cmake --build . --config Release --target install
4142
4243
- name: Mac build
4344
if: matrix.os == 'macos-latest'
4445
run: |
45-
conan profile update settings.compiler.libcxx=libc++ default
4646
mkdir -p build && cd build
47-
conan install .. --build=missing
47+
conan install .. --output-folder=. --build=missing
4848
cmake .. -DBUILD_TESTING=TRUE -DBUILD_SHARED_LIBS=TRUE -DCMAKE_BUILD_TYPE=Release
4949
cmake --build . --config Release --target install
5050
5151
- name: Windows build
5252
if: matrix.os == 'windows-latest'
5353
run: |
5454
md build && cd build
55-
conan install .. --build=missing
55+
conan install .. --output-folder=. --build=missing
5656
cmake .. -DBUILD_TESTING=TRUE -DBUILD_SHARED_LIBS=TRUE -DCMAKE_BUILD_TYPE=Release
5757
cmake --build . --config Release --target install

.github/workflows/build-static.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
os: [ubuntu-20.04, macos-latest, windows-latest]
12+
os: [ubuntu-latest, macos-latest, windows-latest]
1313

1414
runs-on: ${{ matrix.os }}
1515

@@ -20,38 +20,38 @@ jobs:
2020

2121
steps:
2222
- name: Perform checkout
23-
uses: actions/checkout@v2
23+
uses: actions/checkout@v3
2424

2525
- name: Install Python environment
26-
uses: actions/setup-python@v2
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: '3.10'
2729

2830
- name: Install conan
2931
run: |
3032
pip install conan --upgrade
31-
conan profile new default --detect
33+
conan profile detect --force
3234
3335
- name: Linux build
3436
if: matrix.os == 'ubuntu-20.04'
3537
run: |
36-
conan profile update settings.compiler.libcxx=libstdc++11 default
3738
mkdir -p build && cd build
38-
conan install .. --build=missing
39+
conan install .. --output-folder=. --build=missing
3940
cmake .. -DBUILD_TESTING=TRUE -DBUILD_SHARED_LIBS=FALSE -DCMAKE_BUILD_TYPE=Release
4041
cmake --build . --config Release --target install
4142
4243
- name: Mac build
4344
if: matrix.os == 'macos-latest'
4445
run: |
45-
conan profile update settings.compiler.libcxx=libc++ default
4646
mkdir -p build && cd build
47-
conan install .. --build=missing
47+
conan install .. --output-folder=. --build=missing
4848
cmake .. -DBUILD_TESTING=TRUE -DBUILD_SHARED_LIBS=FALSE -DCMAKE_BUILD_TYPE=Release
4949
cmake --build . --config Release --target install
5050
5151
- name: Windows build
5252
if: matrix.os == 'windows-latest'
5353
run: |
5454
md build && cd build
55-
conan install .. --build=missing
55+
conan install .. --output-folder=. --build=missing
5656
cmake .. -DBUILD_TESTING=TRUE -DBUILD_SHARED_LIBS=FALSE -DCMAKE_BUILD_TYPE=Release
5757
cmake --build . --config Release --target install

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build/
22
*.pyc
33
.vscode
4+
CMakeUserPresets.json

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ This repository aims to represent a template for Modern C++ projects, including
99
## Requirements
1010

1111
* a modern C++17 compiler (`gcc-8`, `clang-6.0`, `MSVC 2017` or above)
12-
* [`cmake`](https://cmake.org) 3.10+
13-
* [`conan`](https://conan.io) 1.28+ (optional)
12+
* [`cmake`](https://cmake.org) 3.15+
13+
* [`conan`](https://conan.io) 2.0+ (optional)
1414
* `cppcheck` (optional)
1515
* `clang-format` (optional)
1616

@@ -62,8 +62,8 @@ The project can be built using the following commands:
6262
cd /path/to/this/project
6363
mkdir -p build # md build (on Windows)
6464
cd build
65-
conan install ..
66-
cmake -DBUILD_TESTING=TRUE -DBUILD_SHARED_LIBS=TRUE ..
65+
conan install .. --output-folder=. --build=missing
66+
cmake -DBUILD_TESTING=TRUE -DBUILD_SHARED_LIBS=TRUE -DCMAKE_BUILD_TYPE=Release ..
6767
cmake --build .
6868
cmake --build . --target format
6969
cmake --build . --target package

conanfile.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[requires]
2-
openssl/1.1.1s
3-
doctest/2.4.9
2+
openssl/3.1.1
3+
doctest/2.4.11
44

55
[generators]
6-
cmake_find_package
6+
CMakeDeps
77

88
[options]
9-
openssl:shared=False
9+
pkg/openssl:shared=False

project/hellolib/src/hellolib.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <iostream>
44

55
#ifdef WITH_OPENSSL
6-
#include <openssl/sha.h>
6+
#include <openssl/evp.h>
77

88
#include <array>
99
#include <iomanip>
@@ -30,22 +30,26 @@ int32_t hellolib::saySomethingHashed(
3030
return 1;
3131
}
3232

33-
SHA256_CTX context;
34-
if (!SHA256_Init(&context)) {
35-
std::cerr << "Failed to initialize context\n";
33+
EVP_MD_CTX *context = EVP_MD_CTX_new();
34+
if(context == NULL) {
35+
std::cerr << "Failed to create context\n";
3636
return 2;
3737
}
3838

39-
if (!SHA256_Update(&context, (unsigned char *)something.c_str(),
40-
something.size())) {
41-
std::cerr << "Failed to create hash value\n";
39+
if(1 != EVP_DigestInit_ex(context, EVP_sha256(), NULL)) {
40+
std::cerr << "Failed to initialize context\n";
4241
return 3;
4342
}
4443

44+
if(1 != EVP_DigestUpdate(context, (unsigned char *)something.c_str(), something.size())) {
45+
std::cerr << "Failed to create hash value\n";
46+
return 4;
47+
}
48+
4549
std::array<unsigned char, 32> buffer{};
46-
if (!SHA256_Final(buffer.data(), &context)) {
50+
if(1 != EVP_DigestFinal_ex(context, buffer.data(), NULL)) {
4751
std::cerr << "Failed to finalize hash result\n";
48-
return 4;
52+
return 5;
4953
}
5054

5155
// Transform byte-array to string

0 commit comments

Comments
 (0)