cmake_minimum_required(VERSION 3.2.2)
project(Lexesis VERSION 0.1)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED 11)


include(ExternalProject)
find_package(mstch QUIET)

if (NOT mstch_FOUND)
    ExternalProject_Add(ext-mstch
        GIT_REPOSITORY https://github.com/no1msd/mstch
        GIT_TAG 1.0.2
        #The following line is a dirty hack
        #to prevent cmake from needlessly clone any submodule
        #inspect `ext-mstch-prefix/tmp/ext-mstch-gitclone.cmake` for more info
        GIT_SUBMODULES "NONE\ COMMAND\ true\ ERROR_QUIET"
        CMAKE_ARGS -DWITH_UNIT_TESTS=NO
        INSTALL_COMMAND ""
        EXCLUDE_FROM_ALL 1
        )

    add_library(mstch::mstch IMPORTED STATIC GLOBAL)
    add_dependencies(mstch::mstch ext-mstch)

    ExternalProject_Get_Property(ext-mstch source_dir binary_dir)
    set_target_properties(mstch::mstch PROPERTIES "IMPORTED_LOCATION" "${binary_dir}/src/${CMAKE_STATIC_LIBRARY_PREFIX}mstch${CMAKE_STATIC_LIBRARY_SUFFIX}")
    include_directories(${source_dir}/include)
endif()

##########################################

set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}")

include_directories(include)
add_subdirectory(src)

install(DIRECTORY templates
    DESTINATION share/Lexesis
    )
