
#### TODO
########  dirstocopy              = CommonMacroFuncs Drawers Templates news
########Drawers/Basic/Folder:
########	mkdir -p Drawers/Basic/Folder
########
########BUILT_SOURCES = Drawers/Basic/Folder




set(files
    DemoFonts Metview NormalFonts metview.qss
    BufrKeyProfile_default.xml BufrKeyProfile_all.xml GribKeyProfile_default.xml
    FrameKeyProfile_default.xml FrameKeyProfile_all.xml LayerKeyProfile_default.xml
    Desktop.qss UiTheme.Desktop UiTheme.MacroEditor BufrFilterDef.json world_map_low.svg
)



# set up the version file


execute_process(COMMAND           date +%Y
                OUTPUT_VARIABLE   THIS_YEAR
                OUTPUT_STRIP_TRAILING_WHITESPACE)

execute_process(COMMAND           date +%d-%B-%Y
                OUTPUT_VARIABLE   THIS_VERBOSE_DATE
                OUTPUT_STRIP_TRAILING_WHITESPACE)

configure_file(MvVersion.in         ${CMAKE_BINARY_DIR}/share/metview/app-defaults/MvVersion @ONLY)
configure_file(MvVersionDetails.in  ${CMAKE_BINARY_DIR}/share/metview/app-defaults/MvVersionDetails @ONLY)


foreach( f ${files} )

    # copy to the build 'bin' directory
    configure_file(${f} ${CMAKE_BINARY_DIR}/share/metview/app-defaults/ COPYONLY)

endforeach()


foreach( f ${files} MvVersion MvVersionDetails)

    # ensure file is installed at install time
    install( FILES ${CMAKE_BINARY_DIR}/share/metview/app-defaults/${f}
             DESTINATION share/metview/app-defaults
             PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)

endforeach()



# handle the directories which we just want to copy completely
# for efficiency, we will just create symbolic links to them (this will
# probably not work on Windows; if we want a Windows build, we'll
# need to perform an actual copy)


set(dirs CommonMacroFuncs Templates UserDir)

foreach( dir ${dirs})

    execute_process(COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_BINARY_DIR}/share/metview/app-defaults/${dir})

    execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/${dir}
                                                               ${CMAKE_BINARY_DIR}/share/metview/app-defaults/${dir}
                    RESULT_VARIABLE res
                    OUTPUT_VARIABLE outv
                    ERROR_VARIABLE  errv)
    if(NOT res EQUAL 0)
        ecbuild_critical("Could not create symbolic link to ${dir} : ${res} ${outv} , ${errv}")
    endif()

    install( DIRECTORY   ${dir}
             DESTINATION share/metview/app-defaults
             PATTERN .metview_empty_file EXCLUDE) # don't install the dummy file in Drawers/Basic/Folder

endforeach()


