[CMake] INTERFACE libraries and <lib>-config.cmake files
Domen Vrankar
domen.vrankar at gmail.com
Mon Dec 4 18:07:34 EST 2017
2017-12-04 23:17 GMT+01:00 Saad Khattak <saadrustam at gmail.com>:
> Hi,
>
> I have an interface library and I am not sure how I would get CMake to
> generate the usual <lib>-config.cmake file for the library so that I can
> then use "find_package" on the interface library from an external project.
>
> I am adding (and installing) the library like this:
>
> add_library(myLib INTERFACE)
> target_include_directories(myLib INTERFACE
> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
> $<INSTALL_INTERFACE:include/>
> )
>
> and then installing like this:
>
> install(TARGETS myLib EXPORT myLib_targets INCLUDES DESTINATION include)
> install(EXPORT myLib_targets DESTINATION "lib/cmake")
> install(FILES ${MY_HEADERS} DESTINATION "include/")
>
> Obviously, I am doing it wrong or missing some steps as I do not see the
> myLib-config.cmake file anywhere in the install folder (or the build
> directory for that matter) that is usually generated when using install
> commands.
>
> Ultimately, I would like to use the "find_package" command on the
> interface library from another CMake project.
>
install(EXPORT myLib_targets ,..) will produce myLib_targets.cmake file if
I remember correctly from the top of my head. Just rename it to
"install(EXPORT mylib-config ...)" or create a new config file named
"myLib-config.cmake" and include cmake script produced by the export in
there.
You'll probably also want to create a version file with something like this:
include(CMakePackageConfigHelpers)
write_basic_package_version_file("mylib-config-version.cmake"
VERSION ${myLib_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/mylib-config-version.cmake"
DESTINATION lib/cmake
)
Hope this helps.
Regards,
Domen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20171205/551ff572/attachment-0001.html>
More information about the CMake
mailing list