Skip to content

Commit 16b9cd5

Browse files
authored
Add code formatting (#17)
* add style config and enforce formatting * remove leading underscore from var name
1 parent bb6a707 commit 16b9cd5

13 files changed

Lines changed: 188 additions & 68 deletions

File tree

.clang-format

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
BasedOnStyle: Google
3+
AccessModifierOffset: '-2'
4+
AlignTrailingComments: 'true'
5+
AllowAllParametersOfDeclarationOnNextLine: 'false'
6+
AlwaysBreakTemplateDeclarations: 'No'
7+
BreakBeforeBraces: Attach
8+
ColumnLimit: '100'
9+
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
10+
IncludeBlocks: Regroup
11+
IndentPPDirectives: AfterHash
12+
IndentWidth: '2'
13+
NamespaceIndentation: All
14+
BreakBeforeBinaryOperators: All
15+
BreakBeforeTernaryOperators: 'true'
16+
...

.cmake-format

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
format:
2+
tab_size: 2
3+
line_width: 100
4+
dangle_parens: true
5+
6+
parse:
7+
additional_commands:
8+
cpmaddpackage:
9+
pargs:
10+
nargs: '*'
11+
flags: []
12+
spelling: CPMAddPackage
13+
kwargs: &cpmaddpackagekwargs
14+
NAME: 1
15+
FORCE: 1
16+
VERSION: 1
17+
GIT_TAG: 1
18+
DOWNLOAD_ONLY: 1
19+
GITHUB_REPOSITORY: 1
20+
GITLAB_REPOSITORY: 1
21+
GIT_REPOSITORY: 1
22+
SVN_REPOSITORY: 1
23+
SVN_REVISION: 1
24+
SOURCE_DIR: 1
25+
DOWNLOAD_COMMAND: 1
26+
FIND_PACKAGE_ARGUMENTS: 1
27+
NO_CACHE: 1
28+
GIT_SHALLOW: 1
29+
URL: 1
30+
URL_HASH: 1
31+
URL_MD5: 1
32+
DOWNLOAD_NAME: 1
33+
DOWNLOAD_NO_EXTRACT: 1
34+
HTTP_USERNAME: 1
35+
HTTP_PASSWORD: 1
36+
OPTIONS: +
37+
cpmfindpackage:
38+
pargs:
39+
nargs: '*'
40+
flags: []
41+
spelling: CPMFindPackage
42+
kwargs: *cpmaddpackagekwargs
43+
packageproject:
44+
pargs:
45+
nargs: '*'
46+
flags: []
47+
spelling: packageProject
48+
kwargs:
49+
NAME: 1
50+
VERSION: 1
51+
NAMESPACE: 1
52+
INCLUDE_DIR: 1
53+
INCLUDE_DESTINATION: 1
54+
BINARY_DIR: 1
55+
COMPATIBILITY: 1
56+
VERSION_HEADER: 1
57+
DEPENDENCIES: +

.github/workflows/style.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Style
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
style:
13+
14+
runs-on: macos-latest
15+
16+
steps:
17+
- uses: actions/checkout@v1
18+
19+
- name: Install format dependencies
20+
run: |
21+
brew install clang-format
22+
pip3 install cmake_format==0.6.11 pyyaml
23+
24+
- name: configure
25+
run: cmake -Stest/style -Bbuild/style
26+
27+
- name: check style
28+
run: cmake --build build/style --target check-format

CMakeLists.txt

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,32 @@
1-
2-
set(
3-
PACKAGE_PROJECT_ROOT_PATH
4-
"${CMAKE_CURRENT_LIST_DIR}"
5-
CACHE INTERNAL
6-
"The path to the PackageProject directory"
1+
set(PACKAGE_PROJECT_ROOT_PATH
2+
"${CMAKE_CURRENT_LIST_DIR}"
3+
CACHE INTERNAL "The path to the PackageProject directory"
74
)
85

96
function(packageProject)
107
include(CMakePackageConfigHelpers)
118
include(GNUInstallDirs)
129

1310
cmake_parse_arguments(
14-
PROJECT
15-
"NO_VERSION_SUFFIX"
11+
PROJECT "NO_VERSION_SUFFIX"
1612
"NAME;VERSION;INCLUDE_DIR;INCLUDE_DESTINATION;BINARY_DIR;COMPATIBILITY;VERSION_HEADER;NAMESPACE"
17-
"DEPENDENCIES"
18-
${ARGN}
13+
"DEPENDENCIES" ${ARGN}
1914
)
2015

2116
if(DEFINED PROJECT_NO_VERSION_SUFFIX)
22-
unset(_PROJECT_VERSION_SUFFIX)
17+
unset(PROJECT_VERSION_SUFFIX)
2318
else()
24-
set(_PROJECT_VERSION_SUFFIX -${PROJECT_VERSION})
19+
set(PROJECT_VERSION_SUFFIX -${PROJECT_VERSION})
2520
endif()
2621

2722
# handle default arguments
2823
if(NOT DEFINED PROJECT_COMPATIBILITY)
2924
set(PROJECT_COMPATIBILITY AnyNewerVersion)
3025
endif()
3126

32-
# we wanto to automatically add :: to our namespace, so only append if a namespace was given in the first place
33-
# we also provide an alias to ensure that local and installed versions have the same name
27+
# we wanto to automatically add :: to our namespace, so only append if a namespace was given in
28+
# the first place we also provide an alias to ensure that local and installed versions have the
29+
# same name
3430
if(DEFINED PROJECT_NAMESPACE)
3531
set(PROJECT_NAMESPACE ${PROJECT_NAMESPACE}::)
3632
add_library(${PROJECT_NAMESPACE}${PROJECT_NAME} ALIAS ${PROJECT_NAME})
@@ -41,8 +37,7 @@ function(packageProject)
4137
string(TOUPPER ${PROJECT_NAME} UPPERCASE_PROJECT_NAME)
4238
configure_file(
4339
${PACKAGE_PROJECT_ROOT_PATH}/version.h.in
44-
${PROJECT_VERSION_INCLUDE_DIR}/${PROJECT_VERSION_HEADER}
45-
@ONLY
40+
${PROJECT_VERSION_INCLUDE_DIR}/${PROJECT_VERSION_HEADER} @ONLY
4641
)
4742

4843
get_target_property(target_type ${PROJECT_NAME} TYPE)
@@ -51,11 +46,10 @@ function(packageProject)
5146
else()
5247
set(VISIBILITY PUBLIC)
5348
endif()
54-
target_include_directories(${PROJECT_NAME} ${VISIBILITY} "$<BUILD_INTERFACE:${PROJECT_VERSION_INCLUDE_DIR}>")
55-
install(
56-
DIRECTORY ${PROJECT_VERSION_INCLUDE_DIR}/
57-
DESTINATION ${PROJECT_INCLUDE_DESTINATION}
49+
target_include_directories(
50+
${PROJECT_NAME} ${VISIBILITY} "$<BUILD_INTERFACE:${PROJECT_VERSION_INCLUDE_DIR}>"
5851
)
52+
install(DIRECTORY ${PROJECT_VERSION_INCLUDE_DIR}/ DESTINATION ${PROJECT_INCLUDE_DESTINATION})
5953
endif()
6054

6155
write_basic_package_version_file(
@@ -67,37 +61,37 @@ function(packageProject)
6761
install(
6862
TARGETS ${PROJECT_NAME}
6963
EXPORT ${PROJECT_NAME}Targets
70-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}${_PROJECT_VERSION_SUFFIX} COMPONENT Runtime
71-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}${_PROJECT_VERSION_SUFFIX} COMPONENT Development
72-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/${PROJECT_NAME}${_PROJECT_VERSION_SUFFIX} COMPONENT Runtime
73-
BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}/${PROJECT_NAME}${_PROJECT_VERSION_SUFFIX} COMPONENT Runtime
64+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX}
65+
COMPONENT Runtime
66+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX}
67+
COMPONENT Development
68+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX}
69+
COMPONENT Runtime
70+
BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX}
71+
COMPONENT Runtime
7472
PUBLIC_HEADER DESTINATION ${PROJECT_INCLUDE_DESTINATION} COMPONENT Development
7573
)
7674

