append_source_and_header_files(
    _sources
    _headers
    _private
    DIRECTORIES
    .
    IO
    IO/XmlIO
)
if(OGS_BUILD_GUI)
    append_source_and_header_files(
        _sources _headers _private DIRECTORIES IO/XmlIO/Qt
    )
endif()

# Create the library
ogs_add_library(
    BaseLib
    ${_sources}
    GENERATE_EXPORT_HEADER
    PUBLIC_HEADERS
    ${_headers}
    PRIVATE_HEADERS
    ${_private}
)

if(MSVC)
    # Let the toolchain/Windows SDK resolve system libraries by name. Create
    # IMPORTED library targets that represent the system libraries so
    # LINK_LIBRARIES_ONLY_TARGETS is satisfied.
    add_library(winmm UNKNOWN IMPORTED)
    set_target_properties(winmm PROPERTIES IMPORTED_LOCATION "winmm.lib")

    add_library(dbghelp UNKNOWN IMPORTED)
    set_target_properties(dbghelp PROPERTIES IMPORTED_LOCATION "dbghelp.lib")
endif()

target_link_libraries(
    BaseLib
    PUBLIC Boost::algorithm
           Boost::property_tree
           range-v3
           spdlog::spdlog
           tclap
           $<$<BOOL:${MSVC}>:${WinMM_LIBRARY}> # needed for timeGetTime
           $<$<BOOL:${MSVC}>:${DbgHelp_LIBRARY}> # needed for
                                                 # UnDecorateSymbolName
           $<$<BOOL:${OGS_BUILD_GUI}>:Qt5::Xml>
           $<$<BOOL:${OGS_BUILD_GUI}>:Qt5::XmlPatterns>
           $<$<BOOL:${OGS_USE_PETSC}>:PkgConfig::PETSC>
           $<$<TARGET_EXISTS:OpenMP::OpenMP_CXX>:OpenMP::OpenMP_CXX>
    PRIVATE xmlpatch Boost::interprocess
)

target_compile_definitions(
    BaseLib # Logging.cpp needs a redirection-safe stdout sink in wheel builds.
    PRIVATE $<$<BOOL:${OGS_BUILD_WHEEL}>:OGS_BUILD_WHEEL>
)

target_precompile_headers(BaseLib PRIVATE Error.h ConfigTree.h Logging.h)
