cmakecmake-language

CMAKE_INSTALL_MESSAGE variable won't silence file(INSTALL ...)


I have a part of code in CMake. It should copy files from source folder to a destination folder and I want it to be silent.

According to the documentation set (CMAKE_INSTALL_MESSAGE NEVER) should make it quiet. But it doesn't.

This is the code:

# Silence installation messages
set (SAVE_CMAKE_INSTALL_MESSAGE ${CMAKE_INSTALL_MESSAGE}) # Saving the state
set (CMAKE_INSTALL_MESSAGE NEVER)
message("CMAKE_INSTALL_MESSAGE = ${CMAKE_INSTALL_MESSAGE}") # NEVER

file(INSTALL ${SOURCE} DESTINATION ${DEST} USE_SOURCE_PERMISSIONS)
set (CMAKE_INSTALL_MESSAGE ${SAVE_CMAKE_INSTALL_MESSAGE}) # Restitute

message("CMAKE_INSTALL_MESSAGE = ${CMAKE_INSTALL_MESSAGE}") # <empty>

It is not silent, it prints out every file with -- Installing: /some/destination/path and -- Up-to-date: /some/destination/path

Any ideas how to silence that function?


Solution

  • The documentation tells that variable CMAKE_INSTALL_MESSAGE affects only on install() command:

    Specify verbosity of installation script code generated by the install() command

    The command file(INSTALL) is not affected by that variable.

    If you want file(INSTALL) to be quiet, then use file(COPY) instead (the other parameters would be the same).


    The part about file(INSTALL) describes only internal implementation of verbosity:

    (using the file(INSTALL) command)

    For every install() invocation in CMakeLists.txt CMake adds to the installation script cmake_install.cmake a call to file(INSTALL). That call uses some undocumented parameters, and one of these parameters specifies verbosity. The undocumented parameters are NOT described in the user's documentation and should NOT be used outside of CMake itself.

    That is, when read the documentation, a user could simply omit the part about file(INSTALL). Not sure why internal implementation is ever described in the docs.


    E.g. the call to

    install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/text.txt DESTINATION share)
    

    generates the following file(INSTALL) call in the cmake_install.cmake:

    file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/share" TYPE FILE FILES "/home/tester/tests/cmake/text.txt")
    

    with undocumented option TYPE.

    The same call but after setting CMAKE_INSTALL_MESSAGE variable to NEVER generates instead

    file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/share" TYPE FILE MESSAGE_NEVER FILES "/home/tester/tests/cmake/text.txt")
    

    with undocumented keyword MESSAGE_NEVER.

    Once again, NEVER use these undocumented options in the normal CMake projects.