[CMake] Creating a common (= across several projects) CMake module/include-file/library
Shlomi Fish
shlomif at shlomifish.org
Tue May 14 13:47:37 EDT 2013
Hi Matthew,
On Mon, 13 May 2013 18:17:58 -0400
Matthew Woehlke <matthew.woehlke at kitware.com> wrote:
> On 2013-05-11 17:22, Shlomi Fish wrote:
> > many of my CMake-based projects carry a common top-level "Common.cmake" file
> > that I copy from one project to another and enhance, and since this is
> > duplicate code/functionality I would like to consolidate it.
> >
> > What I want to be able to do is say something like:
> >
> > <CODE>
> > INCLUDE(ShlomifCommon)
> > </CODE>
> >
> > at the top, and then have it read from a system wide "ShlomifCommon.cmake"
> > file that I will maintain in one central location, and install.
>
> If you put the file in one of CMake's default module search paths, it
> should Just Work. And/or if you arrange for your software process to set
> CMAKE_MODULE_PATH to the location of the same, then again it should Just
> Work.
Thanks! That worked.
>
> For redistribution, I would have your project do a list(APPEND) on the
> same to where the file will exist when building from a distribution
> source package. In development, just don't have a copy in that location
> (or you could put one there to override the system copy if for some
> reason you need to do so).
OK.
>
> Another option to consider is keeping the file in an external repository
> and using your VCS's external-repo support to bring it into your other
> projects. This way the file exists in your source tree, but your VCS is
> tracking it against a central repository, rather than each project's
> repo having independent copies. (This will also probably make getting
> the file into your source packages easier.)
>
OK.
> > For a bonus point, I'd like to have a way to copy this file into
> > every project's tarball so it won't require installation.
>
> How do you create tarballs?
>
Using CPack’s "make package_source".
Regards,
Shlomi Fish
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Why I Love Perl - http://shlom.in/joy-of-perl
C++ is complex, complexifying and complexified.
(With apologies to the Oxford English Dictionary).
Please reply to list if it's a mailing list post - http://shlom.in/reply .
More information about the CMake
mailing list