📜 ⬆️ ⬇️

Sunrise Sun Manually # 2: Hardcore for IDE, Cmake, and my frustration with animals

The previous article had the audacity to use CLion as an IDE. And then a man came running with a question: oh, a proprietary paid hack, sold, snickered, and so forth. In fairness, there was only one such comment on Habré, but in reality there are thousands of them. For example, the most active account on the ENT , I have been registered since 2010, and in almost every discussion with the participation of some non-free software, this hell begins. It is clear that I can not prove anything to anyone, but it can help a rare wandering past.


The article is conditionally divided into two parts: social motivational and technical (how to build CMake in Windows under various IDEs).




Where did it all come from


The article was based on this comment from the previous article : "If the podcast is for beginners and non-professionals, then why didn’t they take into account the IDE license :(" and further on.


The article was made based on the results of the stream on Twitch and your feedback on it. Record is on YouTube. This article is not a transcript of a podcast, but a product of its comprehension.



Original message


First, let's check the validity of the original assumption: software is expensive. If you go to the site, it turns out that CLion costs 8.90 bucks a month. 580 rubles. It is clear that for a person who does not earn a living by programming, this can sometimes show a decent amount that can be spent on something more useful. Buy food, for example.


For a professional, everything is completely different, but let's leave this topic. A journalist differs from an employee of the marketing department of a software or game manufacturer in that he does not promote Party policies, does not take steps to promote a product. He says it is. How it all really is, as a journalist truly sees the question. The same with real evangelists.


The essence of the phenomena, and the years of the string,
Faces of friends, and masks of enemies,
Clearly visible and unable to hide
From the gaze of the poet - the owner of the ages.

The light of distant stars and the beginning of dawn,
Life secrets and love secrets
In a moment of inspiration the sun warmed -
Everything is reflected in the souls of the poet -
In the mirror of the world ...

(c) Konstantin Nikolsky, "Mirror of the World"

If it’s really interesting how CLion increases your income, you will find who to turn to, and we’re talking about something else.


Typology


Instead, consider a group of people who are most bombed by closed software.


As you already understood, I’m not a sociologist, and I have only the typology that was developed in the heat of forum clashes. It has only the advantage that it is possible to practically not include the brain by referring a person to a group, looking at the first two comments.


So, people are:



I suggest not to consider the variant of the wrong author. I am another matter .


Fighters for freedom and Opensorts


The purest and lightest are the fighters for the open source. I myself am one of those who heard the word "Linux" constantly correcting, "not Linux, but GNU / Linux . " The problem is that the real world is never black and white. We have a certain amount of freedom, and this is a resource that can be used if necessary. As someone from the Mozilla management joked (or not), “why do we need credit, if we don’t spend it?”.


Example: there was such a person, Miguel de Icaza. He made Gnome and had a hand in shaping the GNU / Linux crash as we know it. And then they kicked him out of the community, and Stallman called him a "traitor of freedom":


“Miguel de Icaza is essentially a traitor to the Free Software community. <...> The project is aimed at improving the operation of ostensibly "open-source" programs on the Windows platform; thus the invaluable time of developers is being led away from free platforms. ”

And where is Miguel now? He and his team are working side by side with one of the greatest projects of recent years — transferring .NET to GNU / Linux under permissive licenses. He truly spent his time.


On the stream, I killed at least twenty minutes to stumble CMake under Visual Studio Code. Did not work out. And in a free, but not free Visual Studio, it came out the first time. This is exactly what we get so often when trying to use free software: in terms of open source, for obvious reasons, there is no time to think over end-to-end scripts and take care of the whole product. Thanks to the developers already for having done at least something. But for us as users, there is still a moral and ethical choice: either choose freedom and spend a lot of time on free software, or, on the contrary, spend our freedom on buying time, which can then be spent on some good deeds.


Since this question goes beyond the framework of solving technical problems, we will finish here. A truly ideological person is faithful to his idea.


Animals


Oh, but from this category I was bombed.


"The specific features of a person that distinguish him from other animals are erect, highly developed brain, thinking and articulate speech. A person studies and changes himself and the world around him, creates culture and his own history." (c) Wikipedia .

Unfortunately, in talking about IDE it often turns out that the interlocutor is not capable of independent thinking, instead of articulate speech he mumbles "and I’m already normal" and eats what they give. Because of the upright approach it is easy to confuse with a person, but make no mistake.


