Skip to content
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

Libsigcpp conanv2 #12775

Closed
Closed
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
97 changes: 52 additions & 45 deletions recipes/libsigcpp/2.x.x/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
from conans import ConanFile, Meson, tools
from conan.tools.files import rename
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.tools.build import check_min_cppstd, cross_building
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import (
get,
rename,
replace_in_file,
rm,
rmdir
)
from conan.tools.gnu import PkgConfigDeps
from conan.tools.layout import basic_layout
from conan.tools.meson import Meson, MesonToolchain
from conan.errors import ConanInvalidConfiguration

import glob
import os
import shutil

required_conan_version = ">=1.43.0"
required_conan_version = ">=1.54.0"


class LibSigCppConanV2(ConanFile):
Expand All @@ -26,71 +38,67 @@ class LibSigCppConanV2(ConanFile):
"fPIC": True,
}

generators = "pkg_config"
short_paths = True

def validate(self):
if hasattr(self, "settings_build") and tools.cross_building(self):
if hasattr(self, "settings_build") and cross_building(self):
raise ConanInvalidConfiguration("Cross-building not implemented")
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 11)

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"
check_min_cppstd(self, 11)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
self.options.rm_safe("fPIC")

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")

def build_requirements(self):
self.build_requires("meson/0.59.1")
self.build_requires("pkgconf/1.7.4")
self.tool_requires("meson/0.63.3")
self.tool_requires("pkgconf/1.9.3")

def layout(self):
basic_layout(self, src_folder="src")

def generate(self):
deps = PkgConfigDeps(self)
deps.generate()

tc = MesonToolchain(self)
tc.project_options.update({
"build-examples": "false",
"build-documentation": "false",
"default_library": "shared" if self.options.shared else "static"
})
tc.generate()

env = VirtualBuildEnv(self)
env.generate()

def source(self):
tools.get(
get(self,
**self.conan_data["sources"][self.version],
strip_root=True,
destination=self._source_subfolder
destination=self.source_folder
)

def build(self):
if not self.options.shared:
tools.replace_in_file(
os.path.join(self._source_subfolder, "sigc++config.h.meson"),
replace_in_file(self,
os.path.join(self.source_folder, "sigc++config.h.meson"),
"define SIGC_DLL 1", "undef SIGC_DLL")
with tools.environment_append(tools.RunEnvironment(self).vars):
meson = self._configure_meson()
meson.build()

def _configure_meson(self):
replace_in_file(self, os.path.join(self.source_folder, "meson.build"), "subdir('tests')", "")
meson = Meson(self)
defs = {}
defs["build-examples"] = "false"
defs["build-documentation"] = "false"
defs["default_library"] = "shared" if self.options.shared else "static"
meson.configure(
defs=defs,
build_folder=self._build_subfolder,
source_folder=self._source_subfolder,
pkg_config_paths=[self.install_folder],
)
return meson
meson.configure()
meson.build()

def package(self):
self.copy("COPYING", dst="licenses", src=self._source_subfolder)
meson = self._configure_meson()
self.copy("COPYING", dst="licenses", src=self.source_folder)
meson = Meson(self)
meson.install()
if self.settings.compiler == "Visual Studio":
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "*.pdb")
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))
if not self.options.shared:
rename(self,
os.path.join(self.package_folder, "lib", "libsigc-2.0.a"),
Expand All @@ -104,10 +112,9 @@ def package(self):
)

for dir_to_remove in ["pkgconfig", "sigc++-2.0"]:
tools.rmdir(os.path.join(
self.package_folder, "lib", dir_to_remove))
rmdir(self, os.path.join(self.package_folder, "lib", dir_to_remove))

def package_info(self):
self.cpp_info.components["sigc++-2.0"].names["pkg_config"] = "sigc++-2.0"
self.cpp_info.components["sigc++-2.0"].set_property("pkg_config_name", "sigc++-2.0")
self.cpp_info.components["sigc++-2.0"].includedirs.append(os.path.join("include", "sigc++-2.0"))
self.cpp_info.components["sigc++-2.0"].libs = ["sigc-2.0"]
5 changes: 1 addition & 4 deletions recipes/libsigcpp/2.x.x/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
cmake_minimum_required(VERSION 3.6)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGET)

find_package(PkgConfig REQUIRED)
pkg_search_module(SIGCPP IMPORTED_TARGET REQUIRED sigc++-2.0)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't appear to work with the new PkgConfigDeps generator - not sure if the recipe is missing something or there's an existing issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You touched a known bug: conan-io/conan#11962

Basically you need a workaround to use pkg_search_module with new cmake generators: https://github.com/conan-io/conan-center-index/blob/master/recipes/libcap/all/test_package/conanfile.py

Not beautiful, but should work.

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PkgConfig::SIGCPP)
target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::SIGCPP)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
29 changes: 23 additions & 6 deletions recipes/libsigcpp/2.x.x/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.env import Environment
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.build import can_run

import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "pkg_config"
generators = "CMakeToolchain", "PkgConfigDeps", "VirtualRunEnv", "VirtualBuildEnv"
test_type = "explicit"

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

def build_requirements(self):
self.build_requires("pkgconf/1.7.4")
self.tool_requires("pkgconf/1.9.3")

def layout(self):
cmake_layout(self)

def generate(self):
env = Environment()
env.prepend_path("PKG_CONFIG_PATH", self.generators_folder)
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):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
11 changes: 11 additions & 0 deletions recipes/libsigcpp/2.x.x/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.6)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

find_package(PkgConfig REQUIRED)
pkg_search_module(SIGCPP IMPORTED_TARGET REQUIRED sigc++-2.0)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
20 changes: 20 additions & 0 deletions recipes/libsigcpp/2.x.x/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package", "pkg_config"

def build_requirements(self):
self.build_requires("pkgconf/1.9.3")

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
7 changes: 0 additions & 7 deletions recipes/libsigcpp/3.x.x/CMakeLists.txt

This file was deleted.

2 changes: 0 additions & 2 deletions recipes/libsigcpp/3.x.x/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ sources:
patches:
"3.0.7":
- patch_file: "patches/3.0.7-0001-libsigcpp.patch"
base_path: "source_subfolder"
"3.0.0":
- patch_file: "patches/3.0.0-0001-libsigcpp.patch"
base_path: "source_subfolder"
Loading