Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
0eff135
Start implementation of generic dependency system
Apr 16, 2019
8e2c79a
Modules for rtcm and sbp
Apr 16, 2019
46f6128
Fix up generic dependency code, new modules
Apr 16, 2019
c818e51
Add googletest module
Apr 29, 2019
90e4830
Allow source to be picked up from multiple places
Apr 29, 2019
ecc36bd
Move submodules back vendored->third_party
Apr 30, 2019
ebd7dd3
Import some more common modules, capitalise package names
May 1, 2019
a319b52
Fix librtcm source path
May 1, 2019
95bf587
Mark gflags as system, add gnss-converters
May 1, 2019
d40e2d2
Add protobuf
May 1, 2019
6a88f07
Alter gflags alias target
May 1, 2019
e166350
Fix find rtcm
May 6, 2019
8aa3820
More modules
May 6, 2019
5c8ce59
Only include header files from eigen
May 9, 2019
1fcb326
Recode Optional's header files as system
May 9, 2019
524fde4
Start standard cmake options module
May 13, 2019
402b75c
Move FindCheck to common repo
May 13, 2019
02ee7a4
Turn swift options in to a function
May 14, 2019
455bad0
Add handler for gtest
May 14, 2019
82adde8
Allow empty test packages argument
May 14, 2019
18bbbb1
Remove some debug messages
May 14, 2019
6851200
Add RapidCheck handler
May 14, 2019
8f25513
Allow a package to specify what options it supports
May 14, 2019
ab73780
Rework enable/disable logic
May 15, 2019
43c93c7
Correct build_test_libs name
May 15, 2019
ba7bebf
Only check test dependencies if we are actually building something
May 15, 2019
b6c0025
Enable correct test components
May 15, 2019
89136bb
Display message when test components are disabled
May 15, 2019
b8b889f
Disable test libs when deps not available
May 17, 2019
de02449
Add more test package handlers
May 17, 2019
582daa9
Add some documentation headers
May 21, 2019
f90a8b5
Correct has examples test
May 21, 2019
795e726
Generalise system includes
May 22, 2019
ed6f8dd
Don't use generalised version for gflags
May 22, 2019
f1a6804
libsettings cmake file is at the top level
woodfell May 22, 2019
1401abe
Tidy up GenericFindDependency, add comments
May 23, 2019
9f13b0e
Change function/macro parameters to use upper case
May 23, 2019
d22d5e4
Permit test libs dependencies to be specified separately
May 24, 2019
54f7e95
Check tests and test libs deps separately
May 27, 2019
c1a4c94
Add initial clang format module
May 24, 2019
01bac3e
Make clang-format support optional
May 24, 2019
dcdfedd
Fix up clang format module, create clang-format-all alias for top lev…
May 26, 2019
1b5bde3
Start clang tidy module
May 27, 2019
3c8d57f
Enable command
May 27, 2019
12b121b
Remove debug message
May 27, 2019
4084d49
Pass argument to custom format/tidy script
May 27, 2019
f2b5657
Change clang-tidy interface
May 28, 2019
ec01202
Mark as system includes
May 28, 2019
876e6cd
Add basic ccache module
May 28, 2019
327931a
Use git commands to filter file list, add diff target
May 28, 2019
3059860
Add namespaced targets
May 28, 2019
e43d46d
Add diff clang format target
May 29, 2019
af61d02
Create extra clang tidy targets using custom script
May 29, 2019
007f9a4
Break up to clarify, add documentation
May 29, 2019
145a240
More docs
May 29, 2019
c36455f
Remove debug messages
May 29, 2019
70705e1
Make some errors fatal
May 31, 2019
f64a41d
Add global clang tidy/format options
May 31, 2019
46fdf00
Remove unreachable code
May 31, 2019
6c48e2f
Corrent clang format default enable logic
May 31, 2019
3c390e5
Revert 'make some errors fatal'
May 31, 2019
c60d105
Add REQUIRED option to clang tools modules
Jun 2, 2019
1987723
SWIFT_ENABLE_CLANG_TIDY -> ENABLE_CLANG_TIDY
Jun 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CCache.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
option(SWIFT_ENABLE_CCACHE "Use ccache to speed up compilation process" OFF)

