Skip to content

Commit

Permalink
Fix clang-tidy errors in RegexAST.hpp; Add Microsoft GSL as a depende…
Browse files Browse the repository at this point in the history
…ncy. (#23)

Co-authored-by: Kirk Rodrigues <[email protected]>
  • Loading branch information
SharafMohamed and kirkrodrigues authored Aug 28, 2024
1 parent 97a66bd commit 6f7c0ec
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 37 deletions.
41 changes: 41 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ endif()

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
include(FetchContent)

find_package(Microsoft.GSL QUIET CONFIG)
if (NOT Microsoft.GSL_FOUND)
FetchContent_Declare(GSL
GIT_REPOSITORY "https://github.com/microsoft/GSL"
GIT_TAG "v4.0.0"
GIT_SHALLOW ON
)
FetchContent_MakeAvailable(GSL)
endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Expand Down Expand Up @@ -69,16 +80,36 @@ set(SOURCE_FILES

set(LCHIP_INSTALL_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/log_surgeon)
set(LCHIP_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR})
# Directory for installing third-party includes that the user doesn't have installed.
set(LCHIP_THIRD_PARTY_INCLUDE_DIR "${LCHIP_INSTALL_INCLUDE_DIR}/log_surgeon/third_party_include")

add_library(log_surgeon ${SOURCE_FILES})
add_library(log_surgeon::log_surgeon ALIAS log_surgeon)
if (Microsoft.GSL_FOUND)
target_link_libraries(log_surgeon
PUBLIC
Microsoft.GSL::GSL
)
endif()
target_include_directories(log_surgeon
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
if (NOT Microsoft.GSL_FOUND)
# Since the user doesn't have GSL installed, use the GSL headers directly.
# NOTE:
# - We can't link against the `Microsoft.GSL::GSL` target since that would require adding `GSL`
# to the `install` command and force the user to have GSL installed when using log-surgeon.
# - At install time, we'll copy GSL into log-surgeon's third-party includes directory.
target_include_directories(log_surgeon
PUBLIC
$<BUILD_INTERFACE:${GSL_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${LCHIP_THIRD_PARTY_INCLUDE_DIR}>
)
endif()

target_compile_features(log_surgeon
PRIVATE cxx_std_20
Expand Down Expand Up @@ -129,6 +160,16 @@ install(
PATTERN "*.hpp"
PATTERN "*.tpp"
)
if (NOT Microsoft.GSL_FOUND)
install(
DIRECTORY
# NOTE: We don't include a trailing slash so that the gsl directory is copied rather than
# its contents.
"${GSL_SOURCE_DIR}/include/gsl"
DESTINATION
"${LCHIP_THIRD_PARTY_INCLUDE_DIR}"
)
endif ()

configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/log_surgeon-config.cmake.in
Expand Down
4 changes: 4 additions & 0 deletions cmake/log_surgeon-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ include(CMakeFindDependencyMacro)

@PACKAGE_INIT@

if (@Microsoft.GSL_FOUND@)
find_dependency(Microsoft.GSL)
endif()

set_and_check(log_surgeon_INCLUDE_DIR "@PACKAGE_LCHIP_INSTALL_INCLUDE_DIR@")

check_required_components(log_surgeon)
Expand Down
2 changes: 1 addition & 1 deletion src/log_surgeon/LogParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void LogParser::add_rules(std::unique_ptr<SchemaAST> schema_ast) {
rule->m_regex_ptr->remove_delimiters_from_wildcard(delimiters);
// currently, error out if non-timestamp pattern contains a delimiter
// check if regex contains a delimiter
bool is_possible_input[cUnicodeMax] = {false};
std::array<bool, cUnicodeMax> is_possible_input{};
rule->m_regex_ptr->set_possible_inputs_to_true(is_possible_input);
bool contains_delimiter = false;
uint32_t delimiter_name = 0;
Expand Down
Loading

0 comments on commit 6f7c0ec

Please sign in to comment.