CMake/C++: How to deploy a binary with the necessary shared library?

夙愿已清 提交于 2020-06-01 07:42:05

问题


I'm struggling with the task to generate a binary deployed with the required shared libraries.

I created a "hello world" for Qt 5.12 plugins, the app runs as expected in my Ubuntu 18.04 machine, but make install gives an error.

I tried the fixup_bundle() approach for resolving dependencies.

obs.: I never done this before, I'm new to cmake.

cmake_minimum_required(VERSION 3.17)

project(plug-use LANGUAGES CXX)

set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 0)
set(PROJECT_VERSION_PATCH 0)
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt5 COMPONENTS Widgets REQUIRED)

get_target_property(QT_WIDGETS_LIB Qt5::Widgets LOCATION)
get_filename_component(QT_RUNTIME_DIR "${QT_WIDGETS_LIB}" DIRECTORY)
list(APPEND LIBS_PATH "${QT_RUNTIME_DIR}")
message(path: ${LIBS_PATH})

add_subdirectory(plug)

add_executable(plug-use
        main.cpp
        MainWindow.cpp
        MainWindow.h
        MainWindow.ui
        GenericPluginInterface.h
        )

target_link_libraries(plug-use PUBLIC Qt5::Widgets plug)

set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/../installation)

include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
        EXPORT ${PROJECT_NAME}_export_target
        BUNDLE  DESTINATION ${CMAKE_INSTALL_PREFIX}
                COMPONENT   ${PROJECT_NAME}_RunTime
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
                COMPONENT   ${PROJECT_NAME}_RunTime
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
                COMPONENT          ${PROJECT_NAME}_RunTime
                NAMELINK_COMPONENT ${PROJECT_NAME}_Development
        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
                COMPONENT   ${PROJECT_NAME}_Development
        )

set( APPS "\${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}" )
set( DIRS ${LIBS_PATH})

install( CODE "
        include(BundleUtilities)
        fixup_bundle( \"${APPS}\" \"\" \"${DIRS}\" )
        " COMPONENT ${PROJECT_NAME}_RunTime)

In the terminal I type:

cmake -B build -S .
cd build
make
make install

And the error message after make install:

-- Install configuration: ""
-- Installing: /media/storage/user/Documents/mitk-test/plug-use/../installation/bin/plug-use
-- Set runtime path of "/media/storage/user/Documents/mitk-test/plug-use/../installation/bin/plug-use" to ""
-- fixup_bundle
--   app='/media/storage/user/Documents/mitk-test/plug-use/../installation/plug-use'
--   libs=''
--   dirs='/usr/lib/x86_64-linux-gnu'
--   ignoreItems=''
-- warning: *NOT* handled - directory/file does not exist...
CMake Error at /usr/local/share/cmake-3.17/Modules/BundleUtilities.cmake:988 (message):
  error: fixup_bundle: not a valid bundle
Call Stack (most recent call first):
  cmake_install.cmake:68 (fixup_bundle)


-- fixup_bundle: done
Makefile:137: recipe for target 'install' failed
make: *** [install] Error 1

I don't know how to interpret this message.

来源:https://stackoverflow.com/questions/62036617/cmake-c-how-to-deploy-a-binary-with-the-necessary-shared-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!