-
Notifications
You must be signed in to change notification settings - Fork 70
Release v2.2.0-rc #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Release v2.2.0-rc #222
Changes from all commits
2cb8e5d
1934708
c7e7983
8cf93d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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() | ||
|
|
||
| # 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 | ||
| 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) | ||||||||||
|
||||||||||
| 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). |
There was a problem hiding this comment.
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_FILEafter theproject()call based onENV{VCPKG_ROOT}. In CMake, the toolchain file must be set before the firstproject()/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 aboveproject().