Sunrise Sun Manually # 2: By 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 chain, The
    faces of friends, and the masks of enemies,
    Clearly visible and can not hide
    From the gaze of the poet - the owner of the centuries.

    The light of distant stars and the beginning of dawn,
    Life's secrets and secrets of love,
    Warmed by the sun in inspiration -
    Everything is reflected in the poet's souls -
    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.


    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:

    • Fighters for freedom and Opensorts
    • Honestly mistaken
    • Animals

    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.


    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:

    • Everything is unbearably slow - a modern phone is more powerful than the computers that sent people to the moon;
    • Everything is HUGE - Android weighs 6 gigabytes;
    • Everything is rotting - old devices do not work or work poorly;
    • In chaos programming, look at the dependency graphs in npm and left-pad.

    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:

    • For applications on Electron (Visual Studio Code, Atom), letters appear on the screen too slowly, whether it is vim or emacs;
    • Eclipse IDE slows down;
    • Generally, Java slows down - along with everything written on it, including NetBeans, IDEA and Clion;
    • Any IDE slow down devour percents just like that;
    • Proprietary - evil;
    • The list goes on.

    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 has seen for the first time expand 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- This is the only file that needs to be collected. And he is going with the help of information, which is entirely located in CMakeLists.txt.

    In the opposite direction: there is CMakeLists.txt, which tells us what exactly we are going to compile. It is spelled 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?


    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.

    • Downloading from the site: . I have cmake-3.12.2-win64-x64;
    • We unpack and add the path to the place where cmake.exe is located in the Windows environment variable PATH;
    • Download the latest ninja generator from the site ;
    • Unpack and also put somewhere in PATH.

    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, you need at least dll files from 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:


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


    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 it mingw64\binis in 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.

    • It would be possible to view the full list of the running application using ListDLLs , but it does not show what is not loaded yet.
    • If you do Tools -> Visual Studio Command Prompt dumpbin /dependents "Z:\game\build\Mingw64-Debug\src.exe", then it will show only the very first level dll. In other words, if you dump only what dumpbin prompts, then after launch there will still be errors - they will just be about other DLLs.

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

    • Download the mingw-bundledlls script,
    • Put next to the executable,
    • In a text editor into an array of blacklist = [add our DirectX pieces: d3d10.dll, d3d11.dll, d3dcompiler_43.dll,
    • chmod 755 ./mingw-bundledlls,
    • To view used dll: ./mingw-bundledlls ./src.exe(well, any version that you are more interested in),
    • To automatically copy and put next: ./mingw-bundledlls --copy ./src.exe
    • PROFIT: the executable is launched just by double-clicking on the exe-file, and from Visual Studio.

    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

    • before.bat
    • Start -> Run -> cmd.exe
    • cd /d z://game/src
    • cmake -G "Ninja" -D EXECUTABLE_OUTPUT_PATH="bin" -D CMAKE_CXX_COMPILER="Z:/msys64/mingw64/bin/g++.exe" -D CMAKE_C_COMPILER="Z:/msys64/mingw64/bin/gcc.exe" .
    • ninja
    • Run the file generated in the bin immediately, or enclose the dll according to the instructions above and run after.bat

    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.

    • before.bat
    • Launch Visual Studio;
    • File -> Open -> CMake;
    • Select CMakeLists.txt;
    • See some time thinking and displaying the project;
    • Main menu -> Cache -> Generate -> project name;
    • We look at the Output and correct the errors (for example, I swore at the version of CMake, I had to drop to 3.11 instead of 3.12);
    • Main menu -> CMake -> Change CMake Settings (select MinGW64-Debug);
    • The project autogenerates the CMakeSettings.json file. We indicate the path to MinGW there (I had this in the previous video "Z: \ msys64 \ mingw64"), save the file;
    • Main menu -> Cache -> Generate -> CMakeLists.txt;
    • Main menu -> Cache -> Generate -> project name;
    • If everything is done correctly, an item with the name of the project will appear in the Select a valid startup item menu (next to the green arrow to launch the application);
    • We start.

    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 sitting behind the TV at home, for example), then the VSCode interface will turn into a mess. To prevent this from happening, you need to launch it with a 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.

    • Install CMake Tools: View -> Extensions -> in the search box enter "CMake Tools", press install in front of the package that the author of vector-of-bool did.
    • View -> Explorer -> Open Folder (select the directory with our project);
    • Command Palette (CP, shortcut Ctrl + P) -> "> CMake: Scan for Kits";
    • Choose our "GCC 8.2.0", even to which it leads to the right place, where msys2 is installed or what you use there;
    • File> Preferences> Settings;
    • Go to the User Settings tab;
    • Click on the three points in the upper right corner of the panel, and from the menu select "Open settings.json";
    • Add the following options:

    "cmake.configureOnOpen": true,
        "": "D:/msys64/usr/bin/bash.exe",
        "": [
        "": {
            "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": [
        "cmake.preferredGenerators": [
        "cmake.loggingLevel": "debug"

    • The build should happen automatically, and the build will be added to the directory build. If this does not happen, you need to click on the button Buildwith the gear in the status line.

    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.

    • "cmake.generator": "MSYS Makefiles"
    • "cmake.preferredGenerators": [ "MSYS Makefiles"]
    • Check that MinGW is not in PATH (after.bat);
    • Verify that the build directory was deleted in the project.
    • Start the Msys2 console;
    • export PATH=/z/msys64/mingw64/bin;$PATH(you can then enter in some "~/.bashrc")
    • From it, run VSCode, for example: "C:\Users\olegchir\AppData\Local\Programs\Microsoft VS Code\Code.exe"
    • And then everything is as before. The file should normally be generated.
    • When you try to immediately launch it from Windows Explorer by double clicking, it will instantly lead to DLL search errors - this means that everything is correct, inside VSCode we really use a special PATH, and outside of it there is no

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


    Summarizing, if you are a normal person, you can use CMake, MinGW, and not to 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

    Also popular now: