CPack NSIS, generate installer for Windows

2019-07-21 04:20发布

问题:

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



标签: cmake nsis cpack