Skip to content

Commit

Permalink
Merge pull request #543 from wazuh/enhancement/542-manage-additional-…
Browse files Browse the repository at this point in the history
…dependencies-with-vcpkg

Manage additional dependencies with vcpkg
  • Loading branch information
TomasTurina authored Jan 24, 2025
2 parents ecd25d5 + ba91c68 commit 09cece0
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 38 deletions.
16 changes: 2 additions & 14 deletions BUILD.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
# Build Instructions

The following dependencies are required for this project:

- **Git**
- **CMake** at least 3.22
- **Make**
- **C++ compiler** (GCC 10 or Clang 13, coroutines support needed)
- **Zip** (for [vcpkg](https://vcpkg.io))
- **Curl** (for [vcpkg](https://vcpkg.io))
- **Tar** (for [vcpkg](https://vcpkg.io))
- **Ninja-build** (for [vcpkg](https://vcpkg.io))
- **Pkg-config**

## Compilation steps for Linux

1. **Installing Dependencies on Debian**
Expand All @@ -20,12 +8,12 @@ The following dependencies are required for this project:

```bash
sudo apt-get update
sudo apt-get install cmake make gcc git zip curl tar ninja-build pkg-config wget gnupg lsb-release software-properties-common libbz2-dev libsystemd-dev
sudo apt-get install cmake make g++ gcc git zip curl tar ninja-build pkg-config wget gnupg lsb-release software-properties-common libsystemd-dev
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 18
sudo apt-get update
sudo apt-get install -y clang-tidy-18 autopoint libtool zlib1g-dev libgcrypt20-dev libpopt-dev libmagic-dev libsqlite3-dev liblua5.4-dev gettext libarchive-dev
sudo apt-get install -y clang-tidy-18 autopoint libtool zlib1g-dev libgcrypt20-dev gettext
```

2. **Clone the Repository**
Expand Down
12 changes: 8 additions & 4 deletions src/common/data_provider/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,17 @@ else()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()

find_package(cJSON CONFIG REQUIRED)
find_package(LibArchive REQUIRED)
find_package(Lua REQUIRED)
if(UNIX AND NOT APPLE)
find_package(Lua REQUIRED)
include_directories(${LUA_INCLUDE_DIR})
endif()

if(APPLE)
find_package(unofficial-libplist CONFIG REQUIRED)
endif()

find_package(cJSON CONFIG REQUIRED)
find_package(LibArchive REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(unofficial-sqlite3 CONFIG REQUIRED)

Expand All @@ -84,7 +89,6 @@ include_directories(${POPT_INCLUDE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/)
include_directories(${SRC_FOLDER}/headers/)
include_directories(${LUA_INCLUDE_DIR})
include_directories(${SRC_FOLDER}/common/)
include_directories(${SRC_FOLDER}/common/utils/)
include_directories(${SRC_FOLDER}/common/byteArrayHelper/include/)
Expand Down
71 changes: 60 additions & 11 deletions src/ports-overlay/librpm/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,47 @@ vcpkg_replace_string("${SOURCE_PATH}/configure.ac"
"RPMCONFIGDIR=\"/usr/lib/rpm\""
)

# RPM looks for "popt" but Vcpkg generates a poptd library file
set(COMMON_PATH "${CURRENT_INSTALLED_DIR}/debug/lib/${VCPKG_TARGET_STATIC_LIBRARY_PREFIX}")
set(LIBPOPTD_FILE "${COMMON_PATH}poptd${VCPKG_TARGET_STATIC_LIBRARY_SUFFIX}/")
set(LIBPOPT_FILE "${COMMON_PATH}popt${VCPKG_TARGET_STATIC_LIBRARY_SUFFIX}")
file(COPY ${LIBPOPTD_FILE} DESTINATION ${LIBPOPT_FILE})

# RPM looks for "bz2d" but Vcpkg generates a bz2 library file, without the d suffix in debug
set(BZ2D_FILE "${COMMON_PATH}bz2d${VCPKG_TARGET_STATIC_LIBRARY_SUFFIX}/")
set(BZ2_FILE "${COMMON_PATH}bz2${VCPKG_TARGET_STATIC_LIBRARY_SUFFIX}")
file(COPY ${BZ2D_FILE} DESTINATION ${BZ2_FILE})

# Vcpkg doesn't generate a lua.pc file, so we need to create it for librpm
file(WRITE ${CURRENT_INSTALLED_DIR}/debug/lib/pkgconfig/lua.pc "
prefix=\${pcfiledir}/../..
exec_prefix=\${prefix}
libdir=\${prefix}/lib
includedir=${prefix}/../include
Name: Lua
Description: Lua
Version: 5.4.2
Libs: -L\${libdir} -llua -lm
Cflags: -I\${includedir}
")

# We need to create one for each build type
file(WRITE ${CURRENT_INSTALLED_DIR}/lib/pkgconfig/lua.pc "
prefix=\${pcfiledir}/../..
exec_prefix=\${prefix}
libdir=\${prefix}/lib
includedir=\${prefix}/include
Name: Lua
Description: Lua
Version: 5.4.2
Libs: -L\${libdir} -llua -lm
Cflags: -I\${includedir}
")

vcpkg_configure_make(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
Expand All @@ -23,19 +64,27 @@ vcpkg_configure_make(
)

vcpkg_install_make()
vcpkg_fixup_pkgconfig()

vcpkg_fixup_pkgconfig(
RELEASE_FILES
${CURRENT_PACKAGES_DIR}/lib/pkgconfig/rpm.pc
DEBUG_FILES
${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/rpm.pc
SKIP_CHECK
)

vcpkg_copy_pdbs()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share"
"${CURRENT_PACKAGES_DIR}/debug/lib/rpm-plugins"
"${CURRENT_PACKAGES_DIR}/debug/lib/rpm/lua"
"${CURRENT_PACKAGES_DIR}/debug/lib/rpm/macros.d"
"${CURRENT_PACKAGES_DIR}/debug/var/tmp"
"${CURRENT_PACKAGES_DIR}/lib/rpm-plugins"
"${CURRENT_PACKAGES_DIR}/lib/rpm/lua"
"${CURRENT_PACKAGES_DIR}/lib/rpm/macros.d"
"${CURRENT_PACKAGES_DIR}/var/tmp"
"${CURRENT_PACKAGES_DIR}/debug/var"
"${CURRENT_PACKAGES_DIR}/var")
"${CURRENT_PACKAGES_DIR}/debug/lib/rpm-plugins"
"${CURRENT_PACKAGES_DIR}/debug/lib/rpm/lua"
"${CURRENT_PACKAGES_DIR}/debug/lib/rpm/macros.d"
"${CURRENT_PACKAGES_DIR}/debug/var/tmp"
"${CURRENT_PACKAGES_DIR}/lib/rpm-plugins"
"${CURRENT_PACKAGES_DIR}/lib/rpm/lua"
"${CURRENT_PACKAGES_DIR}/lib/rpm/macros.d"
"${CURRENT_PACKAGES_DIR}/var/tmp"
"${CURRENT_PACKAGES_DIR}/debug/var"
"${CURRENT_PACKAGES_DIR}/var")

set(VCPKG_POLICY_SKIP_COPYRIGHT_CHECK enabled)
22 changes: 22 additions & 0 deletions src/ports-overlay/librpm/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@
{
"name": "vcpkg-cmake-config",
"host": true
},
{
"name": "bzip2",
"version>=": "1.0.8#5"
},
{
"name": "libmagic"
},
{
"name": "libpopt"
},
{
"name": "lua"
},
{
"name": "sqlite3"
}
],
"overrides": [
{
"name": "lua",
"version": "5.4.2"
}
]
}
2 changes: 2 additions & 0 deletions src/ports-overlay/procps/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ vcpkg_from_github(

vcpkg_configure_make(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
--without-ncurses
)

vcpkg_install_make()
Expand Down
9 changes: 0 additions & 9 deletions src/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@
"version>=": "4.18.2",
"platform": "linux"
},
{
"name": "lua"
},
{
"name": "nlohmann-json",
"version>=": "3.11.3"
Expand Down Expand Up @@ -102,12 +99,6 @@
"version>=": "1.3.1"
}
],
"overrides": [
{
"name": "lua",
"version": "5.4.1"
}
],
"vcpkg-configuration": {
"default-registry": {
"kind": "git",
Expand Down

0 comments on commit 09cece0

Please sign in to comment.