Search code examples
c++linuxcmakepackagecpack

Generate two different package using CPack in cmake : Linux


I want to create two different package for my project.

  1. DCM (Includes all the modules except RCM specific module )
  2. RCM (Specific Module.)

1. DCM : src/CMakeList.txt

cmake_minimum_required (VERSION 2.8)

add_subdirectory(ecs) # Include all modules

set(CPACK_GENERATOR TGZ)
set(CPACK_PACKAGE_NAME "dcm")
set(CPACK_PACKAGE_VENDOR "AB")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Device Control")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ReadMe.txt")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/Copyright.txt")
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
set(CPACK_PACKAGE_VERSION_BUILD ${BUILD_NUMBER})

set(CPACK_COMPONENTS_ALL DCM RCM )

# Include CPack to introduce the appropriate targets
include(CPack)

2. RCM : src/ecs/mqa/mqa_rcm/CMakeList.txt

set(RCM_SCRIPTS 
commit.sh
install.sh
prepare_for_install.sh
system_check.sh
update_init.sh)

INSTALL(FILES ${RCM_SCRIPTS}
        PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE  WORLD_EXECUTE
        DESTINATION ${RCM_INSTALL_PREFIX}/install
        COMPONENT RCM )
# Create version file
install(FILES "${CMAKE_BINARY_DIR}/version" 
        DESTINATION ${RCM_INSTALL_PREFIX}
        COMPONENT RCM )

Try Out : On Linux virtual machine prompt.

$make -j4
$make install
$make package

It creates only single package DCM-1.90.0-Linux.tar.gz.

Reference : CMake Wiki and CPack and StackOverflow

Problem : I want to create 1. DCM-1.90.0-Linux.tar.gz and 2. RCM-1.90.0-Linux.tar.gz package.

I googled but, unable to find exact solution.

Let me know in case of you want more information.

Many Thanks in advance.


Solution

  • I just need to set CPACK flag ON.

    set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
    

    just before

    include(CPack)
    

    And run command.

    make
    make install
    make package
    

    And it creates two different packages.