Giter VIP home page Giter VIP logo

cmake-practice's Introduction

Introduction

CMake is a build system for projects build with C or C++ programmig language. There are many build system for C/C++ but CMake is the most popular one. This repo will contain my practice for building project using C/C++. I will mainly use C++ as a programming language for this repo but almost everything is applicable for C language too.

How to build this project

Make sure your system has cmake installed. To check whether your system has cmake installed properly you can the command below

cmake --version

Then make a build directory for building the project and compiling it using the below command

mkdir build
cd build
cmake ..

Enabling Options

CMake allow certain feature of project depending on the option passed during build process. This can be activated using the below approach.

cmake -DOPTION_NAME=ON ..

The project will be built using the given feature enabled. Options needed to be explicitly declared in CMakeLists file for building.

Selecting Generator

We can use microsoft or gcc for generating a project from command line using cmake.

cmake -G"Visual Studio 16 2019" //Microsoft Toolchain
cmake -G "Unix Makefiles" . //Unix Makefile

Warning

Compiler warnings are messages produced by a compiler regarding program code fragments to be considered by the developer, as they may contain errors. Unlike compilation errors, warnings don’t interrupt the compilation process. A warning could result because of the use of obsolete features; or the use of nonstandard features of C++.

  • GCC and Clang Options(Most Common ones)
-Wall -Wextra -Wpedantic
  • MSVC
/W4
/permissive

There a lot of warning that can be found in GNU Warning options and MSVC pages.

Sanitizer

Sanitizers that find memory bugs in programs written in memory-unsafe languages. Memory-checking tools are for memory-unsafe languages such as C and C++, not for Java, Python, and similar memory-safe languages. In memory-unsafe languages, it is easy to mistakenly write past the end of a memory buffer or read memory after it has been freed. Programs containing such bugs might run flawlessly most of the time and crash only very rarely. Catching these bugs is difficult, which is why we need tools for that purpose.

  • GCC and Clang Option
-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment

Dependency Management

There are multiple ways to manage dependency in C/C++ as their standard doesn't define standard for managing dependancy.

In this template I will use cpm as a package manager.

Do not use multiple dependency manager for one project. As this will lead to more problem in run.

Adding CPM

From cpm repo download cpm.cmake and add it to project directory. Then specify the directory using include() function. For more detail read cpm repository.

Issue

For vscode clangd LSP(Language Server Protocol) from LLVM directory doesn't bootup and original issue for this has no solution currently. But clangd plugin from Visual Studio Code Marketplace works perfectly. This issue is only for Windows. I didn't check Linux.

cmake-practice's People

Contributors

rushad01 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.