1
0
mirror of https://github.com/altlinux/admc.git synced 2024-10-26 08:55:21 +03:00

Add 'clangformat' target to CMake

... to simplify use of clang-format for formatting
the sources, using ClangFormat.cmake module from
https://github.com/zemasoft/clangformat-cmake .
This commit is contained in:
Ivan A. Melnikov 2023-02-14 17:27:50 +04:00
parent e359cdfa1f
commit 0a60e0f422
5 changed files with 71 additions and 1 deletions

View File

@ -47,6 +47,7 @@ set(LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH})
enable_testing()
include(GNUInstallDirs)
include(ClangFormat)
option(ADMC_BUILD_DEB "Build the deb package of ADMC." OFF)

View File

@ -19,6 +19,13 @@ $ make -j12
If the build fails, check build output for missing dependencies.
You can also format the sources by building `clangformat`
target after `cmake` is run, for example:
```
make -C build clangformat
```
# Usage:
This app requires a working Active Directory domain and for the client machine to be connected and logged into the domain. You can find articles about these topics on [ALTLinux wiki](https://www.altlinux.org/%D0%94%D0%BE%D0%BC%D0%B5%D0%BD).

52
cmake/ClangFormat.cmake Normal file
View File

@ -0,0 +1,52 @@
# 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(FATAL_ERROR "ClangFormat: ${CLANGFORMAT_EXECUTABLE} not found! Aborting")
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()

View File

@ -22,7 +22,7 @@ configure_file("adldap_config.h.in" "adldap_config.h")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
add_library(adldap SHARED
set(ADLDAP_SOURCES
ad_interface.cpp
ad_config.cpp
ad_utils.cpp
@ -31,7 +31,11 @@ add_library(adldap SHARED
ad_filter.cpp
ad_security.cpp
gplink.cpp
)
prefix_clangformat_setup(adldap ${ADLDAP_SOURCES})
set(ADLDAP_SAMBA_SOURCES
samba/gp_manage.c
samba/ndr_security.c
samba/dom_sid.c
@ -39,7 +43,12 @@ add_library(adldap SHARED
samba/ndr_misc.c
samba/libsmb_xattr.c
samba/security_descriptor.c
)
add_library(adldap SHARED
${ADLDAP_SOURCES}
${ADLDAP_SAMBA_SOURCES}
adldap.qrc
)

View File

@ -192,6 +192,7 @@ add_executable(admc
main.cpp
${ADMC_SOURCES}
)
target_clangformat_setup(admc)
# NOTE: build admc as library to streamline building tests.
# Tests just link to this lib and use all of admc's code.