On these creatures go all who are not hitting. In the games they sell lutboksy and DLC with nostalgic music. In editors, they are planted on various anally occupied things, with the aim of tying the patient to a specific environment, ecosystem, and so that the end of the day is that no phenazepam is needed. They will eat everything. "And to me, and so the norm."


It is important to add that not only marketers drive over the ears, but also just trolls, or natural clinical schizo. There are many schizo, you will not believe how much.


For example, remember the manifesto that Nikitonsky recently laid out (more precisely, his translation into Habr): My disappointment in software ? How I bombed it. I sincerely hope that Nikitonsky wrote all this in order to notably manage, and not really.


Look what theses are:



Trolling by trolling, but someone may not have known that the size of the source code "that brought a man to the moon," that is, Apollo 11, is such that the author would hardly have wanted to read them.




That modern OSes define any hardware and have everything in them for every occasion. That the inactivity of the devices led to a wonderful situation, when the Merssian capitalissists looked and developed iron to the present level, thanks to which we have a mega-device for all occasions in our pocket. Even towels are not necessary, it is in Google Play. The mentioned npm permits an ordinary person to write an unimaginable complexity of things that would take years before.


And all these comrades who “we are giving what they are giving” suddenly begin to receive mega-ideas from the list above. Let's spread on IDE:



This list is already enough to overhaul the roof. Do not believe any garbage. If vim is better than Eclipse (or vice versa) in some cases, then this is definitely not because neighbors irradiate the Vimera with a microwave, and aliens abduct Eclipse at night.


Unfortunately, as a result of long network-based sofa wars, it was precisely established: the dialogue here can be ignored. Human is human, and animal is animal. That's the way life is. The probability that someone will read this article and come to its senses is extremely small, immolate improved .


Honestly mistaken


Now we are done with extremes: especially clever of the Stallman sect on the one hand of the spectrum, and not very clever animals on the other, let's talk about ordinary people.


The first misconception is that we are somehow nailed to an IDE. It has gone since those times when people used some Delphi 7 and ancient versions of Microsoft Visual Studio. They say that everything in the Vizualka became good with the project files. Hello, hello, now in the yard in 2018, slavery is no more.


To get rid of slavery, we are over given CMake : a toolset from cross-platform open-source utilities that allows us to build, test, and pack applications.


It still doesn’t say anything to the newbie and the hands are drawn to the IDE. All this from fear and misunderstanding of what is happening. I myself come from Java, and therefore I know well how the eyes of a person, who saw pom.xml for the first time, pom.xml .


Let's see what the project created last time consists of, and how to build it in all sorts of different IDEs.


Composition of files:



The shader is compiled right in runtime with the D3DCompile function . The D3DCompiler from the DirectX SDK (which is now the Windows SDK) works. No IDE is needed to build it.


main.cpp is the only file to build. And it is collected using information that is entirely in CMakeLists.txt .


In the opposite direction: there is CMakeLists.txt , which tells us what exactly we are going to compile. It contains the assembly main.cpp . This is enough to compile the project. After compilation, an exe-file is obtained, which, after launching, collects both the shader and displays it on the screen. Everything is very simple, the IDE does not participate in this chain and can be anything.


IDE is not required. At all. What's so incomprehensible?


Assembly


Preparatory moments


As always, preparation takes almost the most part of the process. Need to understand a few things.


It is assumed that everything is done on the basis of Msys2, which we installed last time . If this is not the case, you will have to clear it up yourself :)


How to install CMake and Ninja


To be able to collect something, you must install CMake, if you have not done it yet.



How to edit PATH, not to go kukhukha


The first method is known to all: win + pause -> Advanced system settings -> Advanced -> Environment variables. Unfortunately, even in Windows 10, in which the editor of the variable PATH was added, it is still not very convenient.


If you often click on a PATH, using a standard editing window is very irritating. I advise you to use the Rapid Environment Editor - it is free and saves a lot of nerves.


How to connect DLL from MinGW in development mode


The application has started, dll files are needed from at least mingw64\bin .


Unfortunately, I still could not find a really convenient solution for throwing libraries from MinGW to PATH. If any sage in the comments can tell, I will be very grateful.


