Skip to content

Commit

Permalink
Merge pull request wazuh#25085 from wazuh/dev-folder-vcpkg-refactor
Browse files Browse the repository at this point in the history
Use VCPKG dependencies for the engine compilation.
  • Loading branch information
Dwordcito authored Aug 7, 2024
2 parents c226d41 + cd1e90b commit edbb13c
Show file tree
Hide file tree
Showing 40 changed files with 343 additions and 425 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/engine_health_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@ jobs:
pip install ${{env.ENGINE_DIR}}/test/integration_tests/it-utils/
pip install ${{env.ENGINE_DIR}}/tools/engine-suite/
- name: Setup VCPKG
uses: lukka/run-vcpkg@v11
with:
vcpkgDirectory: '${{env.ENGINE_DIR}}/vcpkg'
vcpkgGitCommitId: 'a42af01b72c28a8e1d7b48107b33e4f286a55ef6'
vcpkgJsonGlob: '${{env.ENGINE_DIR}}/vcpkg.json'

- name: Configure CMake
# Configure the CMake build system with the specified build type
run: cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -S ${{env.ENGINE_DIR}} -B ${{env.ENGINE_DIR}}/build
run: cmake --preset=default --no-warn-unused-cli -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -S ${{env.ENGINE_DIR}}

- name: Build
# Build the specified target using CMake
run: cmake --build ${{env.ENGINE_DIR}}/build --config ${{env.BUILD_TYPE}} --target main -j2
run: cmake --build ${{env.ENGINE_DIR}}/build --config ${{env.BUILD_TYPE}} --target main -j$(nproc)

- name: Setup environment
# Set Engine Configuration
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/engine_helper_functions_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,19 @@ jobs:
pip install ${{env.ENGINE_DIR}}/tools/engine-suite/
pip install ${{env.ENGINE_DIR}}/test/helper_tests/engine_helper_test
- name: Configure CMake
- name: Setup VCPKG
uses: lukka/run-vcpkg@v11
with:
vcpkgDirectory: '${{env.ENGINE_DIR}}/vcpkg'
vcpkgGitCommitId: 'a42af01b72c28a8e1d7b48107b33e4f286a55ef6'
vcpkgJsonGlob: '${{env.ENGINE_DIR}}/vcpkg.json'
# Configure the CMake build system with the specified build type
run: cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -S ${{env.ENGINE_DIR}} -B ${{env.ENGINE_DIR}}/build
- name: Configure CMake
run: cmake --preset=default --no-warn-unused-cli -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -S ${{env.ENGINE_DIR}}

- name: Build
# Build the specified target using CMake
run: cmake --build ${{env.ENGINE_DIR}}/build --config ${{env.BUILD_TYPE}} --target main -j2
run: cmake --build ${{env.ENGINE_DIR}}/build --config ${{env.BUILD_TYPE}} --target main -j$(nproc)

- name: Setup environment
# Set Engine Configuration
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/engine_integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,20 @@ jobs:
pip install ${{env.ENGINE_DIR}}/tools/engine-suite/
pip install behave
- name: Setup VCPKG
uses: lukka/run-vcpkg@v11
with:
vcpkgDirectory: '${{env.ENGINE_DIR}}/vcpkg'
vcpkgGitCommitId: 'a42af01b72c28a8e1d7b48107b33e4f286a55ef6'
vcpkgJsonGlob: '${{env.ENGINE_DIR}}/vcpkg.json'

- name: Configure CMake
# Configure the CMake build system with the specified build type
run: cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -S ${{env.ENGINE_DIR}} -B ${{env.ENGINE_DIR}}/build
run: cmake --preset=default --no-warn-unused-cli -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -S ${{env.ENGINE_DIR}}

- name: Build
# Build the specified target using CMake
run: cmake --build ${{env.ENGINE_DIR}}/build --config ${{env.BUILD_TYPE}} --target main -j2
run: cmake --build ${{env.ENGINE_DIR}}/build --config ${{env.BUILD_TYPE}} --target main -j$(nproc)

- name: Setup environment
# Set Engine Configuration
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/engine_unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@ jobs:
with:
key: ${{ github.workflow }}-${{ runner.os }}

- name: Setup VCPKG
uses: lukka/run-vcpkg@v11
with:
vcpkgDirectory: '${{env.ENGINE_DIR}}/vcpkg'
vcpkgGitCommitId: 'a42af01b72c28a8e1d7b48107b33e4f286a55ef6'
vcpkgJsonGlob: '${{env.ENGINE_DIR}}/vcpkg.json'

- name: Configure CMake
# Configure the CMake build system with the specified build type
run: cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -S ${{env.ENGINE_DIR}} -B ${{env.ENGINE_DIR}}/build
run: cmake --preset=default --no-warn-unused-cli -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -S ${{env.ENGINE_DIR}}

- name: Build
# Build the specified target using CMake
run: cmake --build ${{env.ENGINE_DIR}}/build --config ${{env.BUILD_TYPE}} --target all -j2
run: cmake --build ${{env.ENGINE_DIR}}/build --config ${{env.BUILD_TYPE}} --target all -j$(nproc)

