135 lines
3.6 KiB
CMake
135 lines
3.6 KiB
CMake
cmake_minimum_required(VERSION 3.15)
|
|
project(DNSPacketFilter VERSION 1.0.0 LANGUAGES CXX)
|
|
|
|
# Require C++17
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
# Build type
|
|
if(NOT CMAKE_BUILD_TYPE)
|
|
set(CMAKE_BUILD_TYPE Release)
|
|
endif()
|
|
|
|
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
|
|
|
|
# Compiler flags
|
|
if(MSVC)
|
|
add_compile_options(/W4)
|
|
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
|
add_definitions(-DNOMINMAX)
|
|
# Enable multi-processor compilation
|
|
add_compile_options(/MP)
|
|
else()
|
|
add_compile_options(-Wall -Wextra -Wpedantic)
|
|
endif()
|
|
|
|
# Include directories
|
|
include_directories(
|
|
${CMAKE_SOURCE_DIR}/include
|
|
${CMAKE_SOURCE_DIR}/external/WinDivert/include
|
|
${CMAKE_SOURCE_DIR}/external/json
|
|
)
|
|
|
|
# Link directories (Windows only)
|
|
if(WIN32)
|
|
link_directories(
|
|
${CMAKE_SOURCE_DIR}/external/WinDivert/lib
|
|
)
|
|
endif()
|
|
|
|
# Source files
|
|
set(SOURCES
|
|
src/main.cpp
|
|
src/dns_parser.cpp
|
|
src/rule_engine.cpp
|
|
src/logger.cpp
|
|
src/config_manager.cpp
|
|
src/packet_filter.cpp
|
|
)
|
|
|
|
# Header files (for IDE)
|
|
set(HEADERS
|
|
include/common.h
|
|
include/dns_parser.h
|
|
include/rule_engine.h
|
|
include/logger.h
|
|
include/config_manager.h
|
|
include/packet_filter.h
|
|
)
|
|
|
|
# Executable
|
|
add_executable(dns_filter ${SOURCES} ${HEADERS})
|
|
|
|
# Link libraries
|
|
if(WIN32)
|
|
target_link_libraries(dns_filter
|
|
WinDivert
|
|
ws2_32 # Windows Sockets
|
|
iphlpapi # IP Helper API
|
|
)
|
|
else()
|
|
# For development on non-Windows platforms
|
|
target_link_libraries(dns_filter
|
|
pthread
|
|
)
|
|
endif()
|
|
|
|
# Windows-specific: Copy DLL and driver to output directory
|
|
if(WIN32)
|
|
add_custom_command(TARGET dns_filter POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E echo "Copying WinDivert files..."
|
|
)
|
|
|
|
add_custom_command(TARGET dns_filter POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
"${CMAKE_SOURCE_DIR}/external/WinDivert/lib/WinDivert.dll"
|
|
$<TARGET_FILE_DIR:dns_filter>
|
|
COMMENT "Copying WinDivert.dll"
|
|
)
|
|
|
|
add_custom_command(TARGET dns_filter POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
"${CMAKE_SOURCE_DIR}/external/WinDivert/lib/WinDivert64.sys"
|
|
$<TARGET_FILE_DIR:dns_filter>
|
|
COMMENT "Copying WinDivert64.sys"
|
|
)
|
|
endif()
|
|
|
|
# Copy default configuration
|
|
add_custom_command(TARGET dns_filter POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory
|
|
$<TARGET_FILE_DIR:dns_filter>/config
|
|
COMMENT "Creating config directory"
|
|
)
|
|
|
|
add_custom_command(TARGET dns_filter POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
"${CMAKE_SOURCE_DIR}/config/rules.json"
|
|
$<TARGET_FILE_DIR:dns_filter>/config/rules.json
|
|
COMMENT "Copying default configuration"
|
|
)
|
|
|
|
# Installation rules (optional)
|
|
if(WIN32)
|
|
install(TARGETS dns_filter DESTINATION bin)
|
|
install(FILES
|
|
external/WinDivert/lib/WinDivert.dll
|
|
external/WinDivert/lib/WinDivert64.sys
|
|
DESTINATION bin)
|
|
install(FILES config/rules.json DESTINATION bin/config)
|
|
install(FILES README.md DESTINATION .)
|
|
endif()
|
|
|
|
# Print configuration summary
|
|
message(STATUS "")
|
|
message(STATUS "====================================")
|
|
message(STATUS "DNS Packet Filter Configuration")
|
|
message(STATUS "====================================")
|
|
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
|
|
message(STATUS "C++ standard: C++${CMAKE_CXX_STANDARD}")
|
|
message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID}")
|
|
message(STATUS "Platform: ${CMAKE_SYSTEM_NAME}")
|
|
message(STATUS "====================================")
|
|
message(STATUS "")
|