-
Notifications
You must be signed in to change notification settings - Fork 0
Create common cmake modules for dependency resolution [ESD-1245] #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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
8e2c79a
Modules for rtcm and sbp
46f6128
Fix up generic dependency code, new modules
c818e51
Add googletest module
90e4830
Allow source to be picked up from multiple places
ecc36bd
Move submodules back vendored->third_party
ebd7dd3
Import some more common modules, capitalise package names
a319b52
Fix librtcm source path
95bf587
Mark gflags as system, add gnss-converters
d40e2d2
Add protobuf
6a88f07
Alter gflags alias target
e166350
Fix find rtcm
8aa3820
More modules
5c8ce59
Only include header files from eigen
1fcb326
Recode Optional's header files as system
524fde4
Start standard cmake options module
402b75c
Move FindCheck to common repo
02ee7a4
Turn swift options in to a function
455bad0
Add handler for gtest
82adde8
Allow empty test packages argument
18bbbb1
Remove some debug messages
6851200
Add RapidCheck handler
8f25513
Allow a package to specify what options it supports
ab73780
Rework enable/disable logic
43c93c7
Correct build_test_libs name
ba7bebf
Only check test dependencies if we are actually building something
b6c0025
Enable correct test components
89136bb
Display message when test components are disabled
b8b889f
Disable test libs when deps not available
de02449
Add more test package handlers
582daa9
Add some documentation headers
f90a8b5
Correct has examples test
795e726
Generalise system includes
ed6f8dd
Don't use generalised version for gflags
f1a6804
libsettings cmake file is at the top level
woodfell 1401abe
Tidy up GenericFindDependency, add comments
9f13b0e
Change function/macro parameters to use upper case
d22d5e4
Permit test libs dependencies to be specified separately
54f7e95
Check tests and test libs deps separately
c1a4c94
Add initial clang format module
01bac3e
Make clang-format support optional
dcdfedd
Fix up clang format module, create clang-format-all alias for top lev…
1b5bde3
Start clang tidy module
3c8d57f
Enable command
12b121b
Remove debug message
4084d49
Pass argument to custom format/tidy script
f2b5657
Change clang-tidy interface
ec01202
Mark as system includes
876e6cd
Add basic ccache module
327931a
Use git commands to filter file list, add diff target
3059860
Add namespaced targets
e43d46d
Add diff clang format target
af61d02
Create extra clang tidy targets using custom script
007f9a4
Break up to clarify, add documentation
145a240
More docs
c36455f
Remove debug messages
70705e1
Make some errors fatal
f64a41d
Add global clang tidy/format options
46fdf00
Remove unreachable code
6c48e2f
Corrent clang format default enable logic
3c390e5
Revert 'make some errors fatal'
c60d105
Add REQUIRED option to clang tools modules
1987723
SWIFT_ENABLE_CLANG_TIDY -> ENABLE_CLANG_TIDY
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
benjaminaltieri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.