2017-12-04 23:17 GMT+01:00 Saad Khattak <saadrus...@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
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake