diff --git a/recipes/libelfin/all/CMakeLists.txt b/recipes/libelfin/all/CMakeLists.txt index eb2aa34b81ac86..98010e37969935 100644 --- a/recipes/libelfin/all/CMakeLists.txt +++ b/recipes/libelfin/all/CMakeLists.txt @@ -1,9 +1,6 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.12) project(libelfin CXX) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() - if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 11) endif() @@ -11,19 +8,21 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(PythonInterp 3 REQUIRED) -file(GLOB_RECURSE elf_sources source_subfolder/elf/*.cc) +set(src ${CMAKE_CURRENT_LIST_DIR}) + +file(GLOB_RECURSE elf_sources ${src}/elf/*.cc) set(elf_headers - source_subfolder/elf/common.hh - source_subfolder/elf/data.hh - source_subfolder/elf/elf++.hh) -file(GLOB_RECURSE dwarf_sources source_subfolder/dwarf/*.cc) + ${src}/elf/common.hh + ${src}/elf/data.hh + ${src}/elf/elf++.hh) +file(GLOB_RECURSE dwarf_sources ${src}/dwarf/*.cc) set(dwarf_headers - source_subfolder/dwarf/data.hh - source_subfolder/dwarf/dwarf++.hh - source_subfolder/dwarf/small_vector.hh) + ${src}/dwarf/data.hh + ${src}/dwarf/dwarf++.hh + ${src}/dwarf/small_vector.hh) add_custom_command( - OUTPUT source_subfolder/elf/to_string.cc + OUTPUT ${src}/elf/to_string.cc COMMAND ${CMAKE_COMMAND} -E echo '// Automatically generated' > to_string.cc COMMAND ${CMAKE_COMMAND} -E echo '// DO NOT EDIT' >> to_string.cc COMMAND ${CMAKE_COMMAND} -E echo >> to_string.cc @@ -34,11 +33,11 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E echo >> to_string.cc COMMAND ${PYTHON_EXECUTABLE} enum-print.py -u --hex --no-type --mask shf --mask pf -x loos -x hios -x loproc -x hiproc < data.hh >> to_string.cc COMMAND ${CMAKE_COMMAND} -E echo 'ELFPP_END_NAMESPACE' >> to_string.cc - DEPENDS source_subfolder/elf/enum-print.py source_subfolder/elf/data.hh - WORKING_DIRECTORY source_subfolder/elf) + DEPENDS ${src}/elf/enum-print.py ${src}/elf/data.hh + WORKING_DIRECTORY ${src}/elf) add_custom_command( - OUTPUT source_subfolder/dwarf/to_string.cc + OUTPUT ${src}/dwarf/to_string.cc COMMAND ${CMAKE_COMMAND} -E echo '// Automatically generated' > to_string.cc COMMAND ${CMAKE_COMMAND} -E echo '// DO NOT EDIT' >> to_string.cc COMMAND ${CMAKE_COMMAND} -E echo >> to_string.cc @@ -49,29 +48,23 @@ add_custom_command( COMMAND ${PYTHON_EXECUTABLE} ../elf/enum-print.py < dwarf++.hh >> to_string.cc COMMAND ${PYTHON_EXECUTABLE} ../elf/enum-print.py -s _ -u --hex -x hi_user -x lo_user < data.hh >> to_string.cc COMMAND ${CMAKE_COMMAND} -E echo 'DWARFPP_END_NAMESPACE' >> to_string.cc - DEPENDS source_subfolder/elf/enum-print.py source_subfolder/dwarf/data.hh - WORKING_DIRECTORY source_subfolder/dwarf) + DEPENDS ${src}/elf/enum-print.py ${src}/dwarf/data.hh + WORKING_DIRECTORY ${src}/dwarf) -add_library(elf++ ${elf_sources} source_subfolder/elf/to_string.cc) +add_library(elf++ ${elf_sources} ${src}/elf/to_string.cc) set_target_properties(elf++ PROPERTIES PUBLIC_HEADER "${elf_headers}" - VERSION ${CONAN_PACKAGE_VERSION}) + VERSION ${libelfin_VERSION}) -add_library(dwarf++ ${dwarf_sources} source_subfolder/dwarf/to_string.cc) +add_library(dwarf++ ${dwarf_sources} ${src}/dwarf/to_string.cc) set_target_properties(dwarf++ PROPERTIES PUBLIC_HEADER "${dwarf_headers}" - VERSION ${CONAN_PACKAGE_VERSION}) + VERSION ${libelfin_VERSION}) include(GNUInstallDirs) install(TARGETS elf++ - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libelfin/elf) install(TARGETS dwarf++ - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libelfin/dwarf) -install(FILES source_subfolder/LICENSE DESTINATION licenses) +install(FILES ${src}/LICENSE DESTINATION licenses) diff --git a/recipes/libelfin/all/conandata.yml b/recipes/libelfin/all/conandata.yml index e1b6341e831851..c74c8954691d87 100644 --- a/recipes/libelfin/all/conandata.yml +++ b/recipes/libelfin/all/conandata.yml @@ -5,7 +5,6 @@ sources: patches: "0.3": - patch_file: "patches/commit-9d0db16d0a0b3c4f8aaa60a3e4dab295df34b6b2.patch" - base_path: "source_subfolder" - patch_file: "patches/const-fix.patch" - base_path: "source_subfolder" - # patch_source: https://github.com/aclements/libelfin/pull/54 + patch_source: "https://github.com/aclements/libelfin/pull/54" + patch_type: "bugfix" diff --git a/recipes/libelfin/all/conanfile.py b/recipes/libelfin/all/conanfile.py index d53acbbfd0abe4..852c1494c8a650 100644 --- a/recipes/libelfin/all/conanfile.py +++ b/recipes/libelfin/all/conanfile.py @@ -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++" diff --git a/recipes/libelfin/all/test_package/CMakeLists.txt b/recipes/libelfin/all/test_package/CMakeLists.txt index 36df85d833b7f2..3d1d60bfa18346 100644 --- a/recipes/libelfin/all/test_package/CMakeLists.txt +++ b/recipes/libelfin/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/libelfin/all/test_package/conanfile.py b/recipes/libelfin/all/test_package/conanfile.py index e2a48eb337ec0b..c2a19b9121acf4 100644 --- a/recipes/libelfin/all/test_package/conanfile.py +++ b/recipes/libelfin/all/test_package/conanfile.py @@ -1,10 +1,20 @@ -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) @@ -12,8 +22,7 @@ def build(self): 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") diff --git a/recipes/libelfin/all/test_v1_package/CMakeLists.txt b/recipes/libelfin/all/test_v1_package/CMakeLists.txt new file mode 100644 index 00000000000000..91630d79f4abb3 --- /dev/null +++ b/recipes/libelfin/all/test_v1_package/CMakeLists.txt @@ -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/) diff --git a/recipes/libelfin/all/test_v1_package/conanfile.py b/recipes/libelfin/all/test_v1_package/conanfile.py new file mode 100644 index 00000000000000..fe9ecdf1845cc5 --- /dev/null +++ b/recipes/libelfin/all/test_v1_package/conanfile.py @@ -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)