Skip to content

Commit

Permalink
vcpkg integration
Browse files Browse the repository at this point in the history
Overlay ports for projects (sleigh, lief) that don't exist in upstream
vcpkg repo and/or are required overlays (mbedtls v3) because upstream
won't accept them due to single-version package policy and mandatory
compatibility of all existing packages.

This uses a development version of sleigh that does a large refactor of
the CMake and some target names.

The lief portfile was copied from an existing PR
  • Loading branch information
ekilmer committed Jul 7, 2022
1 parent bb4b1e9 commit e72d8f0
Show file tree
Hide file tree
Showing 12 changed files with 613 additions and 7 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ add_custom_command(
# Allow user to override sleigh compiler to support cross-compilation. Default
# location is the one imported when we found the sleigh package
if(CMAKE_CROSSCOMPILING)
find_program(maat_SLEIGH_COMPILER "sleigh_opt"
find_program(maat_SLEIGH_COMPILER "sleigh"
DOC "Sleigh compiler executable"
)
if(NOT maat_SLEIGH_COMPILER)
message(FATAL_ERROR "Maat needs a sleigh compiler. Specify path manually by setting 'maat_SLEIGH_COMPILER'")
endif()
else()
set(maat_SLEIGH_COMPILER "$<TARGET_FILE:sleigh::sleigh_opt>" CACHE PATH "Sleigh compiler executable")
set(maat_SLEIGH_COMPILER "$<TARGET_FILE:sleigh::sleigh>" CACHE PATH "Sleigh compiler executable")
endif()

macro(maat_sleigh_compile ARCH_DIR ARCH)
Expand Down
25 changes: 20 additions & 5 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@
"maat_DEVELOPER_MODE": "ON"
}
},
{
"name": "vcpkg",
"hidden": true,
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"VCPKG_OVERLAY_PORTS": "${sourceDir}/ports"
}
},
{
"name": "vcpkg-win64-static",
"hidden": true,
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "x64-windows-static-md"
}
},
{
"name": "cppcheck",
"hidden": true,
Expand Down Expand Up @@ -98,15 +113,15 @@
},
{
"name": "ci-coverage",
"inherits": ["coverage-unix", "dev-mode"],
"inherits": ["coverage-unix", "dev-mode", "vcpkg"],
"cacheVariables": {
"COVERAGE_HTML_COMMAND": ""
}
},
{
"name": "ci-sanitize",
"binaryDir": "${sourceDir}/build/sanitize",
"inherits": ["ci-unix", "dev-mode"],
"inherits": ["ci-unix", "dev-mode", "vcpkg"],
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Sanitize",
"CMAKE_CXX_FLAGS_SANITIZE": "-O2 -g -fsanitize=address,undefined -fno-omit-frame-pointer -fno-common",
Expand All @@ -120,15 +135,15 @@
},
{
"name": "ci-macos",
"inherits": ["ci-build", "ci-unix", "dev-mode"]
"inherits": ["ci-build", "ci-unix", "dev-mode", "vcpkg"]
},
{
"name": "ci-ubuntu",
"inherits": ["ci-build", "ci-unix", "dev-mode"]
"inherits": ["ci-build", "ci-unix", "dev-mode", "vcpkg"]
},
{
"name": "ci-windows",
"inherits": ["ci-build", "ci-win64", "dev-mode"]
"inherits": ["ci-build", "ci-win64", "dev-mode", "vcpkg", "vcpkg-win64-static"]
}
]
}
45 changes: 45 additions & 0 deletions ports/lief/0001-Support-vcpkg.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
From 426d8167648fff0ad79832a701223b8171dad096 Mon Sep 17 00:00:00 2001
From: Eric Kilmer <[email protected]>
Date: Tue, 12 Apr 2022 10:42:27 -0400
Subject: [PATCH] Support vcpkg

Remove msvccrt choosing and fix install paths on Windows
---
CMakeLists.txt | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b89d0522..9ca50c35 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,9 +11,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_CROSSCOMPILING)
endif()


-if(WIN32 OR ${IS_WIN_CROSS_COMPILE})
- include(ChooseMSVCCRT)
-endif()
include(CheckCXXCompilerFlag)
include(CheckCCompilerFlag)
include(ExternalProject)
@@ -667,7 +664,7 @@ endif()
# Installation
# ======================

