CMake and Visual Studio Tips

How to change working directory in Visual Studio

Select Debug or Debug and Launch Settings then add

"currentDir": "${ProjectDir}"

How to enable CMake multi-config in Visual Studio Code

CMake supports two types of generators: single-configurations (makefiles, nmake) and multi-configurations (IDEs). By adding the following lines to settings.json. This should then update your CMAKE_BUILD_TYPE accordingly and set it as -D CLI option.

"cmake.configureSettings": {
   "CMAKE_BUILD_TYPE": "${buildType}"
}

See this link for reference.

Another way is:

Settings: Cmake: Set Build Type On Multi Config

  • Set CMAKE_BUILD_TYPE also on multi-config generators

How to embed MSVC runtime in the executable file

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

See MSVC_RUNTIME_LIBRARY and CMAKE_MSVC_RUNTIME_LIBRARY for reference.

Linyuan Shi
Linyuan Shi
Lecturer

My research interests include non-equilibrium reactive molecular dynamics simulation and first principles computation.