7775
configure_package_config_file(
78-
${PACKAGE_PROJECT_ROOT_PATH}/Config.cmake.in
79-
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
80-
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}${_PROJECT_VERSION_SUFFIX}
76+
${PACKAGE_PROJECT_ROOT_PATH}/Config.cmake.in "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
77+
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX}
8178
)
8279

8380
install(
8481
EXPORT ${PROJECT_NAME}Targets
85-
DESTINATION lib/cmake/${PROJECT_NAME}${_PROJECT_VERSION_SUFFIX}
82+
DESTINATION lib/cmake/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX}
8683
NAMESPACE ${PROJECT_NAMESPACE}
8784
)
8885

89-
install(
90-
FILES
91-
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
92-
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
93-
DESTINATION
94-
lib/cmake/${PROJECT_NAME}${_PROJECT_VERSION_SUFFIX}
86+
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
87+
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
88+
DESTINATION lib/cmake/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX}
9589
)
9690

97-
install(
98-
DIRECTORY ${PROJECT_INCLUDE_DIR}/
99-
DESTINATION ${PROJECT_INCLUDE_DESTINATION}
100-
)
91+
install(DIRECTORY ${PROJECT_INCLUDE_DIR}/ DESTINATION ${PROJECT_INCLUDE_DESTINATION})
10192

