mirror of
https://github.com/altlinux/admc.git
synced 2025-01-06 21:18:15 +03:00
10c45a0a64
clang-format executable should not be required to build this project.
55 lines
1.6 KiB
CMake
55 lines
1.6 KiB
CMake
# Copyright Tomas Zeman 2019-2020.
|
|
# Distributed under the Boost Software License, Version 1.0.
|
|
# (See accompanying file LICENSE_1_0.txt or copy at
|
|
# http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
function(prefix_clangformat_setup prefix)
|
|
if(NOT CLANGFORMAT_EXECUTABLE)
|
|
set(CLANGFORMAT_EXECUTABLE clang-format)
|
|
endif()
|
|
|
|
if(NOT EXISTS ${CLANGFORMAT_EXECUTABLE})
|
|
find_program(clangformat_executable_tmp ${CLANGFORMAT_EXECUTABLE})
|
|
if(clangformat_executable_tmp)
|
|
set(CLANGFORMAT_EXECUTABLE ${clangformat_executable_tmp})
|
|
unset(clangformat_executable_tmp)
|
|
else()
|
|
message(WARNING "${CLANGFORMAT_EXECUTABLE} executable not found!"
|
|
" ClangFormat targets will not be generated.")
|
|
return()
|
|
endif()
|
|
endif()
|
|
|
|
foreach(clangformat_source ${ARGN})
|
|
get_filename_component(clangformat_source ${clangformat_source} ABSOLUTE)
|
|
list(APPEND clangformat_sources ${clangformat_source})
|
|
endforeach()
|
|
|
|
add_custom_target(${prefix}_clangformat
|
|
COMMAND
|
|
${CLANGFORMAT_EXECUTABLE}
|
|
-style=file
|
|
-i
|
|
${clangformat_sources}
|
|
WORKING_DIRECTORY
|
|
${CMAKE_SOURCE_DIR}
|
|
COMMENT
|
|
"Formatting ${prefix} with ${CLANGFORMAT_EXECUTABLE} ..."
|
|
)
|
|
|
|
if(TARGET clangformat)
|
|
add_dependencies(clangformat ${prefix}_clangformat)
|
|
else()
|
|
add_custom_target(clangformat DEPENDS ${prefix}_clangformat)
|
|
endif()
|
|
endfunction()
|
|
|
|
function(clangformat_setup)
|
|
prefix_clangformat_setup(${PROJECT_NAME} ${ARGN})
|
|
endfunction()
|
|
|
|
function(target_clangformat_setup target)
|
|
get_target_property(target_sources ${target} SOURCES)
|
|
prefix_clangformat_setup(${target} ${target_sources})
|
|
endfunction()
|