<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ronaldd Pinho</title>
    <description>The latest articles on DEV Community by Ronaldd Pinho (@ronalddpinho).</description>
    <link>https://dev.to/ronalddpinho</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F302363%2Fb59d5fcb-b5ac-4341-8504-61474ffe92c6.webp</url>
      <title>DEV Community: Ronaldd Pinho</title>
      <link>https://dev.to/ronalddpinho</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ronalddpinho"/>
    <language>en</language>
    <item>
      <title>Loading dependencies in C++ projects using CMake</title>
      <dc:creator>Ronaldd Pinho</dc:creator>
      <pubDate>Wed, 26 Jan 2022 14:23:54 +0000</pubDate>
      <link>https://dev.to/ronalddpinho/loading-dependencies-in-c-projects-using-cmake-3ijb</link>
      <guid>https://dev.to/ronalddpinho/loading-dependencies-in-c-projects-using-cmake-3ijb</guid>
      <description>&lt;p&gt;With the modern programming languages, has turned common has a way to manage dependencies of your projects, either using npm, yarn, pip, or cargo this process is easy. However, when using C or C++ this process is not trivial. With this in mind, I thought to write this post about how I automate the download and configuration of libraries from Git repositories using the &lt;a href="https://cmake.org/" rel="noopener noreferrer"&gt;CMake&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Some solutions were created to solve this problem, such as &lt;a href="https://conan.io/" rel="noopener noreferrer"&gt;conan&lt;/a&gt; and &lt;a href="https://vcpkg.io/" rel="noopener noreferrer"&gt;vcpkg&lt;/a&gt; but it loads another dependency installed on your system and requires your dependency to be indexed by its server.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  The FetchContent module
&lt;/h2&gt;

&lt;p&gt;CMake is a build system that automates the generation of Makefiles that define the compilation process of a source code project. It provides various modules that help with configuration in many ways. One of these modules is &lt;a href="https://cmake.org/cmake/help/latest/module/FetchContent.html" rel="noopener noreferrer"&gt;FetchContent&lt;/a&gt;, which helps to fetch external content at configuration time, ie when CMake is generating the Makefile.&lt;/p&gt;

&lt;p&gt;It is quite simple to use it, in the example below we have added GoogleTest to our project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cmake"&gt;&lt;code&gt;&lt;span class="nb"&gt;include&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;FetchContent&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;FetchContent_Declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;GoogleTest
    GIT_REPOSITORY https://github.com/google/googletest.git
    GIT_TAG        master
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;FetchContent_MakeAvailable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;GoogleTest&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, we have the GoogleTest project as well as its libraries accessible at configuration time, so we can link any executable (or library) with GoogleTest, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cmake"&gt;&lt;code&gt;&lt;span class="c1"&gt;# create the main target for run the tests&lt;/span&gt;
&lt;span class="nb"&gt;add_executable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;mytests
        test/main.cpp
        test/awesome_test.cpp&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# link with the googletest main library&lt;/span&gt;
&lt;span class="nb"&gt;target_link_libraries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;mytests gtest_main&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create a CMake function
&lt;/h2&gt;

