How to switch toolchains in CLion 2018.2? - clion

I started trying to use of CLion 2018.2 today and the first problem with I stuck is how to switch toolchains in CLion.
I want to switch the toolchain from MinGW to Visual Studio and I can switch it by making Visual Studio toolchain as default (File->Settings->Build, Execution, Deployment->Toolchains->Select Visual Studio->Click Up arrow).
But I don't want to make this toolchain as default.
I just wanted to try it.
Should I press this up arrow button if I want to switch toolchains or there is any simpler way?
Thanks.

No need to many any toolchain a default one. Do the following:
Configure all necessary toolchains in settings. https://www.jetbrains.com/help/clion/how-to-create-toolchain-in-clion.html
Then in Settings | Build, Execution, Deployment | CMake configure several CMake profiles using different toolchains. https://www.jetbrains.com/help/clion/configuring-cmake.html#CMProfile
Then in the same switcher where you can change the run/debug configuration, there is also a list of available CMake profiles with corresponding toolchains. Select the combination you need and then you can run/debug.

1. Add Toolchains:
2. Switch in CMake tab, like below:

Related

Using cmakesettings.json with cmake

I am novice at cmake, so please be gentle.
I have a medium sized project that has been using visual studio with cmake. I would like to use the build/install features that I currently use in visual studio, but with cmake in the terminal.
Currently the project uses a cmakesettings.json to switch between the different builds and locations. When I searched this though, it seems to be specific to visual studio?
https://github.com/microsoft/CmakeSettings
Is there a tool or easy way to use these settings with cmake instead of visual studio?
Note that in VS2019, the correct way to do this is to use CMakePresets.json and then you can build in a VS2019 or higher, VS2022, or in a CI using cmake from the cmd.exe. CMakeSettings.json is deprecated. To enabled support for them, there is an option that needs to be enabled. See this link https://learn.microsoft.com/en-us/cpp/build/cmake-presets-vs?view=msvc-160 for more information.

How to configure VS2017 to use system CMake instead of nested one

Visual Studio 2017 add a new feature supporting directly open CMake project now. But it always use its own nested CMake. It's quite annoying since i can't touch that CMake. It has different version, different configuration from my usual one.
So I want to know is there a way to change this behavior, like in CLion, by assigning which CMake to use?

How to use GCC with Microsoft Visual Studio?

