Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't abort if clang-format cannot be found #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmake/ClangFormat.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ function(prefix_clangformat_setup prefix)
set(CLANGFORMAT_EXECUTABLE ${clangformat_executable_tmp})
unset(clangformat_executable_tmp)
else()
message(FATAL_ERROR "ClangFormat: ${CLANGFORMAT_EXECUTABLE} not found! Aborting")
if (CLANGFORMAT_FORCED)
message(FATAL_ERROR "ClangFormat: ${CLANGFORMAT_EXECUTABLE} not found! Aborted.")
else()
message(STATUS "ClangFormat: ${CLANGFORMAT_EXECUTABLE} not found! clangformat target will not be available.")
return()
endif()
endif()
endif()

Expand Down
12 changes: 12 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.10)
project(example-clang-format-cmake)

include(../cmake/ClangFormat.cmake)

add_Executable(${PROJECT_NAME} main.cpp)

# Set the following to ON to abort CMake's configuration process if clang-format could not be found.
# On default, it will just emit a status message and continue without creating the clangformat target.
set(CLANGFORMAT_FORCED OFF)
target_clangformat_setup(${PROJECT_NAME})

6 changes: 6 additions & 0 deletions example/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>

int main() {
std::cout << "Hello World" << std::endl;
return 0;
}