&lt;p&gt;To automate this process, I usually create a simple function that concentrates the code that uses FetchContent, this makes the CMake script more readable and easier to add new dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cmake"&gt;&lt;code&gt;&lt;span class="nb"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;GET_DEPENDENCY D_NAME D_URL D_TAG&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nb"&gt;message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;CHECK_START &lt;span class="s2"&gt;"Configuring &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;D_NAME&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;FetchContent_Declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;D_NAME&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        GIT_REPOSITORY &lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;D_URL&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        GIT_TAG        &lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;D_TAG&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;FetchContent_MakeAvailable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;D_NAME&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;endfunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So I can use the &lt;code&gt;get_dependency&lt;/code&gt; function passing three parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;D_NAME&lt;/code&gt;: the name to refers to this dependency.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;D_URL&lt;/code&gt;: the link remote Git repository (example: &lt;code&gt;https://github.com/...&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;D_TAG&lt;/code&gt;: the Git tag to get, may be the commit hash or version (examples: &lt;code&gt;de6e5fa&lt;/code&gt;,&lt;code&gt;v1.0.2&lt;/code&gt;, etc).
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cmake"&gt;&lt;code&gt;&lt;span class="nf"&gt;get_dependency&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;GoogleTest &lt;span class="s2"&gt;"https://github.com/google/googletest.git"&lt;/span&gt; master&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To add more dependencies...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cmake"&gt;&lt;code&gt;&lt;span class="nf"&gt;get_dependency&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;spdlog &lt;span class="s2"&gt;"https://github.com/gabime/spdlog"&lt;/span&gt; v1.8.5&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;get_dependency&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;CLI11 &lt;span class="s2"&gt;"https://github.com/CLIUtils/CLI11"&lt;/span&gt; v1.9.1&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;get_dependency&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;GoogleTest &lt;span class="s2"&gt;"https://github.com/google/googletest"&lt;/span&gt; master&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When I use this configuration, it becomes much easier to add and remove dependencies on external libraries, especially since I use open source libraries on Github. This also helps in team design by not having to have a complex set of steps to set up the development environment on the developers' different machines. It also brings a benefit to using CI (Continuous Integration).&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;When you run the configuration command, such as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cmake"&gt;&lt;code&gt;cmake -S . -B &amp;lt;build-dir&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CMake downloads the source code from &lt;code&gt;D_URL&lt;/code&gt; and store into a directory &lt;code&gt;&amp;lt;build-dir&amp;gt;/_deps&lt;/code&gt;. Inside the directory, FetchContent create three sub-directories: &lt;code&gt;${D_NAME}-src&lt;/code&gt;, &lt;code&gt;${D_NAME}-build&lt;/code&gt; and &lt;code&gt;${D_NAME}-subbuild&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Example with GoogleTest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;build-dir&amp;gt;/
|   _deps/
|   |   googletest-src/
|   |   googletest-subbuild/
|   |   googletest-build/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;src&lt;/code&gt;: source code of the dependency (from Git repository).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;build&lt;/code&gt;: CMakeFiles directory of the dependency.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;subbuild&lt;/code&gt;: created to perform the population of content.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For details, see &lt;a href="https://cmake.org/cmake/help/latest/module/FetchContent.html" rel="noopener noreferrer"&gt;FecthContent documentation&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>cmake</category>
      <category>beginners</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Primeiros passos com a linguagem Go: Por onde começar?</title>
      <dc:creator>Ronaldd Pinho</dc:creator>
      <pubDate>Wed, 26 Jan 2022 12:12:53 +0000</pubDate>
      <link>https://dev.to/ronalddpinho/primeiros-passos-com-a-linguagem-go-por-onde-comecar-46o3</link>
      <guid>https://dev.to/ronalddpinho/primeiros-passos-com-a-linguagem-go-por-onde-comecar-46o3</guid>
      <description>&lt;p&gt;Ao se deparar com uma tecnologia nova, sendo alguém experiente em programação ou não, acredito que a mesma pergunta sempre passa pela cabeça de todos: "Por onde eu começo?". Particularmente, eu sempre fui um programador autodidata e, mesmo depois de iniciar uma graduação em computação eu sempre busquei informações de forma proativa e adianto para quem está iniciando na área de desenvolvimento de software que, essa é uma característica essencial para o desenvolvimento técnico de qualquer pessoa programadora.&lt;/p&gt;

&lt;p&gt;Ao começar a estudar Go eu percebi uma grande quantidade de alternativas que na minha opinião pode deixar qualquer um confuso sobre como iniciar nos estudos da linguagem. Pensando nisso, resolvi escrever esse artigo com recomendações de por onde começar a estudar e praticar com a linguagem Go baseado na minha experiência estudando programação, com a esperança de que seja útil para qualquer pessoa interessada em aprender a linguagem independente de ter experiência em estudos de tecnologia ou não. Nas próximas seções, apresento opções de passos iniciais com a linguagem Go.&lt;/p&gt;




&lt;h2&gt;
  
  
  Go Tour
&lt;/h2&gt;