if(SWIFT_ENABLE_CCACHE)
find_program(CCACHE_PATH ccache)
if(CCACHE_PATH)
message(STATUS "Using ccache at ${CCACHE_PATH}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PATH})
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_PATH})
else()
message(STATUS "Could not find ccache")
endif()
endif()
208 changes: 208 additions & 0 deletions ClangFormat.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
#
# A module to create custom targets to format source and header files in a git repo
#
# The function swift_setup_clang_format will create several targets which will
# use clang-format to format source code according to a configuration file. 2 types
# of targets will be created, one for formatting all files in the repository and the
# other for formatting only the files which differ from master. The list of files to
# format is generated by git itself.
#
# The created targets have the names
#
# - clang-format-all-${PROJECT_NAME} - formats all files in the repo
# - clang-format-diff-${PROJECT_NAME} - formats only changed files
#
# In addition if the current project is at the top level of the working tree 2 more
# targets will be created
#
# - clang-format-all
# - clang-format-diff
#
# which are aliases for the namespaced targets. If every project in a working
# directory uses this module to create auto-formatting targets there will never be
# a name clash
#
# The parameter SCRIPT can be used to specify a custom formatting command instead
# of calling clang-format directly. This should be executable and will be called
# with a single argument of either 'all' or 'diff' according to the target
#
# clang-format-all-${PROJECT_NAME} will run `<script> all`
# clang-format-diff-${PROJECT_NAME} will run `<script> diff`
#
# If a script is not specified explicitly this function will first search for an
# appropriate script. It must live in ${CMAKE_CURRENT_SOURCE_DIR}/scripts and be
# named either clang-format.sh or clang-format.bash. If found the custom targets
# will run this script with the same parameters as above
#
# If not script is found or specified default formatting commands will be run.
# This function will find an appropriate clang-format program and run it against
# the file list provided by git.
#
# The list of program names can be overriden by passing the CLANG_FORMAT_NAMES
# parameter with a list of names to search for
#
# All commands will be run from the source directory which calls this function.
# It is highly recommended to include this module and call swift_setup_clang_format
# from the top level CMakeLists.txt, using in a subdirectory may not work as
# intended.
#
# In addition this function sets up a cmake option which can be used to control
# whether the targets are created either on the command line or by a super project.
# The option has the name
#
# ${PROJECT_NAME}_ENABLE_CLANG_FORMAT
#
# The default value is ON for top level projects, and OFF for any others.
#
# Running
#
# cmake -D<project>_ENABLE_CLANG_FORMAT=OFF ..
#
# will explicitly disable these targets from the command line at configure time
#

# Helper function to actually create the targets, not to be used outside this file
function(create_targets)
set(argOption "")
set(argSingle "TOP_LEVEL")
set(argMulti "ALL_COMMAND" "DIFF_COMMAND")

cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN})

