I am using CMake 3.10.1 and trying to use CPack to generate archives for a library and I cannot get it to add the interface include directory to the archive.
The library and the generated export files are added as expected, however the include directory (added using target_include_directories(... PUBLIC ...)
is missing entirely.
The CMakeLists.txt
:
cmake_minimum_required(VERSION 3.5)
project(Test VERSION 1.0.0 LANGUAGES CXX)
add_library(${PROJECT_NAME} SHARED foo.cpp) #add sources and executable
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
$<INSTALL_INTERFACE:inc>
)
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}
INCLUDES DESTINATION inc
PUBLIC_HEADER DESTINATION inc
LIBRARY DESTINATION lib
)
install(EXPORT ${PROJECT_NAME} DESTINATION .)
include(CPack)
The contents of my source dir:
├── CMakeLists.txt
├── foo.cpp
└── inc
└── foo.h
The contents of the tgz generated by cpack -G TGZ .
├── lib
│ └── libTest.so
├── Test.cmake
└── Test-noconfig.cmake
Any ideas why it could be missing the inc
directory?
Generator-like expression $<INSTALL_INTERFACE>
used in the target_include_directories()
command by itself doesn't install corresponded directory. You need to install this directory manually (with install(FILES)
or install(DIRECTORY)
).
Expression $<INSTALL_INTERFACE>
specifies interface include directory for the target in the config file, which exports install tree (see install(EXPORT)
command).
Expression $<BUILD_INTERFACE>
specified interface include directory for the target in the project itself, and in the config file which exports build tree (see EXPORT()
command).
But these expressions doesn't enforce $<BUILD_INTERFACE>
directory to be copied into $<INSTALL_INTERFACE>
one on installation. As opposite, content of this directories usually differs: aside from header files for outer use, installed into $<INSTALL_INTERFACE>
directory, a directory $<BUILD_INTERFACE>
may contain header files for project's internal use, which are not installed.