Git Product home page Git Product logo

clang-cmake's Introduction

language.badge license.badge

Clang.cmake module

Clang.cmake is a cmake module for clang-format, clang-tidy and include-what-you-use.

Requirements

The module requires CMake 3.0 or higher and some version of clang-format clang-tidy and iwyu installed.

Integration

  1. Obtain the module and add it into your project's CMake modules path:

    • Submodule approach:

      $ git submodule add https://github.com/erezamihud/clang-cmake
      # CMakeLists.txt
      
      list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/clang-cmake/cmake)
  2. Include the modules:

    # CMakeLists.txt
    
    include(ClangFormat)
    include(ClangTidy)
    include(IWYU)
  3. Setup the module:

    # CMakeLists.txt
    
    clangformat_setup(
      src/hello.hpp
      src/hello.cpp
    )
    clangtidy_setup(
      src/hello.hpp
      src/hello.cpp
    )
    iwyu_setup(
      src/hello.hpp
      src/hello.cpp
    )

    or to get the sources from existing targets:

    # CMakeLists.txt
    
    target_clangformat_setup(sometarget)
    target_clangtidy_setup(sometarget)
    target_iwyu_setup(sometarget)

To setup all the things for a specific target: target_setup(sometarget)

Usage

The module add a few custom commands:

  • check - run all of the target with warnings as errors (as you would in ci) Do cmake --build build --target help to look at everything else. To add iwyu mapping files use the variable IWYU_IMP is a list, that should have all of the mapping files
  1. Generate the build system:

    $ cmake -S . -Bbuild
  2. Run things:

    $ cmake --build build --target format

Extra changes worth noting

  • In iwyu python scripts I added code to make sure that when exit code 2 is received the script exit with exit code 0 (code 2 in iwyu states that everything worked well)

Example

See an example here.

clang-cmake's People

Contributors

developerpaul123 avatar erezamihud avatar zemasoft 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.