diff --git a/cmake/ClangFormat.cmake b/cmake/ClangFormat.cmake index 6abde7f..d1a76c8 100644 --- a/cmake/ClangFormat.cmake +++ b/cmake/ClangFormat.cmake @@ -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() diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt new file mode 100644 index 0000000..f04f987 --- /dev/null +++ b/example/CMakeLists.txt @@ -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}) + diff --git a/example/main.cpp b/example/main.cpp new file mode 100644 index 0000000..147d50d --- /dev/null +++ b/example/main.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + std::cout << "Hello World" << std::endl; + return 0; +}