&lt;p&gt;O Go Tour é um fluxo de aprendizado disponibilizado através do próprio &lt;a href="https://go.dev" rel="noopener noreferrer"&gt;site oficial da linguagem&lt;/a&gt;, onde você pode conhecer a linguagem Go do zero. É ideal para quem está iniciando, nele você navega por páginas onde são apresentados desde conceitos básicos de programação como variáveis e controle de fluxo, até conceitos específicos de Go como a forma como ele lida com concorrência usando &lt;em&gt;goroutines&lt;/em&gt; e &lt;em&gt;channels&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;O Tour consiste de uma sequência de passos agrupados em módulos onde cada um apresenta algum conteúdo simples e a possibilidade de praticar com um exemplo pronto na própria página usando o Go Playground. Não precisa fazer nenhuma instalação e tem pouco (ou quase nenhum) pré-requisito para acompanhar. Está disponível em vários idiomas inclusive em português do Brasil e, é a melhor opção de primeiro passo para iniciantes. Mesmo pra quem já é da área, é interessante acompanhar o Tour como o contato inicial com a linguagem pois não consome muito tempo e apresenta conceitos específicos da linguagem de forma simples.&lt;/p&gt;




&lt;h2&gt;
  
  
  Curso: Aprenda Go
&lt;/h2&gt;

&lt;p&gt;“&lt;a href="https://aprendago.com" rel="noopener noreferrer"&gt;Aprenda Go&lt;/a&gt;” é um canal no YouTube que disponibiliza um curso completamente gratuito apresentado pela &lt;a href="https://twitter.com/veekorbes/" rel="noopener noreferrer"&gt;Ellen Körbes&lt;/a&gt;. O curso é super completo e organizado em capítulos, cobrindo desde conceitos básicos de programação até as peculiaridades da linguagem Go com uma excelente didática o uso da linguagem na prática. Além disso, fornece muitos exercícios práticos entre um capítulo e outro.&lt;/p&gt;

&lt;p&gt;Por se tratar de um curso de aulas em vídeo com mais de 20 capítulos, o conteúdo é um pouco mais extenso e, para pessoas que já possuem experiência com programação pode ser repetitivo no início. Ainda assim, é interessante acompanhar alguém com bastante conhecimento em Go falando sobre a linguagem, principalmente nos capítulos mais específicos sobre a mesma. Para pessoas com menos experiência, é a alternativa perfeita após terminar o Go Tour.&lt;/p&gt;




&lt;h2&gt;
  
  
  Go Blog
&lt;/h2&gt;

&lt;p&gt;O site oficial da linguagem também possui um &lt;a href="https://go.dev/blog/" rel="noopener noreferrer"&gt;blog&lt;/a&gt; onde muitos dos core developers do projeto Go escrevem, além de muitos desenvolvedores ativos na comunidade (Gophers). O blog possui conteúdo escrito apresentando as propostas da linguagem bem como bibliotecas, sintaxe e etc, features novas que foram implementadas em versões específicas e, a maior parte do conteúdo encontrado lá é interessante para aprofundar em assuntos específicos da linguagem Go. Vale destacar que todos os artigos do blog são escritos em inglês&lt;/p&gt;

&lt;p&gt;Abaixo seguem algumas postagens que eu julgo interessantes para quem está iniciando entender melhor a idéia do Go e como funcionam alguns conceitos. Também é interessante procurar aplicar os exemplos mostrados nas postagens de forma prática.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://go.dev/blog/declaration-syntax" rel="noopener noreferrer"&gt;Go's Declaration Syntax&lt;/a&gt;: Escrito por Rob Pike, um dos idealizadores da linguagem, o artigo fala sobre a sintaxe declarativa do Go comparando com a linguagem C e explica o por quê Go faz as coisas do jeito que faz.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://go.dev/blog/defer-panic-and-recover" rel="noopener noreferrer"&gt;Defer, Panic, and Recover&lt;/a&gt;: Esse artigo explica como funcionam três comandos específicos da linguagem Go.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://go.dev/blog/concurrency-timeouts" rel="noopener noreferrer"&gt;Go Concurrency Patterns: Timing out, moving on&lt;/a&gt;: Esse breve artigo mostra dicas de como trabalhar com concorrência de melhor forma em Go.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://go.dev/blog/context" rel="noopener noreferrer"&gt;Go Concurrency Patterns: Context&lt;/a&gt;: Esse post apresenta a idéia da interface &lt;code&gt;Context&lt;/code&gt;, uma interface pertencente à biblioteca padrão do Go e que é uma base do paradigma da linguagem para aplicações web.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://go.dev/blog/json" rel="noopener noreferrer"&gt;JSON and Go&lt;/a&gt;: Proposta inicial e primeiro contato com o pacote &lt;code&gt;encoding/json&lt;/code&gt; da biblioteca padrão do Go.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://go.dev/blog/using-go-modules" rel="noopener noreferrer"&gt;Using Go Modules&lt;/a&gt;: Um introdução aos modules, a forma como a linguagem Go gerencia conjuntos de pacotes e dependências. Essa postagem é a parte 1 de uma série de 5 postagens sobre o assunto.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;[Bônus] Para quem tem interesse em entender mais afundo como trabalham os modules em Go, eu recomendo estudar o &lt;a href="https://go.dev/ref/mod" rel="noopener noreferrer"&gt;Go Modules Reference&lt;/a&gt;. Trata-se de uma documentação bem mais extensa e detalhada sobre módulos, e fica mais como uma dica para quem já tem experiência com programação e documentações de tecnologias e tem a intenção de se aprofundar na linguagem.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Pratique, pratique e pratique mais!
&lt;/h2&gt;

