[CMake] Adding MIME-types and .desktop files using CMake
Amir Pakdel
pakdel at gmail.com
Tue Sep 7 06:39:20 EDT 2010
On Tue, Sep 7, 2010 at 10:36 AM, Michael Wild <themiwi at gmail.com> wrote:
>
> On 7. Sep, 2010, at 6:45 , Amir Pakdel wrote:
>
>> Hi developers,
>>
>> I am trying to add a MIME type for "Basket Note Pads" files so that
>> Desktop Environments (KDE and GNOME) can recognise them. For that
>> purpose, I created a basket.xml and included the MIME type in the
>> basket.desktop file; then, I have added the MIME
>> type and associated this MIME type with the basket.desktop using the
>> following commands:
>>
>> xdg-mime install --novendor basket.xml
>> xdg-desktop-menu install --novendor basket.desktop
>> xdg-mime default basket.desktop application/x-basket-item
>>
>> This procedure seems work fine, but I cannot add it to the CMake. I
>> mean, I cannot do it automatically during installation via CMake
>> rules.
>>
>> Below is basket.xml:
>> <?xml version="1.0" encoding="UTF-8"?>
>> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
>> <mime-type type="application/x-basket-item">
>> <sub-class-of type="text/xml"/>
>> <sub-class-of type="application/xml"/>
>> <comment>Basket Note Pads</comment>
>> <icon>basket</icon>
>> <glob pattern=".basket" weight="50" />
>> <magic priority="90">
>> <match type="string" offset="2" value="xml">
>> <match type="string" offset="39" value="!DOCTYPE basket>"/>
>> </match>
>> </magic>
>> <root-XML localName="basket" />
>> </mime-type>
>> </mime-info>
>>
>>
>> And this is the basket.desktop file:
>> [Desktop Entry]
>> Type=Application
>> Exec=basket %f
>> MimeType=application/x-basket-archive;application/x-basket-template;application/x-basket-item;
>> Icon=basket
>> Categories=Qt;KDE;Office;
>> X-DBUS-StartupType=Unique
>> Name=BasKet Note Pads
>> GenericName=Multi-Purpose Notepad
>> Comment=Taking care of your ideas.
>>
>>
>>
>>
>>
>> Can anyone help me please.
>>
>> Cheers,
>>
>> Amir
>
> Write the commands to a script file (probably created using configure_file) and then invoke it in
>
> install(SCRIPT ${CMAKE_BINARY_DIR}/script_name)
>
> You can write a shell script, or if you prefer a CMake script that uses execute_process to run the xdg-* commands.
>
> It would also be advisable to use find_program in your CMakeLists.txt file to find these executables and then configure them into the script, otherwise you're never sure whether the user has them actually installed.
>
> HTH
>
> Michael
>
> --
> There is always a well-known solution to every human problem -- neat, plausible, and wrong.
> H. L. Mencken
>
>
Hi,
Thank you very much. That worked for me. I have added the following to
my CMakeLists.txt:
find_program(XDG-MIME_EXECUTABLE xdg-mime)
find_program(XDG-DESKTOP-MENU_EXECUTABLE xdg-desktop-menu)
execute_process(COMMAND ${XDG-MIME_EXECUTABLE} install --novendor basket.xml)
execute_process(COMMAND ${XDG-DESKTOP-MENU_EXECUTABLE} install
--novendor basket.desktop)
execute_process(COMMAND ${XDG-MIME_EXECUTABLE} default basket.desktop
"application/x-basket-item")
Any other tips or tricks?
Moreover, Pedro sent me the following. It merely solves the first part
of my problem; nevertheless, it might worth taking a look:
There is a custom KDE CMake module,
http://api.kde.org/cmake/modules.html#module_FindSharedMimeInfo
Example:
set( SHARED_MIME_INFO_MINIMUM_VERSION "0.30" )
find_package( SharedMimeInfo )
if( SHARED_MIME_INFO_FOUND )
install( FILES basket.xml DESTINATION ${XDG_MIME_INSTALL_DIR} )
update_xdg_mimetypes( ${XDG_MIME_INSTALL_DIR} )
endif( SHARED_MIME_INFO_FOUND )
Thanks again for your prompt reply.
Cheers,
Amir
More information about the CMake
mailing list