[CMake] Creating a common (= across several projects) CMake module/include-file/library
Matthew Woehlke
matthew.woehlke at kitware.com
Mon May 13 18:17:58 EDT 2013
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.
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).
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.)
> 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?
--
Matthew
More information about the CMake
mailing list