[CMake] Adding files to ARCHIVE packages only in CPack

Eric Noulard eric.noulard at gmail.com
Fri Sep 25 04:27:40 EDT 2015


2015-09-24 22:42 GMT+02:00 Bruno Barberi Gnecco <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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150925/33b80320/attachment.html>


More information about the CMake mailing list