2023-02-14 17:27:50 +04:00
# 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 ( )
2023-02-15 00:47:33 +04:00
message ( WARNING "${CLANGFORMAT_EXECUTABLE} executable not found!"
" C l a n g F o r m a t t a r g e t s w i l l n o t b e g e n e r a t e d . " )
return ( )
2023-02-14 17:27:50 +04:00
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
C O M M A N D
$ { C L A N G F O R M A T _ E X E C U T A B L E }
- s t y l e = f i l e
- i
$ { c l a n g f o r m a t _ s o u r c e s }
W O R K I N G _ D I R E C T O R Y
$ { C M A K E _ S O U R C E _ D I R }
C O M M E N T
" F o r m a t t i n g $ { p r e f i x } w i t h $ { C L A N G F O R M A T _ E X E C U T A B L E } . . . "
)
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 ( )