Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/sdl-compliance-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ jobs:
queries: security-and-quality # Default is "security-extended"
build-mode: ${{ matrix.build-mode }}

- name: Install vcpkg and nlohmann-json
run: |
git clone https://github.com/microsoft/vcpkg.git vcpkg
.\vcpkg\bootstrap-vcpkg.bat
.\vcpkg\vcpkg.exe install nlohmann-json:x64-windows
.\vcpkg\vcpkg.exe integrate install

# https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-command-line-reference?view=vs-2022#arguments
- name: Build LogMonitor
run: |
Expand All @@ -84,4 +91,4 @@ jobs:
with:
# The path of the directory in which to save the SARIF results (../results/cpp.sarif)
output: ${{ env.CodeQLResultsDir }}
upload: "always" # Options: 'always', 'failure-only', 'never'
upload: "always" # Options: 'always', 'failure-only', 'never'
55 changes: 55 additions & 0 deletions LogMonitor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
cmake_minimum_required(VERSION 3.15)

# Define the project
project(LogMonitor)

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)

# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_BUILD_TYPE Release)
set(VCPKG_TARGET_TRIPLET x64-windows-static)

# Use vcpkg if available
if(DEFINED ENV{VCPKG_ROOT})
set(VCPKG_ROOT $ENV{VCPKG_ROOT})
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file" FORCE)
set(VCPKG_TARGET_TRIPLET "x64-windows-static" CACHE STRING "Vcpkg target triplet")
endif()

Comment on lines +17 to +23
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This root CMakeLists sets CMAKE_TOOLCHAIN_FILE after the project() call based on ENV{VCPKG_ROOT}. In CMake, the toolchain file must be set before the first project()/language enable to reliably take effect; setting it here is typically too late and can lead to confusing, non-reproducible dependency resolution. Prefer requiring callers/CI to pass -DCMAKE_TOOLCHAIN_FILE=... on the command line (as the pipeline already does) and remove the late mutation here, or move toolchain selection above project().

Copilot uses AI. Check for mistakes.
# Enforce static MSVC runtime (/MT or /MTd)
if(MSVC)
foreach(flag_var CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG)
string(REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endforeach()
endif()

# Set Windows SDK version if available
if (DEFINED ENV{SDKVersion})
set(CMAKE_SYSTEM_VERSION $ENV{SDKVersion})
endif()

# Enable Unicode globally
add_definitions(-DUNICODE -D_UNICODE)

# Enable warnings
if (MSVC)
add_compile_options(/W4)
else()
add_compile_options(-Wall -Wextra -pedantic)
endif()

# Enable testing framework
enable_testing()

# Find dependencies
find_package(nlohmann_json CONFIG REQUIRED)

# Include subdirectories for main and test executables
add_subdirectory(src) # Add main executable's CMake
add_subdirectory(LogMonitorTests) # Add test executable's CMake
42 changes: 42 additions & 0 deletions LogMonitor/LogMonitorTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.15)

project(LogMonitorTests)

find_package(nlohmann_json CONFIG REQUIRED)

# Automatically gather all test source files
file(GLOB_RECURSE TEST_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.cpp")

# Ensure all source files exist before proceeding
if(NOT TEST_SOURCES)
message(FATAL_ERROR "No valid source files found for LogMonitorTests.")
endif()

# Define test shared library (DLL)
add_library(LogMonitorTests SHARED ${TEST_SOURCES})

# Add a definition for symbol exporting
target_compile_definitions(LogMonitorTests PRIVATE LOGMONITORTESTS_EXPORTS)

# Include directories (for headers)
target_include_directories(LogMonitorTests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR} # Includes Utility.h and pch.h
${CMAKE_CURRENT_SOURCE_DIR}/../src
${CMAKE_CURRENT_SOURCE_DIR}/../src/LogMonitor
)

# Set Windows-specific linker flags
set_target_properties(LogMonitorTests PROPERTIES
COMPILE_PDB_NAME "LogMonitorTests"
COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
LINK_FLAGS "/DEBUG:FULL /OPT:REF /OPT:ICF"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
)

# Link LogMonitor and Nlohmann JSON
target_link_libraries(LogMonitorTests PRIVATE LogMonitorLib nlohmann_json::nlohmann_json)

# Enable testing
enable_testing()

add_test(NAME LogMonitorTests COMMAND LogMonitorTests)
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add_test(NAME LogMonitorTests COMMAND LogMonitorTests) attempts to execute LogMonitorTests, but this target is declared as add_library(LogMonitorTests SHARED ...) (a DLL), not an executable, so ctest will fail if used. Either produce a proper test runner executable for CTest, or remove the add_test entry and document that tests must be run via vstest.console.exe (as the Azure pipeline does).

Suggested change
add_test(NAME LogMonitorTests COMMAND LogMonitorTests)
# LogMonitorTests is built as a shared library (DLL), not a standalone executable.
# Do not register it as a CTest command; run it with an external test runner
# such as vstest.console.exe (as used by the Azure pipeline).

Copilot uses AI. Check for mistakes.
Loading
Loading