# Integration test for cx_boost_* macros
# This creates a real project context to validate boost detection and linking

cmake_minimum_required(VERSION 3.10)
project(CxBoostIntegrationTest VERSION 1.0.0)

# Add parent modules to path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../Modules")

# Include the macros being tested
include(cx_boost_base)
include(cx_boost_filesystem)
include(cx_boost_system)
include(cx_boost_component)

# Test boost detection with cx_boost macros
message(STATUS "Testing cx_boost_* macros in real project context...")

# Use the macros
cx_boost_base(1.40 VERBOSE)
cx_boost_filesystem(VERBOSE)  
cx_boost_system(VERBOSE)

# Validate results
if(BOOST_FOUND)
    message(STATUS "✅ Boost detection successful")
    message(STATUS "  Version: ${BOOST_VERSION}")
    message(STATUS "  Include dir: ${BOOST_INCLUDEDIR}")
    message(STATUS "  Library dir: ${BOOST_LIBRARYDIR}")
    
    # Add library directory to link search paths (must be before add_executable)
    if(BOOST_LIBRARYDIR)
        link_directories(${BOOST_LIBRARYDIR})
    endif()
    
    # Create a simple test executable to verify linking
    add_executable(boost_test_simple boost_test_simple.cpp)
    
    # Link boost libraries if found
    if(BOOST_FILESYSTEM_FOUND AND BOOST_SYSTEM_FOUND)
        # Set include directories
        target_include_directories(boost_test_simple PRIVATE ${BOOST_INCLUDEDIR})
        
        # Link libraries - the cx_boost_* macros now provide a consistent interface
        # They automatically use modern CMake targets when available
        target_link_libraries(boost_test_simple 
            ${BOOST_FILESYSTEM_LIB} 
            ${BOOST_SYSTEM_LIB}
        )
        
        message(STATUS "✅ Test executable configured with boost libraries")
        message(STATUS "  Filesystem: ${BOOST_FILESYSTEM_LIB}")
        message(STATUS "  System: ${BOOST_SYSTEM_LIB}")
        message(STATUS "  Library dir: ${BOOST_LIBRARYDIR}")
        
        # The macros handle the complexity internally - users get consistent interface
    else()
        message(STATUS "⚠️  Some boost components not found")
        if(NOT BOOST_FILESYSTEM_FOUND)
            message(STATUS "  Missing: boost filesystem")
        endif()
        if(NOT BOOST_SYSTEM_FOUND)
            message(STATUS "  Missing: boost system")
        endif()
    endif()
    
else()
    message(STATUS "❌ Boost detection failed")
endif()

# Test individual components
message(STATUS "Testing individual component detection...")

set(TEST_COMPONENTS filesystem system thread chrono)
foreach(COMPONENT ${TEST_COMPONENTS})
    cx_boost_component(${COMPONENT})
    string(TOUPPER ${COMPONENT} COMPONENT_UPPER)
    if(BOOST_${COMPONENT_UPPER}_FOUND)
        message(STATUS "✅ Component ${COMPONENT}: found")
    else()
        message(STATUS "❌ Component ${COMPONENT}: not found")
    endif()
endforeach()

# Summary
message(STATUS "cx_boost_* macro integration testing complete")