Pepek91
Pepek91

Reputation: 23

CMake and Visual Studio with not default installation folder

I am trying to build something using CMake and VS 2012. The problem is I have my VS installation on D:\Pliki programów (x86)\Microsoft Visual Studio 11.0. I have no free space on my C drive.

CMake have problem with finding my VS. I tried to specify VS compiler cl.exe but it was asking for dll in the same folder anyway. I also tried to use specified toolchaing with vcvarsall.bat. But I am not sure if I am doing those things right. I guess that I need to add VS location to CMake, but how? I tried setting PATH but it did not work.

And searching about that problem is difficult, all search engines think that I want to change installation path for my program that I want to build.

UPDATE

I've added variable_watch(CMAKE_MAKE_PROGRAM).

CMake Debug Log at CMakeLists.txt:3 (project): Variable "CMAKE_MAKE_PROGRAM" was accessed using UNKNOWN_READ_ACCESS with value . CMake Debug Log at CMakeLists.txt:3 (project): Variable "CMAKE_MAKE_PROGRAM" was accessed using MODIFIED_ACCESS with value C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe. The C compiler identification is unknown The CXX compiler identification is unknown CMake Error at CMakeLists.txt:3 (project): No CMAKE_C_COMPILER could be found.

In output file:

LINK : fatal error LNK1104: cannot open file 'MSVCRTD.lib'

Is CMake looking for libs in VS 11 installation folder? The thing is that VS installer put libs in C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64.

Upvotes: 0

Views: 2235

Answers (1)

DevSolar
DevSolar

Reputation: 70263

For cases like this (and similar), I keep a VCEnvCmd.bat in my source trees:

call "%VS110COMNTOOLS%\..\..\VC\vcvarsall.bat" amd64 & %*

Executing that .bat without parameters will find and run vcvarsall.bat, setting up the environment for the amd64 target in the current shell (which you could change or parameterize according to your needs, like the version number embedded in that environment variable).

The nice trick is, for those Nightly / Continuous builds, you can use the .bat as a "prefix" for setting up the environment, e.g. in the task manager:

VCEnvCmd.bat ctest -S CTestScript.cmake,Nightly

The advantage is that you use what MSVC already gives you (the VS...COMNTOOLS variable), without having to clutter your environment further with persistent changes to PATH etc.

Upvotes: 3

Related Questions