Files
LumberJack_TUI/CMakeLists.txt

144 lines
5.1 KiB
CMake

cmake_minimum_required(VERSION 3.15)
project(LumberJack LANGUAGES CXX)
# System and compiler configurations
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
# ==========================================
# 1. CORE LIBRARY TARGET
# ==========================================
add_library(LumberJack_core
log_parsing/log_parsing.cpp
ip_to_geo/ip_to_geo.cpp
config_reader/config.cpp
third_party/src/GeoLite2PP.cpp
third_party/src/GeoLite2PP_error_category.cpp
)
# Include paths for your modules and MaxMind headers
target_include_directories(LumberJack_core PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/log_parsing
${CMAKE_CURRENT_SOURCE_DIR}/ip_to_geo
${CMAKE_CURRENT_SOURCE_DIR}/third_party/include
)
# CROSS-PLATFORM FIXED: Automatically links appropriate binary dependencies based on OS/Architecture
if(WIN32)
if(MSVC)
# Windows via Visual Studio Compiler
target_link_libraries(LumberJack_core PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/third_party/lib/maxminddb.lib
)
else()
# Windows via MinGW/GCC Cross-Toolchain
target_link_libraries(LumberJack_core PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/third_party/lib/mingw_libmaxminddb.a
)
endif()
# Windows requires Windows Sockets API linked for libmaxminddb network resolutions
target_link_libraries(LumberJack_core PRIVATE ws2_32)
elseif(APPLE)
# macOS Specific Path Integrations
find_library(MAXMIND_LIB maxminddb HINTS /opt/homebrew/lib /usr/local/lib /opt/local/lib)
if(MAXMIND_LIB)
target_link_libraries(LumberJack_core PRIVATE ${MAXMIND_LIB})
else()
target_link_libraries(LumberJack_core PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/third_party/lib/libmaxminddb.a
)
endif()
else()
# Standard Linux (Ubuntu, Arch Linux, Fedora, or Cross-Compiling to Raspberry Pi)
if(CMAKE_CROSSCOMPILING)
# ─────────────── RASPBERRY PI TARGETING MODE ───────────────
# Forces CMake to ignore your system paths and use your ARM .so file explicitly!
message(STATUS "[LumberJack] Cross-compiling detected! Explicitly forcing ARM .so dependency.")
target_link_libraries(LumberJack_core PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/third_party/lib/libmaxminddb.so"
)
else()
# ─────────────── NATIVE ARCH LINUX HOST MODE ───────────────
# Standard configuration behavior when compiling to run on your local Arch computer
find_library(MAXMIND_LINUX maxminddb)
if(MAXMIND_LINUX)
target_link_libraries(LumberJack_core PRIVATE ${MAXMIND_LINUX})
else()
target_link_libraries(LumberJack_core PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/lib/libmaxminddb.a)
endif()
endif()
endif()
# Version definitions needed by your GeoLite2PP wrapper
target_compile_definitions(LumberJack_core PRIVATE
GEOLITE2PP_VERSION="0.0.1"
)
# ==========================================
# 2. FTXUI Library Download
# ==========================================
FetchContent_Declare(
ftxui
GIT_REPOSITORY https://github.com/ArthurSonzogni/FTXUI.git
GIT_TAG v6.1.9
)
FetchContent_MakeAvailable(ftxui)
# ==========================================
# 3. APPLICATION EXECUTABLE
# ==========================================
add_executable(LumberJack main.cpp)
# Second: Link your internal libraries and FTXUI
target_link_libraries(LumberJack PRIVATE
LumberJack_core
ftxui::screen
ftxui::dom
ftxui::component
)
# Third: Apply your static linking flags (Target now exists safely!)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(WIN32)
if(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
else()
target_link_options(LumberJack PRIVATE -static)
endif()
elseif(APPLE)
set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES)
else()
# RASPBERRY PI FIXED: Static linking libstdc++ can cause issues when cross-compiling
# without a complete sysroot. We wrap this safely.
# FORCE complete compiler runtime embedding during cross-compilation
if(CMAKE_CROSSCOMPILING)
target_link_options(LumberJack PRIVATE -static-libgcc -static-libstdc++)
else()
target_link_options(LumberJack PRIVATE -static-libgcc -static-libstdc++)
endif()
endif()
endif()
# Fourth: Set directory runtime properties
set_target_properties(LumberJack PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_BINARY_DIR}/bin/debug"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_BINARY_DIR}/bin/release"
)
# ==========================================
# 4. TEST SUITE
# ==========================================
# Disable testing during cross-compilation because your Arch Linux computer
# cannot execute compiled ARM/AArch64 test binaries locally.
if(NOT CMAKE_CROSSCOMPILING)
enable_testing()
endif()