mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-18 15:49:37 +08:00
added clang format
This commit is contained in:
parent
50df8d3d6d
commit
675b72e44b
5
.clang-format
Normal file
5
.clang-format
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
Language: Cpp
|
||||
BasedOnStyle: Google
|
||||
ColumnLimit: 120
|
||||
SortIncludes: false
|
@ -539,6 +539,23 @@ if(EIGEN_BUILD_BTL)
|
||||
add_subdirectory(bench/btl EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
find_package(CLANG_FORMAT 9 EXACT)
|
||||
if(CLANG_FORMAT_FOUND)
|
||||
set(FORMAT_SOURCES)
|
||||
list(APPEND FORMAT_SUBDIRS blas bench demos "doc" Eigen include lapack scripts share unsupported test failtest)
|
||||
foreach(DIR ${FORMAT_SUBDIRS})
|
||||
set(ABS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${DIR})
|
||||
file(GLOB_RECURSE ${DIR}_SOURCES ${ABS_DIR}/*.cc ${ABS_DIR}/*.h ${ABS_DIR}/*.cpp ${ABS_DIR}/*.hpp ${ABS_DIR}/*.c)
|
||||
list(APPEND FORMAT_SOURCES ${${DIR}_SOURCES})
|
||||
endforeach()
|
||||
file(GLOB FORMAT_SOURCES_WITHOUTENDING LIST_DIRECTORIES false ${CMAKE_CURRENT_SOURCE_DIR}/Eigen/* ${CMAKE_CURRENT_SOURCE_DIR}/Eigen/CXX11/* ${CMAKE_CURRENT_SOURCE_DIR}/unsupported/Eigen/* ${CMAKE_CURRENT_SOURCE_DIR}/unsupported/Eigen/CXX11/*)
|
||||
list(FILTER FORMAT_SOURCES_WITHOUTENDING EXCLUDE REGEX ".*.txt$")
|
||||
list (APPEND FORMAT_SOURCES ${FORMAT_SOURCES_WITHOUTENDING})
|
||||
add_custom_target(format
|
||||
COMMAND ${CLANG_FORMAT_EXECUTABLE} -i -style=file ${FORMAT_SOURCES}
|
||||
DEPENDS ${FORMAT_SOURCES})
|
||||
endif()
|
||||
|
||||
if(NOT WIN32)
|
||||
add_subdirectory(bench/spbench EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
@ -577,6 +594,9 @@ if(PROJECT_IS_TOP_LEVEL)
|
||||
message(STATUS "check | Build and run the unit-tests. Read this page:")
|
||||
message(STATUS " | http://eigen.tuxfamily.org/index.php?title=Tests")
|
||||
endif()
|
||||
if(CLANG_FORMAT_FOUND)
|
||||
message(STATUS "format | Formats the source code according to .clang-format file")
|
||||
endif()
|
||||
message(STATUS "blas | Build BLAS library (not the same thing as Eigen)")
|
||||
message(STATUS "uninstall| Remove files installed by the install target")
|
||||
message(STATUS "---------+--------------------------------------------------------------")
|
||||
|
61
cmake/FindCLANG_FORMAT.cmake
Normal file
61
cmake/FindCLANG_FORMAT.cmake
Normal file
@ -0,0 +1,61 @@
|
||||
|
||||
|
||||
# Find clang-format
|
||||
#
|
||||
# CLANG_FORMAT_EXECUTABLE - Path to clang-format executable
|
||||
# CLANG_FORMAT_FOUND - True if the clang-format executable was found.
|
||||
# CLANG_FORMAT_VERSION - The version of clang-format found
|
||||
#
|
||||
# Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org)
|
||||
#
|
||||
# Licensed under the Mozilla Public License Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.mozilla.org/en-US/MPL/2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
find_program(CLANG_FORMAT_EXECUTABLE
|
||||
NAMES
|
||||
clang-format-9
|
||||
clang-format
|
||||
clang-format-11
|
||||
clang-format-10
|
||||
clang-format-8
|
||||
clang-format-7
|
||||
|
||||
DOC "clang-format executable")
|
||||
mark_as_advanced(CLANG_FORMAT_EXECUTABLE)
|
||||
|
||||
# Extract version from command "clang-format -version"
|
||||
if(CLANG_FORMAT_EXECUTABLE)
|
||||
execute_process(COMMAND ${CLANG_FORMAT_EXECUTABLE} -version
|
||||
OUTPUT_VARIABLE clang_format_version
|
||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
if(clang_format_version MATCHES "^.*clang-format version .*")
|
||||
# clang_format_version sample: "clang-format version 3.9.1-4ubuntu3~16.04.1
|
||||
# (tags/RELEASE_391/rc2)"
|
||||
string(REGEX
|
||||
REPLACE "^.*clang-format version ([.0-9]+).*"
|
||||
"\\1"
|
||||
CLANG_FORMAT_VERSION
|
||||
"${clang_format_version}")
|
||||
# CLANG_FORMAT_VERSION sample: "3.9.1"
|
||||
else()
|
||||
set(CLANG_FORMAT_VERSION 0.0)
|
||||
endif()
|
||||
else()
|
||||
set(CLANG_FORMAT_VERSION 0.0)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
# handle the QUIETLY and REQUIRED arguments and set CLANG_FORMAT_FOUND to TRUE
|
||||
# if all listed variables are TRUE
|
||||
find_package_handle_standard_args(CLANG_FORMAT REQUIRED_VARS CLANG_FORMAT_EXECUTABLE VERSION_VAR CLANG_FORMAT_VERSION)
|
Loading…
x
Reference in New Issue
Block a user