Reputation: 61
I'm trying to generate msi-package using CPack WiX Generator.
In my CMakeLists.txt
there is CMAKE_INSTALL_PREFIX
set to "C:/Program Files/My Project"
. I need to have the full path, because some significant part of project's source code depends on this path. Also, I split the project into some components, one of which is named core
.
I successfully generate Visual Studio solution using cmake-gui. But when I try to build the project PACKAGE
, I get the following error:
53>EXEC : CPack error : Problem creating temporary directory: D:/Projects/build-Project-MSVC2015/_CPack_Packages/win64/WIX/project-2.3.0-20.AMD64/coreC:/Program Files/My Project
The same error occurs, when I leave CMAKE_INSTALL_PREFIX
empty. In that case this variable is initialized by default to "C:/Program Files/Project_Name"
and the rror is:
53>EXEC : CPack error : Problem creating temporary directory: D:/Projects/build-Project-MSVC2015/_CPack_Packages/win64/WIX/project-2.3.0-20.AMD64/coreC:/Program Files/Project_Name
Only when I set CMAKE_INSTALL_PREFIX
to just My Project
(absent prepending C:/
or /
) everything works well. The directory is created as D:/Projects/build-Project-MSVC2015/_CPack_Packages/win64/WIX/project-2.3.0-20.AMD64/coreMy Project
and msi-package is created.
It seems, that CPack tries to make DESTDIR="D:/Projects/build-Project-MSVC2015/_CPack_Packages/win64/WIX/project-2.3.0-20.AMD64/core"
install as an intermediate step, but as stated at cmake's documentation:
WARNING: DESTDIR may not be used on Windows because installation prefix usually contains a drive letter like in “C:/Program Files” which cannot be prepended with some other prefix.
Do I misunderstand the usage of CMAKE_INSTALL_PREFIX
with CPack WiX Generator? Or is this is specific to Visual Studio? Or is there a workaround for this problem, like forcing DESTDIR
to be empty (yes, I know that's dangerous)?
Upvotes: 2
Views: 2021
Reputation: 61
I really was somewhat misunderstanding the usage of CPack. After reading some information on CPack, I managed to create an msi-package the following way.
For Windows-based package installations I turned off the usage of DESTDIR
by setting CPACK_SET_DESTDIR
to FALSE.
As stated in cmake's documentation on CPACK_SET_DESTDIR
:
The most noticeable difference is that without CPACK_SET_DESTDIR, CPack uses CPACK_PACKAGING_INSTALL_PREFIX as a prefix whereas with CPACK_SET_DESTDIR set, CPack will use CMAKE_INSTALL_PREFIX as a prefix.
That is, I should set CPACK_PACKAGING_INSTALL_PREFIX
variable to appropriate value.
If I set CPACK_PACKAGING_INSTALL_PREFIX
to a non-empty value, e. g. to /My Project
(note the leading /
), CPack will append this to C:/Program files/${CPACK_PACKAGE_INSTALL_DIRECTORY}
. CPACK_PACKAGE_INSTALL_DIRECTORY
, in turn, defaults to "${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_VERSION}"
. The full install path would be C:/Program Files/my-project 1.0.0/My Project
, if I set CPACK_PACKAGE_NAME
to "my-project"
and CPACK_PACKAGE_VERSION
to 1.0.0
.
So, to build an msi-package that will install the program to C:\Program files\My Project
, I use the following lines in CMakeLists.txt
:
SET(CMAKE_INSTALL_PREFIX "C:/Program Files/My Project" CACHE PATH "Install path" FORCE)
...
SET(CPACK_SET_DESTDIR FALSE)
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "My Project")
SET(CPACK_PACKAGING_INSTALL_PREFIX "")
For WiX generator CPACK_PACKAGE_INSTALL_DIRECTORY
may not contain the full path, so SET(CPACK_PACKAGE_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX})
will not work.
CPACK_PACKAGING_INSTALL_PREFIX
seems to be empty by default, so the last line is redundant.
Upvotes: 3