-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libcap/2.65 + conan v2 compatibility #12241
Changes from all commits
dbde3bd
5d61048
657eb43
0b20246
e01ccdc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(PackageTest C) | ||
cmake_minimum_required(VERSION 3.15) | ||
project(PackageTest LANGUAGES C) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
find_package(PkgConfig REQUIRED) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add pkgconf to build_requirements of test_package There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
pkg_check_modules(CAP REQUIRED IMPORTED_TARGET libcap) | ||
|
||
add_executable(example example.c) | ||
target_link_libraries(example ${CONAN_LIBS}) | ||
target_link_libraries(example PRIVATE PkgConfig::CAP) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,40 @@ | ||
import os | ||
|
||
from conans import ConanFile, CMake, tools | ||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import CMake | ||
from conan.tools.env import Environment | ||
from conan.tools.cmake import cmake_layout | ||
|
||
required_conan_version = ">=1.38.0" | ||
|
||
|
||
class LibcapTestConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake" | ||
generators = "CMakeToolchain", "PkgConfigDeps", "VirtualBuildEnv" | ||
test_type = "explicit" | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def build_requirements(self): | ||
self.tool_requires("pkgconf/1.7.4") | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def generate(self): | ||
env = Environment() | ||
env.prepend_path("PKG_CONFIG_PATH", self.generators_folder) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👋 @franramirez688 @czoido is this the right way to use CMakeToolchain and PkgConfigDeps generators together? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After digging deeper into it, I figured out that CMake is adding the suffix
Yes, you're right, but it should not be necessary as far as CMake should use that
Given that information, I tend to say that yes, it could be one way to solve that issue, and I think there could be another workaround like: def build(self):
pkg_lib_folder = os.path.join(self.generators_folder, "lib", "pkgconfig")
copy(self, "*.pc", self.generators_folder, pkg_lib_folder)
cmake = CMake(self)
cmake.configure()
cmake.build() Anyway, we could discuss if it could be a chance to create a mechanism to add the |
||
envvars = env.vars(self) | ||
envvars.save_script("pkg_config") | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if not tools.cross_building(self.settings): | ||
bin_path = os.path.join("bin", "example") | ||
self.run(bin_path, run_environment=True) | ||
if can_run(self): | ||
bin_path = os.path.join(self.cpp.build.bindirs[0], "example") | ||
self.run(bin_path, env="conanrun") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(PackageTest C) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
|
||
find_package(PkgConfig REQUIRED) | ||
pkg_check_modules(CAP REQUIRED IMPORTED_TARGET libcap) | ||
|
||
add_executable(example ../test_package/example.c) | ||
target_link_libraries(example PRIVATE PkgConfig::CAP) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
|
||
from conan import ConanFile | ||
from conan.tools.build import cross_building | ||
from conans import CMake | ||
|
||
|
||
class LibcapTestConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake", "pkg_config" | ||
|
||
def build_requirements(self): | ||
self.tool_requires("pkgconf/1.7.4") | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if not cross_building(self): | ||
bin_path = os.path.join("bin", "example") | ||
self.run(bin_path, run_environment=True) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ versions: | |
folder: all | ||
"2.62": | ||
folder: all | ||
"2.65": | ||
folder: all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I'm trying to build a test package with this line, I get a warning: "(test package): WARN: [libcap/2.65] The PC package name libcap.pc already exists and it matches with another component one. Please, review all the component's pkg_config_name defined. Skipping it!". But I don't know how to figure out what's wrong here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because there's a global one by default for v1 generators.
You need to set a root level one like AFAIK (not an expert just say that in another PR I reviewed recently)