Now the easiest place is to put the MinGW bin directory directly in first place in the PATH. (In the case of Visual Studio, you can simply jot libraries into the build directory.) Unfortunately, this method has a huge disadvantage: some of the software in Windows begins to fall off immediately after modifying the PATH. For example, I have stopped running Overwatch, and this is a completely fatal thing.


If you, like me, live in a computer, and not only turn it on during business hours, the following scheme is suggested: add MinGW to PATH before programming and remove it afterwards. To facilitate the process, you need to make two batch files that can be launched by double clicking:


before.bat:


 setx path "Z:\msys64\mingw64\bin;%path%" 

after.bat:


 setx PATH "%PATH:Z:\msys64\mingw64\bin;=%" 

How to connect a DLL in the "test release" mode


It is clear that the previous method works only while mingw64\bin is in the PATH, that is, only on the developer's computer. And even there, I do not always want to disfigure the PATH. If an ordinary person starts it (or ourselves after running after.bat), then something like this will happen:





The easiest way to solve this problem is to put the necessary dll next to the executable file. But for this you need to know which dll are used!


We already have some Microsoft-made utilities for this.



To run through dependencies in depth, there is such a script that can be executed directly from the command line (msys2, cygwin, etc. - it’s enough to install python2 / 3 and objdump inside).



There are still various tricky ways to make CMake copy the dll itself, but if you start to delve into the distribution issues, then you can never finish this article.


Manual build



We said that we were not tied to the IDE at all.


Build in Visual Studio


But still, developing without IDE is not the case. Last time, we already built a test application using CLion. But this is paid proprietarism and zashkvar, right? Forget it. Now only free.


In Visual Studio, the sequence of necessary actions is super simple.



As in the case of the console, you can start right this way (remembering that MinGW is in the PATH), or run after.bat and put the necessary DLLs according to the instructions. The DLL must be placed directly in the directory where the application is going. It can be specified in the buildRoot parameter in the CMakeSettings.json file.


So, gentlemen, the most important thing: from Visual Studio, everything compiles perfectly and runs. We said that we were not tied to a commercial IDE.


Build in Visual Studio Code


Unfortunately, Visual Studio is still proprietary closed software. We need to move to something more free, and this is Visual Studio Code.


First funny amindfack. If you run VSCode on a monitor with a large zoom (I’m at home sitting at the TV, for example), then the VSCode interface will turn into a mess. To prevent this from happening, you need to run it with the key --force-device-scale-factor (make a shortcut on the desktop, or something like that).


Unfortunately, I still haven't mastered the PATH management for VSCode, so the only way to start it is to modify the PATH using before.bat and another hack, which I will describe below.


Next you need to configure VSCode.



 "cmake.configureOnOpen": true, "terminal.integrated.shell.windows": "D:/msys64/usr/bin/bash.exe", "terminal.integrated.shellArgs.windows": [ "-i" ], "terminal.integrated.env.windows": { "PATH": "/mingw64/bin;/usr/local/bin;/usr/bin;/bin;Z:/msys64/bin/;Z:/msys64/usr/local/bin;Z:/msys64/usr/bin;Z:/msys64/bin;Z:/msys64/mingw64/bin/;%PATH%" }, "cmake.buildDirectory": "${workspaceRoot}/build/${buildType}", "cmake.clearOutputBeforeBuild": true, "cmake.generator": "Ninja", "cmake.cmakePath": "C:\\my\\opt\\cmake-3.12.2-win64-x64\\cmake-3.12.2-win64-x64\\bin\\cmake.exe", "cmake.mingwSearchDirs": [ "Z:/msys64/mingw64", ], "cmake.preferredGenerators": [ "Ninja" ], "cmake.loggingLevel": "debug" 


It is clear that there you need to directly specify the path to mingw and cmake. "But I have the same PATH!" Just specify, please, this will solve a whole complex of problems.


There is, however, one exclusive way to not trash yourself PATH.



So, we proved that in a free IDE we also can live quite well.


Results


Summarizing, if you are a normal person, you can use CMake, MinGW and never blow. Everything is portable between IDEs, everything just works. We can use any paid, closed, non-free IDE at any time, and we will have nothing for it. But everyone else will suffer, and rightly so.


In future articles your opinion will be taken into account. You can direct questions and offer suggestions in the comments directly during Tvic stream. Whether there will be these articles at all depends on how fiercely you play the arrow up under this comment.


                  

© Alexander Raevsky


')

Source: https://habr.com/ru/post/425209/


All Articles