Skip to content

Commit 7bac262

Browse files
[lief] add new port LIEF-0.16.0 (microsoft#42374)
Co-authored-by: WangWeiLin-MV <[email protected]>
1 parent 78030b6 commit 7bac262

File tree

11 files changed

+352
-0
lines changed

11 files changed

+352
-0
lines changed

ports/lief/fix-cmakelists.patch

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index fc2b679..4ec92b9 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -113,19 +113,7 @@ message(STATUS "CMAKE_CXX_IMPLICIT_LINK_LIBRARIES: ${CMAKE_CXX_IMPLICIT_LINK_LIB
6+
message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
7+
message(STATUS "CMAKE_MSVC_RUNTIME_LIBRARY: ${CMAKE_MSVC_RUNTIME_LIBRARY}")
8+
9+
-if(LIEF_INSTALL)
10+
- if(UNIX)
11+
- include(GNUInstallDirs)
12+
- set(CMAKE_INSTALL_LIBDIR "lib")
13+
- else()
14+
- set(CMAKE_INSTALL_LIBDIR "lib")
15+
- set(CMAKE_INSTALL_DATADIR "share")
16+
set(CMAKE_INSTALL_INCLUDEDIR "include")
17+
- set(CMAKE_INSTALL_BINDIR "bin")
18+
- set(CMAKE_INSTALL_DATAROOTDIR "share")
19+
- message(STATUS "Setting installation destination to: ${CMAKE_INSTALL_PREFIX}")
20+
- endif()
21+
-endif()
22+
23+
# LIEF Source definition
24+
# ======================
25+
@@ -318,7 +306,9 @@ else()
26+
${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/third-party/internal/span.hpp)
27+
endif()
28+
29+
-target_link_libraries(LIB_LIEF PRIVATE lief_spdlog)
30+
+find_package(fmt CONFIG REQUIRED)
31+
+find_package(spdlog CONFIG REQUIRED)
32+
+target_link_libraries(LIB_LIEF PRIVATE fmt::fmt spdlog::spdlog)
33+
34+
if(ANDROID AND LIEF_LOGGING)
35+
target_link_libraries(LIB_LIEF PUBLIC log)
36+
@@ -507,11 +497,11 @@ if(LIEF_INSTALL)
37+
endif()
38+
39+
install(
40+
- TARGETS LIB_LIEF lief_spdlog
41+
+ TARGETS LIB_LIEF
42+
EXPORT LIEFExport
43+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
44+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
45+
- RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries
46+
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libraries
47+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
48+
49+
install(
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
diff --git a/cmake/LIEFConfig.cmake.in b/cmake/LIEFConfig.cmake.in
2+
index dba7363..7f88f98 100644
3+
--- a/cmake/LIEFConfig.cmake.in
4+
+++ b/cmake/LIEFConfig.cmake.in
5+
@@ -69,7 +69,7 @@ macro(LIEF_load_targets lib_type)
6+
return()
7+
endif ()
8+
9+
- if("${lib_type}" STREQUAL "static")
10+
+ if(1)
11+
# Need to find all dependencies even if they're private when LIEF is
12+
# compiled statically
13+
include(CMakeFindDependencyMacro)
14+
@@ -93,6 +93,10 @@ macro(LIEF_load_targets lib_type)
15+
if(NOT @LIEF_DISABLE_FROZEN@ AND @LIEF_OPT_FROZEN_EXTERNAL@)
16+
find_dependency(frozen)
17+
endif()
18+
+
19+
+ find_dependency(tl-expected)
20+
+ find_dependency(fmt)
21+
+ check_required_components(lief)
22+
endif()
23+
24+
# Include the respective targets file

ports/lief/fix-vcpkg-includes.patch

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
diff --git a/src/BinaryStream/BinaryStream.cpp b/src/BinaryStream/BinaryStream.cpp
2+
index 83e618c..6447b7b 100644
3+
--- a/src/BinaryStream/BinaryStream.cpp
4+
+++ b/src/BinaryStream/BinaryStream.cpp
5+
@@ -15,7 +15,7 @@
6+
*/
7+
#include "LIEF/BinaryStream/BinaryStream.hpp"
8+
#include "LIEF/DWARF/enums.hpp"
9+
-#include "third-party/utfcpp.hpp"
10+
+#include <utf8cpp/utf8.h>
11+
12+
#include <mbedtls/x509.h>
13+
#include <mbedtls/x509_crt.h>
14+
diff --git a/src/PE/Builder.cpp b/src/PE/Builder.cpp
15+
index 8cbe7b2..994e9bf 100644
16+
--- a/src/PE/Builder.cpp
17+
+++ b/src/PE/Builder.cpp
18+
@@ -21,7 +21,7 @@
19+
20+
#include "logging.hpp"
21+
22+
-#include "third-party/utfcpp.hpp"
23+
+#include <utf8cpp/utf8.h>
24+
25+
26+
#include "LIEF/PE/Builder.hpp"
27+
diff --git a/src/logging.cpp b/src/logging.cpp
28+
index 39936fe..f5e1345 100644
29+
--- a/src/logging.cpp
30+
+++ b/src/logging.cpp
31+
@@ -20,7 +20,7 @@
32+
#include "logging.hpp"
33+
34+
#include "spdlog/spdlog.h"
35+
-#include "spdlog/fmt/bundled/args.h"
36+
+#include <fmt/args.h>
37+
#include "spdlog/sinks/stdout_color_sinks.h"
38+
#include "spdlog/sinks/basic_file_sink.h"
39+
#include "spdlog/sinks/android_sink.h"
40+
diff --git a/src/utils.cpp b/src/utils.cpp
41+
index 0acbba1..b624a1d 100644
42+
--- a/src/utils.cpp
43+
+++ b/src/utils.cpp
44+
@@ -22,7 +22,7 @@
45+
#include "LIEF/utils.hpp"
46+
#include "LIEF/errors.hpp"
47+
48+
-#include "third-party/utfcpp.hpp"
49+
+#include <utf8cpp/utf8.h>
50+
51+
#include "LIEF/config.h"
52+
#include "logging.hpp"

ports/lief/portfile.cmake

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
vcpkg_download_distfile(
2+
FIX_FMT_V11_JOIN_LINUX_INCLUDE_MEMORY_PATCH
3+
URLS https://github.com/lief-project/LIEF/commit/41166332a2435fdb7d2bdc5c73f9ff9b442c5459.patch?full_index=1
4+
FILENAME fix-fmt-v11-join-linux-include-memory-41166332a2435fdb7d2bdc5c73f9ff9b442c5459.patch
5+
SHA512 14d5f7380352bd340c16447905b8185dbd2d977c8ba245e01d982fe7fbbdffb71004b9d4fdd732bc13e71a11aa3f46a4822cdeb2277e2cec6b841492d0de5606
6+
)
7+
8+
vcpkg_from_github(
9+
OUT_SOURCE_PATH SOURCE_PATH
10+
REPO lief-project/LIEF
11+
REF ${VERSION}
12+
SHA512 7df75fab6c7023e37a6a4d27fac8dcb4200e0235625fc5952bb23cedb2e582a37fb67ee471c1ae953c0b205fd9cca5538a835f65ef80a771f72dc7ff68000ed9
13+
HEAD_REF master
14+
PATCHES
15+
fix-cmakelists.patch
16+
fix-liefconfig-cmake-in.patch
17+
fix-vcpkg-includes.patch
18+
"${FIX_FMT_V11_JOIN_LINUX_INCLUDE_MEMORY_PATCH}"
19+
)
20+
21+
file(REMOVE_RECURSE "${SOURCE_PATH}/third-party")
22+
23+
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
24+
FEATURES
25+
"c-api" LIEF_C_API # C API
26+
"enable-json" LIEF_ENABLE_JSON # Enable JSON-related APIs
27+
"extra-warnings" LIEF_EXTRA_WARNINGS # Enable extra warning from the compiler
28+
"logging" LIEF_LOGGING # Enable logging
29+
"logging-debug" LIEF_LOGGING_DEBUG # Enable debug logging
30+
31+
"use-ccache" LIEF_USE_CCACHE # Use ccache to speed up compilation
32+
33+
"elf" LIEF_ELF # Build LIEF with ELF module
34+
"pe" LIEF_PE # Build LIEF with PE module
35+
"macho" LIEF_MACHO # Build LIEF with MachO module
36+
37+
"oat" LIEF_OAT # Build LIEF with OAT module
38+
"dex" LIEF_DEX # Build LIEF with DEX module
39+
"vdex" LIEF_VDEX # Build LIEF with VDEX module
40+
"art" LIEF_ART # Build LIEF with ART module
41+
)
42+
43+
vcpkg_cmake_configure(
44+
SOURCE_PATH "${SOURCE_PATH}"
45+
OPTIONS
46+
${FEATURE_OPTIONS}
47+
-DLIEF_EXAMPLES=OFF
48+
49+
# Build with external vcpkg dependencies
50+
-DLIEF_OPT_MBEDTLS_EXTERNAL=ON
51+
-DLIEF_EXTERNAL_SPDLOG=ON
52+
-DLIEF_OPT_NLOHMANN_JSON_EXTERNAL=ON
53+
-DLIEF_OPT_FROZEN_EXTERNAL=ON
54+
-DLIEF_OPT_EXTERNAL_SPAN=ON
55+
-DLIEF_OPT_UTFCPP_EXTERNAL=ON
56+
-DLIEF_OPT_EXTERNAL_EXPECTED=ON
57+
-DLIEF_DISABLE_FROZEN=OFF
58+
-DLIEF_DISABLE_EXCEPTIONS=OFF
59+
60+
"-DLIEF_EXTERNAL_SPAN_DIR=${_VCPKG_INSTALLED_DIR}/${TARGET_TRIPLET}/include/tcb"
61+
)
62+
63+
vcpkg_cmake_install()
64+
65+
vcpkg_cmake_config_fixup(CONFIG_PATH "lib/cmake/LIEF")
66+
67+
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/share/lief/LIEFConfig.cmake"
68+
[[include("${LIEF_${lib_type}_export}")]]
69+
[[include("${CMAKE_CURRENT_LIST_DIR}/LIEFExport-${lib_type}.cmake")]]
70+
)
71+
72+
vcpkg_fixup_pkgconfig()
73+
74+
file(REMOVE_RECURSE
75+
"${CURRENT_PACKAGES_DIR}/debug/include"
76+
"${CURRENT_PACKAGES_DIR}/debug/share"
77+
)
78+
79+
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")

ports/lief/vcpkg.json

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"name": "lief",
3+
"version-semver": "0.16.0",
4+
"description": "LIEF - Library to Instrument Executable Formats",
5+
"homepage": "https://lief.quarkslab.com",
6+
"license": "Apache-2.0",
7+
"dependencies": [
8+
"fmt",
9+
"frozen",
10+
"mbedtls",
11+
"spdlog",
12+
"tcb-span",
13+
"tl-expected",
14+
"utfcpp",
15+
{
16+
"name": "vcpkg-cmake",
17+
"host": true
18+
},
19+
{
20+
"name": "vcpkg-cmake-config",
21+
"host": true
22+
}
23+
],
24+
"default-features": [
25+
"art",
26+
"dex",
27+
"elf",
28+
"enable-json",
29+
"logging",
30+
"macho",
31+
"oat",
32+
"pe",
33+
"vdex"
34+
],
35+
"features": {
36+
"art": {
37+
"description": "Build LIEF with ART module"
38+
},
39+
"c-api": {
40+
"description": "C API"
41+
},
42+
"dex": {
43+
"description": "Build LIEF with DEX module"
44+
},
45+
"elf": {
46+
"description": "Build LIEF with ELF module"
47+
},
48+
"enable-json": {
49+
"description": "Enable JSON-related APIs",
50+
"dependencies": [
51+
"nlohmann-json"
52+
]
53+
},
54+
"extra-warnings": {
55+
"description": "Enable extra warning from the compiler"
56+
},
57+
"logging": {
58+
"description": "Enable logging"
59+
},
60+
"logging-debug": {
61+
"description": "Enable debug logging"
62+
},
63+
"macho": {
64+
"description": "Build LIEF with MachO module"
65+
},
66+
"oat": {
67+
"description": "Build LIEF with OAT module"
68+
},
69+
"pe": {
70+
"description": "Build LIEF with PE module"
71+
},
72+
"use-ccache": {
73+
"description": "Use ccache to speed up compilation"
74+
},
75+
"vdex": {
76+
"description": "Build LIEF with VDEX module"
77+
}
78+
}
79+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SET(VCPKG_POLICY_EMPTY_PACKAGE enabled)
2+
3+
vcpkg_cmake_configure(
4+
SOURCE_PATH "${CURRENT_PORT_DIR}/project"
5+
)
6+
7+
vcpkg_cmake_build()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cmake_minimum_required(VERSION 3.24)
2+
3+
project(vcpkg-ci-lief LANGUAGES C CXX)
4+
5+
set(CMAKE_CXX_STANDARD 14)
6+
7+
find_package(LIEF CONFIG REQUIRED)
8+
add_executable(main main.cpp)
9+
target_link_libraries(main PRIVATE LIEF::LIEF)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <iostream>
2+
#include <LIEF/LIEF.hpp>
3+
#include <LIEF/version.h>
4+
5+
int main()
6+
{
7+
std::cout << "access flags public = " << LIEF::DEX::to_string(LIEF::DEX::access_flags_list[1]) << std::endl;
8+
std::cout << "Version = " << LIEF_VERSION << std::endl;
9+
return 0;
10+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "vcpkg-ci-lief",
3+
"version-string": "ci",
4+
"description": "Testing packages which provide lief",
5+
"license": null,
6+
"dependencies": [
7+
{
8+
"name": "lief",
9+
"features": [
10+
"c-api",
11+
"enable-json",
12+
"extra-warnings",
13+
"logging",
14+
"logging-debug",
15+
"use-ccache",
16+
"elf",
17+
"pe",
18+
"macho",
19+
"oat",
20+
"dex",
21+
"vdex",
22+
"art"
23+
]
24+
},
25+
{
26+
"name": "vcpkg-cmake",
27+
"host": true
28+
}
29+
]
30+
}

versions/baseline.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5532,6 +5532,10 @@
55325532
"baseline": "2020-11-24",
55335533
"port-version": 0
55345534
},
5535+
"lief": {
5536+
"baseline": "0.16.0",
5537+
"port-version": 0
5538+
},
55355539
"lightgbm": {
55365540
"baseline": "4.5.0",
55375541
"port-version": 0

versions/l-/lief.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"versions": [
3+
{
4+
"git-tree": "fafe51c4db1abe4b79e44013592db1c89945740d",
5+
"version-semver": "0.16.0",
6+
"port-version": 0
7+
}
8+
]
9+
}

0 commit comments

Comments
 (0)