1

I am trying to use cpack with cmake and nsis to generate an installer which add the .exe files generated to the environment variable.

I have a main cmakelist.txt

in which I add subdirectory with add_subdirectory( each subdirectory has a cmakelist.txt.

in the main subdirectory at the end for now I added:

SET(CPACK_NSIS_MODIFY_PATH ON) SET(CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION OFF) INCLUDE(CPack)

and in each "sub"cmakelist.txt I added : SET(CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION OFF) INCLUDE(CPack)

I have this error:

CPack: Create package using NSIS CPack: Install projects CPack: - Install project: MIALSRTK CMake Error at D:... ABSOLUTE path INSTALL DESTINATION forbidden (by caller):

(this is why I tried: SET(CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION OFF) but it hasn't change anything). I tried to run as administrator as well.

I also tried the solution here: CPack NSIS, generate installer for Windows

but if(pack) doesn't seem to works. it goes into the else(pack) part (i used the command message to see where it goes).

Do you have any idea on how to solve this problem ?

p.deman
  • 584
  • 2
  • 10
  • 24

1 Answers1

0

Setting variable CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION to OFF cannot disable checking for NSIS CPack generator:

Some CPack generators, like NSIS, enforce this internally.

With NSIS generator you have no other way than using relative install paths.


Construction if(pack) will work only if you pass pack variable explicitly to cmake. There is no implicit way for CMakeLists.txt to detect, whether it is run under CPack.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • ok, I added SET(Pack True CACHE BOOL "Use CPACK") in the main cmakelist.txt and at least it goes in the good if statement. but the destination is still not good. it does not go into the bin directory IF(Pack) message("i am here") INSTALL(TARGETS mialsrtkRefineHRMaskByIntersection DESTINATION bin) ELSE(Pack) message("I should not be here") INSTALL(TARGETS mialsrtkRefineHRMaskByIntersection DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) ENDIF(Pack) – p.deman Dec 12 '17 at 09:25
  • What do you mean by `but the destination is still not good`? Does error "ABSOLUTE path INSTALL DESTINATION forbidden" remain? Or what? – Tsyvarev Dec 12 '17 at 11:18
  • not anymore, bu the .exe files are not in the wanted directory. (I want all .exe going in a directory called bin, in the build folder from where I call cmake and cpack. in works when I build the Install using virtual studio in the "cmake without cpack" mode. but not when I am using cpack. I do the cmake ., configuration and generation with pack = true. so "destination bin". I build the whole project in visual studio. in run install (and .exe are not in bin/test). then when I run cpack . , cpack is looking for the exe in the release folder made by default by virtual studio – p.deman Dec 12 '17 at 11:30
  • Relative path in *DESTINATION* option is counted against directory, contained in *CMAKE_INSTALL_PREFIX* variable, which can be adjusted by a user. It is a good style to install things under this directory, as opposite to install under build directory. (BTW, after **build step** you already have the program under build directory, why you need to **install** it there?). – Tsyvarev Dec 12 '17 at 11:40
  • yes I'ld like the .exe to go in cmake_install_prefix/bin. which works fine using INSTALL(TARGETS mialsrtkRefineHRMaskByIntersection DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) without using cpack. and INSTALL(TARGETS mialsrtkRefineHRMaskByIntersection DESTINATION bin) doesn't reproduce the same when using cpack. after build step all .exe I have when using cpack are in build/Toolbox_subdirectory/Release i'ld like to have them all in /build/bin in order to add /build/bin to the environment path using the cmake command SET(CPACK_NSIS_MODIFY_PATH ON) (not sure how to do exactly yet) – p.deman Dec 12 '17 at 12:26
  • Hmm, CPack just creates a package file (in case of NSIS - installation executable). You need to perform specific steps to install the package from that file (in case of NSIS - run installation executable). Have you done these steps? – Tsyvarev Dec 12 '17 at 12:32
  • not sure what you mean. I found there is very few documentation for the cpack/nsis use. for now the only modification to what worked in cmake are : set(CPACK_PACKAGE_NAME "CPackTest") SET(CPACK_NSIS_MODIFY_PATH ON) SET(CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION OFF) INCLUDE(CPack) and the if(pack) to make the destination a relative path. then I do the configuration and generation using cmake-gui. building using visual studio. and then try the command cpack . to generage the CPackTest.exe installer. and it's not working. – p.deman Dec 12 '17 at 12:44
  • In that tutorial I see only how to write `CMakeLists.txt` for CPack. It doesn't describe how to run CPack. – Tsyvarev Dec 12 '17 at 12:49
  • yes i don't find anything about how to run cpack, at least when using windows – p.deman Dec 12 '17 at 12:57
  • What is wrong with simple googling for CPack? E.g. this question: https://stackoverflow.com/questions/13144181/how-to-create-an-installer-with-cmake-cpack-nsis-on-windows. – Tsyvarev Dec 12 '17 at 13:08
  • I have already look at this. but still don't get it. I did the modification of the cmakelist.txt according to this. I can generate the installer.exe for this example. in this case under visual studio I can build "Package". but when I double click on it I have this: "windows cannot access the specific device, path or file. you may not have the appropriate permissions to access the item". even when I run it as administrator. – p.deman Dec 12 '17 at 13:28
  • So, in the simple example in the referenced question CPack works correctly. But in your case things become wrong when your are trying to build the "Package". Do I understand your last comment correctly? If so, you want probably to **update your question post** with related information: which commands do you execute, and which result do you get (error message). – Tsyvarev Dec 12 '17 at 13:36
  • If I download the ComponentExample.zip, I use cmake to configure and generate, open the project under visual studio. I have "MyLib-1.0.0-win64.exe" generated. and when I try to launch it, I have the error: "windows cannot access the specific device, path or file. you may not have the appropriate permissions to access the item" even when I run it as administrator. In my case, my code, I can't generate the .exe yet. – p.deman Dec 12 '17 at 13:44