CPack NSIS, generate installer for Windows

别说谁变了你拦得住时间么 提交于 2019-12-11 03:14:25

问题


I´m trying to run packet generator within a VS project, it crashes while compiling because of the use of absolute path on installation from Targets and Files.

 ABSOLUTE path INSTALL DESTINATION forbidden (by caller): ...

I checked twice and all installation directories are relative. I set quite a lot of variables as sub-folders of ${PROJECT_BINARY_DIR} (which should be relative) such as:

set(INSTALL_DIR ${PROJECT_BINARY_DIR}/bin)
set(LIB_DIR ${PROJECT_BINARY_DIR}/bin/lib)
set(EXT_DIR ${PROJECT_BINARY_DIR}/bin/ext)
...

does CMAKE/CPACK interpret those variables as absolute paths? If so, is there a way to make CPack working properly with those variables? How do I use CPack when sub-relative path are involved?

thanks


回答1:


Ok I see, the ${PROJECT_BINARY_DIR} is interpreted as an ABSOLUTE path, from there all sub-folder of it will be rejected.

To avoid this problem I surrounded the install variables in if else blocks, and if it is the case of packaging then a relative folder will be used as follows:

if(PACK)
   set(INSTALL_DIR bin)
   set(LIB_DIR bin/lib)
   set(EXT_DIR /bin/ext)
   ...
else(PACK)
   set(INSTALL_DIR ${PROJECT_BINARY_DIR}/bin)
   set(LIB_DIR ${PROJECT_BINARY_DIR}/bin/lib)
   set(EXT_DIR ${PROJECT_BINARY_DIR}/bin/ext)
   ...
endif(PACK)

this solves it, but it is really dirty, waiting for a better function on new CPack version.

ciao




回答2:


This fatal error is meant to tell you installation root should be specified at the moment when user executes the installer. I guess somewhere in your cmake config might have code like this:

INSTALL (TARGET myApp DESTINATION ${SOME_INSTALL_PATH}/bin )

If you assign SOME_INSTALL_PATH an absolute path when cmake cache is generated, you incur the CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION error, which gave you the "ABSOLUTE path INSTALL DESTINATION forbidden (by caller)" message.

To solve this problem, either always use relative path for installation DESTINATION or assign only package prefix to SOME_INSTALL_PATH variable.

For reference, following is the link to INSTALL command. http://www.cmake.org/cmake/help/v3.0/variable/CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION.html

There was also a similar question asked on the CMake mailing list. http://public.kitware.com/pipermail/cmake/2013-May/054656.html



来源:https://stackoverflow.com/questions/23613624/cpack-nsis-generate-installer-for-windows

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