This article describes the current proof-of-concept support for CMake in Visual Studio. As we evolve the experience in upcoming preview releases, we will continue to update the content here.
What is CMake
CMake is a cross-platform open-source tool for managing build processes across multiple platforms by abstracting away native build environments and compilers. CMake interprets a CMake script the user authors and generates a build plan in a build environment of choice (e.g. in Visual studio projects, make scripts, Xcode projects, etc.).
Since the beginning, CMake had support for Visual Studio targeting and it has closely paired each release of Visual Studio with a CMake generator allowing users to target a long list of VS versions throughout the years. The latest version supports every version of VS starting with 2005 and up to our latest preview release VS ’15’.
CMake momentum and your feedback
CMake has seen a tremendous uptick in the C++ community in recent years across all platforms. In our developer surveys, we have seen CMake constantly grow in usage year over year since 2012, surpassing in 2015 the make family (make/gmake/nmake) in terms of adoption.
With so many of you starting to use CMake with Visual Studio, we heard a lot of feedback and we’ve been constantly thinking of ways to improve the VS experience for CMake users. In 2014, we’ve contributed support for generating Visual Studio C++ projects targeting Windows Store and Windows Phone and in 2015, we’ve contributed support for generating Visual Studio C++ projects targeting Android.
But that only scratched the surface of the feedback we’ve been hearing. There is only so much a command line tool — even one like CMake — can do to control the C++ IDE experience and we heard from many of you that:
- It is not obvious which IDE features apply to CMake projects and which get lost when regenerating the VS projects
- For developers new to CMake, CMake language has a steep learning curve and its generated MSBuild-based projects are difficult to diagnose
- The switch between command line (to invoke CMake) and IDE to write code creates friction, made worse by the need to generate separate solutions to target x86 or X64to target various architectures
- CMake regeneration of VS projects causes a non-elegant solution reload experience in VS that disrupts the coding experience. Solution reload required by CMake during build is even more aggravating.
- Solution Explorer’s view of the generated VS projects does not resemble the disk organization of the CMake projects making it hard to navigate
Visual Studio support for CMake
Two initiatives that started taking shape in early 2016 marked a turning point in our planning. By this time, we already knew we wanted to tackle this problem space but we weren’t sure yet how to fix many of the challenges we heard from you.
- The first initiative, in the CMake community, was the CMake-server prototype developed initially by Stephen Kelly to improve the tooling story for CMake. This started some interesting conversation in the CMake community as well as internally in our team and it was dubbed the missing link between CMake and the IDE.
- The second one, a Visual Studio initiative (“Open Folder”) designed to enable the developer inner-loop (edit-build-debug experience) without the existing VS solution & C++ project system infrastructure, allowing non-MSBuild C++ codebases to be loaded in Visual Studio in a folder-based experience. This is now part of Visual Studio ’15’ “Open Folder” C++ capability.
Visual Studio ’15’ Preview 5 is the first release where we use both functionalities in conjunction in a proof-of-concept implementation of our CMake support in Visual Studio. While it will not be something you can try with your own CMake projects yet — this is coming in a future preview –, the current implementation tells us a lot about the underlying technologies and we’re more confident now that with future previews, we can deliver a solid CMake integration. VS can now:
- Enumerate CMake targets and files for each target,
- Detect outputs for CMake targets,
- Collect compiler switches including default system paths for files,
- Configure, build and install CMake scripts,
- Detect changes in CMakeLists.txt and dependents and reconfigure automatically
- All without needing a dedicated CMake generator
What’s next
Moving forward we will continue building on this functionality — stay tuned for a future preview in which you can try the VS support with your own CMake project. For now, if you want to experiment with our early prototype start with the example below and watch the CMake demo in our Visual Studio talk “Latest and Greatest from the Visual Studio Family for C++ developers” at CppCon.
CMakeLists.txt
cmake_minimum_required (VERSION 3.6) project (hello-world) add_executable(hello-world hello.cpp) install(TARGETS hello-world DESTINATION bin)
Hello.cpp
#include#include int main(int argc, char* argv[]) { std::cout << "Hello" << std::endl; }
The list of possible operations is available by right clicking on the CMakeLists.txt in Solution Explorer: Build, Clean, Install and Debug.