-if(UNIX)
+if(1)
include(GNUInstallDirs)
set(CMAKE_INSTALL_LIBDIR "lib")
else()
@@ -688,7 +685,7 @@ install(
EXPORT LIEFExport
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libraries
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

install(
--
2.35.1

19 changes: 19 additions & 0 deletions ports/lief/0002-Fix-Uninitialized-CMake-var.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff --git a/LIEFConfig.cmake.in b/LIEFConfig.cmake.in
index 8c35eeab..ea09099f 100644
--- a/LIEFConfig.cmake.in
+++ b/LIEFConfig.cmake.in
@@ -165,7 +165,8 @@ set(LIEF_LIBRARIES LIEF::LIEF)
get_target_property(LIEF_INCLUDE_DIRS LIEF::LIEF INTERFACE_INCLUDE_DIRECTORIES)

# Set the following for backwards compatibility
-if(LIEF_INCLUDE_DIR AND EXISTS "${LIEF_INCLUDE_DIR}/LIEF/version.h")
+if(LIEF_INCLUDE_DIR)
+if(EXISTS "${LIEF_INCLUDE_DIR}/LIEF/version.h")
file(STRINGS "${LIEF_INCLUDE_DIR}/LIEF/version.h" LIEF_H REGEX "^#define LIEF_VERSION \"[^\"]*\"$")

string(REGEX REPLACE "^.*LIEF_VERSION \"([0-9]+).*$" "\\1" LIEF_VERSION_MAJOR "${LIEF_H}")
@@ -177,3 +178,4 @@ if(LIEF_INCLUDE_DIR AND EXISTS "${LIEF_INCLUDE_DIR}/LIEF/version.h")
set(LIEF_MINOR_VERSION "${LIEF_VERSION_MINOR}")
set(LIEF_PATCH_VERSION "${LIEF_VERSION_PATCH}")
endif()
+endif()
88 changes: 88 additions & 0 deletions ports/lief/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO lief-project/LIEF
REF 0.12.1
SHA512 833a04ece5ff7365717aee3408a2d522756319e43cf4ff795047021c46b48d5d525c2a56cdafd04259ddfcf6888972d19655924f999460ce05f52a32ac7e8bca
HEAD_REF master
PATCHES
0001-Support-vcpkg.patch
0002-Fix-Uninitialized-CMake-var.patch
)

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
"tests" LIEF_TESTS # Enable tests
"c-api" LIEF_C_API # C API
"examples" LIEF_EXAMPLES # Build LIEF C++ examples
"force32" LIEF_FORCE32 # Force build LIEF 32 bits version
"coverage" LIEF_COVERAGE # Perform code coverage
"use-ccache" LIEF_USE_CCACHE # Use ccache to speed up compilation
"extra-warnings" LIEF_EXTRA_WARNINGS # Enable extra warning from the compiler
"logging" LIEF_LOGGING # Enable logging
"logging-debug" LIEF_LOGGING_DEBUG # Enable debug logging
"enable-json" LIEF_ENABLE_JSON # Enable JSON-related APIs

"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

# Sanitizer
"asan" LIEF_ASAN # Enable Address sanitizer
"lsan" LIEF_LSAN # Enable Leak sanitizer
"tsan" LIEF_TSAN # Enable Thread sanitizer
"usan" LIEF_USAN # Enable undefined sanitizer

# Fuzzer
"fuzzing" LIEF_FUZZING # Fuzz LIEF

# Profiling
"profiling" LIEF_PROFILING # Enable performance profiling

INVERTED_FEATURES
"enable-frozen" LIEF_DISABLE_FROZEN # Disable Frozen even if it is supported
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"

OPTIONS
${FEATURE_OPTIONS}

-DLIEF_PYTHON_API=OFF
-DLIEF_USE_CCACHE=OFF

# Build with external vcpkg dependencies
-DLIEF_OPT_MBEDTLS_EXTERNAL=ON
-DLIEF_OPT_UTFCPP_EXTERNAL=ON
-DLIEF_EXTERNAL_SPDLOG=ON
-DLIEF_OPT_NLOHMANN_JSON_EXTERNAL=ON
-DLIEF_OPT_FROZEN_EXTERNAL=ON
-DLIEF_OPT_EXTERNAL_LEAF=ON
"-DLIEF_EXTERNAL_LEAF_DIR=${CURRENT_INSTALLED_DIR}/include"
-DLIEF_OPT_EXTERNAL_SPAN=ON
)

vcpkg_cmake_install()

vcpkg_cmake_config_fixup(CONFIG_PATH share/LIEF/cmake)

vcpkg_copy_pdbs()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")

# Check if all-caps directory is empty (it won't be on case-insensitive filesystems).
# These files could have been moved during vcpkg_cmake_config_fixup
file(GLOB dir_files "${CURRENT_PACKAGES_DIR}/share/LIEF/*")
list(LENGTH dir_files dir_files_len)
if(dir_files_len EQUAL 0)
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/share/LIEF")
endif()

# Handle copyright
file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
116 changes: 116 additions & 0 deletions ports/lief/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"name": "lief",
"version-semver": "0.12.1",
"description": "LIEF - Library to Instrument Executable Formats",
"homepage": "https://lief.quarkslab.com",
"license": "Apache-2.0",
"supports": "!uwp",
"dependencies": [
"boost-leaf",
"mbedtls",
"spdlog",
"tcb-span",
"utfcpp",
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
],
"default-features": [
"art",
"c-api",
"dex",
"elf",
"enable-frozen",
"enable-json",
"logging",
"macho",
"oat",
"pe",
"vdex"
],
"features": {
"art": {
"description": "Build LIEF with ART module"
},
"asan": {
"description": "Enable Address sanitizer"
},
"c-api": {
"description": "C API"
},
"coverage": {
"description": "Perform code coverage"
},
"dex": {
"description": "Build LIEF with DEX module"
},
"elf": {
"description": "Build LIEF with ELF module"
},
"enable-frozen": {
"description": "Enable Frozen",
"dependencies": [
"frozen"
]
},
"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"
},
"force32": {
"description": "Force build LIEF 32 bits version"
},
"fuzzing": {
"description": "Fuzz LIEF"
},
"logging": {
"description": "Enable logging"
},
"logging-debug": {
"description": "Enable debug logging"
},
"lsan": {
"description": "Enable Leak sanitizer"
},
"macho": {
"description": "Build LIEF with MachO module"
},
"oat": {
"description": "Build LIEF with OAT module"
},
"pe": {
"description": "Build LIEF with PE module"
},
"profiling": {
"description": "Enable performance profiling"
},
"tests": {
"description": "Enable tests"
},
"tsan": {
"description": "Enable Thread sanitizer"
},
"usan": {
"description": "Enable undefined sanitizer"
},
"use-ccache": {
"description": "Use ccache to speed up compilation"
},
"vdex": {
"description": "Build LIEF with VDEX module"
}
}
}
Loading

0 comments on commit e72d8f0

Please sign in to comment.