Reputation: 1148
I'm trying to build protobuf on my windows machine according to this guide (official proto guide). Compiling works fine. But. I would like to install it in my workspace, where other project can have easy access to it. According to the guide I should specify the install prefix like so:
C:\Path\to\protobuf\cmake\build\release>cmake -G "NMake Makefiles" ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX=../../../../install ^
../..
This does not have the desired effect as the end result installs in C:\ . Also if I use an env variable:
$Env:CMAKE_INSTALL_PREFIX="C:/Users/uname/Workspace/protobuf-3.18.0/install"
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release ..\..
Or
$Env:CMAKE_INSTALL_PREFIX="C:\Users\uname\Workspace\protobuf-3.18.0\install"
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release ..\..
I get a slightly different outcome. It tries to install in:
C:\Program files (x86)\Protobuf\lib
And off course fails due to lack of priveliges. Is it possible to arrange the env in powershell in such a way that cmake actually picks up the install prefix that I want?
Upvotes: 0
Views: 949
Reputation: 736
As of the time of writing, if CMAKE_STAGING_PREFIX
is defined, it overrides CMAKE_INSTALL_PREFIX
in various ways, even if CMAKE_STAGING_PREFIX
is assigned to the empty string.
In particular, if CMAKE_STAGING_PREFIX
is assigned to the empty string (presumably with the intention of not using a staging prefix), you may be surprised to find your project installing to /
, regardless of the value of CMAKE_INSTALL_PREFIX
(or CMAKE_CROSSCOMPILING
, for that matter).
There is some discussion of this behavior here:
https://discourse.cmake.org/t/cmake-staging-prefix-vs-cmake-install-prefix/6485
From the looks of it, it seems this behavior is unforeseen/unintentional.
Upvotes: 0
Reputation: 19916
You must specify CMAKE_INSTALL_PREFIX
as a cache variable, not as an environment variable, and you should always use absolute paths, rather than relative.
C:\Path\to\protobuf\cmake\build\release>cmake -G "NMake Makefiles" ^
-DCMAKE_BUILD_TYPE=Release ^
"-DCMAKE_INSTALL_PREFIX=C:/Users/uname/Workspace/protobuf-3.18.0/install" ^
../..
Upvotes: 2