Git Product home page Git Product logo

clang-mute's Introduction

clang-mute

Tool to comment out all function (and method) implementations in specific files.

Also tutorial for clang's libtooling for source to source transformation.

echo 'void f(){ int x=1; }' > main.cpp
clang-mute main.cpp 
cat main.cpp
void f(){
#if 0
 int x=1; 
#endif
}

Use

clang-mute target1.cpp [target2.cpp] [-- -Iincludepath -Ddefinition]

To use on real project, for example qt application, you need to create compilation database or compile flags file to provide all necessary includepaths to the tool.

Sample session

git clone https://github.com/mugiseyebrows/cmake-qt-sample.git
cd cmake-qt-sample
mkdir build
cd build
# to fix file not found errors add missing includepaths to CMAKE_CXX_FLAGS variable
cmake -G Ninja -D CMAKE_CXX_FLAGS="-I/usr/lib/gcc/x86_64-linux-gnu/11/include" ..
# to generate ui_*.h files compile the app
ninja app
cmake . -DCMAKE_EXPORT_COMPILE_COMMANDS=1
clang-mute ../mainwindow.cpp

As alternative to compilation database you can specify includepaths and other compiler flags after --

clang-mute ../mainwindow.cpp -- -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -I/home/overloop/cmake-qt-sample/build -I/home/overloop/cmake-qt-sample -I/home/overloop/cmake-qt-sample/build/app_autogen/include -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -I/usr/lib/gcc/x86_64-linux-gnu/11/include -fPIC

You can store flags in compile_flags.txt file, one per line.

echo -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -I/home/overloop/cmake-qt-sample/build -I/home/overloop/cmake-qt-sample -I/home/overloop/cmake-qt-sample/build/app_autogen/include -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -I/usr/lib/gcc/x86_64-linux-gnu/11/include -fPIC | tr ' ' '\n' > compile_flags.txt
clang-mute ../mainwindow.cpp

Build

To compile you need llvm-project distribution which you can git clone from repository or curl from llvm-project releases.

See also: build.sh file and build.bat file.

Ubuntu

sudo apt install build-essential cmake ninja-build git
git clone --depth 1 https://github.com/llvm/llvm-project.git
cd llvm-project/clang/tools
git clone https://github.com/mugiseyebrows/clang-mute.git
echo "add_clang_subdirectory(clang-mute)" >> CMakeLists.txt
cd ../..
mkdir build
cd build
cmake -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release -G Ninja ../llvm
cmake --build . --target clang-mute
sudo cp bin/clang-mute /usr/bin

Windows

(Common steps for MinGW and Visual Studio)

  • Install ninja
  • Add ninja to %PATH%
  • Clone sources
git clone --depth 1 https://github.com/llvm/llvm-project.git
cd llvm-project\clang\tools
git clone https://github.com/mugiseyebrows/clang-mute.git
echo add_clang_subdirectory(clang-mute) >> CMakeLists.txt
cd ..\..
mkdir build
cd build

Visual Studio

  • Use visual studio command prompt or call vcvars64.bat
  • Build using cmake
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
cmake -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release -G Ninja ../llvm
cmake --build . --target clang-mute

MinGW

  • Add compiler to %PATH%
  • Build using cmake
cmake -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release -G Ninja -D CMAKE_C_COMPILER=gcc -D CMAKE_CXX_COMPILER=g++ ../llvm
cmake --build . --target clang-mute

See also

post on medium

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.