&lt;p&gt;Isso não é segredo mas nunca é demais repetir, ninguém aprende nenhuma linguagem de programação somente lendo sobre ela. Então é interessante encontrar meios de praticar o uso da linguagem de forma que se possa aplicar os conceitos estudados, eu recomendo procurar aplicar qualquer conhecimento lido em postagens do blog para fixá-los e entendê-los melhor. O curso Aprenda Go ajuda bastante nesse quesito fornecendo uma boa quantidade de exercícios.&lt;/p&gt;

&lt;p&gt;Também existem várias plataformas que podem ser usadas para exercitar programação, tais como: &lt;a href="https://codewars.com" rel="noopener noreferrer"&gt;Codewars&lt;/a&gt;, &lt;a href="https://hackerrank.com" rel="noopener noreferrer"&gt;HackerRank&lt;/a&gt;, &lt;a href="https://exercismo.io" rel="noopener noreferrer"&gt;Exercism&lt;/a&gt;, etc. &lt;/p&gt;

&lt;p&gt;Invente projetos pessoais, isso com certeza vai te fazer exercitar não só o uso da linguagem de programação mas também fornece um certo exercício de criatividade que todo bom desenvolvedor deve ter para resolver os mais variados problemas.&lt;/p&gt;




&lt;h2&gt;
  
  
  Pra finalizar...
&lt;/h2&gt;

&lt;p&gt;Minha recomendação pessoal é: acompanhar o Go Tour, depois assistir ao curso Aprenda Go procurando praticar com os exercícios (para quem já tem boa experiência em programação, recomendo avançar direto para capítulos mais específicos do curso). Em seguida fazer as leituras dos artigos de blog citados enquanto pratica o uso da linguagem através de exercícios ou mesmo projetos pessoais.&lt;/p&gt;

&lt;p&gt;O ecossistema da linguagem Go tem ganhado cada vez mais popularidade no mercado e com isso têm surgido cada vez mais conteúdo sobre a linguagem na internet, dentre esses muito conteúdo gratuito de qualidade. Nesse post busquei apresentar as alternativas mais simples para os primeiros passos com a linguagem de forma a atender tanto pessoas com experiência em programação quanto iniciantes.&lt;/p&gt;

&lt;p&gt;Por fim, vale lembrar que isso esses são somente passos iniciais nos estudos da linguagem. Não pare por aqui, busque mais conteúdo, pratique, estude a documentação de módulos do Go, pratique mais um pouco, dê uma olhada no &lt;a href="https://github.com/Alikhll/golang-developer-roadmap/blob/master/i18n/pt-BR/ReadMe-pt-BR.md" rel="noopener noreferrer"&gt;&lt;em&gt;Golang Developer Roadmap&lt;/em&gt;&lt;/a&gt; e busque pelas bibliotecas em alta no mercado, pratique ainda mais... E não deixe que esse loop seja quebrado.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>go</category>
      <category>programming</category>
    </item>
    <item>
      <title>Carregando dependências em projetos C++ usando o CMake</title>
      <dc:creator>Ronaldd Pinho</dc:creator>
      <pubDate>Wed, 14 Jul 2021 13:32:41 +0000</pubDate>
      <link>https://dev.to/ronalddpinho/carregando-dependencias-em-projetos-c-usando-o-cmake-111p</link>
      <guid>https://dev.to/ronalddpinho/carregando-dependencias-em-projetos-c-usando-o-cmake-111p</guid>
      <description>&lt;p&gt;Com as linguagens de programação modernas é muito comum possuir-se um meio de obter e gerenciar dependências, seja usando o &lt;code&gt;pip&lt;/code&gt;, &lt;code&gt;cargo&lt;/code&gt;, &lt;code&gt;npm&lt;/code&gt; ou &lt;code&gt;yarn&lt;/code&gt;, esse processo se torna extremamente simples. Contudo, quando se trata de linguagens como C e C++ isso é um pouco diferente, não existe um único meio padronizado de obter bibliotecas externas. Pensando nisso, pensei em escrever esse post mostrando como automatizo a obtenção de bibliotecas de repositórios Git remotos usando o CMake.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Existem soluções criadas pela comunidade como o &lt;code&gt;conan&lt;/code&gt; e o&lt;br&gt;
