1

This tutorial provided by the VS Code team explains how to setup C++ in VS Code with MinGW (https://code.visualstudio.com/docs/cpp/config-mingw), however it seems to only target small-scale projects as it is configured to rebuilds all files each time, and isn't setup to allow for easy configuration of a project (global defines, adding link libraries etc.) (or am I missing something?).

I am looking into using CMake as my build tool inside VS Code, however am really turned off by the idea of having to update the CMakeLists.txt file to change my project's configurations, e.g. every time I add files to my project or link a new library, as I have grown up using IDEs who do this process for me, which I find magnitudes easier as it allows me to purely to focus on writing code.

My question is, is there a known method to setup VS Code that will allow me to use a tool such as CMake without having to tinker with it too often?

This tutorial seems like a good starting point to setup CMake, but its method requires CMake knowledge https://pspdfkit.com/blog/2019/visual-studio-code-for-cpp/

I ideally would like the setup to cater for both small-scale and large-scale projects, both of which should allow for cross-platform building.

Thanks

Gary Allen
  • 1,218
  • 1
  • 13
  • 28
  • I have never come across an IDE that magically adds files and libraries to the project. They have some GUI setup to do the modification of the project/make file. In Make and QMake you can add text to include all cpp files in a directory. But not to add libraries if needed. What if you have multiple versions of a library installed. Which one should be chosen and where should it look for libs? – rioV8 May 28 '20 at 11:05
  • Never did I suggest that I want a feature that "magically adds files" to my project. I simply want the ability for added .cpp and .h files to included in my makefile without the need to do anything other than having it in the VS Code workspace. Visual Studio works like this, Qt Creator works like this, Codeblocks works like this, any modern IDE works like this – Gary Allen May 28 '20 at 11:49
  • VSC is an editor (with benefits) not an IDE. Then write an extension that does this for your particular build tool. – rioV8 May 28 '20 at 13:07
  • The whole idea behind VSC is modularity - allowing programmers to use it as just an editor, or to convert it into a fully-fledged IDE. It has debugging tools, it has version control tools, and so on and so on. The idea behind it is configurability - I was simply asking if there was a tool that did this job for me. ;) – Gary Allen May 28 '20 at 14:17
  • If you write this extension for CMake we all benifit – rioV8 May 28 '20 at 17:00

1 Answers1

1

As Visual Studio Code is not a heavy weight IDE, you will need to put some effort to get it run the way you want it to have, either: Write a CMake InputFile generator, e.g. :

list(APPEND EXECUTABLE_LIST executable_1 executable_2)
list(APPEND LIBRARY_LIST library_2 library_2 library_3)

foreach(lib IN LISTS LIBRARY_LIST)
     add_library(${lib} STATIC ${lib}.cpp)
endforeach()

foreach(exe IN LISTS EXECUTABLE_LIST)
    add_executable(${exe} ${exe}.cpp)
    target_include_directories(${exe} PUBLIC ${CMAKE_CURRENT_LIST_DIR})
    target_link_libraries(${exe} ${LIBRARY_LIST})
endforeach()

or you could also use Visual Studio Code CMake Tool extention

For sure, you couldn't expect the highly functionality like Visual Studio in VS Code as they serve different purpose (highly specialised, deep system couple but slow and big vs small, fast, highly configurable).

dboy
  • 1,004
  • 2
  • 16
  • 24