Skip to content

Commit

Permalink
fix: improve the common cmakefiles
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasTurina committed Feb 10, 2025
1 parent 1e5f6a0 commit da13669
Show file tree
Hide file tree
Showing 77 changed files with 107 additions and 221 deletions.
5 changes: 2 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ if(ENABLE_LOGCOLLECTOR OR ENABLE_INVENTORY)
add_subdirectory(common)
else()
add_subdirectory(common/config)
add_subdirectory(common/data_provider)
add_subdirectory(common/filesystem_wrapper)
add_subdirectory(common/logger)
add_subdirectory(common/pal)
add_subdirectory(common/utils)
add_subdirectory(common/data_provider)
add_subdirectory(common/networkHelper)
add_subdirectory(common/filesystem_wrapper)
endif()

add_subdirectory(modules)
Expand Down
25 changes: 14 additions & 11 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
add_subdirectory(binaries_op)
add_subdirectory(byteArrayHelper)
add_subdirectory(cmdHelper)
add_subdirectory(config)
add_subdirectory(data_provider)
add_subdirectory(dbsync)
add_subdirectory(error_messages)
if(NOT MSVC)
add_subdirectory(file_op)
endif()
add_subdirectory(encodingHelper)
add_subdirectory(fileHelper)
add_subdirectory(filesystem_wrapper)
add_subdirectory(globHelper)
add_subdirectory(hashHelper)
add_subdirectory(jsonHelper)
add_subdirectory(linuxHelper)
add_subdirectory(logger)
add_subdirectory(mem_op)
add_subdirectory(mapWrapper)
add_subdirectory(networkHelper)
add_subdirectory(pal)
add_subdirectory(privsep_op)
add_subdirectory(pthreads_op)
add_subdirectory(randombytes)
add_subdirectory(regex_op)
add_subdirectory(pipelineHelper)
add_subdirectory(registryHelper)
add_subdirectory(sqliteWrapper)
add_subdirectory(time_op)
add_subdirectory(stringHelper)
add_subdirectory(threadDispatcher)
add_subdirectory(timeHelper)
add_subdirectory(utils)
add_subdirectory(windowsHelper)

if(BUILD_TESTS)
enable_testing()
Expand Down
15 changes: 0 additions & 15 deletions src/common/binaries_op/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +0,0 @@
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
${COMMON_FOLDER}/error_messages/include
${COMMON_FOLDER}/file_op/include
${COMMON_FOLDER}/pal/include
${COMMON_FOLDER}/utils/include)

target_link_libraries(binaries_op
utils
Logger
pal
time_op)
1 change: 0 additions & 1 deletion src/common/binaries_op/src/binaries_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <stdlib.h>
#include "os_err.h"
#include "os_macros.h"
#include "pal.h"

#ifndef WIN32
#include "file_op.h"
Expand Down
2 changes: 1 addition & 1 deletion src/common/byteArrayHelper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12.4)
cmake_minimum_required(VERSION 3.22)

if(UNIT_TEST)
add_subdirectory(tests)
Expand Down
2 changes: 1 addition & 1 deletion src/common/byteArrayHelper/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12.4)
cmake_minimum_required(VERSION 3.22)

project(utils_unit_test)

Expand Down
2 changes: 1 addition & 1 deletion src/common/cmdHelper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12.4)
cmake_minimum_required(VERSION 3.22)

if(UNIT_TEST)
add_subdirectory(tests)
Expand Down
2 changes: 1 addition & 1 deletion src/common/cmdHelper/include/cmdHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <cstdio>
#include <memory>
#include <vector>
#include "pal.h"
#include "../../pal/include/pal.h"

#ifdef __GNUC__
#pragma GCC diagnostic push
Expand Down
2 changes: 1 addition & 1 deletion src/common/cmdHelper/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12.4)
cmake_minimum_required(VERSION 3.22)

project(utils_unit_test)

Expand Down
37 changes: 15 additions & 22 deletions src/common/data_provider/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,29 +90,21 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/)
include_directories(${SRC_FOLDER}/headers/)
include_directories(${SRC_FOLDER}/common/)
include_directories(${SRC_FOLDER}/common/utils/)
include_directories(${SRC_FOLDER}/common/byteArrayHelper/include/)
include_directories(${SRC_FOLDER}/common/cmdHelper/include/)
include_directories(${SRC_FOLDER}/common/globHelper/include/)
include_directories(${SRC_FOLDER}/common/fileHelper/include/)
include_directories(${SRC_FOLDER}/common/jsonHelper/include/)
include_directories(${SRC_FOLDER}/common/linuxHelper/include/)
include_directories(${SRC_FOLDER}/common/networkHelper/include/)
include_directories(${SRC_FOLDER}/common/sqliteWrapper/include/)
include_directories(${SRC_FOLDER}/common/stringHelper/include/)
include_directories(${SRC_FOLDER}/common/timeHelper/include/)
include_directories(${SRC_FOLDER}/shared_modules/common/)
include_directories(${SRC_FOLDER}/common/pal/include/)