add_custom_target(clang-format-all-${PROJECT_NAME}
COMMAND ${x_ALL_COMMAND}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_custom_target(clang-format-diff-${PROJECT_NAME}
COMMAND ${x_DIFF_COMMAND}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

# Top level projects will create the targets clang-format-all and
# clang-format-diff with the same commands as the namespaced targets
# above. However, cmake doesn't support aliases for non-library targets
# so we have to create them fully.
if(x_TOP_LEVEL)
add_custom_target(clang-format-all
COMMAND ${x_ALL_COMMAND}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_custom_target(clang-format-diff
COMMAND ${x_DIFF_COMMAND}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endif()
endfunction()

macro(early_exit level msg)
message(${level} "${msg}")
if(x_REQUIRED)
message(FATAL_ERROR "clang-format support is REQUIRED for ${PROJECT_NAME}")
endif()
return()
endmacro()

# External function to create clang-format-* targets. Call according to the
# documentation in the file header.
function(swift_setup_clang_format)
set(argOption "REQUIRED")
set(argSingle "SCRIPT")
set(argMulti "CLANG_FORMAT_NAMES")

cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN})

if(x_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unparsed arguments ${x_UNPARSED_ARGUMENTS}")
endif()

# Global clang-format enable option, influences the default project specific enable option
option(ENABLE_CLANG_FORMAT "Enable auto-formatting of code using clang-format globally" ON)
if(NOT ENABLE_CLANG_FORMAT)
early_exit(STATUS "auto-formatting is disabled globally")
endif()

if(${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME})
# This is the top level project, ie the CMakeLists.txt which cmake was run
# on directly, not a submodule/subproject. We can do some special things now.
# The option to enable clang formatting will be enabled by default only for
# top level projects. Also the top level project will create an alias target
# clang-format-all against the project specific target
set(top_level_project ON)
else()
set(top_level_project OFF)
endif()

# Create a cmake option to enable formatting of this specific project
option(${PROJECT_NAME}_ENABLE_CLANG_FORMAT "Enable auto-formatting of code using clang-format for project ${PROJECT_NAME}" ${top_level_project})

if(NOT ${PROJECT_NAME}_ENABLE_CLANG_FORMAT)
# Explicitly disabled
early_exit(STATUS "${PROJECT_NAME} clang-format support is DISABLED")
endif()

# If a custom script has been specified always use that by default
if(x_SCRIPT)
if(EXISTS ${x_SCRIPT})
message(STATUS "Initialising clang format targets for ${PROJECT_NAME} using existing script in ${x_SCRIPT}")
create_targets(
TOP_LEVEL ${top_level_project}
ALL_COMMAND ${x_SCRIPT} all
DIFF_COMMAND ${x_SCRIPT} diff
)
else()
message(FATAL_ERROR "Specified clang-format script ${x_SCRIPT} doesn't exist")
endif()
return()
endif()

# Search for a custom formatting script in some reasonable places
set(custom_scripts "${CMAKE_CURRENT_SOURCE_DIR}/scripts/clang-format.sh" "${CMAKE_CURRENT_SOURCE_DIR}/scripts/clang-format.bash")

foreach(script ${custom_scripts})
if(EXISTS ${script})
# Found a custom formatting script
message(STATUS "Initialising clang format target for ${PROJECT_NAME} using existing script in ${script}")
create_targets(
TOP_LEVEL ${top_level_project}
ALL_COMMAND ${script} all
DIFF_COMMAND ${script} diff
)
return()
endif()
endforeach()

# Did not find any script to use, generate a default formatting command to process all code files in the repo

# First try to find clang-format
if(NOT x_CLANG_FORMAT_NAMES)
set(x_CLANG_FORMAT_NAMES
clang-format60 clang-format-6.0
clang-format40 clang-format-4.0
clang-format39 clang-format-3.9
clang-format38 clang-format-3.8
clang-format37 clang-format-3.7
clang-format36 clang-format-3.6
clang-format35 clang-format-3.5
clang-format34 clang-format-3.4
clang-format
)
endif()
find_program(CLANG_FORMAT NAMES ${x_CLANG_FORMAT_NAMES})

if("${CLANG_FORMAT}" STREQUAL "CLANG_FORMAT-NOTFOUND")
# clang-format not found, can't continue
early_exit(WARNING "Could not find appropriate clang-format, targets disabled")
endif()

message(STATUS "Using ${CLANG_FORMAT}")
set(${PROJECT_NAME}_CLANG_FORMAT ${CLANG_FORMAT} CACHE STRING "Absolute path to clang-format for ${PROJECT_NAME}")

# Format all source and header files in the repo, use a git command to build the file list
set(default_patterns "*.[ch]" "*.cpp" "*.cc" "*.hpp")

create_targets(
TOP_LEVEL ${top_level_project}
ALL_COMMAND git ls-files ${default_patterns} | xargs ${${PROJECT_NAME}_CLANG_FORMAT} -i
DIFF_COMMAND git diff --diff-filter=ACMRTUXB --name-only master -- ${default_patterns} | xargs ${${PROJECT_NAME}_CLANG_FORMAT} -i
)
endfunction()
Loading