docs

a slatepencil documentail site

View on GitHub

CMake 3.28.1

# cmake usuage https://cmake.org/cmake/help/latest/manual/cmake.1.html
cd some_software-1.4.2
mkdir build
cd build
# specify a generator
cmake .. -G "MinGW Makefiles"
cmake --build .
# If using an IDE, simply build the `INSTALL` target.
cmake --build . --target install --config Debug
# use `--prefix` argument to overridden CMake Variable `CMAKE_INSTALL_PREFIX`
cmake --install . --prefix "/home/myuser/installdir"

# cmake-gui https://cmake.org/cmake/help/latest/manual/cmake-gui.1.html
cmake-gui [<options>]
cmake-gui [<options>] -B <path-to-build> [-S <path-to-source>]
cmake-gui [<options>] <path-to-source | path-to-existing-build>
cmake-gui [<options>] --browse-manual [<filename>]

CMake Tutorial

Compile a c++ file on MacOS and run it

xcode-select --install
# check your gcc version
g++ -v

Apple clang version 13.1.6 (clang-1316.0.21.2.3)
Target: x86_64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

cd ~
g++ -o ./helloworld ./hello.cpp

CMakePresets.json

{
  "version": 6,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 23,
    "patch": 0
  },
  "include": ["otherThings.json", "moreThings.json"],
  "configurePresets": [
    {
      "name": "default",
      "displayName": "Default Config",
      "description": "Default build using Ninja generator",
      "generator": "Ninja",
      "binaryDir": "${sourceDir}/build/default",
      "cacheVariables": {
        "FIRST_CACHE_VARIABLE": {
          "type": "BOOL",
          "value": "OFF"
        },
        "SECOND_CACHE_VARIABLE": "ON"
      },
      "environment": {
        "MY_ENVIRONMENT_VARIABLE": "Test",
        "PATH": "$env{HOME}/ninja/bin:$penv{PATH}"
      },
      "vendor": {
        "example.com/ExampleIDE/1.0": {
          "autoFormat": true
        }
      }
    },
    {
      "name": "ninja-multi",
      "inherits": "default",
      "displayName": "Ninja Multi-Config",
      "description": "Default build using Ninja Multi-Config generator",
      "generator": "Ninja Multi-Config"
    },
    {
      "name": "windows-only",
      "inherits": "default",
      "displayName": "Windows-only configuration",
      "description": "This build is only available on Windows",
      "condition": {
        "type": "equals",
        "lhs": "${hostSystemName}",
        "rhs": "Windows"
      }
    }
  ],
  "buildPresets": [
    {
      "name": "default",
      "configurePreset": "default"
    }
  ],
  "testPresets": [
    {
      "name": "default",
      "configurePreset": "default",
      "output": { "outputOnFailure": true },
      "execution": { "noTestsAction": "error", "stopOnFailure": true }
    }
  ],
  "packagePresets": [
    {
      "name": "default",
      "configurePreset": "default",
      "generators": ["TGZ"]
    }
  ],
  "workflowPresets": [
    {
      "name": "default",
      "steps": [
        {
          "type": "configure",
          "name": "default"
        },
        {
          "type": "build",
          "name": "default"
        },
        {
          "type": "test",
          "name": "default"
        },
        {
          "type": "package",
          "name": "default"
        }
      ]
    }
  ],
  "vendor": {
    "example.com/ExampleIDE/1.0": {
      "autoFormat": false
    }
  }
}

cmake-properties