[CMake] CPack: Different installation prefixes per CPACK_GENERATOR

Rainer Poisel rainer.poisel at gmail.com
Sat Jun 20 01:53:04 EDT 2015


Hi,

and thanks for your quick reply!

Starting from a minimal, stripped down version of my build
configuration (thx for the tip!) I found that what I described
initially actually works. The reason it was not working was, that I
had turned the CPACK_SET_DESTDIR flag on in another place. After
removing the relevant SET() directive the installation prefixes worked
as desired.

For the record, this is my minimal, stripped down working version:

8<======== CMakeLists.txt =============
cmake_minimum_required(VERSION 3.2)
project(stripped-down C)

add_executable(main main.c)

install(TARGETS main
    RUNTIME DESTINATION bin
    )

set(CPACK_GENERATOR "DEB;TGZ")
set(CPACK_PROJECT_CONFIG_FILE ${CMAKE_SOURCE_DIR}/package.txt)

set(CPACK_PACKAGE_CONTACT "Some One <some.one at somewhere.com>")

include(CPack)
8<=================================

8<======== ${CMAKE_SOURCE_DIR}/package.txt) =============
IF (CPACK_GENERATOR MATCHES "DEB")
    set(CPACK_PACKAGING_INSTALL_PREFIX "/opt")
ELSEIF(CPACK_GENERATOR MATCHES "TGZ")
    set(CPACK_PACKAGING_INSTALL_PREFIX "")
ENDIF()
8<==================================================

Best regards,
  Rainer

On Fri, Jun 19, 2015 at 10:38 PM, Eric Noulard <eric.noulard at gmail.com> wrote:
>
>
> 2015-06-19 21:13 GMT+02:00 Rainer Poisel <rainer.poisel at gmail.com>:
>>
>> Dear list,
>>
>> how can I specify different installation prefixes for the different
>> CPACK_GENERATORs?
>>
>> For example:
>>
>>   * the DEB package should be installed to `/opt/project`
>>   * the TGZ archive should consist only of the `project` directory
>>
>> From the documentation I understood that I would have to use the
>> CPACK_PROJECT_CONFIG_FILE variable. Using that, it should be possible
>> to achieve the desired goal. However, it did not work for me.
>>
>> This is my CPack configuration:
>>
>> 8<============================
>> set(CPACK_GENERATOR "DEB;TGZ")
>> set(CPACK_PROJECT_CONFIG_FILE ${CMAKE_SOURCE_DIR}/cmake/package.linux.txt)
>> 8<============================
>
>
> Did you set those before include(CPack) ?
>>
>>
>> And this is my ${CMAKE_SOURCE_DIR}/cmake/package.linux.txt file:
>>
>> 8<============================
>> IF (CPACK_GENERATOR MATCHES "DEB")
>>     set(CPACK_NATIVE_INSTALL_DIRECTORY "/opt")
>>     set(CMAKE_INSTALL_PREFIX "/opt")
>>     set(CPACK_PACKAGING_INSTALL_PREFIX "/opt")
>>     set(CPACK_INSTALL_DIRECTORY "/opt")
>> ELSEIF(CPACK_GENERATOR MATCHES "TGZ")
>>     set(CPACK_NATIVE_INSTALL_DIRECTORY "")
>>     set(CMAKE_INSTALL_PREFIX "")
>>     set(CPACK_PACKAGING_INSTALL_PREFIX "")
>>     set(CPACK_INSTALL_DIRECTORY "")
>> ENDIF()
>> 8<============================
>>
>> I ensured that all files get parsed using MESSAGE() directives, but
>> the prefix of my packages is always /usr/local.
>
>
> Looks good Strange enough...
>  Would you be able to give us a standalone strip down example project of
> this
> and may be tell us which version of CPack/CMake you are using on which
> platform.
>
>
> What happen if you do something like;
>
> cpack -G DEB -D CPACK_PACKAGING_INSTALL_PREFIX=/tmp
>
> ?
>>
>>
>> Thanks for giving me a few hints,
>>   Rainer
>> --
>>
>> Powered by www.kitware.com
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Kitware offers various services to support the CMake community. For more
>> information on each offering, please visit:
>>
>> CMake Support: http://cmake.org/cmake/help/support.html
>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/cmake
>
>
>
>
> --
> Eric


More information about the CMake mailing list