if(WIN32)
include_directories(${SRC_FOLDER}/common/time_op/include/)
include_directories(${SRC_FOLDER}/common/regex_op/include/)
include_directories(${SRC_FOLDER}/common/validate_op/include/)
include_directories(${SRC_FOLDER}/common/binaries_op/include/)
include_directories(${SRC_FOLDER}/common/randombytes/include/)
include_directories(${SRC_FOLDER}/common/error_messages/include/)
include_directories(${SRC_FOLDER}/common/encodingHelper/include/)
include_directories(${SRC_FOLDER}/common/registryHelper/include/)
include_directories(${SRC_FOLDER}/common/windowsHelper/include/)
include_directories(${SRC_FOLDER}/common/encodingHelper/include/)
include_directories(${SRC_FOLDER}/common/mem_op/include/)
endif()

get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE)
Expand Down Expand Up @@ -178,20 +170,21 @@ elseif(APPLE)
message(FATAL_ERROR "CoreFoundation library not found! Aborting...")
endif()

target_link_libraries(sysinfo PUBLIC
unofficial::libplist::libplist
unofficial::libplist::libplist++
${iokit_lib}
${corefoundation_lib}
sqliteWrapper
LibArchive::LibArchive)
target_link_libraries(sysinfo PUBLIC
unofficial::libplist::libplist
unofficial::libplist::libplist++
${iokit_lib}
${corefoundation_lib}
LibArchive::LibArchive)
endif(CMAKE_SYSTEM_NAME STREQUAL "Windows")

target_link_libraries(sysinfo PUBLIC
pal
networkHelper
target_link_libraries(sysinfo
PUBLIC
utils
nlohmann_json::nlohmann_json
cjson)
cjson
PRIVATE
pal)

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
find_library(POPT_LIBRARY libpopt.a)
Expand Down
2 changes: 1 addition & 1 deletion src/common/data_provider/src/ports/portWindowsWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "stringHelper.h"
#include "windowsHelper.h"
#include "shared.h"
#include "pal.h"
#include <pal.h>

static const std::map<int32_t, std::string> STATE_TYPE =
{
Expand Down
1 change: 0 additions & 1 deletion src/common/data_provider/testtool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ project(sysinfo_test_tool)

include_directories(${CMAKE_SOURCE_DIR}/include/)
include_directories(${CMAKE_SOURCE_DIR}/src/)
include_directories(${SRC_FOLDER}/shared_modules/common/)

if(COVERITY)
add_definitions(-D__GNUC__=8)
Expand Down
10 changes: 4 additions & 6 deletions src/common/dbsync/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ include_directories(${COMMON_FOLDER}/mapWrapper/include/)
include_directories(${COMMON_FOLDER}/pipelineHelper/include/)
include_directories(${COMMON_FOLDER}/stringHelper/include/)
include_directories(${COMMON_FOLDER}/threadDispatcher/include/)
include_directories(${COMMON_FOLDER}/utils/)
include_directories(${COMMON_FOLDER}/pal/include)

add_definitions(-DPROMISE_TYPE=PromiseType::NORMAL)

Expand All @@ -69,14 +67,14 @@ add_library(dbsync STATIC
${DBSYNC_SRC}
${SRC_FOLDER}/${RESOURCE_OBJ})

target_link_libraries(dbsync utils nlohmann_json::nlohmann_json cjson unofficial::sqlite3::sqlite3)
target_link_libraries(dbsync PUBLIC utils nlohmann_json::nlohmann_json cjson unofficial::sqlite3::sqlite3 pal)

if(BUILD_TESTS)
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_link_libraries(dbsync -fprofile-arcs)
target_link_libraries(dbsync PRIVATE -fprofile-arcs)
else()
target_link_libraries(dbsync gcov)
target_link_libraries(dbsync PRIVATE gcov)
endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")

add_subdirectory(tests)
Expand All @@ -86,7 +84,7 @@ endif(BUILD_TESTS)

if(NOT DEFINED COVERITY AND NOT DEFINED BUILD_TESTS)
if(FSANITIZE)
target_link_libraries(dbsync gcov)
target_link_libraries(dbsync PRIVATE gcov)
endif(FSANITIZE)
add_subdirectory(example)
add_subdirectory(testtool)
Expand Down
1 change: 0 additions & 1 deletion src/common/dbsync/include/dbsync.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include <functional>
#include <nlohmann/json.hpp>
#include "db_exception.h"
#include "commonDefs.h"
#include "builder.hpp"

Expand Down
2 changes: 2 additions & 0 deletions src/common/dbsync/integrationTests/fim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
unofficial::sqlite3::sqlite3
pthread
utils
pal
-static-libgcc
)
else()
Expand All @@ -41,6 +42,7 @@ else()
pthread
dl
utils
pal
)
endif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_test(NAME fim_integration_test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define _DBSYNC_EXCEPTION_H
#include <stdexcept>
#include <string>
#include "pal.h"
#include <pal.h>

using DBSyncExceptionType = const std::pair<int, std::string>;

Expand Down
2 changes: 2 additions & 0 deletions src/common/dbsync/tests/dbengine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
cjson
pthread
utils
pal
-static-libgcc
)
else()
Expand All @@ -48,6 +49,7 @@ else()
pthread
dl
utils
pal
)
endif(CMAKE_SYSTEM_NAME STREQUAL "Windows")

