Skip to content

Commit d24fc9b

Browse files
CharityKathureCharity Kathure
authored andcommitted
Use CMake to build project
Signed-off-by: Charity Kathure <[email protected]>
1 parent 75d5a58 commit d24fc9b

File tree

4 files changed

+107
-202
lines changed

4 files changed

+107
-202
lines changed

LogMonitor/CMakeLists.txt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
cmake_minimum_required(VERSION 3.15)
2+
3+
# Define the project
24
project(LogMonitor)
35

4-
# Use C++17 standard
6+
# Set C++ standard
57
set(CMAKE_CXX_STANDARD 17)
68
set(CMAKE_CXX_STANDARD_REQUIRED ON)
79

8-
# Add src and tests directories
9-
add_subdirectory(src)
10-
add_subdirectory(LogMonitorTests)
10+
# Use vcpkg if available
11+
if (DEFINED ENV{VCPKG_ROOT})
12+
set(VCPKG_ROOT $ENV{VCPKG_ROOT})
13+
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Toolchain file for vcpkg" FORCE)
14+
endif()
15+
16+
# Enable testing framework
17+
enable_testing()
18+
19+
# Enable Unicode globally
20+
add_definitions(-DUNICODE -D_UNICODE)
21+
22+
# Include subdirectories for main and test executables
23+
add_subdirectory(src) # Add main executable's CMake
24+
add_subdirectory(LogMonitorTests) # Add test executable's CMake
Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,58 @@
11
cmake_minimum_required(VERSION 3.15)
22

3-
# Find Boost
3+
project(LogMonitorTests)
4+
45
find_package(Boost REQUIRED)
56

6-
# Define test executable
7-
add_executable(LogMonitorTests
8-
ConfigFileParserTests.cpp
7+
set(TEST_SOURCES
8+
JsonProcessorTests.cpp
99
EtwMonitorTests.cpp
1010
EventMonitorTests.cpp
1111
LogFileMonitorTests.cpp
1212
LogMonitorTests.cpp
1313
UtilityTests.cpp
1414
Utility.cpp
15-
Utility.h
1615
pch.cpp
17-
pch.h
16+
ConfigFileParserTests.cpp
1817
)
1918

20-
# Include directories
19+
# Ensure all source files exist before proceeding
20+
foreach(FILE ${TEST_SOURCES})
21+
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${FILE}")
22+
message(WARNING "File not found: ${FILE}")
23+
list(REMOVE_ITEM TEST_SOURCES ${FILE})
24+
endif()
25+
endforeach()
26+
27+
if(NOT TEST_SOURCES)
28+
message(FATAL_ERROR "No valid source files found for LogMonitorTests.")
29+
endif()
30+
31+
# Define test shared library (DLL)
32+
add_library(LogMonitorTests SHARED ${TEST_SOURCES})
33+
34+
# Add a definition for symbol exporting
35+
target_compile_definitions(LogMonitorTests PRIVATE LOGMONITORTESTS_EXPORTS)
36+
37+
# Include directories (for headers)
2138
target_include_directories(LogMonitorTests PRIVATE
22-
${CMAKE_CURRENT_SOURCE_DIR}/../src/LogMonitor
39+
${CMAKE_CURRENT_SOURCE_DIR} # Includes Utility.h and pch.h
40+
${CMAKE_CURRENT_SOURCE_DIR}/../src
2341
${Boost_INCLUDE_DIRS}
2442
)
2543

44+
# Set Windows-specific linker flags
45+
set_target_properties(LogMonitorTests PROPERTIES
46+
COMPILE_PDB_NAME "LogMonitorTests"
47+
COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
48+
LINK_FLAGS "/DEBUG:FULL /OPT:REF /OPT:ICF"
49+
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
50+
)
51+
2652
# Link with LogMonitor and Boost
2753
target_link_libraries(LogMonitorTests PRIVATE LogMonitor ${Boost_LIBRARIES})
2854

29-
# Enable CTest
55+
# Enable testing
3056
enable_testing()
57+
3158
add_test(NAME LogMonitorTests COMMAND LogMonitorTests)

LogMonitor/src/CMakeLists.txt

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,30 @@
11
cmake_minimum_required(VERSION 3.15)
22

3-
# Find Boost (ensure Boost is installed on your system)
3+
project(LogMonitor)
4+
5+
# Find Boost (Boost is installed)
46
find_package(Boost REQUIRED)
57

6-
# Define the executable
7-
add_executable(LogMonitor
8+
# Define LogMonitor as a library instead of an executable
9+
add_library(LogMonitor
810
LogMonitor/Main.cpp
911
LogMonitor/EtwMonitor.cpp
10-
LogMonitor/EtwMonitor.h
1112
LogMonitor/EventMonitor.cpp
12-
LogMonitor/EventMonitor.h
1313
LogMonitor/JsonFileParser.cpp
1414
LogMonitor/JsonProcessor.cpp
15-
LogMonitor/JsonProcessor.h
1615
LogMonitor/LogFileMonitor.cpp
17-
LogMonitor/LogFileMonitor.h
1816
LogMonitor/ProcessMonitor.cpp
19-
LogMonitor/ProcessMonitor.h
2017
LogMonitor/Utility.cpp
21-
LogMonitor/Utility.h
2218
LogMonitor/FileMonitor/FileMonitorUtilities.cpp
23-
LogMonitor/FileMonitor/FileMonitorUtilities.h
2419
LogMonitor/pch.cpp
25-
LogMonitor/pch.h
2620
)
2721

28-
# Include directories
22+
# Include directories for LogMonitor
2923
target_include_directories(LogMonitor PRIVATE
3024
${CMAKE_CURRENT_SOURCE_DIR}/LogMonitor
31-
${CMAKE_CURRENT_SOURCE_DIR}/LogMonitor/FileMonitor
32-
${Boost_INCLUDE_DIRS} # Add Boost include directories
25+
${CMAKE_CURRENT_SOURCE_DIR}/LogMonitor/FileMonitor
26+
${Boost_INCLUDE_DIRS}
3327
)
3428

35-
# Link Boost
29+
# Link Boost libraries to LogMonitor
3630
target_link_libraries(LogMonitor PRIVATE ${Boost_LIBRARIES})

0 commit comments

Comments
 (0)