Skip to content

Commit

Permalink
Feature: conan2 (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
liss-h authored Nov 14, 2023
1 parent cc42308 commit 1dfc5d3
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 18 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/code_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
fail-fast: false
matrix:
config:
- os: ubuntu-22.04
compiler: clang-14
- os: ubuntu-22.04
compiler: clang-15
- os: ubuntu-22.04
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-conan-branch-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
with:
public_artifactory: true
os: ubuntu-22.04
compiler: clang-14
compiler: clang-15
cmake-version: 3.22.6
conan-version: 1.59
conan-version: 2.0.13
secrets:
CONAN_USER: ${{ secrets.CONAN_USER }}
CONAN_PW: ${{ secrets.CONAN_PW }}
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
os: ubuntu-22.04
compiler: clang-14
cmake-version: 3.22.6
conan-version: 1.59
conan-version: 2.0.13
secrets:
CONAN_USER: ${{ secrets.CONAN_USER }}
CONAN_PW: ${{ secrets.CONAN_PW }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,5 @@ modules.xml

# docu folder
/docu/

test_package/build
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.22)

project(
dice-hash
Expand Down Expand Up @@ -34,13 +34,13 @@ target_include_directories(
include(cmake/install_interface_library.cmake)
install_interface_library(${PROJECT_NAME} "include")

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTING)
include(CTest)
enable_testing()
add_subdirectory(tests)
endif()

option(BUILD_EXAMPLES "Build example programs" OFF)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_EXAMPLES)
if(PROJECT_IS_TOP_LEVEL AND BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
19 changes: 12 additions & 7 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re, os
import re
import os

from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
Expand Down Expand Up @@ -32,16 +33,20 @@ def set_version(self):
cmake_file = load(self, os.path.join(self.recipe_folder, "CMakeLists.txt"))
self.description = re.search(r"project\([^)]*DESCRIPTION\s+\"([^\"]+)\"[^)]*\)", cmake_file).group(1)

def layout(self):
cmake_layout(self)

def package_id(self):
self.info.header_only()

def package(self):
cmake = CMake(self)
cmake.configure()
cmake.install()

for dir in ("lib", "res", "share"):
rmdir(self, os.path.join(self.package_folder, dir))

copy(self, pattern="LICENSE*", dst="licenses", src=self.folders.source_folder)

def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []

self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.set_property("cmake_target_name", "dice-hash::dice-hash")
self.cpp_info.set_property("cmake_file_name", "dice-hash")
11 changes: 8 additions & 3 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from conan import ConanFile
from conan.tools.cmake import CMake
from conan.tools.layout import cmake_layout
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout

required_conan_version = ">=1.59"

Expand All @@ -10,6 +10,9 @@ class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

Expand All @@ -19,4 +22,6 @@ def build(self):
cmake.build()

def test(self):
self.run(os.path.join(self.cpp.build.bindirs[0], "example"), run_environment=True)
if can_run(self):
cmd = os.path.join(self.cpp.build.bindir, "example")
self.run(cmd, env="conanrun")

0 comments on commit 1dfc5d3

Please sign in to comment.