[CMake] Adding files to ARCHIVE packages only in CPack

Eric Noulard eric.noulard at gmail.com
Fri Sep 25 12:57:59 EDT 2015


You missed the fact that not all CPack generator do handle component as a
default.

You have to
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON

see:
http://cmake.org/Wiki/CMake:Component_Install_With_CPack#CPack_Generator_specific_behavior

You'll find a working example in the attached archive.

2015-09-25 18:13 GMT+02:00 Bruno Barberi Gnecco <brunobg at corollarium.com>:

> On 09/25/2015 05:27 AM, Eric Noulard wrote:
>
>>
>>
>> 2015-09-24 22:42 GMT+02:00 Bruno Barberi Gnecco <brunobg at corollarium.com
>> <mailto:brunobg at corollarium.com>>:
>>
>>
>>              How is it possible to add some files only to the ARCHIVE
>> generators with
>>     CMake/CPack? Apparently components do that, but I can't figure how to
>> say "only add
>>     component X to generator Y". I did something like this:
>>
>>              In CPackConfig.cmake:
>>
>>     set(CPACK_PROJECT_CONFIG_FILE
>>     "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/CMakeCPackOptions.cmake")
>>
>>              In CMakeCPackOptions.cmake
>>
>>     IF (CPACK_GENERATOR MATCHES "TGZ")
>>              install(FILES myextrafile DESTINATION "." COMPONENT static)
>>     ENDIF()
>>
>>              But I get the following error:
>>
>>     /usr/local/bin/cpack --config ./CPackConfig.cmake
>>     CMake Error at CMakeModules/CMakeCPackOptions.cmake:4 (install):
>>        Unknown CMake command "install".
>>
>>     CPack Error: Cannot initialize the generator TGZ
>>
>>              What am I doing wrong? Any other way to run `install()` only
>> for certain
>>     generators? Thanks
>>
>>
>>
>> CMakeCPackOptions.cmake is run when CPack runs a.k.a. "CPack time"
>> At that time the CMake language interpreter running is in **scripting
>> mode** (much like
>> when you run cmake -P yourscript.cmake)
>>
>> "install" command is not a scriptable command meaning that is cannot be
>> used
>> in such CMake script. The same is true for add_library or add_executable
>> etc...
>> This is because those commande are **declarative** they do not act when
>> they are processed
>> but they trigger the generation of other commands that will be run when
>> building/installing.
>>
>> Those "non-scriptable" commands may only be used at "CMake time" i.e.
>> when CMake is
>> running for configuring your project.
>>
>> Using COMPONENT is a possible solution.
>>
>> When using COMPONENT the variable CPACK_COMPONENTS_ALL controls which
>> components are to be
>> shipped by the CPack generator.
>> So what you can do in your CPACK_PROJECT_CONFIG_FILE is to selectively set
>>   CPACK_COMPONENTS_ALL
>> to appropriate value:
>>
>> if ("${CPACK_GENERATOR}" MATCHES "ZIP")
>>     set(CPACK_COMPONENTS_ALL comp1 com2 extracomp)
>> else()
>>      set(CPACK_COMPONENTS_ALL comp1 com2)
>> endif()
>>
>> And this should work.
>>
>> More doc references here:
>> http://cmake.org/Wiki/CMake:Component_Install_With_CPack
>>
>> http://cmake.org/Wiki/CMake:CPackPackageGenerators#Overall_usage_.28common_to_all_generators.29
>> http://cmake.org/cmake/help/v3.0/module/CPackComponent.html
>>
>> http://cmake.org/cmake/help/v3.0/module/CPack.html?highlight=cpack_project#variable:CPACK_PROJECT_CONFIG_FILE
>>
>> --
>> Eric
>>
>
> Eric,
>
>         I appreciate your detailed reply, but I'm still can't make it
> work. Here's what I did:
>
> CPackConfig.cmake:
> SET(CPACK_PROJECT_CONFIG_FILE
> "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/CMakeCPackOptions.cmake")
> # SET(CPACK_COMPONENTS_ALL "") commented out
> ....
> install(PROGRAMS "something" DESTINATION "." COMPONENT basic)
> install(PROGRAMS "otherthing" DESTINATION "." COMPONENT optional)
>
> CMakeCPackOptions.cmake
> IF ("${CPACK_GENERATOR}" MATCHES "TGZ")
>         set(CPACK_COMPONENTS_ALL basic)
> ELSEIF ("${CPACK_GENERATOR}" MATCHES "TBZ2")
>         set(CPACK_COMPONENTS_ALL basic optional)
> ELSE()
>         SET(CPACK_COMPONENTS_ALL basic)
> ENDIF()
>
>         Result: all files from all components are added to the packages.
>
>         What am I doing wrong? Do you know of some example that I could
> follow? Thanks.
>



-- 
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150925/e926fa66/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ComponentAndCPackProjectCfgFile.zip
Type: application/zip
Size: 1581 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150925/e926fa66/attachment.zip>


More information about the CMake mailing list