project(coreschema)

if (PACKAGING_NSIS)
    set(LIB_NAME library_coreschema)
else()
    set(LIB_NAME library-coreschema)
endif()

# XSD really needed
find_package(XSD REQUIRED)

# Create lib files from xsd
file (GLOB_RECURSE XSD_INPUT_FILES *.xsd)

# generates headers from scratch
set (XSD_H)
set (XSD_SRCS)

if (XSD_COMMAND)
    set(XSD_COMMAND xsdcxx CACHE STRING "name of the XSD code synthesis compiler")
    # generates headers from scratch
    foreach(xsdFile ${XSD_INPUT_FILES})
        get_filename_component(xsdFileName ${xsdFile} NAME_WE)
        add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${xsdFileName}.hxx ${CMAKE_CURRENT_BINARY_DIR}/${xsdFileName}.cxx
                        COMMAND ${XSD_COMMAND}
                        ARGS cxx-tree --generate-polymorphic --generate-serialization --namespace-map =coreschema --polymorphic-type Method --polymorphic-type Criteria ${xsdFile}
                        DEPENDS ${xsdFile})
        set(XSD_H ${XSD_H} ${CMAKE_CURRENT_BINARY_DIR}/${xsdFileName}.hxx)
        set(XSD_SRCS ${XSD_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/${xsdFileName}.cxx)
    endforeach()
else()
    message(FATAL_ERROR "Cannot find xsdcxx command: cannot generate mml from scratch, try with MML_GENERATE_XSD_LIB set to OFF")
    set(MML_GENERATE_XSD_LIB OFF)
endif()

camitk_library(STATIC
               SOURCES ${XSD_H} ${XSD_SRCS}
               NEEDS_XSD
               HEADERS_TO_INSTALL ${XSD_H}
               CEP_NAME SDK
               DESCRIPTION "Allows data-binding in XML of core basic classes. Required by the application wizard for instance."
)