Skip to content

Instantly share code, notes, and snippets.

@hongyue
Last active December 31, 2023 03:08
Show Gist options
  • Save hongyue/d4f015bb385bd36bc0e3af5ab448c5b2 to your computer and use it in GitHub Desktop.
Save hongyue/d4f015bb385bd36bc0e3af5ab448c5b2 to your computer and use it in GitHub Desktop.
cmake, vcpkg and qt creator integration related stuff

VS Code's CMake Tools integration with vcpkg

Add the "cmake.configureSettings" section to vs code's settings.json.

For remote development, using 'open remote settings' to open settings.json.

{
    "cmake.configureSettings": {
        "CMAKE_TOOLCHAIN_FILE": "<vcpkg root folder>/scripts/buildsystems/vcpkg.cmake"
    }
}

Qt Creator CMake integration with vcpkg

Add the following line to Qt Creator's CMake Configuration (Options->Kits-><kit>->CMake Configuration):

CMAKE_TOOLCHAIN_FILE:STRING=<vcpkg root folder>/scripts/buildsystems/vcpkg.cmake

Qt Creator environment variables

QtCreator only looks for system-wide environment variables on Linux, the ones set in .bashrc or .bash_profile are valid only for the user.

To set a system-wide environment variable one can add it to /etc/environment, or to be more multi-user friendly one can set the variable in '/etc/profile` instead. This way the environment variable can contain another environment variable, like:

export QT5_CMAKE=$HOME/Qt5.13.1/5.13.1/gcc_64/lib/cmake/Qt5/

Finding QT5 with CMake

Append QT5's cmake path to CMAKE_PREFIX_PATH variable, for example:

list(APPEND CMAKE_PREFIX_PATH "~/Qt5.13.1/5.13.1/gcc_64/lib/cmake/Qt5/")

VS Code Remote-SSH environment variables

When adding envrionment variables to the remote host, you need to run "Kill VS Code Server on Host..." command to take changes effect.

[More details]

CMake platform checks

CMake sets certain variables to true depending on the current platform and toolchain in use. These always describe the target platform. In older versions of CMake, these were the only way of detecting the current platform.

  • UNIX : is TRUE on all UNIX-like OS's, including Apple OS X and CygWin
  • WIN32 : is TRUE on Windows. Prior to 2.8.4 this included CygWin
  • APPLE : is TRUE on Apple systems. Note this does not imply the system is Mac OS X, only that APPLE is #defined in C/C++ header files.
  • MINGW : is TRUE when using the MinGW compiler in Windows
  • MSYS : is TRUE when using the MSYS developer environment in Windows
  • CYGWIN : is TRUE on Windows when using the CygWin version of cmake

[More details]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment