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'
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,7 @@ ASALocalRun/

# MFractors (Xamarin productivity tool) working folder
.mfractor/

# Project-specific ignores
LogMonitor/build/
vcpkg/
52 changes: 52 additions & 0 deletions LogMonitor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
cmake_minimum_required(VERSION 3.15)

# Set vcpkg toolchain before project() so CMake's compiler detection uses it.
# Callers may also pass -DCMAKE_TOOLCHAIN_FILE on the command line (takes precedence).
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "Vcpkg toolchain file")
endif()

set(VCPKG_TARGET_TRIPLET "x64-windows-static" CACHE STRING "Vcpkg target triplet")

# Define the project
project(LogMonitor)

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

# 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()

# Require C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 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
# Use $<CONFIG> so binaries land in Release/ or Debug/, matching the pipeline's $(buildConfiguration) layout.
set_target_properties(LogMonitorTests PROPERTIES
COMPILE_PDB_NAME "LogMonitorTests"
COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIG>"
LINK_FLAGS "/DEBUG:FULL /OPT:REF /OPT:ICF"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIG>"
)

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

# LogMonitorTests is a shared library (DLL) for VSTest, not a standalone executable.
# Run tests with: vstest.console.exe <build>/Release/LogMonitorTests.dll
# (as used by the Azure pipeline)
Loading
Loading