&lt;code&gt;vcpkg&lt;/code&gt; mas elas carregam outra dependência na máquina e&lt;br&gt;
requerem que a biblioteca que você quer esteja indexada por eles.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  O módulo FetchContent
&lt;/h2&gt;

&lt;p&gt;O CMake é sistema de build que atomatiza a geração de &lt;code&gt;Makefile&lt;/code&gt;s que definem o processo de compilação de um projeto de código-fonte. Ele fornece vários módulos que ajudam na configuração de várias formas. Um desses módulos é o &lt;a href="https://cmake.org/cmake/help/latest/module/FetchContent.html" rel="noopener noreferrer"&gt;FetchContent&lt;/a&gt;, que ajuda a obter conteúdo externo em tempo de configuração, ou seja, quando o CMake está gerando o Makefile.&lt;/p&gt;

&lt;p&gt;É bastante simples de usá-lo, no exemplo abaixo adicionamos o  GoogleTest ao nosso projeto:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cmake"&gt;&lt;code&gt;&lt;span class="nb"&gt;include&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;FetchContent&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;FetchContent_Declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;GoogleTest
    GIT_REPOSITORY https://github.com/google/googletest.git
    GIT_TAG        master
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;FetchContent_MakeAvailable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;GoogleTest&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Depois disso, temos o projeto do GoogleTest bem como suas bibliotecas acessíveis em tempo de configuração, então podemos vincular qualquer executável/biblioteca com o GoogleTest, por exemplo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cmake"&gt;&lt;code&gt;&lt;span class="nb"&gt;add_executable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;mytests &lt;span class="s2"&gt;"test/main.cpp"&lt;/span&gt; &lt;span class="s2"&gt;"test/awesome_test.cpp"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;target_link_libraries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;mytests gtest_main&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Criando uma função CMake
&lt;/h2&gt;

&lt;p&gt;Para automatizar esse processo, eu costumo criar uma função simples que concentra o código que usa o FetchContent, isso torna o script CMake mais legível e fácil de adicionar novas dependências.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cmake"&gt;&lt;code&gt;&lt;span class="nb"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;GET_DEPENDENCY D_NAME D_URL D_TAG&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nb"&gt;message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;CHECK_START &lt;span class="s2"&gt;"Configuring &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;D_NAME&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;FetchContent_Declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;D_NAME&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        GIT_REPOSITORY &lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;D_URL&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        GIT_TAG        &lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;D_TAG&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;FetchContent_MakeAvailable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;D_NAME&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;endfunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Assim consigo usar a funcção &lt;code&gt;get_dependecy&lt;/code&gt; passando o nome, a URL e a versão (ou tag) da biblioteca.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cmake"&gt;&lt;code&gt;&lt;span class="nf"&gt;get_dependency&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;GoogleTest &lt;span class="s2"&gt;"https://github.com/google/googletest.git"&lt;/span&gt; master&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Para adicionar mais dependências...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cmake"&gt;&lt;code&gt;&lt;span class="nf"&gt;get_dependency&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;spdlog &lt;span class="s2"&gt;"https://github.com/gabime/spdlog"&lt;/span&gt; v1.8.5&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;get_dependency&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;CLI11 &lt;span class="s2"&gt;"https://github.com/CLIUtils/CLI11"&lt;/span&gt; v1.9.1&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;get_dependency&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;GoogleTest &lt;span class="s2"&gt;"https://github.com/google/googletest"&lt;/span&gt; master&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Quando uso essa configuração, se torna muito mais fácil adicionar e remover dependências de bibliotecas externas, principalmente por usar bibliotecas abertas com código-fonte no Github. Isso também ajuda em projeto em equipes permitindo que não seja necessário um conjunto de passos complexos para configurar o ambiente de desenvolvimento nas diferentes máquinas dos desenvolvedores. Também traz um benefício para o uso CI (&lt;em&gt;Continous Integration&lt;/em&gt;).&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>beginners</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Different basic ways to undo commits on git</title>
      <dc:creator>Ronaldd Pinho</dc:creator>
      <pubDate>Wed, 18 Mar 2020 23:38:25 +0000</pubDate>
      <link>https://dev.to/ronalddpinho/different-basic-ways-to-undo-commits-on-git-5g7n</link>
      <guid>https://dev.to/ronalddpinho/different-basic-ways-to-undo-commits-on-git-5g7n</guid>
      <description>&lt;p&gt;Git is undoubtedly one of the best version control tools today. However, some features provided by it still are confusing for beginners, especially when it comes to manipulations of the directory tree and the various "status" of files in it. So, I thought about making this post talking about different ways to undoing changes in a git repository in accordance with the situation.&lt;/p&gt;

