On 09/25/2015 05:27 AM, Eric Noulard wrote:


2015-09-24 22:42 GMT+02:00 Bruno Barberi Gnecco <[email protected]
<mailto:[email protected]>>:

             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.
--

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

Reply via email to