I am creating a very large project (a few thousand lines) and so would rather not use Notepad++. An IDE would make it so much easier. I have experience with Microsoft Visual Studio and love it. Is there some easy way to use Cygwin's GCC from within Microsoft Visual Studio?
Alternately, are there any other good Windows IDEs for GCC besides NetBeans and Eclipse? (I hate both of them with a passion.)
There are several ways to go here:
Option 1: Create a Custom Build Tool
Visual Studio 2005 and newer will let you register custom build tools. They tell the IDE how to transform files of one form (e.g. a .cpp file) into another form (e.g. an .obj file).
So far as I know, no one has done this yet for GCC. And, doing it yourself requires writing COM code, which is probably too deep a pool to dive into just for a single project. You'd have to have a compelling reason to take this project on.
You then have to manually adjust each project to tell it to use the custom build tool instead of the default, since you're using a file name extension (.cpp, probably) that Visual C++ already knows about. You'll run into trouble if you try to mix the VC++ and g++ compilers for a single executable built from multiple modules.
On the plus side, if you were looking to start an open source project, this sounds like a good one to me. I expect you'd quickly gather a big user base.
Option 2: Makefile Project
Start Visual Studio and say File > New Project.
In the Visual C++ section, select Makefile Project
Fill out the Makefile Project Wizard:
Build command line: make
Clean commands: make clean
Rebuild command line: make clean all
You can leave the Output (for debugging) field alone if you've named your executable after the project name and it lands where Visual Studio expects to find it.
Leave the rest of the fields alone unless you know what they are and why you want to change them. As an example, you might choose to pass a -D flag on the Preprocessor definitions line to get separate debug and release outputs. If you know you want this, you know how to set it up, so I'm not going to make this long answer even longer in order to explain it.
You'll be asked the same set of questions for the Release build. If you want to bother with separate debug and release builds, you'd make any changes here.
Having done all this, you still have to create the Makefile, and add a make.exe to your PATH. As with the debug vs. release question, going into that level of detail would push this answer off topic.
As ugly as this looks, it's still easier than creating custom build tools. Plus, you say you need to port to Unix eventually, so you're going to need that Makefile anyway.
Option 3: Cross-Platform Development
You say you want to port this program to Unix at some point, but that doesn't mean you must use GCC on Windows now. It is quite possible to write your program so that it builds under Visual C++ on Windows and GCC/Makefiles on *ix systems.
There are several tools that make this easier. One very popular option is CMake, which is available as an installation time option in newer versions of Visual Studio. There are many alternatives such as SCons and Bakefile.
Clang
You can use the Clang compiler with Visual Studio to target Android, iOS, and Windows.
If you are targeting Android, you can use the Clang/LLVM compiler that ships with the Android NDK and toolchain to build your project. Likewise, Visual Studio can use Clang running on a Mac to build projects targeting iOS. Support for Android and iOS is included in the “Mobile Development with C++” workload. For more information about targeting Android or iOS check out our posts tagged with the keywords “Android” and “iOS”.
If you are targeting Windows, you have a few options:
Use Clang/LLVM; “Clang for Windows” includes instructions to install Clang/LLVM as a platform toolset in Visual Studio.
Use Clang to target Windows with Clang/C2 (Clang frontend with Microsoft Code Generation).
GCC
If your project targets Linux or Android, you can consider using GCC. Visual Studio’s C++ Android development natively supports building your projects with the GCC that ships with the Android NDK, just like it does for Clang. You can also target Linux – either remotely or locally with the Windows Subsystem for Linux – with GCC.
Check out our post on Visual C++ for Linux Development for much more info about how to use Visual Studio to target Linux with GCC. If you are specifically interested in targeting WSL locally, check out Targeting WSL from Visual Studio.
Source: https://devblogs.microsoft.com/cppblog/use-any-c-compiler-with-visual-studio/
I'm from the future.
I keep (poking at) a C/C++ toolchain using Visual Code on Win/Lin/Mac and MinGW installed from Choclatey.
(This was done for my sanity - install GDB and GCC however you want)
I've run it with GCC and GDB with IntelliSense using MS's own weird JSON makefiles.
Someday, someone (you?) will write a Gradle or Python script to generate these; for now the examples online in the docs seem to work.
It seems to require three types of JSON thing;
a single IntelliSense configuration for the whole workspace
a Debugging Configuration entry for each binary you want to debug
these can invoke the build tasks
a Build Task per-artifact
I don't think that there's a "require" or "dependency" thingie-mah-bob; sorry

Using Windows/Linux Makefile with Microsoft Visual Studio 2010

I have a Makefile that I use to build my application in both Windows and Linux. All complex project- and platform-related stuff are already dealt in this Makefile.
Today, I use a common editor to code and call GNU make from command line. Now I am considering to move to Microsoft Visual Studio 2010. I already use MSVS2010 when debuging using a not-configured Intel Visual Fortran Empty Project with my files.
I don't want to duplicate my work configuring a new Visual Studio project and I want to use the Makefile instead.
Is there a way to do it with MSVS2010? Or, is there any other better way to keep the configuration at one place "usable" from Windows and Linux?
In the somewhat distant past I used VC++2005 in just this way. The trick is to create an external project (or command-line project or something like that—I forget the terminology now). The command-line you give to this project is make -j4 target (ymmv). Naturally the makefile needs to use cl as the compiler, link as the linker &c.
Now everthing is hooked up, and you can press the f7 key in VC++ to build your project, and f4 takes you through the errors. [I used cygwin make, and it all worked rather well.]

Setting both Debug and Release settings in Visual C++ 2008

A common mistake when configuring the compilation/linking/etc. settings in VC++ 2008 is to set them in Release but not Debug (or vice versa) rather than setting them for "All Configurations". Any suggestions on how to avoid this kind of mistake?
Some beginnings of ideas that I have:
Find a way to make VC++ go to the "All Configurations" settings by default when you open the property pages rather than the active (Release / Debug) settings.
Have a VB script that can be run (inside or outside VC++) to check the project settings and raise any inconsistencies detected.
vb or js script is perfectly ok for the task. Just dont forget to teach it that some settings should differ, such as preprocessor defines, or used runtime libraries.
We recently switched to Qt's build (qmake) tool which is capable of generating both makefiles (used in batch product build) as well as project (.vcproj) files when working on individual projects.
The nice thing about it is that we have enforced all settings one could ever wish for beforehand once for all available build targets (i.e. we have debug, release and non optimized release) and have forgotten about manipulating settings ever since.
You can generate .vsproj files with CMake or Scons or similar cross platform build system.

Resources