cmake_minimum_required(VERSION 3.15)
project(cire
    VERSION 0.2.4
    DESCRIPTION "Multi-language NLP keyword extractor (C++17, header-only deps)"
    LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
    set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE)
endif()

include(CheckIPOSupported)
check_ipo_supported(RESULT lto_supported OUTPUT error)
if(lto_supported)
    set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()


if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
    add_compile_options(-Wall -Wextra -Wpedantic -Wno-unused-parameter)
endif()

# ----- core library -----
add_library(cire
    src/types.cpp
    src/tokenizer.cpp
    src/stopwords.cpp
    src/ngrams.cpp
    src/tfidf.cpp
    src/yake.cpp
    src/textrank.cpp
    src/rake.cpp
    src/extractor.cpp
    src/snapper.cpp
)
target_include_directories(cire
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        $<INSTALL_INTERFACE:include>
)
target_compile_features(cire PUBLIC cxx_std_17)
set_target_properties(cire PROPERTIES POSITION_INDEPENDENT_CODE ON)

# ----- example programs -----
add_executable(cire_demo examples/demo.cpp)
target_link_libraries(cire_demo PRIVATE cire)

add_executable(example1 examples/example1.cpp)
target_link_libraries(example1 PRIVATE cire)

add_executable(example2_twi examples/example2_twi.cpp)
target_link_libraries(example2_twi PRIVATE cire)



# ----- tests -----
enable_testing()
add_executable(cire_tests tests/test_main.cpp)
target_link_libraries(cire_tests PRIVATE cire)
add_test(NAME cire_tests COMMAND cire_tests)

add_executable(cire_bench tests/benchmark_main.cpp)
target_link_libraries(cire_bench PRIVATE cire)

# ----- Python bindings (optional) -----
# Build with:  cmake -DCIRE_BUILD_PYTHON=ON ..
# Requires pybind11 (find_package or add_submodule).
option(CIRE_BUILD_PYTHON "Build the pybind11 Python module" OFF)
if(CIRE_BUILD_PYTHON)
    find_package(pybind11 QUIET)
    if(NOT pybind11_FOUND)
        message(FATAL_ERROR
            "pybind11 not found. Install with `pip install pybind11` or set "
            "pybind11_DIR to the cmake config directory.")
    endif()
    pybind11_add_module(cire_native
        ../python/bindings.cpp
    )
    target_link_libraries(cire_native PRIVATE cire pybind11::module)
    target_include_directories(cire_native PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/include
    )
    install(TARGETS cire_native
        LIBRARY DESTINATION cire
        RUNTIME DESTINATION cire
        ARCHIVE DESTINATION cire
    )
endif()