- name: Unit Test
# Run unit tests using CTest
Expand Down
106 changes: 48 additions & 58 deletions src/engine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Minimum 3.14 required by googletest discover tests
# Todo find wich component is not working properly until 3.24 version
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
# Todo find wich component is not working properly until 3.22.1 version
cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR)

# Set c++17
set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -108,57 +108,64 @@ include(${CPM_DOWNLOAD_LOCATION})
####################################################################################################
include(cmake/CPM.cmake)

# Concurrent Queue
CPMAddPackage(
NAME CameronQueue
GITHUB_REPOSITORY cameron314/concurrentqueue
GIT_TAG v1.0.3
VERSION 1.0.3
EXCLUDE_FROM_ALL YES
)

CPMAddPackage(
NAME RxCpp
GITHUB_REPOSITORY ReactiveX/RxCpp
GIT_TAG v4.1.1
VERSION 4.1.1
EXCLUDE_FROM_ALL YES
)

CPMAddPackage(
NAME CLI11
GITHUB_REPOSITORY CLIUtils/CLI11
GIT_TAG v2.2.0
VERSION 2.2.0
DOWNLOAD_ONLY YES
)
function(find_and_create_imported_target package_name target_name)
find_package(${package_name} CONFIG REQUIRED)
if (${package_name}_FOUND)
if (NOT TARGET ${target_name})
add_library(${target_name} INTERFACE IMPORTED)
set_target_properties(${target_name} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${${package_name}_INCLUDE_DIRS}")
message(STATUS "Created imported target ${target_name}")
else()
message(STATUS "Target ${target_name} already exists")
endif()
else()
message(FATAL_ERROR "${package_name} not found!")
endif()
endfunction()

# Build test
if(ENGINE_BUILD_TEST)
enable_testing()
CPMAddPackage(
NAME googletest
GITHUB_REPOSITORY google/googletest
GIT_TAG release-1.11.0
VERSION 1.11.0
OPTIONS
"INSTALL_GTEST OFF"
EXCLUDE_FROM_ALL YES
)
find_and_create_imported_target("GTest" "GTest::gtest")
find_and_create_imported_target("GTest" "GTest::gtest_main")
find_and_create_imported_target("GTest" "GTest::gmock")
find_and_create_imported_target("GTest" "GTest::gmock_main")
include(GoogleTest)
endif(ENGINE_BUILD_TEST)

find_and_create_imported_target("RapidJSON" "RapidJSON::RapidJSON")
find_and_create_imported_target("rxcpp" "RxCpp::RxCpp")
# yaml-cpp::yaml-cpp vs yaml-cpp #FIXME 70 stars on github
find_and_create_imported_target("yaml-cpp" "yaml-cpp::yaml-cpp")
find_and_create_imported_target("spdlog" "spdlog::spdlog")
find_and_create_imported_target("fmt" "fmt::fmt-header-only")
find_and_create_imported_target("RocksDB" "RocksDB::rocksdb")
find_and_create_imported_target("Taskflow" "Taskflow::Taskflow")
find_and_create_imported_target("unofficial-concurrentqueue" "unofficial-concurrentqueue::concurrentqueue")
find_and_create_imported_target("CLI11" "CLI11::CLI11")
find_and_create_imported_target("re2" "re2::re2")
find_and_create_imported_target("CURL" "CURL::libcurl")
find_and_create_imported_target("maxminddb" "maxminddb::maxminddb")
find_and_create_imported_target("benchmark" "benchmark::benchmark")
find_and_create_imported_target("pugixml" "pugixml::pugixml")

find_and_create_imported_target("libuv" "libuv::libuv")
find_and_create_imported_target("uvw" "uvw::uvw")

find_and_create_imported_target("opentelemetry-cpp" "opentelemetry-cpp::api")
find_and_create_imported_target("opentelemetry-cpp" "opentelemetry-cpp::sdk")
find_and_create_imported_target("opentelemetry-cpp" "opentelemetry-cpp::logs")
find_and_create_imported_target("opentelemetry-cpp" "opentelemetry-cpp::metrics")

find_and_create_imported_target("Protobuf" "protobuf::libprotobuf")

####################################################################################################
# Targets
####################################################################################################
# Build main
add_executable(main ${ENGINE_SOURCE_DIR}/main.cpp)

target_include_directories(main
PRIVATE
${CLI11_SOURCE_DIR}/include
)

add_subdirectory(${ENGINE_SOURCE_DIR}/base)
add_subdirectory(${ENGINE_SOURCE_DIR}/sockiface)
add_subdirectory(${ENGINE_SOURCE_DIR}/bk)
Expand All @@ -184,25 +191,8 @@ add_subdirectory(${ENGINE_SOURCE_DIR}/metrics)
add_subdirectory(${ENGINE_SOURCE_DIR}/geo)
add_subdirectory(${ENGINE_SOURCE_DIR}/queue)


#TODO isolate rxcpp
target_link_libraries(main base cmds api)

# Build test
if(ENGINE_BUILD_TEST)
# Add googletest as CPM dependency
CPMAddPackage(
NAME googletest
GITHUB_REPOSITORY google/googletest
GIT_TAG release-1.11.0
VERSION 1.11.0
OPTIONS
"INSTALL_GTEST OFF"
EXCLUDE_FROM_ALL YES
)

include(GoogleTest)
endif(ENGINE_BUILD_TEST)
target_link_libraries(main base cmds api CLI11::CLI11)

# Build benchmark
if(ENGINE_BUILD_BENCHMARK)
Expand Down
13 changes: 13 additions & 0 deletions src/engine/CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 2,
"configurePresets": [
{
"name": "default",
"generator": "Unix Makefiles",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
}
]
}
10 changes: 0 additions & 10 deletions src/engine/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
# Add google benchmark as CPM dependency
include(../cmake/CPM.cmake)
CPMAddPackage(
NAME benchmark
GITHUB_REPOSITORY google/benchmark
VERSION 1.6.1
OPTIONS
"BENCHMARK_ENABLE_TESTING Off"
EXCLUDE_FROM_ALL YES
)

