From install documentation:
The FILES_MATCHING option may be given before the first match option to disable
installation of files (but not directories) not matched by any expression.
Usage
cmake_minimum_required(VERSION 2.8)
project(foo)
install(
DIRECTORY
"./src"
DESTINATION
"include/foo"
FILES_MATCHING
PATTERN
"*.hpp"
)
Example
> cmake -H. -B_builds -DCMAKE_INSTALL_PREFIX=`pwd`/_install
> cmake --build _builds/ --target install
> find src/ -type f
src/a.hpp
src/a.cpp
src/B/b.hpp
src/B/b.cpp
Only *.hpp
files installed:
> find _install/ -type f
_install/include/foo/src/a.hpp
_install/include/foo/src/B/b.hpp