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?
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" ^
../..