CPack 为空 CPACK_PACKAGE_DIRECTORY
CPack empty CPACK_PACKAGE_DIRECTORY
我真的很难让 CPack 以我想象的方式运行。我在下面有一个小示例设置,在将它应用到更大的项目之前,我一直在努力工作。本质上,我正在尝试使用 fixup_bundle 来收集所有依赖项并将它们复制到打包目录以合并到安装程序(和 zip)中。
main.cpp:
int main(unsigned int argc, const char* argv[])
{
return 0;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.1.0)
find_package(Qt5 REQUIRED COMPONENTS Core Gui Multimedia Widgets AxContainer OpenGL)
add_executable(TEST main.cpp)
target_link_libraries(TEST
Qt5::AxContainer
Qt5::Core
Qt5::Multimedia
Qt5::Gui
Qt5::Widgets
Qt5::OpenGL
)
install(
TARGETS TEST
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
COMPONENT Runtime
)
install(CODE "MESSAGE(\"CPACK_PACKAGING_PREFIX=${CPACK_PACKAGING_PREFIX}\")")
install(CODE "MESSAGE(\"CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}\")")
install(CODE "MESSAGE(\"CPACK_INSTALL_PREFIX=${CPACK_INSTALL_PREFIX}\")")
install(CODE "MESSAGE(\"CPACK_INSTALL_DIRECTORY=${CPACK_INSTALL_DIRECTORY}\")")
install(CODE "MESSAGE(\"CPACK_PACKAGE_INSTALL_DIRECTORY=${CPACK_PACKAGE_INSTALL_DIRECTORY}\")")
install(CODE "MESSAGE(\"CPACK_PACKAGING_INSTALL_PREFIX=${CPACK_PACKAGING_INSTALL_PREFIX}\")")
install(CODE "MESSAGE(\"CPACK_PACKAGE_DIRECTORY=${CPACK_PACKAGE_DIRECTORY}\")")
install(CODE "MESSAGE(\"CPACK_TOPLEVEL_DIRECTORY=${CPACK_TOPLEVEL_DIRECTORY}\")")
install(CODE "MESSAGE(\"CPACK_TEMPORARY_DIRECTORY=${CPACK_TEMPORARY_DIRECTORY}\")")
install(CODE "MESSAGE(\"CPACK_OUTPUT_FILE_NAME=${CPACK_OUTPUT_FILE_NAME}\")")
install(CODE "MESSAGE(\"CPACK_OUTPUT_FILE_PATH=${CPACK_OUTPUT_FILE_PATH}\")")
install(CODE "MESSAGE(\"CPACK_TEMPORARY_PACKAGE_FILE_NAME=${CPACK_TEMPORARY_PACKAGE_FILE_NAME}\")")
install(CODE "MESSAGE(\"CPACK_NATIVE_INSTALL_DIRECTORY=${CPACK_NATIVE_INSTALL_DIRECTORY}\")")
install(CODE "MESSAGE(\"CPACK_TEMPORARY_INSTALL_DIRECTORY=${CPACK_TEMPORARY_INSTALL_DIRECTORY}\")")
install(CODE "
include(BundleUtilities)
fixup_bundle(\"${CPACK_PACKAGE_DIRECTORY}/TEST${CMAKE_EXECUTABLE_SUFFIX}\" \"\" \"${DIRS}\")
" COMPONENT Runtime)
set(CPACK_GENERATOR "ZIP" "NSIS")
include(CPack)
并且输出总是一堆空变量:
CPACK_PACKAGING_PREFIX=
CMAKE_INSTALL_PREFIX=C:/Program Files (x86)/Project
CPACK_INSTALL_PREFIX=
CPACK_INSTALL_DIRECTORY=
CPACK_PACKAGE_INSTALL_DIRECTORY=
CPACK_PACKAGING_INSTALL_PREFIX=
CPACK_PACKAGE_DIRECTORY=
CPACK_TOPLEVEL_DIRECTORY=
CPACK_TEMPORARY_DIRECTORY=
CPACK_OUTPUT_FILE_NAME=
CPACK_OUTPUT_FILE_PATH=
CPACK_TEMPORARY_PACKAGE_FILE_NAME=
CPACK_NATIVE_INSTALL_DIRECTORY=
CPACK_TEMPORARY_INSTALL_DIRECTORY=
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.4/Modules/BundleUtilities.cmake:861 (message):
error: fixup_bundle: not a valid bundle, app: /TEST.exe
显然它找不到正确的可执行文件。我希望 CPACK_PACKAGE_DIRECTORY 是这样的:
${CMAKE_BINARY_DIR}/_CPack_Packages/${CPACK_SYSTEM_NAME}/${CPACK_GENERATOR}/${CPACK_PACKAGE_FILE_NAME}
更新2016-06-23
感谢@Tsyvarev 帮助确定问题和解决方案。问题是安装命令中变量的过早扩展。 CMake 将对文本行中的任何 ${} 变量进行第一级扩展。将变量转义为 \${} 可避免这种扩展,稍后将由 CPack 正确扩展。
尽管如此,除一个变量外,所有变量仍然为空。还好选对了:
install(CODE "MESSAGE(\"CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}\")")
结果:
CMAKE_INSTALL_PREFIX=C:/Users/User/Documents/dev/build-test_deploy-Desktop_Qt_5_5_1_MSVC2012_32bit-Default/_CPack_Packages/win32/ZIP/Project-0.1.1-win32
现在捆绑将这样工作:
install(CODE "
include(BundleUtilities)
fixup_bundle(\"${CMAKE_INSTALL_PREFIX}/bin/TEST${CMAKE_EXECUTABLE_SUFFIX}\" \"\" \"\")
" COMPONENT Runtime)
也许还有一个重要的注意事项,因为 fixup_bundle 使用一组固定字符串,您将必须有一个漂亮的脊安装结构。本质上,以上仅适用于整体安装:
set(CPACK_MONOLITHIC_INSTALL on)
我对比上述更好的解决方案感兴趣,但我可以使用它。
使用 CPack 变量的正确方法,在 安装时 定义,使用 install(CODE)
命令:
install(CODE "
include(CPack)
MESSAGE(\"CPACK_PACKAGE_DIRECTORY=${CPACK_PACKAGE_DIRECTORY}\")
")
这里要点:
应转义变量的扩展:${...}
。否则,变量在 configure 阶段立即扩展,当它还没有定义时。
安装代码仍然需要include(CPack)
以使CPack变量可用。
对于那些绝望地尝试在互联网上应用所有食谱的人(比如我),我还有一个可以获取这个对我有用的目录:
install(CODE "MESSAGE(\"DESTDIR=$ENV{DESTDIR}\")")
我真的很难让 CPack 以我想象的方式运行。我在下面有一个小示例设置,在将它应用到更大的项目之前,我一直在努力工作。本质上,我正在尝试使用 fixup_bundle 来收集所有依赖项并将它们复制到打包目录以合并到安装程序(和 zip)中。
main.cpp:
int main(unsigned int argc, const char* argv[])
{
return 0;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.1.0)
find_package(Qt5 REQUIRED COMPONENTS Core Gui Multimedia Widgets AxContainer OpenGL)
add_executable(TEST main.cpp)
target_link_libraries(TEST
Qt5::AxContainer
Qt5::Core
Qt5::Multimedia
Qt5::Gui
Qt5::Widgets
Qt5::OpenGL
)
install(
TARGETS TEST
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
COMPONENT Runtime
)
install(CODE "MESSAGE(\"CPACK_PACKAGING_PREFIX=${CPACK_PACKAGING_PREFIX}\")")
install(CODE "MESSAGE(\"CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}\")")
install(CODE "MESSAGE(\"CPACK_INSTALL_PREFIX=${CPACK_INSTALL_PREFIX}\")")
install(CODE "MESSAGE(\"CPACK_INSTALL_DIRECTORY=${CPACK_INSTALL_DIRECTORY}\")")
install(CODE "MESSAGE(\"CPACK_PACKAGE_INSTALL_DIRECTORY=${CPACK_PACKAGE_INSTALL_DIRECTORY}\")")
install(CODE "MESSAGE(\"CPACK_PACKAGING_INSTALL_PREFIX=${CPACK_PACKAGING_INSTALL_PREFIX}\")")
install(CODE "MESSAGE(\"CPACK_PACKAGE_DIRECTORY=${CPACK_PACKAGE_DIRECTORY}\")")
install(CODE "MESSAGE(\"CPACK_TOPLEVEL_DIRECTORY=${CPACK_TOPLEVEL_DIRECTORY}\")")
install(CODE "MESSAGE(\"CPACK_TEMPORARY_DIRECTORY=${CPACK_TEMPORARY_DIRECTORY}\")")
install(CODE "MESSAGE(\"CPACK_OUTPUT_FILE_NAME=${CPACK_OUTPUT_FILE_NAME}\")")
install(CODE "MESSAGE(\"CPACK_OUTPUT_FILE_PATH=${CPACK_OUTPUT_FILE_PATH}\")")
install(CODE "MESSAGE(\"CPACK_TEMPORARY_PACKAGE_FILE_NAME=${CPACK_TEMPORARY_PACKAGE_FILE_NAME}\")")
install(CODE "MESSAGE(\"CPACK_NATIVE_INSTALL_DIRECTORY=${CPACK_NATIVE_INSTALL_DIRECTORY}\")")
install(CODE "MESSAGE(\"CPACK_TEMPORARY_INSTALL_DIRECTORY=${CPACK_TEMPORARY_INSTALL_DIRECTORY}\")")
install(CODE "
include(BundleUtilities)
fixup_bundle(\"${CPACK_PACKAGE_DIRECTORY}/TEST${CMAKE_EXECUTABLE_SUFFIX}\" \"\" \"${DIRS}\")
" COMPONENT Runtime)
set(CPACK_GENERATOR "ZIP" "NSIS")
include(CPack)
并且输出总是一堆空变量:
CPACK_PACKAGING_PREFIX=
CMAKE_INSTALL_PREFIX=C:/Program Files (x86)/Project
CPACK_INSTALL_PREFIX=
CPACK_INSTALL_DIRECTORY=
CPACK_PACKAGE_INSTALL_DIRECTORY=
CPACK_PACKAGING_INSTALL_PREFIX=
CPACK_PACKAGE_DIRECTORY=
CPACK_TOPLEVEL_DIRECTORY=
CPACK_TEMPORARY_DIRECTORY=
CPACK_OUTPUT_FILE_NAME=
CPACK_OUTPUT_FILE_PATH=
CPACK_TEMPORARY_PACKAGE_FILE_NAME=
CPACK_NATIVE_INSTALL_DIRECTORY=
CPACK_TEMPORARY_INSTALL_DIRECTORY=
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.4/Modules/BundleUtilities.cmake:861 (message):
error: fixup_bundle: not a valid bundle, app: /TEST.exe
显然它找不到正确的可执行文件。我希望 CPACK_PACKAGE_DIRECTORY 是这样的:
${CMAKE_BINARY_DIR}/_CPack_Packages/${CPACK_SYSTEM_NAME}/${CPACK_GENERATOR}/${CPACK_PACKAGE_FILE_NAME}
更新2016-06-23
感谢@Tsyvarev 帮助确定问题和解决方案。问题是安装命令中变量的过早扩展。 CMake 将对文本行中的任何 ${} 变量进行第一级扩展。将变量转义为 \${} 可避免这种扩展,稍后将由 CPack 正确扩展。
尽管如此,除一个变量外,所有变量仍然为空。还好选对了:
install(CODE "MESSAGE(\"CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}\")")
结果:
CMAKE_INSTALL_PREFIX=C:/Users/User/Documents/dev/build-test_deploy-Desktop_Qt_5_5_1_MSVC2012_32bit-Default/_CPack_Packages/win32/ZIP/Project-0.1.1-win32
现在捆绑将这样工作:
install(CODE "
include(BundleUtilities)
fixup_bundle(\"${CMAKE_INSTALL_PREFIX}/bin/TEST${CMAKE_EXECUTABLE_SUFFIX}\" \"\" \"\")
" COMPONENT Runtime)
也许还有一个重要的注意事项,因为 fixup_bundle 使用一组固定字符串,您将必须有一个漂亮的脊安装结构。本质上,以上仅适用于整体安装:
set(CPACK_MONOLITHIC_INSTALL on)
我对比上述更好的解决方案感兴趣,但我可以使用它。
使用 CPack 变量的正确方法,在 安装时 定义,使用 install(CODE)
命令:
install(CODE "
include(CPack)
MESSAGE(\"CPACK_PACKAGE_DIRECTORY=${CPACK_PACKAGE_DIRECTORY}\")
")
这里要点:
应转义变量的扩展:
${...}
。否则,变量在 configure 阶段立即扩展,当它还没有定义时。安装代码仍然需要
include(CPack)
以使CPack变量可用。
对于那些绝望地尝试在互联网上应用所有食谱的人(比如我),我还有一个可以获取这个对我有用的目录:
install(CODE "MESSAGE(\"DESTDIR=$ENV{DESTDIR}\")")