# enable FetchContent
include(FetchContent)


if(NOT fmt_FOUND)
  # If it was not found, download fmt
  message(STATUS "Downloading fmt 9.1.0 from github")
  FetchContent_Declare(fmt                            # name of the content
    GIT_REPOSITORY https://github.com/fmtlib/fmt.git  # the repository
    GIT_TAG        9.1.0                              # the tag
    SOURCE_SUBDIR  _ignore_                           # ignore CMakeLists
  )
  FetchContent_MakeAvailable(fmt)

  dune_add_library(fmt
    SOURCES ${fmt_SOURCE_DIR}/src/format.cc
    EXPORT_NAME fmt NAMESPACE fmt::)
  target_compile_features(fmt PRIVATE cxx_std_17)
  target_include_directories(fmt PUBLIC
    $<BUILD_INTERFACE:${fmt_SOURCE_DIR}/include>)
  file(GLOB FMT_HEADERS ${fmt_SOURCE_DIR}/include/fmt/*.h)
  install(FILES ${FMT_HEADERS}
    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/fmt)
endif()


if(NOT muparser_FOUND)
  # If it was not found, download muparser
  message(STATUS "Downloading muparser v2.3.4 from github")
  FetchContent_Declare(muparser                       # name of the content
    GIT_REPOSITORY https://github.com/beltoforion/muparser.git  # the repository
    GIT_TAG        v2.3.4                             # the tag
    SOURCE_SUBDIR  _ignore_                           # ignore CMakeLists
  )
  FetchContent_MakeAvailable(muparser)

  dune_add_library(muparser
    SOURCES ${muparser_SOURCE_DIR}/src/muParser.cpp
            ${muparser_SOURCE_DIR}/src/muParserBase.cpp
            ${muparser_SOURCE_DIR}/src/muParserBytecode.cpp
            ${muparser_SOURCE_DIR}/src/muParserCallback.cpp
            ${muparser_SOURCE_DIR}/src/muParserDLL.cpp
            ${muparser_SOURCE_DIR}/src/muParserError.cpp
            ${muparser_SOURCE_DIR}/src/muParserInt.cpp
            ${muparser_SOURCE_DIR}/src/muParserTest.cpp
            ${muparser_SOURCE_DIR}/src/muParserTokenReader.cpp
    EXPORT_NAME muparser NAMESPACE muparser::)

  target_compile_features(muparser PRIVATE cxx_std_17)
  target_include_directories(muparser PUBLIC
    $<BUILD_INTERFACE:${muparser_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:include/muparser>)
  file(GLOB MUPARSER_HEADERS ${muparser_SOURCE_DIR}/include/*.h)
  install(FILES ${MUPARSER_HEADERS}
    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/muparser)
endif()