Coder Social home page Coder Social logo

cmake-tutorial's Introduction

CMake Tutorial

Simple tutorial for CMake and C++.

Getting Started

Following this tutorial here: CMake Tutorial - CMake 3.25.1 Documentation

  1. Create a new folder and navigate inside: my-cpp-project
  2. Create a new file called main.cpp and add a simple Hello World script:
#include <iostream>
using namespace std;

int main() {
    cout << "Hello World!";
    return 0;
}
  1. Create a new file called CMakeLists.txt:
# Set a minimum version of CMake
cmake_minimum_required(VERSION 3.10)

# Name your project (no spaces)
# Version is optional
project(MyCppProject VERSION 1.0)

# Create an executable for your project
add_executable(MyCppProject main.cpp)
  1. Create a build folder and navigate inside.
  2. Generate a native build system for the project: cmake ../
    • This will default to whatever build system you have installed, like Visual Studio.
    • You could also run cmake ../ -A x64 and get a Visual Studio solution
  3. Now you can run the build: cmake --build .
    • You could also open the .sln file and run Build Solution for the same result.
  4. Your .exe should be available in build\Debug\
  5. Ideally you should make a .gitignore and add build to it.

Set C++ version

Sets version to C++ 20:

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

cmake-tutorial's People

Contributors

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