Skip to content

Commit 6e5d5fa

Browse files
author
Colin Robertson
committed
Update Linux CMake instructions for issue 312
1 parent f16949e commit 6e5d5fa

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

docs/linux/cmake-linux-project.md

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,25 @@ ms.workload: ["cplusplus", "linux"]
1414
---
1515

1616
# Configure a Linux CMake project
17-
18-
**Visual Studio 2017 version 15.4**
19-
When you install the Linux C++ workload, CMake support for Linux is selected by default. You can now work on your existing code base that uses CMake without having to convert it to a Visual Studio project. If your code base is cross-platform, you can target both Windows and Linux from within Visual Studio.
2017

21-
This topic assumes you have basic familiarity with CMake support in Visual Studio. For more information, see [CMake Tools for Visual C++](../ide/cmake-tools-for-visual-cpp.md). For more information about CMake itself, see [Build, Test and Package Your Software With CMake](https://cmake.org/).
22-
23-
> [!NOTE]
24-
> The CMake support in Visual Studio requires the server mode support that was introduced in CMake 3.8. If your package manager provides an older version of CMake, you can work around it by building CMake 3.8 from source.
18+
**Visual Studio 2017 version 15.4 and later**
19+
When you install the Linux C++ workload, CMake support for Linux is selected by default. You can now work on your existing code base that uses CMake without having to convert it to a Visual Studio project. If your code base is cross-platform, you can target both Windows and Linux from within Visual Studio.
2520

21+
This topic assumes you have basic familiarity with CMake support in Visual Studio. For more information, see [CMake Tools for Visual C++](../ide/cmake-tools-for-visual-cpp.md). For more information about CMake itself, see [Build, Test and Package Your Software With CMake](https://cmake.org/).
2622

23+
> [!NOTE]
24+
> The CMake support in Visual Studio requires the server mode support that was introduced in CMake 3.8. If your package manager provides an older version of CMake, you can work around it by [building CMake from source](#build-a-supported-cmake release-from-source) or downloading it from the official [CMake download page](https://cmake.org/download/).
2725
2826
## Open a folder
29-
To get started, choose **File | Open | Folder** from the main menu or else type `devenv.exe <foldername>` on the command line. The folder you open should have a CMakeLists.txt file in it, along with your source code.
27+
28+
To get started, choose **File** > **Open** > **Folder** from the main menu or else type `devenv.exe <foldername>` on the command line. The folder you open should have a CMakeLists.txt file in it, along with your source code.
3029
The following example shows a simple CMakeLists.txt file and .cpp file:
3130

3231
```cpp
3332
// Hello.cpp
3433

3534
#include <iostream>;
36-
35+
3736
int main(int argc, char* argv[])
3837
{
3938
std::cout << "Hello" << std::endl;
@@ -48,21 +47,26 @@ add_executable(hello-cmake hello.cpp)
4847
```
4948

5049
## Choose a Linux target
51-
As soon as you open the folder, Visual Studio parses the CMakeLists.txt file and specifies a Windows target of x86-Debug. To target Linux, change the project settings to Linux-Debug or Linux-Release.
5250

53-
By default, Visual Studio chooses the first remote system in the list (under **Tools | Options | Cross Platform | Connection Manager**). If no remote connections are found, you are prompted to create one.
51+
As soon as you open the folder, Visual Studio parses the CMakeLists.txt file and specifies a Windows target of **x86-Debug**. To target Linux, change the project settings to **Linux-Debug** or **Linux-Release**.
52+
53+
By default, Visual Studio chooses the first remote system in the list under **Tools** > **Options** > **Cross Platform** > **Connection Manager**. If no remote connections are found, you are prompted to create one.
5454

55-
After you specify a Linux target, your source is copied to your Linux machine. Then, CMake is run on the Linux machine to generate the CMake cache for your project.
55+
After you specify a Linux target, your source is copied to your Linux machine. Then, CMake is run on the Linux machine to generate the CMake cache for your project.
5656

57-
![Generate CMake cache on Linux](media/cmake-linux-1.png "Generate the CMake cache on Linux")
57+
![Generate CMake cache on Linux](media/cmake-linux-1.png "Generate the CMake cache on Linux")
5858

59-
**Visual Studio 2017 version 15.7 and later:**
59+
**Visual Studio 2017 version 15.7 and later:**
6060
To provide IntelliSense support for remote headers, Visual Studio automatically copies them to a directory on your local Windows machine. For more information, see [IntelliSense for remote headers](configure-a-linux-project.md#remote_intellisense).
6161

62-
## Debug the project
63-
To debug your code on the remote system, set a breakpoint, select the CMake target as the startup item in the toolbar menu next to the project setting, and click run (or press F5).
62+
## Debug the project
63+
64+
To debug your code on the remote system, set a breakpoint, select the CMake target as the startup item in the toolbar menu next to the project setting, and choose **&#x23f5; Start** on the toolbar, or press F5.
65+
66+
To customize your program’s command line arguments, right-click on the executable in **Solution Explorer** and select **Debug and Launch Settings**. This opens or creates a launch.vs.json configuration file that contains information about your program. To specify additional arguments, add them in the `args` JSON array. For more information, see [Open Folder projects in Visual C++](https://docs.microsoft.com/en-us/cpp/ide/non-msbuild-projects).
67+
68+
## Configure CMake settings for Linux
6469

65-
## Configure CMake Settings for Linux
6670
To change the default CMake settings, choose **CMake | Change CMake Settings | CMakeLists.txt** from the main menu, or right-click CMakeSettings.txt in **Solution Explorer** and choose **Change CMake Settings**. Visual Studio then creates a new file in your folder called `CMakeSettings.json` that is populated with the default configurations that are listed in the project settings menu item. The following example shows the default configuration for Linux-Debug based on the previous code example:
6771

6872
```json
@@ -87,7 +91,8 @@ To change the default CMake settings, choose **CMake | Change CMake Settings | C
8791

8892
The `name` value can be whatever you like. The `remoteMachineName` value specifies which remote system to target, in case you have more than one. IntelliSense is enabled for this field to help you select the right system. The field `remoteCMakeListsRoot` specifies where your project sources will be copied to on the remote system. The field `remoteBuildRoot` is where the build output will be generated on your remote system. That output is also copied locally to the location specified by `buildRoot`.
8993

90-
## Building a supported CMake release from source
94+
## Build a supported CMake release from source
95+
9196
The minimum version of CMake required on your Linux machine is 3.8, and it must also support server mode. To verify this run this command:
9297

9398
```cmd
@@ -100,9 +105,11 @@ To verify that server mode is enabled, run:
100105
cmake -E capabilities
101106
```
102107

103-
In the output, look for “serverMode”:true. Note that even when you compile CMake from source as described below you should check the capabilities when done. Your Linux system may have limitations that prevent server mode from being enabled.
108+
In the output, look for **"serverMode":true**. Note that even when you compile CMake from source as described below you should check the capabilities when done. Your Linux system may have limitations that prevent server mode from being enabled.
109+
110+
To get started building CMake from source in the shell for your Linux system, make sure your package manager is up to date, and that you have git and cmake available.
104111

105-
To get started building from source in the shell for your Linux system make sure your package manager is up to date, and that you have git and cmake available. First, clone the CMake sources from our repo where we use for Visual Studio's CMake support:
112+
First, clone the CMake sources from the [Microsoft CMake repo](https://github.com/Microsoft/CMake) where we maintain a fork for Visual Studio's CMake support:
106113

107114
```cmd
108115
sudo apt-get update
@@ -111,7 +118,7 @@ git clone https://github.com/Microsoft/CMake.git
111118
cd CMake
112119
```
113120

114-
Next, run the following commands:
121+
Next, to build and install the current release of CMake to /usr/local/bin, run these commands:
115122

116123
```cmd
117124
mkdir out
@@ -121,13 +128,14 @@ make
121128
sudo make install
122129
```
123130

124-
The above commands build and install the current release of CMake to /usr/local/bin. Run this command to verify the version is >= 3.8 and that server mode is enabled:
131+
Next, run this command to verify the version is >= 3.8 and that server mode is enabled:
125132

126133
```cmd
127134
/usr/local/bin/cmake –version
128135
cmake -E capabilities
129136
```
130137

131-
## See Also
138+
## See also
139+
132140
[Working with Project Properties](../ide/working-with-project-properties.md)
133-
[CMake Tools for Visual C++](../ide/cmake-tools-for-visual-cpp.md)
141+
[CMake Tools for Visual C++](../ide/cmake-tools-for-visual-cpp.md)

0 commit comments

Comments
 (0)