102-
set(${PROJECT_NAME}_VERSION ${PROJECT_VERSION} CACHE INTERNAL "")
93+
set(${PROJECT_NAME}_VERSION
94+
${PROJECT_VERSION}
95+
CACHE INTERNAL ""
96+
)
10397
endfunction()

test/CMakeLists.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
22

33
option(TEST_INSTALLED_VERSION "Test the version found by find_package" OFF)
44

5-
project(PackageProjectTest
5+
project(
6+
PackageProjectTest
67
VERSION 1.0
78
LANGUAGES CXX
89
)
910

10-
if (TEST_INSTALLED_VERSION)
11+
if(TEST_INSTALLED_VERSION)
1112
find_package(dependency 1.2.3 REQUIRED)
1213
find_package(namespaced_dependency 4.5.6 REQUIRED)
1314
find_package(transitive_dependency 7.8.9 REQUIRED)
@@ -19,9 +20,6 @@ endif()
1920

2021
add_executable(test main.cpp)
2122

22-
target_link_libraries(test
23-
dependency
24-
ns::namespaced_dependency
25-
transitive_dependency::transitive_dependency
23+
target_link_libraries(
24+
test dependency ns::namespaced_dependency transitive_dependency::transitive_dependency
2625
)
27-

test/dependency/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
22

3-
project(dependency
3+
project(
4+
dependency
45
VERSION 1.2.3
56
LANGUAGES CXX
67
)
78

89
add_library(dependency source/dependency.cpp)
910

10-
target_include_directories(dependency
11-
PUBLIC
12-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
13-
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
11+
target_include_directories(
12+
dependency PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
13+
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
1414
)
1515

1616
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/PackageProject)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#include <iostream>
21
#include <dependency/version.h>
32

3+
#include <iostream>
4+
45
void dependencyFunction() {
56
std::cout << "Using dependency version " << DEPENDENCY_VERSION << std::endl;
67
}

test/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <namespaced_dependency/version.h>
55
#include <transitive_dependency/transitive_dependency.h>
66
#include <transitive_dependency/version.h>
7+
78
#include <string>
89

910
int main() {

test/namespaced_dependency/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
22

3-
project(namespaced_dependency
3+
project(
4+
namespaced_dependency
45
VERSION 4.5.6
56
LANGUAGES CXX
67
)
@@ -10,10 +11,9 @@ add_library(${PROJECT_NAME} source/namespaced_dependency.cpp)
1011
# the alias ${PROJECT_NAMESPACE}::${PROJECT_NAME} is automatically provided by PackageProject.cmake
1112
# if we use the `NAMESPACE` parameter
1213

13-
target_include_directories(namespaced_dependency
14-
PUBLIC
15-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
16-
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
14+
target_include_directories(
15+
namespaced_dependency PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
16+
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
1717
)
1818

1919
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/PackageProject)

test/namespaced_dependency/include/namespaced_dependency/namespaced_dependency.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
namespace ns {
44

5-
void namespacedDependencyFunction();
5+
void namespacedDependencyFunction();
66

77
}

0 commit comments

Comments
 (0)