(Windows) Install and Configure VSCode with CMake - kurogane1031/itolab_weekly_cpp GitHub Wiki
Installing Visual Studio Code
- Download VSCode installer. Once finished, run the executable.
- When prompt
Select Additional Tasks
, select the following optionsAdd "Open with Code" action to Windows Explorer
Add "Open with Code" action to Windows Explorer directory context Menu
Register Code as an editor for supported file types
Add to PATH (requires shell restart)
- Select
Next
to complete installation.
Install Extensions
We need to install 3 extensions: C/C++, CMake, CMake Tools.
- Open VSCode.
- On the left sidebar, click on
Extensions
Icon (keybinding:Ctrl
+Shift
+x
). - Search for
C/C++
extension by Microsoft. Click onInstall
. - Repeat the same for
CMake
andCMake Tools
. - For completion purpose, close and reopen VSCode.
Configuring CMake's User settings
- Open VSCode
- Go to
File
,Preferences
andSettings
(keybinding:Ctrl
+,
). - In
Settings
tab, underUser
, selectExtensions
andCMake configuration
. - On the
Cmake Path
, type the location ofcmake.exe
. By default isC:\Program Files\CMake\bin\cmake.exe
. - Next under
CMake Tools configuration
, findCmake: Cmake Path
and again, make sure the location ofcmake.exe
. It should be similar to the one inCMake configuration
. - Just to make sure thing is okay, open
settings.json
. You can do this byCtrl
+Shift
+P
and searchPreference: Open Settings (JSON). At the very least, your
settings.json` should look as follow.
{
"cmake.cmakePath": "C:\\Program Files\\CMake\\bin\\cmake.exe",
"cmake.copyCompileCommands": "${workspaceFolder}",
"cmake.generator": "MinGW Makefiles",
"C_Cpp.updateChannel": "Insiders",
"cmake.configureOnOpen": true,
"C_Cpp.default.compilerPath": "C:\\MinGW\\bin",
}
If one of them is missing, you can just copy and paste them.
Testing CMake
-
Close any open folder.
-
(Assuming you cloned this repository) Open
Week02
folder. -
You may be prompt to select the compiler. However, if you accidentally lost the selection, type
Ctrl
+Shift
+P
, search and selectCMake: Configure
.3.1 Open
CMakeLists.txt
, and comment out the following# SET(CMAKE_CXX_COMPILER "/usr/bin/clang++-10") # SET(CMAKE_CXX_FLAGS "-g -Wall -Wno-conversion -Wextra -Wpedantic -ftime-trace")
-
If the OUTPUT console is as follows, it means you're successful.
[main] Configuring folder: week02
[main] Configuring folder: week02
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.exe" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=C:\MinGW\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\MinGW\bin\g++.exe "-Hd:/Google Drive (Shibaura)/New folder/itolab_weekly_cpp/itolab_weekly_cpp/week02" "-Bd:/Google Drive (Shibaura)/New folder/itolab_weekly_cpp/itolab_weekly_cpp/week02/build" -G "MinGW Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is GNU 9.2.0
[cmake] -- The CXX compiler identification is GNU 9.2.0
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/MinGW/bin/gcc.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: C:/MinGW/bin/g++.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to:
- Now go to the TERMINAL, type
cd build
the followed bycmake ..
- To compile the program, type
mingw32-make
. - Done!