I have a CMake project and I use CPack to generate RPMs for my CentOS YUM repository. However, when I attempt to install my generated RPM, I get this error:
file /usr from install of clstrd-0.1.0-1.x86_64 conflicts with file from package filesystem-3.2-20.el7.x86_64
file /usr/bin from install of clstrd-0.1.0-1.x86_64 conflicts with file from package filesystem-3.2-20.el7.x86_64
file /usr/lib from install of clstrd-0.1.0-1.x86_64 conflicts with file from package filesystem-3.2-20.el7.x86_64
Further inspecting the RPM's contents, I see that it includes these files and directories:
$ rpm -qlp clstrd-0.1.0-Linux.rpm
/usr
/usr/bin
/usr/bin/clstrd
/usr/lib
/usr/lib/libclstrd.a
My question is: How do I force CMake to exclude common directories like /usr or /usr/bin from the RPM? Shouldn't this be done automatically?
I have tried CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION with no luck.
Edit: Here are the relevant parts of my CMakeLists.txt
# Targets
add_library(clstrd_lib ${SOURCE_FILES})
...
add_executable(clstrd main.cpp)
target_link_libraries(clstrd clstrd_lib)
...
# Installation configuration.
install(TARGETS clstrd_lib clstrd
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
# CPack configuration.
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyAwesomePackage")
set(CPACK_PACKAGE_VENDOR "MyAwesomeVendor")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md")
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "1")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}")
set(CPACK_PACKAGE_EXECUTABLES "clstrd", "MyAwesomeExecutable")
set(CPACK_RPM_PACKAGE_AUTOREQPROV " no")
set(CPACK_RPM_PACKAGE_REQUIRES, "libpqxx, gtest, gflags, root, root-netx, xrootd-client-libs")
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION, "/usr /usr/bin /usr/lib")
set(CPACK_SOURCE_GENERATOR "RPM")
include(CPack)
You can try this,
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/lib")
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/lib/systemd")
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/lib/systemd/system")
Test OK on CentOS7 with cmake 2.8.12.2.
It seems this was a bug in cmake 2.8.9, which was fixed in cmake 2.8.12:
https://public.kitware.com/Bug/view.php?id=13609
Related
I'm trying to build a debian using CMake/Cpack but am running into an issue. The problem is that I am getting unwanted files in my debian. It is caused by including a subdirectory, which contains a CMakeLists.txt that invokes catkin commands for ROS msg generation.
If I look at the contents of the debian I see generated header files in /usr/include/ and message files in /usr/share. But I only want my debian to have the files in /opt/bin which I specified using install().
Below is a simplified example. If I run the following commands:
mkdir build
cd build
cmake ..
make
cpack
The result is a deb package containing /opt/my-pkg/bin/main (which is great), but it also contains several files in /usr/local, /usr/lib, /usr/share that I don't want to be in the debian. I'm sure there must be a way using CMake/CPack to only create a debian with the specific files I want, but I'm not sure how to do it.
FILE TREE
+ my_project
+ CMakeLists.txt
+ main
+ CMakeLists.txt
+ main.cpp
+ my_msgs
+ CMakeLists.txt
+ package.xml
+ msg
+ BoundingBox.msg
# Top level CMakeLists.txt
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(my_project VERSION 1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
# put all executables into bin directory and all libraries into lib directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# the directory name all targets will be installed to in the debian
set(install_dir "/opt/my-pkg/bin")
# LIST OF ALL DIRECTORIES TO BE BUILT
set(DIRS
my_msgs
main
)
foreach(dir ${DIRS})
add_subdirectory(${dir} ${dir})
endforeach()
# CPACK debian settings
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Matthew Mosley")
include(CPack)
# my_msgs/CMakeLists.txt (this is the CMakeLists.txt that is generating extra unwanted files in my debian)
project(my_msgs)
find_package(catkin REQUIRED
geometry_msgs
message_generation
std_msgs
sensor_msgs
)
add_message_files(FILES BoundingBox.msg)
generate_messages(
DEPENDENCIES
geometry_msgs
std_msgs
sensor_msgs)
# my_msgs/package.xml
<?xml version="1.0"?>
<package>
<name>my_msgs</name>
<version>0.0.0</version>
<description> my_msgs package</description>
<license>BSD</license>
<build_depend>message_generation</build_depend>
<run_depend>message_runtime</run_depend>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>uuid_msgs</build_depend>
<build_depend>geometry_msgs</build_depend>
<run_depend>roscpp</run_depend>
<run_depend>std_msgs</run_depend>
<run_depend>uuid_msgs</run_depend>
<run_depend>geometry_msgs</run_depend>
<export>
</export>
</package>
I try to setup a cMake project which create a package containing the output of multiple external projects. So the idea is, that I use this cMake project to create packages for the deployment.
Now the problem is, that when I use the cMakeLists shown bellow, the output of the external project is not included in the package. Just the internal one is in the package.
The install sequence of the external project seems to work, at least the output is in the install directory. It seams, that the package command doesn't see the binaries and for that reason dosn't put them into the zip archive.
Does anyone know, how to put the output of the external project into the package?
By the way: the external project is also cMake based. It contains a install step but no package step.
cmake_minimum_required (VERSION 3.12)
project(PackedBinaries
VERSION 0.0.42
)
set(GLOBAL_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/temp)
include(ExternalProject)
# Builds external projects.
ExternalProject_Add(
myExternalProject
GIT_REPOSITORY "..."
GIT_TAG "master"
UPDATE_COMMAND ""
PATCH_COMMAND ""
SOURCE_DIR "${PROJECT_BINARY_DIR}/repo"
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${GLOBAL_OUTPUT_PATH}
TEST_COMMAND ""
)
# Additional executable
add_executable(myInternalProject hello.c)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "..." FORCE)
set(CPACK_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "..." FORCE)
endif()
install(TARGETS myInternalProject)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/temp DESTINATION "${CMAKE_BINARY_DIR}/install")
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY ${PROJECT_NAME})
set(CPACK_GENERATOR "ZIP")
# Must be after the last CPACK macros
include(CPack)
NB: The files referenced here are all given below the horizontal ruler a bit down.
This is the MWE derived from a project where I ran into this. CMake version used is 3.12.2 on Ubuntu 16.04 (16.04.6 to be precise).
The goal is to create a CMakeLists.txt which can be re-targeted to build a Windows DLL using the MinGW-w64 toolchain (apt-get install mingw-w64 on Ubuntu/Debian).
When using no explicit toolchain file (i.e. without -DCMAKE_TOOLCHAIN_FILE=...), all works as expected and the lib${PRJNAME}.so gets installed as desired. However, once I use the toolchain file given below, I only get the resulting import lib ${PRJNAME}Lib.dll.a but not the corresponding .dll file installed.
If I invoke the Bash script as follows:
./build.sh 2>&1 |grep '^-- Install'
the output is:
-- Install configuration: ""
-- Installing: /home/user/cmake-test/build-native/install-target/lib/libtest.so
-- Install configuration: ""
-- Installing: /home/user/cmake-test/build-windows/install-target/lib/test.dll.a
As you can see the native build installs the actual shared library, but the one targeting Windows only installs the import lib, not the DLL. What I'd expect to see is something like this:
-- Install configuration: ""
-- Installing: /home/user/cmake-test/build-native/install-target/lib/libtest.so
-- Install configuration: ""
-- Installing: /home/user/cmake-test/build-windows/install-target/lib/test.dll
-- Installing: /home/user/cmake-test/build-windows/install-target/lib/test.dll.a
What is it I am doing wrong here? It would seem that the install() function is invoked properly:
install(
TARGETS ${PRJNAME}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library
)
Clearly ARCHIVE DESTINATION takes effect as that's where the import lib ends up. But why is the built .dll completely ignored here?
Side-note: I am aware of GNUInstallDirs, but that fell totally apart once I started cross-compiling for Windows. So I am setting the desired paths "manually" before invoking install().
build.sh (should be executable)
The script will first wipe the folders build-native and build-windows, if present, and then create those again. Then it will invoke cmake from these folders respectively, targeting using the system (native) toolchain and the MinGW-w64 toolchain respectively. Last but not least it will invoke the installation from these folders respectively.
So if you place this into an empty folder along with the other files this should not meddle with your data elsewhere in any way.
#/usr/bin/env bash
for i in native windows; do
D=build-$i
test -d $D && rm -rf $D
mkdir $D
[[ "$i" == "windows" ]] && TCFILE=mingw64-64bit.cmake
( set -x; cd $D && cmake .. -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=. ${TCFILE+-DCMAKE_TOOLCHAIN_FILE=$TCFILE} -DCMAKE_VERBOSE_MAKEFILE=ON )
( set -x; cd $D && cmake --build . --target install )
done
test.cpp
#ifdef _WIN32
# if defined(test_EXPORTS)
# define TEST_API __declspec(dllexport)
# else
# define TEST_API __declspec(dllimport)
# endif
#else
# define TEST_API
#endif
TEST_API void SomeFunction()
{
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.12)
set(PRJNAME test)
set(TARGET_DIR "${CMAKE_CURRENT_BINARY_DIR}/install-target")
project(${PRJNAME})
add_library(${PRJNAME} SHARED test.cpp)
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(DLL_PREFIX)
set(DLL_POSTFIX Lib)
else()
set(DLL_PREFIX lib)
set(DLL_POSTFIX)
endif()
set_target_properties(
${PRJNAME}
PROPERTIES
PREFIX "${DLL_PREFIX}"
IMPORT_PREFIX "${DLL_PREFIX}"
DEBUG_POSTFIX "${DLL_POSTFIX}"
RELEASE_POSTFIX "${DLL_POSTFIX}"
CXX_STANDARD 11
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE 1
)
set(CMAKE_INSTALL_PREFIX ${TARGET_DIR})
set(CMAKE_INSTALL_LIBDIR lib)
set(CMAKE_INSTALL_INCLUDEDIR include)
install(
TARGETS ${PRJNAME}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library
)
mingw64-64bit.cmake
set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc-posix)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++-posix)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
install(
TARGETS ${PRJNAME}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library
)
According to the install command documentation the DLL file is considered a runtime object. I tested the example on Ubuntu 14.04.
I've got CMake (3.02) installing to a DESTDIR when I invoke:
$ make -C build DESTDIR=$(pwd)/build/rootfs install
This results in a file layout that I'm happy with: binaries are located in the .../build/rootfs/usr/local/bin directory and the init scripts are in .../build/rootfs/etc/init.d. To accomplish that, I used a mixture of relative and absolute paths in my CMakeLists.txt file:
set(CPACK_SET_DESTDIR ON)
...
INCLUDE(CPack)
...
set(ROOTFS_BIN_DIR bin)
set(ROOTFS_ETC_INITD_DIR /etc/init.d)
...
INSTALL(TARGETS myDaemon DESTINATION ${ROOTFS_BIN_DIR})
INSTALL(PROGRAMS myDaemon.sh RENAME myDaemon DESTINATION ${ROOTFS_ETC_INITD_DIR})
With that, I think 'working', I'm trying to create a simple tarball package which will eventually become a debian package (with pre/post install/remove scripts) but when I invoke:
$ make -C build DESTDIR=$(pwd)/build/rootfs package
I'm getting errors because cpack is attempting to write my init scripts to the system's /etc/init.d directory (instead of $(pwd)/build/rootfs/etc/init.d). If I wanted that, then $sudo !! would solve the problem. The error (replaced full path with ...):
CMake Error at .../build_src/cmdServer/cmake_install.cmake:44 (file):
file INSTALL cannot copy file
".../src/cmdServer/cmdServer.sh" to
"/etc/init.d/cmdServer".
I'm not using a lot of CPACK directives: in my top level CMakeLists.txt file I have:
SET(CPACK_SET_DESTDIR ON)
SET(CPACK_GENERATOR TGZ)
INCLUDE(CPack)
How can I package my init scripts correctly?
I've been referencing:
https://cmake.org/pipermail/cmake/2008-April/020833.html
and https://cmake.org/pipermail/cmake/2006-November/011890.html
I have a cmake project that uses cpack to produce both a zip file and a debian package and I would like to be able to install different files for the two version of the packages.
To be more specific, here is a sample CMake file that produces both a zip and a debian package:
cmake_minimum_required(VERSION 3.5)
project(test_packaging)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(test_packaging ${SOURCE_FILES})
install(FILES test.txt DESTINATION auxilliary/)
set(CPACK_GENERATOR "ZIP;DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Ford Prefect")
include(CPack)
What I would like to do is to install two different version of the test.txt file in the two different packages? Something like
if(packaging zip)
install(FILES test_zip.txt DESTINATION auxilliary/)
elseif(packaging deb)
install(FILES test_deb.txt DESTINATION auxilliary/)
endif(expression)