if(NOT CMAKE_BUILD_TYPE STREQUAL "Release"
AND NOT CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
message(WARNING
Expand Down
10 changes: 1 addition & 9 deletions src/engine/benchmark/regex/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# dependencies
CPMAddPackage(
NAME RE2
GITHUB_REPOSITORY google/re2
GIT_TAG 2022-02-01
VERSION release 2022-02-01
)

# Configuration regex test
add_executable(regex_bench
regex_bench.cpp
)

# Build benchmarks
target_link_libraries(regex_bench benchmark::benchmark_main re2)
target_link_libraries(regex_bench benchmark::benchmark_main re2::re2)
7 changes: 3 additions & 4 deletions src/engine/source/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(IFACE_DIR ${CMAKE_CURRENT_LIST_DIR}/interface)
# ###################################################################################################
add_library(api_iapi INTERFACE)
target_include_directories(api_iapi INTERFACE ${IFACE_DIR})
target_link_libraries(api_iapi INTERFACE fmt base store::istore)
target_link_libraries(api_iapi INTERFACE base store::istore)
add_library(api::iapi ALIAS api_iapi)

add_library(api STATIC
Expand Down Expand Up @@ -44,7 +44,6 @@ target_include_directories(api
target_link_libraries(api
base
eMessages
fmt
kvdb::ikvdb
metrics
router::irouter
Expand All @@ -69,7 +68,7 @@ if(ENGINE_BUILD_TEST)
# Mocks
add_library(api_mocks INTERFACE)
target_include_directories(api_mocks INTERFACE ${TEST_MOCK_DIR})
target_link_libraries(api_mocks INTERFACE gmock api::iapi)
target_link_libraries(api_mocks INTERFACE GTest::gmock api::iapi)
add_library(api::mocks ALIAS api_mocks)

add_executable(api_utest
Expand All @@ -91,7 +90,7 @@ if(ENGINE_BUILD_TEST)
)

target_link_libraries(api_utest
gtest_main
GTest::gtest_main
base
base::test
api
Expand Down
45 changes: 4 additions & 41 deletions src/engine/source/base/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
####################################################################################################
# logging
####################################################################################################
CPMAddPackage(
NAME fmt
GITHUB_REPOSITORY fmtlib/fmt
GIT_TAG "8.1.1"
OPTIONS "FMT_HEADER_ONLY ON"
)

CPMAddPackage(
NAME spdlog
GITHUB_REPOSITORY gabime/spdlog
GIT_TAG "v1.11.0"
OPTIONS "SPDLOG_FMT_EXTERNAL_HO ON"
)

add_dependencies(spdlog fmt)

####################################################################################################
# json
####################################################################################################
CPMAddPackage(
NAME rapidjson
GITHUB_REPOSITORY Tencent/rapidjson
GIT_TAG 8261c1ddf43f10de00fd8c9a67811d1486b2c784 # Latest master commit from 21/03/2022
OPTIONS
"RAPIDJSON_BUILD_DOC OFF"
"RAPIDJSON_BUILD_EXAMPLES OFF"
"RAPIDJSON_BUILD_TESTS OFF"
DOWNLOAD_ONLY YES
)

####################################################################################################
# BASE
####################################################################################################
Expand All @@ -50,19 +17,15 @@ add_library(base STATIC
target_include_directories(base
PUBLIC
${INC_DIR}
${spdlog_SOURCE_DIR}/include
${rapidjson_SOURCE_DIR}/include

PRIVATE
${INC_DIR}/base
${SRC_DIR}
)
target_link_libraries(base
PUBLIC
fmt

PRIVATE
spdlog
fmt::fmt-header-only
spdlog::spdlog
)

# Tests
Expand Down Expand Up @@ -104,7 +67,7 @@ target_link_libraries(base_utest

PRIVATE
base
gtest_main
GTest::gtest_main
)
gtest_discover_tests(base_utest)

Expand All @@ -120,7 +83,7 @@ target_include_directories(base_logger_utest
target_link_libraries(base_logger_utest
PRIVATE
base
gtest_main
GTest::gtest_main
)
gtest_discover_tests(base_logger_utest)

Expand Down
Loading

0 comments on commit edbb13c

Please sign in to comment.