[CMake] Recommandations for public custom macro/functions installation

David Demelier markand at malikania.fr
Tue Apr 17 05:58:12 EDT 2018


Hello,

In my application I have some custom functions that help the process of
creating executable, libraries, plugins and such.

They don't do magic things but they mostly build, provide installation
to specific place and optionally build the documentation and install
them as well. This happens in my project. Since the project is
extensible, I want to install the libraries **and** those macros so
users will be able to use them so their plugins get installed in the
correct place alongside the documentation without much effort.

Example, the user will just write:

    irccd_define_plugin(
        SOURCES main.cpp
        DOCS myplugin.md
    )

The problem with that macro, is that it has a conditional to build the
documentation depending on an option. This is fine in my project since
the user may build or not build the documentation by setting WITH_DOCS
to Off.

Now I wonder how I should handle this option when the macro is
publicliy installed. The most problematic question is that variables do
not have namespaces so if the user of my macro also have an option
WITH_DOCS in its own CMakeLists.txt, this will interfer with the
installed macro.

What are your recommandations over this?

I personally do not want to prefix all my options in my project with
the project name prefix, I think that would be a bit ugly, and I do
want this macro to build and install the documentation.

Any advice/comment is welcome.

Regards,

-- 
David


More information about the CMake mailing list