Skip to content

Commit bdd9d39

Browse files
authored
Merge pull request #113 from build-cpp/editorconfig
Add `.editorconfig` and linting
2 parents cfee3bb + 1deaec2 commit bdd9d39

File tree

31 files changed

+256
-222
lines changed

31 files changed

+256
-222
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ AlwaysBreakBeforeMultilineStrings: false
1919
AlwaysBreakTemplateDeclarations: true
2020
BinPackArguments: true
2121
BinPackParameters: true
22-
BraceWrapping:
22+
BraceWrapping:
2323
AfterClass: false
2424
AfterControlStatement: false
2525
AfterEnum: false

.editorconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
trim_trailing_whitespace = true
6+
charset = utf-8
7+
8+
[*.{c,h,cpp,hpp,toml}]
9+
indent_style = space
10+
insert_final_newline = true
11+
12+
[{CMakeLists.txt, *.cmake}]
13+
indent_style = tab
14+
tab_width = 8
15+
insert_final_newline = true
16+
17+
# Exclude the third_party folder
18+
[/third_party/**]
19+
charset = unset
20+
end_of_line = unset
21+
insert_final_newline = unset
22+
trim_trailing_whitespace = unset
23+
indent_style = unset
24+
indent_size = unset

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name: CMake
1+
name: build
22

33
on: [push, pull_request]
44

55
jobs:
6-
build:
6+
cmake:
77
# Skip building pull requests from the same repository
88
if: ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) }}
99
runs-on: ${{ matrix.os }}

.github/workflows/lint.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: lint
33
on: [push]
44

55
jobs:
6-
lint:
6+
clang-format:
77
runs-on: ubuntu-latest
88

99
steps:
@@ -24,4 +24,14 @@ jobs:
2424
run: |
2525
# Instructions for fixing the formatting errors
2626
echo -e "\n\033[0;31mTo fix the formatting, run:\nclang-format -style=file -i \$(git ls-files \"*.c\" \"*.h\" \"*.cpp\" \"*.hpp\")\033[0m\n"
27-
exit 1
27+
exit 1
28+
29+
editorconfig:
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v3
35+
36+
- name: Run editorconfig-checker
37+
uses: editorconfig-checker/action-editorconfig-checker@d4fca16fc71adef10fbe101903b654449fa9570c # master 2022-03-15

cmake/bump_version.cmake

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,78 @@
1-
cmake_minimum_required(VERSION 3.20)
2-
3-
if(NOT CMAKE_SCRIPT_MODE_FILE)
4-
message(FATAL_ERROR "Usage: cmake -P bump_version.cmake [1.2.3]")
5-
endif()
6-
7-
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake.toml")
8-
message(FATAL_ERROR "Cannot find cmake.toml")
9-
endif()
10-
11-
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake/cmkr.cmake")
12-
message(FATAL_ERROR "Cannot find cmkr.cmake")
13-
endif()
14-
15-
# Validate branch
16-
find_package(Git REQUIRED)
17-
execute_process(COMMAND "${GIT_EXECUTABLE}" branch --show-current OUTPUT_VARIABLE GIT_BRANCH)
18-
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
19-
if(NOT GIT_BRANCH STREQUAL "main")
20-
message(FATAL_ERROR "You need to be on the main branch, you are on: ${GIT_BRANCH}")
21-
endif()
22-
23-
file(READ "${CMAKE_SOURCE_DIR}/cmake.toml" CMAKE_TOML)
24-
string(FIND "${CMAKE_TOML}" "[project]" PROJECT_INDEX)
25-
string(SUBSTRING "${CMAKE_TOML}" ${PROJECT_INDEX} -1 CMAKE_TOML_PROJECT)
26-
set(SEMVER_REGEX "([0-9]+)\\.([0-9]+)\\.([0-9]+)")
27-
set(VERSION_REGEX "version = \"${SEMVER_REGEX}\"")
28-
if(CMAKE_TOML_PROJECT MATCHES "${VERSION_REGEX}")
29-
set(MAJOR "${CMAKE_MATCH_1}")
30-
set(MINOR "${CMAKE_MATCH_2}")
31-
set(PATCH "${CMAKE_MATCH_3}")
32-
set(OLDVERSION "${MAJOR}.${MINOR}.${PATCH}")
33-
else()
34-
message(FATAL_ERROR "Failed to match semantic version in cmake.toml")
35-
endif()
36-
37-
if(CMAKE_ARGV3)
38-
if(NOT CMAKE_ARGV3 MATCHES "${SEMVER_REGEX}")
39-
message(FATAL_ERROR "Invalid semantic version number '${CMAKE_ARGV3}'")
40-
endif()
41-
set(NEWVERSION "${CMAKE_ARGV3}")
42-
else()
43-
math(EXPR NEWPATCH "${PATCH} + 1")
44-
set(NEWVERSION "${MAJOR}.${MINOR}.${NEWPATCH}")
45-
endif()
46-
47-
message(STATUS "Version ${OLDVERSION} -> ${NEWVERSION}")
48-
49-
find_program(CMKR_EXECUTABLE "cmkr" PATHS "${CMAKE_SOURCE_DIR}/build" PATH_SUFFIXES Debug Release RelWithDebInfo MinSizeRel NO_CACHE REQUIRED)
50-
message(STATUS "Found cmkr: ${CMKR_EXECUTABLE}")
51-
52-
# Replace version in cmake.toml
53-
string(REPLACE "version = \"${OLDVERSION}\"" "version = \"${NEWVERSION}\"" CMAKE_TOML "${CMAKE_TOML}")
54-
file(CONFIGURE
55-
OUTPUT "${CMAKE_SOURCE_DIR}/cmake.toml"
56-
CONTENT "${CMAKE_TOML}"
57-
@ONLY
58-
NEWLINE_STYLE LF
59-
)
60-
61-
# Run cmkr gen
62-
execute_process(COMMAND "${CMKR_EXECUTABLE}" gen RESULT_VARIABLE CMKR_EXEC_RESULT)
63-
if(NOT CMKR_EXEC_RESULT EQUAL 0)
64-
message(FATAL_ERROR "cmkr gen failed (exit code ${CMKR_EXEC_RESULT})")
65-
endif()
66-
67-
# Replace version in cmkr.cmake
68-
file(READ "${CMAKE_SOURCE_DIR}/cmake/cmkr.cmake" CMKR_CMAKE)
69-
string(REGEX REPLACE "CMKR_TAG \"[^\"]+\"" "CMKR_TAG \"v${NEWVERSION}\"" CMKR_CMAKE "${CMKR_CMAKE}")
70-
file(CONFIGURE
71-
OUTPUT "${CMAKE_SOURCE_DIR}/cmake/cmkr.cmake"
72-
CONTENT "${CMKR_CMAKE}"
73-
@ONLY
74-
NEWLINE_STYLE LF
75-
)
76-
77-
# Print git commands
1+
cmake_minimum_required(VERSION 3.20)
2+
3+
if(NOT CMAKE_SCRIPT_MODE_FILE)
4+
message(FATAL_ERROR "Usage: cmake -P bump_version.cmake [1.2.3]")
5+
endif()
6+
7+
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake.toml")
8+
message(FATAL_ERROR "Cannot find cmake.toml")
9+
endif()
10+
11+
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake/cmkr.cmake")
12+
message(FATAL_ERROR "Cannot find cmkr.cmake")
13+
endif()
14+
15+
# Validate branch
16+
find_package(Git REQUIRED)
17+
execute_process(COMMAND "${GIT_EXECUTABLE}" branch --show-current OUTPUT_VARIABLE GIT_BRANCH)
18+
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
19+
if(NOT GIT_BRANCH STREQUAL "main")
20+
message(FATAL_ERROR "You need to be on the main branch, you are on: ${GIT_BRANCH}")
21+
endif()
22+
23+
file(READ "${CMAKE_SOURCE_DIR}/cmake.toml" CMAKE_TOML)
24+
string(FIND "${CMAKE_TOML}" "[project]" PROJECT_INDEX)
25+
string(SUBSTRING "${CMAKE_TOML}" ${PROJECT_INDEX} -1 CMAKE_TOML_PROJECT)
26+
set(SEMVER_REGEX "([0-9]+)\\.([0-9]+)\\.([0-9]+)")
27+
set(VERSION_REGEX "version = \"${SEMVER_REGEX}\"")
28+
if(CMAKE_TOML_PROJECT MATCHES "${VERSION_REGEX}")
29+
set(MAJOR "${CMAKE_MATCH_1}")
30+
set(MINOR "${CMAKE_MATCH_2}")
31+
set(PATCH "${CMAKE_MATCH_3}")
32+
set(OLDVERSION "${MAJOR}.${MINOR}.${PATCH}")
33+
else()
34+
message(FATAL_ERROR "Failed to match semantic version in cmake.toml")
35+
endif()
36+
37+
if(CMAKE_ARGV3)
38+
if(NOT CMAKE_ARGV3 MATCHES "${SEMVER_REGEX}")
39+
message(FATAL_ERROR "Invalid semantic version number '${CMAKE_ARGV3}'")
40+
endif()
41+
set(NEWVERSION "${CMAKE_ARGV3}")
42+
else()
43+
math(EXPR NEWPATCH "${PATCH} + 1")
44+
set(NEWVERSION "${MAJOR}.${MINOR}.${NEWPATCH}")
45+
endif()
46+
47+
message(STATUS "Version ${OLDVERSION} -> ${NEWVERSION}")
48+
49+
find_program(CMKR_EXECUTABLE "cmkr" PATHS "${CMAKE_SOURCE_DIR}/build" PATH_SUFFIXES Debug Release RelWithDebInfo MinSizeRel NO_CACHE REQUIRED)
50+
message(STATUS "Found cmkr: ${CMKR_EXECUTABLE}")
51+
52+
# Replace version in cmake.toml
53+
string(REPLACE "version = \"${OLDVERSION}\"" "version = \"${NEWVERSION}\"" CMAKE_TOML "${CMAKE_TOML}")
54+
file(CONFIGURE
55+
OUTPUT "${CMAKE_SOURCE_DIR}/cmake.toml"
56+
CONTENT "${CMAKE_TOML}"
57+
@ONLY
58+
NEWLINE_STYLE LF
59+
)
60+
61+
# Run cmkr gen
62+
execute_process(COMMAND "${CMKR_EXECUTABLE}" gen RESULT_VARIABLE CMKR_EXEC_RESULT)
63+
if(NOT CMKR_EXEC_RESULT EQUAL 0)
64+
message(FATAL_ERROR "cmkr gen failed (exit code ${CMKR_EXEC_RESULT})")
65+
endif()
66+
67+
# Replace version in cmkr.cmake
68+
file(READ "${CMAKE_SOURCE_DIR}/cmake/cmkr.cmake" CMKR_CMAKE)
69+
string(REGEX REPLACE "CMKR_TAG \"[^\"]+\"" "CMKR_TAG \"v${NEWVERSION}\"" CMKR_CMAKE "${CMKR_CMAKE}")
70+
file(CONFIGURE
71+
OUTPUT "${CMAKE_SOURCE_DIR}/cmake/cmkr.cmake"
72+
CONTENT "${CMKR_CMAKE}"
73+
@ONLY
74+
NEWLINE_STYLE LF
75+
)
76+
77+
# Print git commands
7878
message(STATUS "Git commands to create new version:\ngit commit -a -m \"Bump to ${NEWVERSION}\"\ngit tag v${NEWVERSION}\ngit push origin main v${NEWVERSION}")

cmake/generate_documentation.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function(generate_documentation)
1515
message(FATAL_ERROR "This should not happen (wrong regex?)")
1616
endif()
1717
endforeach()
18-
18+
1919
# Delete previously generated examples
2020
set(example_folder "${PROJECT_SOURCE_DIR}/docs/examples")
2121
file(GLOB example_files "${example_folder}/*.md")
@@ -41,21 +41,21 @@ function(generate_documentation)
4141
# Read cmake.toml file
4242
file(READ "${test_toml}" test_contents NO_HEX_CONVERSION)
4343
string(LENGTH "${test_contents}" toml_length)
44-
44+
4545
# Extract header text
4646
string(REGEX MATCH "^(\n*(#[^\n]+\n)+\n*)" EXAMPLE_HEADER "${test_contents}")
4747
string(LENGTH "${EXAMPLE_HEADER}" header_length)
4848
string(STRIP "${EXAMPLE_HEADER}" EXAMPLE_HEADER)
4949
string(REGEX REPLACE "\n# ?" "\n\n" EXAMPLE_HEADER "\n${EXAMPLE_HEADER}")
5050
string(STRIP "${EXAMPLE_HEADER}" EXAMPLE_HEADER)
51-
51+
5252
# Extract footer text
5353
string(REGEX MATCH "(((#[^\n]+)(\n+|$))+)$" EXAMPLE_FOOTER "${test_contents}")
5454
string(LENGTH "${EXAMPLE_FOOTER}" footer_length)
5555
string(STRIP "${EXAMPLE_FOOTER}" EXAMPLE_FOOTER)
5656
string(REGEX REPLACE "\n# ?" "\n\n" EXAMPLE_FOOTER "\n${EXAMPLE_FOOTER}")
5757
string(STRIP "${EXAMPLE_FOOTER}" EXAMPLE_FOOTER)
58-
58+
5959
# Extract toml body
6060
math(EXPR toml_length "${toml_length}-${header_length}-${footer_length}")
6161
string(SUBSTRING "${test_contents}" ${header_length} ${toml_length} EXAMPLE_TOML)
@@ -64,7 +64,7 @@ function(generate_documentation)
6464
# Extract title from description
6565
if("${EXAMPLE_TOML}" MATCHES "description *= *\"([^\"]+)\"")
6666
set(EXAMPLE_TITLE "${CMAKE_MATCH_1}")
67-
67+
6868
# Generate documentation markdown page
6969
configure_file("${PROJECT_SOURCE_DIR}/cmake/example.md.in" "${example_folder}/${EXAMPLE_PERMALINK}.md" @ONLY NEWLINE_STYLE LF)
7070
else()

cmake/resource.hpp.in

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
namespace cmkr {
2-
namespace resources {
3-
4-
static const char* @RESOURCE_NAME@ = R"RESOURCE(@RESOURCE_CONTENTS@)RESOURCE";
5-
6-
}
1+
namespace cmkr {
2+
namespace resources {
3+
4+
static const char* @RESOURCE_NAME@ = R"RESOURCE(@RESOURCE_CONTENTS@)RESOURCE";
5+
6+
}
77
}

docs/CNAME

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cmkr.build
1+
cmkr.build

docs/cmake-toml.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ arch64 = "CMAKE_SIZEOF_VOID_P EQUAL 8"
4949
arch32 = "CMAKE_SIZEOF_VOID_P EQUAL 4"
5050
```
5151

52-
This will make the `arch64` and `arch32` conditions available with their respective CMake expressions.
52+
This will make the `arch64` and `arch32` conditions available with their respective CMake expressions.
5353

5454
You can also prefix most keys with `condition.` to represent a conditional:
5555

docs/getting-started.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
---
2-
layout: null
3-
permalink: /getting-started/
4-
---
5-
6-
<html>
7-
<head>
8-
<meta http-equiv="refresh" content="0;url=https://cmkr.build">
9-
</head>
1+
---
2+
layout: null
3+
permalink: /getting-started/
4+
---
5+
6+
<html>
7+
<head>
8+
<meta http-equiv="refresh" content="0;url=https://cmkr.build">
9+
</head>
1010
</html>

0 commit comments

Comments
 (0)