&lt;h2&gt;
  
  
  The "Three Trees" concept
&lt;/h2&gt;

&lt;p&gt;First of all, it is necessary to understand one of the basic concepts of git called "Three Trees". Basically, the directory tree of a git repository has three states, 1) the &lt;strong&gt;working directory&lt;/strong&gt; which is the current file system you are interacting with directly, 2) the &lt;strong&gt;staging area&lt;/strong&gt; which are the files that were selected for the next commit and 3) the &lt;strong&gt;history of commits&lt;/strong&gt; which is the file system saved in the repository through snapshots.&lt;/p&gt;

&lt;p&gt;This is a base concept for understanding git. For a more detailed explanation, I suggest this &lt;a href="https://www.atlassian.com/git/tutorials/undoing-changes/git-reset" rel="noopener noreferrer"&gt;Bitbucket tutorial&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  When I need to revert changes?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fefkyeghtxcers0b1njsp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fefkyeghtxcers0b1njsp.jpg" alt="Alt Text" width="800" height="581"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Commonly we are faced with situations where we want to reverse changes committed in the project, and these situations can be quite varied. To know what command is more appropriated to undo the changes which you desire, it is important to know well your reason for you want to undo these changes on the project. Come discuss some possibilities.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Your more recent modification has caused an error or a regression of the project, so you need to only undo the recent changes discarding it.&lt;/li&gt;
&lt;li&gt;You found a better way to solve a problem and want to redo something keeping this moment on commit history.&lt;/li&gt;
&lt;li&gt;You committed several files, and you want to undo this commit and do a commit with fewer files.&lt;/li&gt;
&lt;li&gt;Your commit made a snapshot of changes in a set of files, but you want to restore the content of a specific file no removing the commit.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Commands to undo changes
&lt;/h2&gt;

&lt;p&gt;There are several ways to undo changes/commits with git. I tried to consider the most basic methods to make the post accessible to all levels of git users. With three simple commands, it is possible to make the most diverse manipulations in the &lt;strong&gt;"Three Trees"&lt;/strong&gt; of git, these are: &lt;code&gt;git checkout&lt;/code&gt;, &lt;code&gt;git reset&lt;/code&gt; and &lt;code&gt;git revert&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Think on the commits as steps of a ladder, where you can take steps forward and steps backward. Some commands allow you to manipulate the &lt;code&gt;HEAD&lt;/code&gt; (the pointer that set the current structure of directory) to "walk" through the commits, undoing changes on the directory and letting you made new changes from past commits by overwriting the recent commits.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git checkout&lt;/code&gt;:&lt;br&gt;
This command is used to change the &lt;code&gt;HEAD&lt;/code&gt; reference. It is very used to switch for another branch, but also may be used to move the &lt;code&gt;HEAD&lt;/code&gt; to another commit in the same branch.&lt;br&gt;
Using &lt;code&gt;git checkout [commit-hash]&lt;/code&gt;, the &lt;code&gt;HEAD&lt;/code&gt; is pointed to the commit specified by hash. This command also may be used to undo changes not stagged in one specific file using &lt;code&gt;git checkout -- &amp;lt;file&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git reset&lt;/code&gt;:&lt;br&gt;
Using this command is possible made the directory "forget" all changes of the specific commits (using the &lt;code&gt;--hard&lt;/code&gt; flag) or keep the modifications made by the commits on the &lt;em&gt;staged area&lt;/em&gt; (using the &lt;code&gt;--soft&lt;/code&gt; flag). The main difference between &lt;code&gt;git reset&lt;/code&gt; and &lt;code&gt;git checkout&lt;/code&gt; commands are the &lt;code&gt;checkout&lt;/code&gt; move only the &lt;code&gt;HEAD&lt;/code&gt; ref, while the &lt;code&gt;reset&lt;/code&gt; allows moving all working tree - inclusive the current branch - to the specified commit, breaking the commit history continuity.&lt;/p&gt;

