3
votes

I am using cmake to generate solutions for visual studio and it worked very well.

I noted that as part of build, it also generate a target called install on visual studio, supposedly to install the build files (such as libraries or include files), but how can I use it on visual studio?

I select this target and try to build or run it without any success or any result (no file copied to anywhere else and so on).

Can you please help me how I can use install target in visual studio to install the generated files (in my case it is a library).

I am suing cmake gui, but I can use cmake command line if it needs.

Update 1:

I know that it is generated for install target on my cmake file, but my question is how I can run it?

when I build install on VS solution, I am getting this error:

Error   3   error MSB3073: The command "setlocal
"C:\Program Files (x86)\CMake\bin\cmake.exe" -DBUILD_TYPE=Debug -P cmake_install.cmake
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
:VCEnd" exited with code 1. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets  132 5   INSTALL

so I am not able to use it inside VS.

How can I use it inside VS (if it is possible at all!)

How can I use it with cmake GUI?

How can I configure t to install the product at a specific place? (I define the install directory which I don't want to be inside c:\program files

1

1 Answers

5
votes

The CMake generated VS INSTALL target is linked to CMake's install() command.

So you have to tell CMake what you like to install trough the install() command. Normally its also only there if in your code you have an install() call somewhere.

Try e.g.

include(InstallRequiredSystemLibraries)

install(
    TARGETS MyApplication 
    RUNTIME DESTINATION "."
    CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES}
)

If you get an error while building the INSTALL target like

-- Install configuration: "Debug"
CMake Error at cmake_install.cmake:31 (file):
file cannot create directory: C:/Program Files (x86)/cmakeTesting/bin.
Maybe need administrative privileges.

You have to start your VS with administrator privileges or set/change the CMAKE_INSTALL_PREFIX variable e.g. with the CMake's GUI before doing the generate step:

enter image description here

Reference