diff --git a/ports/lief/portfile.cmake b/ports/lief/portfile.cmake new file mode 100644 index 00000000000000..9558c168716947 --- /dev/null +++ b/ports/lief/portfile.cmake @@ -0,0 +1,216 @@ +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO lief-project/LIEF + REF ${VERSION} + SHA512 7df75fab6c7023e37a6a4d27fac8dcb4200e0235625fc5952bb23cedb2e582a37fb67ee471c1ae953c0b205fd9cca5538a835f65ef80a771f72dc7ff68000ed9 + HEAD_REF master +) + +file(REMOVE_RECURSE "${SOURCE_PATH}/third-party") + +vcpkg_replace_string("${SOURCE_PATH}/CMakeLists.txt" + "target_link_libraries(LIB_LIEF PRIVATE lief_spdlog)" + "find_package(fmt CONFIG REQUIRED)\nfind_package(spdlog CONFIG REQUIRED)\ntarget_link_libraries(LIB_LIEF PRIVATE fmt::fmt spdlog::spdlog)" +) + +vcpkg_replace_string("${SOURCE_PATH}/cmake/LIEFConfig.cmake.in" + [[if("${lib_type}" STREQUAL "static")]] + [[if(1)]] +) + +vcpkg_replace_string("${SOURCE_PATH}/cmake/LIEFConfig.cmake.in" + "include(CMakeFindDependencyMacro)" + "include(CMakeFindDependencyMacro)\nfind_dependency(tl-expected)\nfind_dependency(fmt)" +) + +vcpkg_replace_string("${SOURCE_PATH}/cmake/LIEFConfig.cmake.in" + "if(DEFINED LIEF_INCLUDE_DIR)" + "check_required_components(lief)\nif(DEFINED LIEF_INCLUDE_DIR)" +) + +vcpkg_replace_string("${SOURCE_PATH}/CMakeLists.txt" + "TARGETS LIB_LIEF lief_spdlog" + "TARGETS LIB_LIEF" +) + +vcpkg_replace_string("${SOURCE_PATH}/CMakeLists.txt" + [[set(CMAKE_INSTALL_LIBDIR "lib")]] + [[#set(CMAKE_INSTALL_LIBDIR "lib")]] +) +vcpkg_replace_string("${SOURCE_PATH}/CMakeLists.txt" + "set(CMAKE_INSTALL_LIBDIR \"lib\")" + "#[[set(CMAKE_INSTALL_LIBDIR \"lib\")" +) + +vcpkg_replace_string("${SOURCE_PATH}/CMakeLists.txt" + "set(CMAKE_INSTALL_DATAROOTDIR \"share\")" + "set(CMAKE_INSTALL_DATAROOTDIR \"share\")]]\nset(CMAKE_INSTALL_INCLUDEDIR \"include\")" +) + +vcpkg_replace_string("${SOURCE_PATH}/CMakeLists.txt" + "COMPONENT libraries" + " " +) + +vcpkg_replace_string("${SOURCE_PATH}/CMakeLists.txt" + [[ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}]] + " " +) + +vcpkg_replace_string("${SOURCE_PATH}/CMakeLists.txt" + [[RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}]] + " " +) + +vcpkg_replace_string("${SOURCE_PATH}/src/BinaryStream/BinaryStream.cpp" + [[#include "third-party/utfcpp.hpp"]] + [[#include ]] +) + +vcpkg_replace_string("${SOURCE_PATH}/src/utils.cpp" + [[#include "third-party/utfcpp.hpp"]] + [[#include ]] +) + +vcpkg_replace_string("${SOURCE_PATH}/src/PE/Builder.cpp" + [[#include "third-party/utfcpp.hpp"]] + [[#include ]] +) + +vcpkg_replace_string("${SOURCE_PATH}/src/logging.cpp" + [[#include "spdlog/fmt/bundled/args.h"]] + "#include " +) + +vcpkg_replace_string("${SOURCE_PATH}/src/logging.hpp" + "#include " + "#include \n#include " +) + +vcpkg_replace_string("${SOURCE_PATH}/src/utils.cpp" + "#include " + "#include \n#include " +) + +vcpkg_replace_string("${SOURCE_PATH}/src/internal_utils.hpp" + [[#include "spdlog/fmt/fmt.h"]] + "#include \n#include " +) + +vcpkg_replace_string("${SOURCE_PATH}/src/PE/Header.cpp" + "#include " + "#include \n#include " +) + +vcpkg_replace_string("${SOURCE_PATH}/src/PE/OptionalHeader.cpp" + "#include " + "#include \n#include " +) + +vcpkg_replace_string("${SOURCE_PATH}/src/PE/TLS.cpp" + [[#include "spdlog/fmt/fmt.h"]] + "#include \n#include " +) + +vcpkg_replace_string("${SOURCE_PATH}/src/MachO/BuildVersion.cpp" + "#include " + "#include \n#include " +) + +vcpkg_replace_string("${SOURCE_PATH}/src/MachO/SourceVersion.cpp" + [[#include "spdlog/fmt/fmt.h"]] + "#include \n#include " +) + +vcpkg_replace_string("${SOURCE_PATH}/src/MachO/DylibCommand.cpp" + [[#include "spdlog/fmt/fmt.h"]] + "#include \n#include " +) + +vcpkg_replace_string("${SOURCE_PATH}/src/MachO/VersionMin.cpp" + [[#include "spdlog/fmt/fmt.h"]] + "#include \n#include " +) + +if (VCPKG_TARGET_IS_LINUX) + vcpkg_replace_string("${SOURCE_PATH}/src/internal_utils.hpp" + [[#include "LIEF/iterators.hpp"]] + "#include \n#include " + ) +endif() + +vcpkg_replace_string("${SOURCE_PATH}/include/LIEF/errors.hpp" + [[#include ]] + "#include " +) + +vcpkg_replace_string("${SOURCE_PATH}/include/LIEF/span.hpp" + [[#include ]] + "#include " +) + +vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS + FEATURES + "c-api" LIEF_C_API # C API + "enable-json" LIEF_ENABLE_JSON # Enable JSON-related APIs + "examples" LIEF_EXAMPLES # Build LIEF C++ examples + "extra-warnings" LIEF_EXTRA_WARNINGS # Enable extra warning from the compiler + "logging" LIEF_LOGGING # Enable logging + "logging-debug" LIEF_LOGGING_DEBUG # Enable debug logging + + "use-ccache" LIEF_USE_CCACHE # Use ccache to speed up compilation + + "elf" LIEF_ELF # Build LIEF with ELF module + "pe" LIEF_PE # Build LIEF with PE module + "macho" LIEF_MACHO # Build LIEF with MachO module + + "oat" LIEF_OAT # Build LIEF with OAT module + "dex" LIEF_DEX # Build LIEF with DEX module + "vdex" LIEF_VDEX # Build LIEF with VDEX module + "art" LIEF_ART # Build LIEF with ART module + + "debug" LIEF_DEBUG_INFO # Build LIEF with DWARF/PDB support + "objc" LIEF_OBJC # Build LIEF with inspect Objective-C metadata support + "dyld-shared-cache" LIEF_DYLD_SHARED_CACHE # Build LIEF with dyld shared cache support + "asm" LIEF_ASM # Build LIEF with assembler/disassembler support +) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + ${FEATURE_OPTIONS} + + # Build with external vcpkg dependencies + -DLIEF_OPT_MBEDTLS_EXTERNAL=ON + -DLIEF_EXTERNAL_SPDLOG=ON + -DLIEF_OPT_NLOHMANN_JSON_EXTERNAL=ON + -DLIEF_OPT_FROZEN_EXTERNAL=ON + -DLIEF_OPT_EXTERNAL_SPAN=ON + -DLIEF_OPT_UTFCPP_EXTERNAL=ON + -DLIEF_OPT_EXTERNAL_EXPECTED=ON + -DLIEF_DISABLE_FROZEN=OFF + -DLIEF_DISABLE_EXCEPTIONS=OFF +) + +vcpkg_cmake_install() + +vcpkg_cmake_config_fixup(CONFIG_PATH "lib/cmake/LIEF") + +vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/share/lief/LIEFConfig.cmake" + [[include("${LIEF_${lib_type}_export}")]] + [[include("${CMAKE_CURRENT_LIST_DIR}/LIEFExport-${lib_type}.cmake")]] +) + +vcpkg_fixup_pkgconfig() + +if("debug" IN_LIST FEATURES) + vcpkg_copy_pdbs() +endif() + +file(REMOVE_RECURSE + "${CURRENT_PACKAGES_DIR}/debug/include" + "${CURRENT_PACKAGES_DIR}/debug/share" +) + +file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") diff --git a/ports/lief/usage b/ports/lief/usage new file mode 100644 index 00000000000000..8a738c9f0f8e6a --- /dev/null +++ b/ports/lief/usage @@ -0,0 +1,9 @@ +lief provides CMake targets: + + find_package(LIEF CONFIG REQUIRED) + target_link_libraries(main PRIVATE LIEF::LIEF) + +lief provides pkg-config modules: + + # Library to Instrument Executable Formats + LIEF \ No newline at end of file diff --git a/ports/lief/vcpkg.json b/ports/lief/vcpkg.json new file mode 100644 index 00000000000000..6c1ffa1efe8649 --- /dev/null +++ b/ports/lief/vcpkg.json @@ -0,0 +1,99 @@ +{ + "name": "lief", + "version-semver": "0.16.0", + "description": "LIEF - Library to Instrument Executable Formats", + "homepage": "https://lief.quarkslab.com", + "license": "Apache-2.0", + "dependencies": [ + "fmt", + "frozen", + "mbedtls", + "spdlog", + "tcb-span", + "tl-expected", + "utfcpp", + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ], + "default-features": [ + "art", + "c-api", + "dex", + "elf", + "enable-json", + "logging", + "macho", + "oat", + "pe", + "vdex" + ], + "features": { + "art": { + "description": "Build LIEF with ART module" + }, + "asm": { + "description": "Build LIEF with assembler/disassembler support", + "supports": "!(windows & !static)" + }, + "c-api": { + "description": "C API" + }, + "debug": { + "description": "Build LIEF with DWARF/PDB support", + "supports": "!(windows & !static)" + }, + "dex": { + "description": "Build LIEF with DEX module" + }, + "dyld-shared-cache": { + "description": "Build LIEF with Dyld shared cache support", + "supports": "!(windows & !static)" + }, + "elf": { + "description": "Build LIEF with ELF module" + }, + "enable-json": { + "description": "Enable JSON-related APIs", + "dependencies": [ + "nlohmann-json" + ] + }, + "examples": { + "description": "Build LIEF C++ examples" + }, + "extra-warnings": { + "description": "Enable extra warning from the compiler" + }, + "logging": { + "description": "Enable logging" + }, + "logging-debug": { + "description": "Enable debug logging" + }, + "macho": { + "description": "Build LIEF with MachO module" + }, + "oat": { + "description": "Build LIEF with OAT module" + }, + "objc": { + "description": "Build LIEF with ObjC metadata support", + "supports": "!(windows & !static)" + }, + "pe": { + "description": "Build LIEF with PE module" + }, + "use-ccache": { + "description": "Use ccache to speed up compilation" + }, + "vdex": { + "description": "Build LIEF with VDEX module" + } + } +} diff --git a/scripts/test_ports/vcpkg-ci-lief/portfile.cmake b/scripts/test_ports/vcpkg-ci-lief/portfile.cmake new file mode 100644 index 00000000000000..11e54c088578a0 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-lief/portfile.cmake @@ -0,0 +1,7 @@ +SET(VCPKG_POLICY_EMPTY_PACKAGE enabled) + +vcpkg_cmake_configure( + SOURCE_PATH "${CURRENT_PORT_DIR}/project" +) + +vcpkg_cmake_build() \ No newline at end of file diff --git a/scripts/test_ports/vcpkg-ci-lief/project/CMakeLists.txt b/scripts/test_ports/vcpkg-ci-lief/project/CMakeLists.txt new file mode 100644 index 00000000000000..545650d59ed497 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-lief/project/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.24) + +project(vcpkg-ci-lief LANGUAGES C CXX) + +set(CMAKE_CXX_STANDARD 14) + +find_package(LIEF CONFIG REQUIRED) + +add_executable(main main.cpp) + +target_link_libraries(main PRIVATE LIEF::LIEF) diff --git a/scripts/test_ports/vcpkg-ci-lief/project/main.cpp b/scripts/test_ports/vcpkg-ci-lief/project/main.cpp new file mode 100644 index 00000000000000..ea2490fb7c62fc --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-lief/project/main.cpp @@ -0,0 +1,11 @@ +#include +#include +#include +using namespace std; +using namespace LIEF; +int main() +{ + std::cout << "access flags public = " << LIEF::DEX::to_string(LIEF::DEX::access_flags_list[1]) << std::endl; + std::cout << "Version = " << LIEF_VERSION << std::endl; + return 0; +} \ No newline at end of file diff --git a/scripts/test_ports/vcpkg-ci-lief/vcpkg.json b/scripts/test_ports/vcpkg-ci-lief/vcpkg.json new file mode 100644 index 00000000000000..2bab34a57ba74c --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-lief/vcpkg.json @@ -0,0 +1,13 @@ +{ + "name": "vcpkg-ci-lief", + "version-string": "ci", + "description": "Testing packages which provide lief", + "license": null, + "dependencies": [ + "lief", + { + "name": "vcpkg-cmake", + "host": true + } + ] +} \ No newline at end of file diff --git a/versions/baseline.json b/versions/baseline.json index 139148aadd76de..6d0e958a1b2891 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -5524,6 +5524,10 @@ "baseline": "2020-11-24", "port-version": 0 }, + "lief": { + "baseline": "0.16.0", + "port-version": 0 + }, "lightgbm": { "baseline": "4.5.0", "port-version": 0 diff --git a/versions/l-/lief.json b/versions/l-/lief.json new file mode 100644 index 00000000000000..e41a2d69f254ea --- /dev/null +++ b/versions/l-/lief.json @@ -0,0 +1,9 @@ +{ + "versions": [ + { + "git-tree": "aff018b24b685b86596713f8819c4e3d13d1e6d4", + "version-semver": "0.16.0", + "port-version": 0 + } + ] +}