&lt;p&gt;A simple example of usage is setting the number of commits for jump backward. Using &lt;code&gt;git reset [commit-hash] HEAD~4&lt;/code&gt;, the state of the working directory is changed to 4 commits backward from the actual (Pointed by HEAD).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git revert&lt;/code&gt;:&lt;br&gt;
Using this command, you reverse the changes of the last commit and create a new commit to save this reversion. So, you will keep the reversed commit in the history of your project.&lt;/p&gt;
&lt;h2&gt;
  
  
  Applying on the different situations
&lt;/h2&gt;

&lt;p&gt;Knowing these commands and their basic operation, we will look for the most appropriate method of undoing changes for each of the situations mentioned above.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Your more recent modification has caused an error or a regression of the project, so you need to only undo the recent changes discarding it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this case, I use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git reset --hard &amp;lt;commit-hash&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;--hard&lt;/code&gt; flag reverses all changes directly on the working directory, thus the modifications are forgotten immediately.&lt;br&gt;
OBS: This command with the &lt;code&gt;--hard&lt;/code&gt; flag is considered &lt;em&gt;dangerous&lt;/em&gt; because you can't recovery your modifications.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You found a better way to solve a problem and want to redo something keeping this moment on commit history.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this case, I use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git revert &amp;lt;commit-hash&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this command a new commit is created on the commit history, allow to identify where the changes were reversed and if I want to recovery these changes, I have them in the commit history.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You committed several files, and you want to undo this commit and do a commit with fewer files. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is interesting for reorganizing the next commits separating the files in several commits. In this case, I use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git reset --soft HEAD~2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this command, the state of the working directory such as the current branch is changed to two steps backward, the current state (step 1) and state of the last commit (step 2), setting the state to one commit before the last commit keeping the more recent changes in the working directory (because the &lt;code&gt;--soft&lt;/code&gt; flag) allowing to commit it as I desire.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You made a commit that made a snapshot of changes in a set of files, but you want to restore the content of a specific file no removing the commit.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this case, I use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git checkout &amp;lt;commit-hash&amp;gt; &amp;lt;file&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this command, the file &lt;code&gt;&amp;lt;file&amp;gt;&lt;/code&gt; will be reversed to its state in the commit &lt;code&gt;&amp;lt;commit-hash&amp;gt;&lt;/code&gt; and will be staged for the next commit automatically&lt;/p&gt;

&lt;h2&gt;
  
  
  Remarks
&lt;/h2&gt;

&lt;p&gt;It is very important to know the situation that led to the need to undo something. Here, simple examples have been shown. &lt;br&gt;
I believe that looking for simple solutions to recurring problems is a good starting point for starting studies of any technology, and with git, it is no different.&lt;/p&gt;

&lt;p&gt;However, there are always more complete and complex ways to work. For an in-depth look at git, I recommend the official git documentation and Atlassian tutorials.&lt;/p&gt;

&lt;p&gt;I hope this post can answer someone's doubts.&lt;br&gt;
Thanks for reading ;)&lt;/p&gt;

&lt;h2&gt;
  
  
  References used
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://git-scm.com/docs" rel="noopener noreferrer"&gt;Git Docs&lt;/a&gt;&lt;br&gt;
&lt;a href="https://git-scm.com/book/en/v2" rel="noopener noreferrer"&gt;Git Book&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.atlassian.com/git/tutorials/undoing-changes/git-reset" rel="noopener noreferrer"&gt;Atlassian Tutorials - Git reset&lt;/a&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
