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
.tararchive wouldn't produce working image), why do you want to remove it?abclibrary 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