[CMake] Finding out in a CMake script whether it's being run by CPack or CMake

Attila Krasznahorkay attila.krasznahorkay at gmail.com
Thu Jan 7 13:00:07 EST 2016


Dear All,

I have a maybe unusual problem.

In my code I have an installation rule like the following:

      install( CODE "execute_process( COMMAND ${CMAKE_COMMAND}
                        -E create_symlink ../src/${pkgDir}/${dir}
                        ${CMAKE_INSTALL_INCDIR}/${dir}
                        WORKING_DIRECTORY ${CMAKE_INSTALL_INCDIR} )" )

Where CMAKE_INSTALL_INCDIR is set to ${DESTDIR}/${CMAKE_INSTALL_PREFIX}/include upstream.

This worked fine so far. But now we want to start building RPM packages from this code. For which we had to set

set( CPACK_SET_DESTDIR FALSE )

in a CPack installation script. As far as I understand from the description of this variable (https://cmake.org/cmake/help/v3.0/variable/CPACK_SET_DESTDIR.html), in this setup I should set CMAKE_INSTALL_INCDIR to ${CPACK_PACKAGING_INSTALL_PREFIX}/install instead.

But how can I determine in this install rule that CPack is running the show now. I can't just look for CPACK_SET_DESTDIR to be set. As in a normal build it's also not set, and I still need to rely on ${DESTDIR} and ${CMAKE_INSTALL_PREFIX}. I'm sure that there is a reasonably simple way to test for this, but I just couldn't find it. :-(

Cheers,
            Attila


More information about the CMake mailing list