Skip to content

Commit

Permalink
Refactored kafka_consumer.cpp and added an executable to `CMakeList…
Browse files Browse the repository at this point in the history
…s.txt`
  • Loading branch information
dmccoystephenson committed Apr 21, 2023
1 parent 442cb57 commit 93b5650
Show file tree
Hide file tree
Showing 4 changed files with 591 additions and 558 deletions.
97 changes: 58 additions & 39 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
# Minimum required version of CMake
cmake_minimum_required(VERSION 2.6)

# Project name
project(ppm)

# need to set these prior to setting any targets.
# Set C++ standard to 11 and make it required
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Optimization flags
set(CMAKE_CXX_FLAGS "-O3")
set(CMAKE_C_FLAGS "-O3")

# Set options for macOS
if (${APPLE})
set(CMAKE_CXX_EXTENSIONS OFF)
set(MACPORTS_DIR "/opt")
endif ()

if(CMAKE_COMPILER_IS_GNUCXX) # add coverage compiler option
# Add coverage compiler option for GNU C++
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)
endif()
Expand All @@ -32,53 +37,73 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/spdlog")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/general-redaction")
include_directories("/usr/local/include")

# Add include directory for macOS
if (${APPLE})
include_directories( "${MACPORTS_DIR}/local/include")
include_directories("${MACPORTS_DIR}/local/include")
link_directories("${MACPORTS_DIR}/local/lib" "/usr/lib" "/usr/local/lib")
endif ()

#### BUILD TARGET FOR THE PPM ####

set(PPM_SRC "src/general-redaction/redactionPropertiesManager.cpp"
"src/general-redaction/rapidjsonRedactor.cpp"
"src/bsm.cpp"
"src/bsmHandler.cpp"
"src/idRedactor.cpp"
"src/ppm.cpp"
"src/tool.cpp"
"src/velocityFilter.cpp"
"src/ppmLogger.cpp"
)

add_executable(ppm ${PPM_SRC})
target_link_libraries(ppm pthread CVLib rdkafka++)

#### BUILD TARGET FOR THE PPM UNIT TESTS AND CODE COVERAGE ####

set(PPM_TEST_SRC "src/tests.cpp") # unit tests

#### Build target for the PPM
# List all the source files in project
set(SOURCES
"src/general-redaction/redactionPropertiesManager.cpp"
"src/general-redaction/rapidjsonRedactor.cpp"
"src/bsm.cpp"
"src/bsmHandler.cpp"
"src/idRedactor.cpp"
"src/tool.cpp"
"src/velocityFilter.cpp"
"src/ppmLogger.cpp"
)

# Create a library target for the shared sources
add_library(ppm-lib STATIC ${SOURCES})

# Link the library target with the Kafka libraries
target_link_libraries(ppm-lib PUBLIC
rdkafka
rdkafka++
)

#### Create a target for the PPM executable
add_executable(ppm "src/ppm.cpp")

# Link the PPM executable with the PPM library target
target_link_libraries(ppm PUBLIC ppm-lib CVLib)

#### Create a target for the Kafka consumer executable
add_executable(kafka_consumer "src/kafka_consumer.cpp")

# Link the Kafka consumer executable with the PPM library target and the Kafka libraries
target_link_libraries(kafka_consumer PUBLIC ppm-lib
rdkafka
rdkafka++
CVLib
)

#### Build target for the PPM unit tests and code coverage
set(PPM_TEST_SRC "src/tests.cpp") # unit tests

# Include the Catch header-only test framework
set(CATCH_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/catch")
add_library(Catch INTERFACE)
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR}) # catch is header only; tell where to find header.
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})


add_executable(ppm_tests ${PPM_TEST_SRC} ${PPM_SRC}) # need everything to build tests.
# Build the tests executable
add_executable(ppm_tests ${PPM_TEST_SRC} ${SOURCES})
target_link_libraries(ppm_tests pthread CVLib rdkafka++ Catch)
target_compile_definitions(ppm_tests PRIVATE _PPM_TESTS) # flag to exclude the tool's main.

#### BUILD TARGET FOR THE KAFKA TEST TOOL ####
target_compile_definitions(ppm_tests PRIVATE _PPM_TESTS)

#### Build target for the Kafka test tool
add_subdirectory(kafka-test)

# Copy the data to the build. TODO make this part of the test or data target.
# Copy the data and config directories to the build directory
set(BSM_DATA_DIR $<TARGET_FILE_DIR:ppm>/unit-test-data)
set(BSM_CONFIG_DIR $<TARGET_FILE_DIR:ppm>/config)

# Make the base data directory.
# Make the base data directory and copy the data files
add_custom_command(TARGET ppm PRE_BUILD COMMAND ${CMAKE_COMMAND}
-E make_directory ${BSM_DATA_DIR})
# Copy the data files.
add_custom_command(TARGET ppm PRE_BUILD COMMAND echo "Copying the data directory")
add_custom_command(TARGET ppm PRE_BUILD COMMAND ${CMAKE_COMMAND}
-E copy_directory ${PROJECT_SOURCE_DIR}/unit-test-data
${BSM_DATA_DIR})
Expand All @@ -91,9 +116,3 @@ add_custom_command(TARGET ppm POST_BUILD COMMAND echo "Copying the config direct
add_custom_command(TARGET ppm POST_BUILD COMMAND ${CMAKE_COMMAND}
-E copy_directory ${PROJECT_SOURCE_DIR}/config
${BSM_CONFIG_DIR})

# option(BUILD_TESTS "Determines whether to build tests." ON)
# if(BUILD_TESTS)
# enable_testing()
# add_test(NAME mytest1 COMMAND ppm_tests)
# endif()
7 changes: 7 additions & 0 deletions build_and_exec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# format of tag: 01-01-2020t12.00pm (lowercase t, am, pm)
tag=$(date +"%m-%d-%Yt%I.%M%p" | tr '[:upper:]' '[:lower:]')
echo "Building ppm-test-$tag"
docker build . -t ppm-test-$tag

echo "Running ppm-test-$tag"
docker run -it ppm-test-$tag /bin/bash
Loading

0 comments on commit 93b5650

Please sign in to comment.