[CMake] Adding MIME-types and .desktop files using CMake

Michael Wild themiwi at gmail.com
Tue Sep 7 07:01:39 EDT 2010


On 7. Sep, 2010, at 12:39 , Amir Pakdel wrote:

> 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")

You'll want to put those execute_process calls inside an install(CODE ...) command, otherwise you install update the MIME database when configuring. E.g:

install(CODE "
  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)"
  )

Michael


--
There is always a well-known solution to every human problem -- neat, plausible, and wrong.
H. L. Mencken

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100907/8d9ef382/attachment.pgp>


More information about the CMake mailing list