forked from conan-io/conan-center-index
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(conan-io#18681) libelfin: migrate to Conan v2
* libelfin: migrate to Conan v2 * libelfin: restore VirtualRunEnv in test_package * libelfin: fix v1 build * libelfin: fix patched sources not being used * libelfin: add legacy pkg_config names --------- Co-authored-by: Francisco Ramírez <franchuti688@gmail.com>
- Loading branch information
1 parent
39ac1ed
commit 0c3c53e
Showing
7 changed files
with
122 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,82 @@ | ||
import os | ||
from conans import ConanFile, CMake, tools | ||
from conans.errors import ConanInvalidConfiguration | ||
from conan import ConanFile | ||
from conan.errors import ConanInvalidConfiguration | ||
from conan.tools.build import check_min_cppstd | ||
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout | ||
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get | ||
from conan.tools.microsoft import is_msvc | ||
|
||
required_conan_version = ">=1.53.0" | ||
|
||
|
||
class LibelfinConan(ConanFile): | ||
name = "libelfin" | ||
description = "C++11 library for reading ELF binaries and DWARFv4 debug information" | ||
license = "MIT" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://github.com/aclements/libelfin" | ||
license = "MIT" | ||
topics = ("conan", "elf", "dwarf", "libelfin") | ||
topics = ("elf", "dwarf") | ||
|
||
package_type = "library" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = {"shared": [True, False], "fPIC": [True, False]} | ||
default_options = {"shared": False, "fPIC": True} | ||
|
||
exports_sources = "CMakeLists.txt", "patches/*" | ||
generators = "cmake" | ||
options = { | ||
"shared": [True, False], | ||
"fPIC": [True, False], | ||
} | ||
default_options = { | ||
"shared": False, | ||
"fPIC": True, | ||
} | ||
|
||
_cmake = None | ||
_source_subfolder = "source_subfolder" | ||
def export_sources(self): | ||
copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder) | ||
export_conandata_patches(self) | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
def configure(self): | ||
if self.settings.compiler == "Visual Studio": | ||
raise ConanInvalidConfiguration("libelfin doesn't support compiler: {} on OS: {}.". | ||
format(self.settings.compiler, self.settings.os)) | ||
if self.options.shared: | ||
del self.options.fPIC | ||
if self.settings.compiler.cppstd: | ||
tools.check_min_cppstd(self, "11") | ||
self.options.rm_safe("fPIC") | ||
|
||
def layout(self): | ||
cmake_layout(self, src_folder="src") | ||
|
||
def validate(self): | ||
if self.settings.compiler.get_safe("cppstd"): | ||
check_min_cppstd(self, 11) | ||
if is_msvc(self): | ||
raise ConanInvalidConfiguration(f"libelfin doesn't support compiler: {self.settings.compiler}.") | ||
|
||
def source(self): | ||
tools.get(**self.conan_data["sources"][self.version]) | ||
extracted_dir = self.name + "-" + self.version | ||
os.rename(extracted_dir, self._source_subfolder) | ||
get(self, **self.conan_data["sources"][self.version], strip_root=True) | ||
|
||
def _configure_cmake(self): | ||
if self._cmake: | ||
return self._cmake | ||
self._cmake = CMake(self) | ||
self._cmake.configure() | ||
return self._cmake | ||
def generate(self): | ||
tc = CMakeToolchain(self) | ||
tc.variables["libelfin_VERSION"] = self.version | ||
tc.generate() | ||
|
||
def _patch_sources(self): | ||
apply_conandata_patches(self) | ||
copy(self, "CMakeLists.txt", src=self.export_sources_folder, dst=self.source_folder) | ||
|
||
def build(self): | ||
for patch in self.conan_data.get("patches", {}).get(self.version, []): | ||
tools.patch(**patch) | ||
cmake = self._configure_cmake() | ||
self._patch_sources() | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def package(self): | ||
cmake = self._configure_cmake() | ||
cmake = CMake(self) | ||
cmake.install() | ||
|
||
def package_info(self): | ||
self.cpp_info.components["libelf++"].names["pkg_config"] = "libelf++" | ||
self.cpp_info.components["libelf++"].set_property("pkg_config_name", "libelf++") | ||
self.cpp_info.components["libelf++"].libs = ["elf++"] | ||
self.cpp_info.components["libdwarf++"].names["pkg_config"] = "libdwarf++" | ||
self.cpp_info.components["libdwarf++"].set_property("pkg_config_name", "libdwarf++") | ||
self.cpp_info.components["libdwarf++"].libs = ["dwarf++"] | ||
self.cpp_info.components["libdwarf++"].requires = ["libelf++"] | ||
|
||
# TODO: Legacy, to be removed on Conan 2.0 | ||
self.cpp_info.components["libelf++"].names["pkg_config"] = "libelf++" | ||
self.cpp_info.components["libdwarf++"].names["pkg_config"] = "libdwarf++" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
cmake_minimum_required(VERSION 3.15) | ||
project(test_package CXX) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
find_package(libelfin REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.cpp) | ||
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE libelfin::libelfin) | ||
set_target_properties(${PROJECT_NAME} PROPERTIES | ||
CXX_STANDARD 11 | ||
CXX_STANDARD_REQUIRED ON) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
from conans import ConanFile, CMake, tools | ||
import os | ||
|
||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import cmake_layout, CMake | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake" | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" | ||
test_type = "explicit" | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if tools.cross_building(self.settings): | ||
return | ||
bin_path = os.path.join("bin", "test_package") | ||
elf_path = os.path.join(self.source_folder, "hello") | ||
self.run("{} {}".format(bin_path, elf_path), run_environment=True) | ||
if can_run(self): | ||
bin_path = os.path.join(self.cpp.build.bindir, "test_package") | ||
elf_path = os.path.join(self.source_folder, "hello") | ||
self.run(f"{bin_path} {elf_path}", env="conanrun") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
project(test_package) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup(TARGETS) | ||
|
||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ | ||
${CMAKE_CURRENT_BINARY_DIR}/test_package/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from conans import ConanFile, CMake, tools | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake", "cmake_find_package_multi" | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if tools.cross_building(self.settings): | ||
return | ||
bin_path = os.path.join("bin", "test_package") | ||
elf_path = os.path.join(self.source_folder, os.pardir, "test_package", "hello") | ||
self.run(f"{bin_path} {elf_path}", run_environment=True) |