Expand Down
2 changes: 2 additions & 0 deletions src/common/dbsync/tests/interface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
cjson
pthread
utils
pal
-static-libgcc
)
else()
Expand All @@ -38,6 +39,7 @@ else()
pthread
dl
utils
pal
)
endif(CMAKE_SYSTEM_NAME STREQUAL "Windows")

Expand Down
3 changes: 2 additions & 1 deletion src/common/dbsync/tests/pipelineFactory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ project(dbsyncPipelineFactory_unit_test)
set(CMAKE_CXX_FLAGS_DEBUG "-g --coverage")

include_directories(${CMAKE_SOURCE_DIR}/src/)
include_directories(${CMAKE_SOURCE_DIR}/utils/)
link_directories(${CMAKE_BINARY_DIR}/lib)


Expand All @@ -32,6 +31,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
unofficial::sqlite3::sqlite3
cjson
utils
pal
-static-libgcc
)
else()
Expand All @@ -45,6 +45,7 @@ else()
cjson
dl
utils
pal
)
endif(CMAKE_SYSTEM_NAME STREQUAL "Windows")

Expand Down
2 changes: 2 additions & 0 deletions src/common/dbsync/tests/sqlite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
unofficial::sqlite3::sqlite3
cjson
utils
pal
-static-libgcc
)
else()
Expand All @@ -38,6 +39,7 @@ else()
cjson
dl
utils
pal
)
endif(CMAKE_SYSTEM_NAME STREQUAL "Windows")

Expand Down
3 changes: 2 additions & 1 deletion src/common/dbsync/testtool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.22)
project(dbsync_test_tool)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/utils/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/testtool/)
link_directories(${CMAKE_BINARY_DIR}/lib)

Expand All @@ -26,10 +25,12 @@ add_executable(dbsync_test_tool
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(dbsync_test_tool
dbsync
utils
)
else()
target_link_libraries(dbsync_test_tool
dbsync
utils
pthread
dl
)
Expand Down
2 changes: 1 addition & 1 deletion src/common/encodingHelper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12.4)
cmake_minimum_required(VERSION 3.22)

if(UNIT_TEST)
add_subdirectory(tests)
Expand Down
2 changes: 1 addition & 1 deletion src/common/encodingHelper/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12.4)
cmake_minimum_required(VERSION 3.22)

project(utils_unit_test)

Expand Down
3 changes: 0 additions & 3 deletions src/common/error_messages/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
add_library(error_messages INTERFACE)

target_include_directories(error_messages INTERFACE include)
2 changes: 1 addition & 1 deletion src/common/fileHelper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12.4)
cmake_minimum_required(VERSION 3.22)

if(UNIT_TEST)
add_subdirectory(tests)
Expand Down
2 changes: 1 addition & 1 deletion src/common/fileHelper/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12.4)
cmake_minimum_required(VERSION 3.22)

project(utils_unit_test)

Expand Down
10 changes: 0 additions & 10 deletions src/common/file_op/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
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
${COMMON_FOLDER}/pal/include)

target_link_libraries(file_op utils time_op ZLIB::ZLIB Logger)
Loading

0 comments on commit da13669

Please sign in to comment.