I'm experimenting with CPack
module of CMake
and got somewhat confusing behavior. I have CpackMylib.cmake
that is included into a root CMakeLists.txt
. It looks as follows:
include(CPack) #included on top
install (TARGETS mylib
LIBRARY
DESTINATION /usr/lib
COMPONENT mylib-all
)
install (DIRECTORY include/
DESTINATION /usr/include/mylib
COMPONENT mylib-all)
set(CPACK_PACKAGE_NAME "mylib")
set(CPACK_GENERATOR "DEB")
And when running make package
it fails to create the package with the following trace:
Run CPack packaging tool...
CPack: Create package using STGZ
CPack: Install projects
CPack: - Run preinstall target for: mylib
CPack: - Install project: mylib
CMake Error at /home/krjoff/mylib/cmake_install.cmake:55 (file):
file INSTALL cannot copy file "/home/krjoff/mylib/libmylib.so" to
"/usr/lib/mylib.so".
CMake Error at /home/krjoff/mylib/cmake_install.cmake:73 (file):
file INSTALL cannot set permissions on "/usr/include/mylib"
CPack Error: Error when generating package: mylib
Makefile:129: recipe for target 'package' failed
make: *** [package] Error 1
It looks like it simply ignores all variables I put after the include(CPack)
and trying to build some STGZ
package and install it immediately. But if I put the include(CPack)
in the end of the CpackMylib.cmake
after all configuration's been made it works perfectly fine.
Can someone explain why is it necessary to put the include(CPack)
after all the configuration settings?