
set(_MACROCORE_LIB_SRC
    value.cc code.cc variable.cc context.cc script.cc files.cc
    misc.cc number.cc stack.cc date.cc mstring.cc request.cc
    Unix.cc grib.cc mlist.cc module.cc remote.cc function.cc
    matrix.cc image.cc arith.cc extern.cc mvector.cc mtable.cc library.cc
    debug.cc bufr.cc compute.cc mgptset.cc vismod.cc
    netcdf.cc object.cc pngjpeg.cc mflextra.cc
    methods.cc
    python.cc
    macroy.c
    compile.cc
)

 # relative to the current source directory
include_directories( include )


if( HAVE_PPROC_MIR )
    add_definitions( -DHAVE_PPROC_MIR )
    include_directories(${MIR_INCLUDE_DIRS})
endif()

if( HAVE_PPROC_EMOS )
    add_definitions( -DHAVE_PPROC_EMOS )
endif()

if( ENABLE_UI )
    add_definitions( -DENABLE_UI )
endif()

if( ENABLE_PLOTTING )
    add_definitions( -DENABLE_PLOTTING )
endif()


ecbuild_generate_yy(YYPREFIX zz LEX macrol YACC macroy DEPENDANT compile.cc)

if(ENABLE_ODB)
    list(APPEND _MACROCORE_LIB_SRC codb.cc)
    list(APPEND _MACRO_LIBS ${METVIEW_ODB_API_LIBRARIES})
endif()


ecbuild_append_to_rpath("../lib") # so that libMvMacro can find libMvUtil, etc

ecbuild_add_library(
    TARGET  MvMacro
    TYPE             SHARED
    SOURCES          ${_MACROCORE_LIB_SRC}
    TEMPLATES        ${common_templates}
    DEFINITIONS      ${METVIEW_EXTRA_DEFINITIONS}
    PRIVATE_INCLUDES ${METVIEW_STANDARD_INCLUDES}
    PUBLIC_LIBS      ${STANDARD_METVIEW_LIBS} ${_MACRO_LIBS} ${METVIEW_EXTRA_LIBRARIES}
)

set(_MACRO_EXE_LIBS MvMacro)
if (HAVE_METVIEW_FORTRAN)
    list(APPEND _MACRO_EXE_LIBS macro_api_f90)
endif()

#target_link_libraries(MvMacro
#	 ${Macro_libs} ${STANDARD_METVIEW_LIBS} ${METVIEW_EXTRA_LIBRARIES}
#	"-Wl,--whole-archive"
##    app models
##    "-Wl,--no-whole-archive"
#)
# GIVES THE FOLLOWING ERROR:
#/usr/lib64/libmvec_nonshared.a(svml_finite_alias.oS): In function `_ZGVbN2v___log_finite':
#/home/abuild/rpmbuild/BUILD/glibc-2.22/mathvec/../sysdeps/x86_64/fpu/svml_finite_alias.S:31: multiple definition of `_ZGVbN2v___log_finite'
#/usr/lib64/libmvec_nonshared.a(svml_finite_alias.oS):/home/abuild/rpmbuild/BUILD/glibc-2.22/mathvec/../sysdeps/x86_64/fpu/svml_finite_alias.S:31: first defined here
#/usr/lib64/libmvec_nonshared.a(svml_finite_alias.oS): In function `_ZGVcN4v___log_finite':


ecbuild_add_executable( TARGET       macro
                        SOURCES      main.cc
                        DEFINITIONS  ${METVIEW_EXTRA_DEFINITIONS}
                        INCLUDES     ${METVIEW_STANDARD_INCLUDES}
                        LIBS         ${_MACRO_EXE_LIBS}
                    )

# -------------------------------
# Macro to Python converter
# -------------------------------

ecbuild_generate_yy(YYPREFIX zzc LEX macro2py_l YACC macro2py_y DEPENDANT macro2py.cc)


set(_MACRO_CONVERT_EXE_LIBS MvMacro)
if (HAVE_METVIEW_FORTRAN)
    list(APPEND _MACRP_CONVERT_EXE_LIBS macro_api_f90)
endif()


ecbuild_add_executable( TARGET       macro2py
                        SOURCES      macro2py.cc macro2py_y.c
                        DEFINITIONS  ${METVIEW_EXTRA_DEFINITIONS}
                        INCLUDES     ${METVIEW_STANDARD_INCLUDES}
                        LIBS         ${_MACRO_CONVERT_EXE_LIBS} ${MARSCLIENT_LIBS}
 )

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

set(_MVIMPORT_SRC
    mvimport.c
)

ecbuild_add_executable( TARGET       mvimport
                        SOURCES      ${_MVIMPORT_SRC}
                        DEFINITIONS
                        INCLUDES     ${METVIEW_STANDARD_INCLUDES}
                        LIBS         ${STANDARD_METVIEW_LIBS}
                    )


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

set(_MVIMPORT_DESKTOP_SRC
    mvimportDesktop.c
)

ecbuild_add_executable( TARGET       mvimportDesktop
                        SOURCES      ${_MVIMPORT_DESKTOP_SRC}
                        DEFINITIONS
                        INCLUDES     ${METVIEW_STANDARD_INCLUDES}
                        LIBS         ${STANDARD_METVIEW_LIBS}
                    )


