Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run INSTALL with Visual Studio's CMake support?

With CMake support in Visual Studio, how can I run the INSTALL build?

enter image description here From the CMake menu in the top toolbar, I don't see any selection to run the INSTALL project.

EDIT: The minimum settings suggested by vre worked, the INSTALL option showed up in the toolbar menu:

  • CMakeLists.txt

    # 3.9.2 is the current version the newest VS is using
    cmake_minimum_required(VERSION 3.9.2)
    project(test2017)
    add_executable(hello hello.cpp)
    install(TARGETS hello DESTINATION hello/bin)
    
  • hello.cpp

But when I moved hello.cpp to a subfolder, the option was gone:

  • CMakeLists.txt

    cmake_minimum_required(VERSION 3.9.2)
    project(test2017)
    add_subdirectory("src")
    
  • src/CMakeLists.txt

    add_executable(hello hello.cpp)
    install(TARGETS hello DESTINATION "hello/bin")
    
  • src/hello.cpp

like image 217
MiP Avatar asked Jan 27 '18 01:01

MiP


People also ask

Can you use CMake with Visual Studio code?

The latest version of CMake tools is now available for download in the VS Code Marketplace or using the . vsix file. We have been working hard on improving the CMake experience and are excited to share some new features and improvements for users starting in version 1.11.

How do I run with CMake?

Run cmake-gui.exe, which should be in your Start menu under Program Files, there may also be a shortcut on your desktop, or if you built from source, it will be in the build directory. A GUI will appear similar to what is shown below. The top two entries are the source code and binary directories.

How do I add a CMake project to Visual Studio solution?

On the Visual Studio main menu, choose File > Open > CMake. Navigate to the CMakeLists. txt file in the root of the bullet3 repo you just downloaded. As soon as you open the folder, your folder structure becomes visible in the Solution Explorer.


1 Answers

It seems there is a bug when using subfolders and still hasn't been fixed in the current VS 15.5.5.

A workaround is adding an install argument to buildCommandArgs inside the CMakeSettings.json file. Example:

{
  "configurations": [
    {
      "name": "x86-Debug",
      "generator": "Ninja",
      "configurationType": "Debug",
      "inheritEnvironments": [ "msvc_x86" ],
      "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
      "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
      "cmakeCommandArgs": "",
      "buildCommandArgs": "-v install",
      "ctestCommandArgs": ""
    }
  ]
}
like image 141
MiP Avatar answered Nov 15 '22 06:11

MiP