简体   繁体   中英

Use VS Code for Cross-Platform Scalable C++ Project

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, eg 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

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, eg :

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM