1

This is an extended post/question of my previous post CPack package doesn't include the executable file. From the solution of my previous post I was able to create the package with required binary and library files using make package command. Now what I want is, is it possible to create only the package(tar.gz) file using make package command without being able to install them using make install command. In the below main CMakeLists.txt, as you can see I can issue make install command to install the binary and library files which I don't want. Basically if I issue make install command, it should fail with an error message like No rule for installation.

main.cpp

#include <iostream>

#include "math_lib/lib.h"

int main(int, char**) {
    std::cout << "Hello, from cpack_demo!\n";
    std::cout << add(2, 3) << std::endl;
    std::cout << subtract(2, 3) << std::endl;
    std::cout << multiply(2, 3) << std::endl;
    std::cout << divide(2, 3) << std::endl;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.10.0)
project(cpack_demo VERSION 0.1.0 LANGUAGES C CXX)

add_subdirectory(math_lib)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} math_lib)

install(TARGETS math_lib ARCHIVE DESTINATION lib COMPONENT libraries)
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin COMPONENT applications)
install(FILES math_lib/lib.h DESTINATION include COMPONENT headers)

# Set CPack configuration
set(CPACK_GENERATOR "TGZ") 
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_SET_DESTDIR "on")
set(CPACK_PACKAGE_DESCRIPTION "Cpack demo")
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${PROJECT_NAME})
set(CPACK_COMPONENTS_ALL applications libraries headers)

include(CPack)

math/lib.h

int add(const int a, const int b);
int subtract(const int a, const int b);
int multiply(const int a, const int b);
int divide(const int a, const int b);

math/lib.cpp

int add(const int a, const int b) {
    return a + b;
}

int subtract(const int a, const int b) {
    return a - b;
}

int multiply(const int a, const int b) {
    return a * b;
}

int divide(const int a, const int b) {
    return a / b;
}

math_lib/CMakeLists.txt

cmake_minimum_required(VERSION 3.10.0)
project(math_lib VERSION 0.1.0 LANGUAGES C CXX)

add_library(${PROJECT_NAME} lib.h lib.cpp)

Commands

mkdir build
cd build
cmake ..
make
make package
12
  • You could try stackoverflow.com/questions/72021705/… but I wouldn't be surprised if it breaks cpack Commented Feb 26 at 6:53
  • @AlanBirtles that didn't work Commented Feb 26 at 6:59
  • Didn't remove the target or broke cpack? Commented Feb 26 at 7:52
  • I don't think that you will able to remove the install functionality, which is effectively used by CPack. And I hardly can imagine usage of such deletion: the installation just works (otherwise unpacking your .tar archive wouldn't produce working image), why do you want to remove it? Commented Feb 26 at 8:06
  • @Tsyvarev let's say for e.g. the binary target depends on abc library which already exists in /usr/local/lib. So, installing it doesn't make sense. Only the binary target installation I agree upon but not the dependencies, since they already exist in that path Commented Feb 26 at 9:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.