From b9c60009874d448ebd8219186168114856ab85c8 Mon Sep 17 00:00:00 2001 From: ncvicchi Date: Thu, 12 Dec 2024 11:55:20 -0300 Subject: [PATCH] fix: PR comments --- src/CMakeLists.txt | 2 +- src/common/CMakeLists.txt | 2 +- src/common/binaries_op/CMakeLists.txt | 11 ++++++----- src/common/file_op/CMakeLists.txt | 5 +++-- src/common/mem_op/CMakeLists.txt | 7 ++++--- src/common/pal/CMakeLists.txt | 3 +-- src/common/pal/README.md | 4 ++-- src/common/privsep_op/CMakeLists.txt | 5 +++-- src/common/pthreads_op/CMakeLists.txt | 5 +++-- src/common/randombytes/CMakeLists.txt | 7 ++++--- src/common/regex_op/CMakeLists.txt | 7 ++++--- src/common/time_op/CMakeLists.txt | 11 ++++++----- src/common/version_op/CMakeLists.txt | 15 +++++++-------- src/modules/inventory/CMakeLists.txt | 6 +++--- 14 files changed, 48 insertions(+), 42 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6949f8477c..c28128728b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.22) set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake") -if(CMAKE_SYSTEM_NAME STREQUAL "Linux") +if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++") endif() diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index da54526a76..40c605591a 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -5,8 +5,8 @@ add_subdirectory(dbsync) add_subdirectory(error_messages) add_subdirectory(filesystem_wrapper) add_subdirectory(hashHelper) -add_subdirectory(mem_op) add_subdirectory(logger) +add_subdirectory(mem_op) add_subdirectory(networkHelper) add_subdirectory(pal) add_subdirectory(privsep_op) diff --git a/src/common/binaries_op/CMakeLists.txt b/src/common/binaries_op/CMakeLists.txt index 3ff2886f43..0faf5c1ef1 100644 --- a/src/common/binaries_op/CMakeLists.txt +++ b/src/common/binaries_op/CMakeLists.txt @@ -1,11 +1,12 @@ add_library(binaries_op STATIC src/binaries_op.c) get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE) -target_include_directories(binaries_op PUBLIC include) -include_directories(${COMMON_FOLDER}/pal/include) -include_directories(${COMMON_FOLDER}/error_messages/include) -include_directories(${COMMON_FOLDER}/utils/include) -include_directories(${COMMON_FOLDER}/file_op/include) +target_include_directories(binaries_op PUBLIC + include + ${COMMON_FOLDER}/error_messages/include + ${COMMON_FOLDER}/file_op/include + ${COMMON_FOLDER}/pal/include + ${COMMON_FOLDER}/utils/include) target_link_libraries(binaries_op utils diff --git a/src/common/file_op/CMakeLists.txt b/src/common/file_op/CMakeLists.txt index b328c56afb..a5e76512af 100644 --- a/src/common/file_op/CMakeLists.txt +++ b/src/common/file_op/CMakeLists.txt @@ -3,7 +3,8 @@ find_package(ZLIB REQUIRED) add_library(file_op STATIC src/file_op.c) get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE) -target_include_directories(file_op PUBLIC include) -include_directories(${COMMON_FOLDER}/pal/include) +target_include_directories(file_op PUBLIC + include + ${COMMON_FOLDER}/pal/include) target_link_libraries(file_op utils time_op version_op ZLIB::ZLIB Logger) diff --git a/src/common/mem_op/CMakeLists.txt b/src/common/mem_op/CMakeLists.txt index 08ac41d97a..cc5ef54989 100644 --- a/src/common/mem_op/CMakeLists.txt +++ b/src/common/mem_op/CMakeLists.txt @@ -1,8 +1,9 @@ add_library(mem_op STATIC src/mem_op.c) get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE) -target_include_directories(mem_op PUBLIC include) -include_directories(${COMMON_FOLDER}/pal/include) -include_directories(${COMMON_FOLDER}/error_messages/include) +target_include_directories(mem_op PUBLIC + include + ${COMMON_FOLDER}/error_messages/include + ${COMMON_FOLDER}/pal/include) target_link_libraries(mem_op utils Logger time_op) diff --git a/src/common/pal/CMakeLists.txt b/src/common/pal/CMakeLists.txt index 4e9f0a0460..98fffe954f 100644 --- a/src/common/pal/CMakeLists.txt +++ b/src/common/pal/CMakeLists.txt @@ -11,8 +11,6 @@ else() message(FATAL_ERROR "Unsupported OS") endif() -include_directories(include/${OS_NAME}) - file(GLOB_RECURSE SOURCE_FILES src/${OS_NAME}/*.c) message(STATUS "Source files: ${SOURCE_FILES}") @@ -22,6 +20,7 @@ if(NOT SOURCE_FILES) endif() add_library(pal STATIC ${SOURCE_FILES}) +target_include_directories(pal PUBLIC include/${OS_NAME}) if(BUILD_TESTS) enable_testing() diff --git a/src/common/pal/README.md b/src/common/pal/README.md index 9aacd53ffb..51f9223f05 100644 --- a/src/common/pal/README.md +++ b/src/common/pal/README.md @@ -9,7 +9,7 @@ Since we are currently using GNU C for Linux. AppleClang for MacOS and MSVC for pal ├── README.md ├── CMakeLists.txt - ├── include + ├── include │ ├── Linux │ │ ├── pal_file.h │ │ ├── pal_thread.h @@ -46,7 +46,7 @@ pal ### Usage A commom public file named "pal.h" should be included in every file that will be platform dependant. No more includes should be necessary. -Thos definitions, prototypes, etc, provided by the PAL should be used in Wazuh agent's code, avoiding whenever possible the usage of pre-processor in higher level code. +Those definitions, prototypes, etc, provided by the PAL should be used in Wazuh agent's code, avoiding whenever possible the usage of pre-processor in higher level code. If situations not considered in the PAL are found during development, it should be prioritized to extend the PAL than taking shortcuts as ad-hoc solutions, except if this option is no available for implementation reasons. #### NOTE: Due to time available for this proposal, an emulation of POSIX functions and structures were implemented. It will be left for later to implement a fully abstracted layer to improve code quality. diff --git a/src/common/privsep_op/CMakeLists.txt b/src/common/privsep_op/CMakeLists.txt index 93d02500b5..42a1e849dc 100644 --- a/src/common/privsep_op/CMakeLists.txt +++ b/src/common/privsep_op/CMakeLists.txt @@ -2,7 +2,8 @@ add_library(privsep_op STATIC src/privsep_op.c) get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE) target_include_directories(privsep_op PUBLIC include) -include_directories(${COMMON_FOLDER}/pal/include) -include_directories(${COMMON_FOLDER}/error_messages/include) +target_include_directories(privsep_op PUBLIC + ${COMMON_FOLDER}/error_messages/include + ${COMMON_FOLDER}/pal/include) target_link_libraries(privsep_op utils time_op Logger) diff --git a/src/common/pthreads_op/CMakeLists.txt b/src/common/pthreads_op/CMakeLists.txt index ccfdd5efae..67040014db 100644 --- a/src/common/pthreads_op/CMakeLists.txt +++ b/src/common/pthreads_op/CMakeLists.txt @@ -2,7 +2,8 @@ add_library(pthreads_op STATIC src/pthreads_op.c) get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE) target_include_directories(pthreads_op PUBLIC include) -include_directories(${COMMON_FOLDER}/pal/include) -include_directories(${COMMON_FOLDER}/error_messages/include) +target_include_directories(pthreads_op PUBLIC + ${COMMON_FOLDER}/error_messages/include + ${COMMON_FOLDER}/pal/include) target_link_libraries(pthreads_op utils time_op Logger) diff --git a/src/common/randombytes/CMakeLists.txt b/src/common/randombytes/CMakeLists.txt index 68aeeffb6a..16a4816825 100644 --- a/src/common/randombytes/CMakeLists.txt +++ b/src/common/randombytes/CMakeLists.txt @@ -1,9 +1,10 @@ add_library(randombytes STATIC src/randombytes.c) get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE) -target_include_directories(randombytes PUBLIC include) -include_directories(${COMMON_FOLDER}/pal/include) -include_directories(${COMMON_FOLDER}/error_messages/include) +target_include_directories(randombytes PUBLIC + include + ${COMMON_FOLDER}/error_messages/include + ${COMMON_FOLDER}/pal/include) target_link_libraries(randombytes utils diff --git a/src/common/regex_op/CMakeLists.txt b/src/common/regex_op/CMakeLists.txt index b531fe153c..0ac885f199 100644 --- a/src/common/regex_op/CMakeLists.txt +++ b/src/common/regex_op/CMakeLists.txt @@ -1,8 +1,9 @@ add_library(regex_op STATIC src/regex_op.c) get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE) -target_include_directories(regex_op PUBLIC include) -include_directories(${COMMON_FOLDER}/pal/include) -include_directories(${COMMON_FOLDER}/error_messages/include) +target_include_directories(regex_op PUBLIC + include + ${COMMON_FOLDER}/error_messages/include + ${COMMON_FOLDER}/pal/include) target_link_libraries(regex_op utils Logger time_op) diff --git a/src/common/time_op/CMakeLists.txt b/src/common/time_op/CMakeLists.txt index 1995b198a8..6f3be2756a 100644 --- a/src/common/time_op/CMakeLists.txt +++ b/src/common/time_op/CMakeLists.txt @@ -1,10 +1,11 @@ add_library(time_op STATIC src/time_op.c) get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE) -target_include_directories(time_op PUBLIC include) -include_directories(${COMMON_FOLDER}/pal/include) -include_directories(${COMMON_FOLDER}/regex_op/include) -include_directories(${COMMON_FOLDER}/error_messages/include) -include_directories(${COMMON_FOLDER}/utils/include) +target_include_directories(time_op PUBLIC + include + ${COMMON_FOLDER}/error_messages/include + ${COMMON_FOLDER}/pal/include + ${COMMON_FOLDER}/regex_op/include + ${COMMON_FOLDER}/utils/include) target_link_libraries(time_op utils Logger) diff --git a/src/common/version_op/CMakeLists.txt b/src/common/version_op/CMakeLists.txt index 885ebb9724..8dc121afd1 100644 --- a/src/common/version_op/CMakeLists.txt +++ b/src/common/version_op/CMakeLists.txt @@ -1,14 +1,13 @@ add_library(version_op STATIC src/version_op.c) get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE) -target_include_directories(version_op PUBLIC include) -include_directories(${COMMON_FOLDER}/pal/include) -include_directories(${COMMON_FOLDER}/error_messages/include) -include_directories(${COMMON_FOLDER}/utils/include) -include_directories(${COMMON_FOLDER}/file_op/include) -include_directories(${COMMON_FOLDER}/regex_op/include) -include_directories(${COMMON_FOLDER}/binaries_op/include) -include_directories(${COMMON_FOLDER}/pal/include) +target_include_directories(version_op PUBLIC + include + ${COMMON_FOLDER}/binaries_op/include + ${COMMON_FOLDER}/file_op/include + ${COMMON_FOLDER}/pal/include + ${COMMON_FOLDER}/regex_op/include + ${COMMON_FOLDER}/utils/include) target_link_libraries(version_op utils diff --git a/src/modules/inventory/CMakeLists.txt b/src/modules/inventory/CMakeLists.txt index 3f443a8bc6..0bf6fe1366 100644 --- a/src/modules/inventory/CMakeLists.txt +++ b/src/modules/inventory/CMakeLists.txt @@ -17,7 +17,7 @@ add_library(Inventory src/inventory.cpp src/inventoryImp.cpp src/inventoryNormalizer.cpp) - + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_compile_options(Inventory PRIVATE /WX-) endif() @@ -30,13 +30,13 @@ target_include_directories(Inventory PUBLIC ${COMMON_FOLDER}/dbsync/include ${COMMON_FOLDER}/error_messages/include ${COMMON_FOLDER}/hashHelper/include + ${COMMON_FOLDER}/pal/include ${COMMON_FOLDER}/privsep_op/include ${COMMON_FOLDER}/pthreads_op/include ${COMMON_FOLDER}/stringHelper/include ${COMMON_FOLDER}/time_op/include ${COMMON_FOLDER}/timeHelper/include - ${COMMON_FOLDER}/utils - ${COMMON_FOLDER}/pal/include) + ${COMMON_FOLDER}/utils) target_link_libraries(Inventory PUBLIC