Skip to content

Commit 75d7bb2

Browse files
authored
upgrade to conan 2 (#44)
1 parent 3d966b0 commit 75d7bb2

9 files changed

+69
-38
lines changed

.github/workflows/code_testing.yml

+37-4
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ jobs:
3636
sudo apt-get update -y
3737
3838
- name: Install CMake
39-
uses: lukka/get-cmake@v3.24.3
39+
uses: lukka/get-cmake@v3.29.3
4040
with:
41-
cmakeVersion: 3.16.9
41+
cmakeVersion: 3.24
4242

4343
- name: Install compiler
4444
id: install_cc
@@ -49,10 +49,43 @@ jobs:
4949
- name: Install linker
5050
uses: rui314/setup-mold@v1
5151

52-
- uses: actions/checkout@v3
52+
- name: Configure conan
53+
run: |
54+
pip3 install conan==2.3.0
55+
56+
# conan profile update is deprecated (https://github.com/conan-io/conan/issues/13205)
57+
# and they don't want you to use detect because it is unstable
58+
59+
conan profile detect # Force creation of conan directory structure, will be overwritten
60+
61+
echo '{% set compiler, version, c_exe = detect_api.detect_default_compiler() %}' > ~/.conan2/profiles/default
62+
echo '[settings]' >> ~/.conan2/profiles/default
63+
echo 'os={{ detect_api.detect_os() }}' >> ~/.conan2/profiles/default
64+
echo 'arch={{ detect_api.detect_arch() }}' >> ~/.conan2/profiles/default
65+
echo 'build_type=Release' >> ~/.conan2/profiles/default
66+
echo 'compiler={{ compiler }}' >> ~/.conan2/profiles/default
67+
echo 'compiler.version={{ detect_api.default_compiler_version(compiler, version) }}' >> ~/.conan2/profiles/default
68+
echo 'compiler.libcxx=libstdc++11' >> ~/.conan2/profiles/default
69+
70+
conan remote add -f dice-group https://conan.dice-research.org/artifactory/api/conan/tentris
71+
72+
- name: Cache conan data
73+
id: cache-conan
74+
uses: actions/[email protected]
75+
with:
76+
path: ~/.conan2/p
77+
key: ${{ matrix.config.os }}-${{ matrix.config.compiler }}
78+
79+
- uses: actions/[email protected]
80+
81+
- name: Get dependency provider
82+
run: |
83+
sudo apt-get install -y wget
84+
85+
wget https://github.com/conan-io/cmake-conan/raw/develop2/conan_provider.cmake -O conan_provider.cmake
5386
5487
- name: Configure CMake
55-
run: cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=On -DBUILD_EXAMPLES=On -G Ninja -B build .
88+
run: cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=On -DBUILD_EXAMPLES=On -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake -G Ninja -B build .
5689
env:
5790
CC: ${{ steps.install_cc.outputs.cc }}
5891
CXX: ${{ steps.install_cc.outputs.cxx }}

.github/workflows/documentation.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ jobs:
1616
- uses: actions/checkout@v3
1717
# https://github.com/marketplace/actions/doxygen-action
1818
- name: generate docu
19-
uses: mattnotmitt/doxygen-action@v1
19+
uses: mattnotmitt/doxygen-action@v1.9.8
2020
with:
2121
working-directory: '.'
2222
doxyfile-path: 'Doxyfile'
2323

2424
- name: upload to github page branch
25-
uses: peaceiris/actions-gh-pages@v3
25+
uses: peaceiris/actions-gh-pages@v4.0.0
2626
with:
2727
github_token: ${{ secrets.GITHUB_TOKEN }}
2828
publish_dir: ./docu

.github/workflows/publish-conan-branch-package.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ jobs:
1313
public_artifactory: true
1414
os: ubuntu-22.04
1515
compiler: clang-15
16-
cmake-version: 3.22.6
17-
conan-version: 2.0.13
16+
cmake-version: 3.24.0
17+
conan-version: 2.3.0
1818
secrets:
1919
CONAN_USER: ${{ secrets.CONAN_USER }}
2020
CONAN_PW: ${{ secrets.CONAN_PW }}

.github/workflows/publish-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
public_artifactory: true
1919
os: ubuntu-22.04
2020
compiler: clang-14
21-
cmake-version: 3.22.6
21+
cmake-version: 3.24.0
2222
conan-version: 2.0.13
2323
secrets:
2424
CONAN_USER: ${{ secrets.CONAN_USER }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,4 @@ modules.xml
162162
/docu/
163163

164164
test_package/build
165+
conan_provider.cmake

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.22)
1+
cmake_minimum_required(VERSION 3.24)
22

33
project(
44
dice-hash

README.md

+9-19
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,13 @@ A C++20 compatible compiler. Code was only tested on x86_64.
2323

2424
### CMake
2525

26-
add
27-
```cmake
28-
FetchContent_Declare(
29-
dice-hash
30-
GIT_REPOSITORY https://github.com/dice-group/dice-hash.git
31-
GIT_TAG 0.4.4
32-
GIT_SHALLOW TRUE)
33-
34-
FetchContent_MakeAvailable(dice-hash)
26+
### conan
27+
To use it with [conan](https://conan.io/) you need to add the repository:
28+
```shell
29+
conan remote add dice-group https://conan.dice-research.org/artifactory/api/conan/tentris
3530
```
3631

37-
to your CMakeLists.txt
32+
To use it add `dice-hash/0.4.4` to the `[requires]` section of your conan file.
3833

3934
You can now add it to your target with:
4035
```cmake
@@ -43,27 +38,22 @@ target_link_libraries(your_target
4338
)
4439
```
4540

46-
### conan
47-
To use it with [conan](https://conan.io/) you need to add the repository:
48-
```shell
49-
conan remote add dice-group https://conan.dice-research.org/artifactory/api/conan/tentris
50-
```
51-
52-
To use it add `dice-hash/0.4.4` to the `[requires]` section of your conan file.
53-
5441
## build and run tests
5542

5643
```shell
5744
#get it
5845
git clone https://github.com/dice-group/dice-hash.git
5946
cd dice-hash
6047
#build it
48+
wget https://github.com/conan-io/cmake-conan/raw/develop2/conan_provider.cmake -O conan_provider.cmake
6149
mkdir build
6250
cd build
63-
cmake -DBUILD_TESTING -DCMAKE_BUILD_TYPE=Release ..
51+
cmake -DBUILD_TESTING -DCMAKE_BUILD_TYPE=Release .. -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake
6452
make -j tests_dice_hash
6553
./test/tests_dice_hash
6654
```
55+
Note: This example uses conan as dependency provider, other providers are possible.
56+
See https://cmake.org/cmake/help/latest/guide/using-dependencies/index.html#dependency-providers
6757

6858
## usage
6959
You need to include a single header:

conanfile.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,23 @@ def set_version(self):
3333
cmake_file = load(self, os.path.join(self.recipe_folder, "CMakeLists.txt"))
3434
self.description = re.search(r"project\([^)]*DESCRIPTION\s+\"([^\"]+)\"[^)]*\)", cmake_file).group(1)
3535

36+
def requirements(self):
37+
self.test_requires("catch2/2.13.9")
38+
39+
def layout(self):
40+
cmake_layout(self)
41+
42+
def build(self):
43+
if not self.conf.get("tools.build:skip_test", default=False):
44+
cmake = CMake(self)
45+
cmake.configure()
46+
cmake.build()
47+
48+
def package_id(self):
49+
self.info.clear()
50+
3651
def package(self):
3752
cmake = CMake(self)
38-
cmake.configure()
3953
cmake.install()
4054

4155
for dir in ("lib", "res", "share"):

tests/CMakeLists.txt

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@ set(CMAKE_CXX_STANDARD 20)
22
set(CMAKE_CXX_STANDARD_REQUIRED True)
33
set(CMAKE_CXX_EXTENSIONS OFF)
44

5-
include(FetchContent)
6-
FetchContent_Declare(
7-
Catch2
8-
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
9-
GIT_TAG v2.13.9
10-
GIT_SHALLOW TRUE)
11-
12-
FetchContent_MakeAvailable(Catch2)
5+
find_package(Catch2 REQUIRED)
136

147
add_executable(tests_dice_hash TestDiceHash.cpp)
158
target_link_libraries(tests_dice_hash PRIVATE

0 commit comments

Comments
 (0)