One way to entirely disregard BUILD_INTERFACE libraries during the installation process is to set the INSTALL_INTERFACE
property to a different value from the BUILD_INTERFACE
property for the target that includes the libraries. This will ensure that when the target is installed, only the INSTALL_INTERFACE
libraries will be included.
For example, if the MyLib
target includes some libraries that are only needed during the build process, you can set the INSTALL_INTERFACE
property to a different value like this:
set_target_properties(MyLib PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_INSTALL_INCLUDEDIR}"
INTERFACE_LINK_LIBRARIES "${CMAKE_INSTALL_LIBDIR}/MyLibLibraries.lib"
)
set_target_properties(MyLibLibraries PROPERTIES
BUILD_INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/lib"
INSTALL_INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_INSTALL_INCLUDEDIR}"
INSTALL_INTERFACE_LINK_LIBRARIES "${CMAKE_INSTALL_LIBDIR}/MyLibLibraries.lib"
)
In this example, the MyLib
target links to the MyLibLibraries
target, which provides some libraries that are only needed during the build process. The BUILD_INTERFACE
properties for MyLibLibraries
are set to the source directory (CMAKE_CURRENT_SOURCE_DIR
) where the libraries are located. The INSTALL_INTERFACE
properties are set to the installation directory (CMAKE_INSTALL_INCLUDEDIR
and CMAKE_INSTALL_LIBDIR
) where the libraries will be installed.
By setting the INSTALL_INTERFACE
properties for MyLibLibraries
to different values from the BUILD_INTERFACE
properties, the libraries will be completely disregarded during the installation process. Only the INSTALL_INTERFACE
libraries will be included in the installation.
Asked: 2022-11-14 11:00:00 +0000
Seen: 14 times
Last updated: Jul 04 '21