Skip to content

Commit 24ef884

Browse files
Merge branch 'main' of github.com:ZephyrCodesStuff/logparser
2 parents 3aa1db0 + fc5bfd1 commit 24ef884

4 files changed

Lines changed: 67 additions & 22 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,22 @@ jobs:
4242
- name: Checkout repository (uses git)
4343
uses: actions/checkout@v4
4444

45-
- name: Configure with CMake (Windows, use preinstalled GCC)
45+
- name: Configure with CMake (Windows, MSVC)
4646
if: matrix.name == 'windows-x86_64'
4747
shell: pwsh
4848
run: |
49-
Write-Host "Configuring with preinstalled GCC and Ninja on Windows"
50-
# build argument array: basic args
51-
$args = @('-S', 'parsers/cpp', '-B', 'build', '-G', 'Ninja')
52-
# append environment CMAKE_* defs
49+
Write-Host "Configuring with Visual Studio 2022 (MSVC) on Windows"
50+
$args = @('-S', 'parsers/cpp', '-B', 'build', '-G', 'Visual Studio 17 2022', '-A', 'x64')
5351
Get-ChildItem env:CMAKE_* | ForEach-Object { $args += "-D$($_.Name)=$($_.Value)" }
54-
# set compilers explicitly to the preinstalled gcc/g++
55-
$args += '-DCMAKE_C_COMPILER=gcc'
56-
$args += '-DCMAKE_CXX_COMPILER=g++'
5752
Write-Host "Running: cmake $($args -join ' ')"
5853
& cmake @args
5954
60-
- name: Build (Windows using preinstalled GCC/Ninja)
55+
- name: Build (Windows with MSVC)
6156
if: matrix.name == 'windows-x86_64'
6257
shell: pwsh
6358
run: |
64-
Write-Host "Building with Ninja using preinstalled GCC"
65-
cmake --build build --parallel
59+
Write-Host "Building with MSVC using CMake"
60+
cmake --build build --config Release --parallel
6661
6762
- name: Configure with CMake (macOS/Linux)
6863
if: matrix.name != 'windows-x86_64'

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 zeph
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

parsers/cpp/CMakeLists.txt

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
cmake_minimum_required(VERSION 2.8.12...3.15)
22
project(logfile_parser_cpp LANGUAGES CXX)
33

4+
# Use the static runtime on MSVC so the produced binaries do not depend on the
5+
# redistributable DLLs. This also matches the statically built ANTLR runtime.
6+
if(MSVC)
7+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
8+
endif()
9+
10+
set(_antlr_runtime_is_static OFF)
11+
412
# Prefer a known Homebrew install or project-local jar if present
513
if(NOT ANTLR_EXECUTABLE)
614
if(EXISTS "/opt/homebrew/Cellar/antlr/4.13.2/antlr-4.13.2-complete.jar")
@@ -24,19 +32,30 @@ if(NOT TARGET ANTLR4::Runtime AND NOT TARGET ANTLR::Runtime)
2432

2533
include(FetchContent)
2634

35+
# Ensure the fetched ANTLR runtime is built statically. This keeps the
36+
# Windows binary self-contained and avoids shipping libantlr4 DLLs.
37+
set(ANTLR4_BUILD_SHARED OFF CACHE BOOL "Build ANTLR4 shared runtime" FORCE)
38+
set(ANTLR4_BUILD_STATIC ON CACHE BOOL "Build ANTLR4 static runtime" FORCE)
39+
set(ANTLR4_INSTALL OFF CACHE BOOL "Skip installing ANTLR4 runtime" FORCE)
40+
if(MSVC)
41+
set(ANTLR4_WITH_STATIC_CRT ON CACHE BOOL "Link ANTLR4 runtime against the static Microsoft CRT" FORCE)
42+
endif()
43+
2744
# Only fetch/build if we don't already have runtime variables pointing to a prebuilt lib.
2845
if(NOT DEFINED ANTLR_RUNTIME_LIBRARY AND NOT DEFINED ANTLR_LIBRARY)
2946
message(STATUS "Attempting to FetchContent antlr/antlr4 to build the C++ runtime")
3047

48+
# Define the ANTLR 4 branch / commit hash
49+
set(ANTLR4_TAG bd8f9930d053ec6a83e7d751e8c6f69138957665)
50+
3151
FetchContent_Declare(
3252
antlr4
3353
GIT_REPOSITORY https://github.com/antlr/antlr4.git
34-
# Pin to a compatible version (change tag if you want a different release)
35-
GIT_TAG 4.13.2
54+
GIT_TAG ${ANTLR4_TAG} # dev as of 2025-10-16
3655
)
3756

38-
# This will clone into the build directory and make antlr4_SOURCE_DIR available.
39-
FetchContent_MakeAvailable(antlr4)
57+
# This will clone into the build directory and make antlr4_SOURCE_DIR available.
58+
FetchContent_MakeAvailable(antlr4)
4059

4160
# Make ANTLR CMake helper macros discoverable if provided by the fetched source.
4261
if(DEFINED antlr4_SOURCE_DIR)
@@ -70,19 +89,20 @@ if(NOT TARGET ANTLR4::Runtime AND NOT TARGET ANTLR::Runtime)
7089
endif()
7190

7291
# Create alias targets matching common Find module conventions so existing code can link unchanged.
73-
if(TARGET antlr4_shared)
92+
if(TARGET antlr4_static)
7493
if(NOT TARGET ANTLR4::Runtime)
75-
add_library(ANTLR4::Runtime ALIAS antlr4_shared)
94+
add_library(ANTLR4::Runtime ALIAS antlr4_static)
7695
endif()
7796
if(NOT TARGET ANTLR::Runtime)
78-
add_library(ANTLR::Runtime ALIAS antlr4_shared)
97+
add_library(ANTLR::Runtime ALIAS antlr4_static)
7998
endif()
80-
elseif(TARGET antlr4_static)
99+
set(_antlr_runtime_is_static ON)
100+
elseif(TARGET antlr4_shared)
81101
if(NOT TARGET ANTLR4::Runtime)
82-
add_library(ANTLR4::Runtime ALIAS antlr4_static)
102+
add_library(ANTLR4::Runtime ALIAS antlr4_shared)
83103
endif()
84104
if(NOT TARGET ANTLR::Runtime)
85-
add_library(ANTLR::Runtime ALIAS antlr4_static)
105+
add_library(ANTLR::Runtime ALIAS antlr4_shared)
86106
endif()
87107
else()
88108
message(STATUS "FetchContent provided antlr4 but runtime targets not found; will try bundled runtime or Find module variables")
@@ -109,6 +129,11 @@ set_target_properties(logparser PROPERTIES
109129
CXX_EXTENSIONS NO
110130
)
111131

132+
# For Windows, we have to define `NOMINMAX` to prevent Windows headers from defining `min` and `max` macros.
133+
if(MSVC)
134+
target_compile_definitions(logparser PRIVATE NOMINMAX)
135+
endif()
136+
112137
# Link to the ANTLR runtime. Support several possible Find module conventions.
113138
if(TARGET ANTLR4::Runtime)
114139
target_link_libraries(logparser PRIVATE ANTLR4::Runtime)
@@ -122,6 +147,10 @@ else()
122147
message(FATAL_ERROR "ANTLR runtime target or variables not found. Verify FindANTLR.cmake")
123148
endif()
124149

150+
if(_antlr_runtime_is_static)
151+
target_compile_definitions(logparser PRIVATE ANTLR4CPP_STATIC)
152+
endif()
153+
125154
# Add include directories if the find module provided them
126155
if(DEFINED ANTLR_RUNTIME_INCLUDE_DIR)
127156
target_include_directories(logparser PRIVATE ${ANTLR_RUNTIME_INCLUDE_DIR})

parsers/cpp/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ bool parse_file_into_csv( const fs::path& input_file,
286286
if ( !fs::exists( input_file ) )
287287
{
288288
std::cerr << "File not found: " << input_file << '\n';
289-
return 2;
289+
return false;
290290
}
291291

292292
// read file into memory via mmap

0 commit comments

Comments
 (0)