Skip to content

Commit c3fdd43

Browse files
committed
Cleanup with pre-commit
1 parent 6af8e8b commit c3fdd43

15 files changed

Lines changed: 149 additions & 120 deletions

.TODO.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ test 1
2121
1: CMake's support for `import std;` in C++23 and newer is experimental. It
2222
1: is meant only for experimentation and feedback to CMake developers.
2323
1: This warning is for project developers. Use -Wno-dev to suppress it.
24-
1:
24+
1:
2525
1: Generating done (0.0s)
2626
1: Build files have been written to: /Users/clausklein/Workspace/cpp/cxx20/fmt-module/build/dev/tests/find-package-test
2727
1: ======== End CMake output ======
2828
1: Change Dir: '/Users/clausklein/Workspace/cpp/cxx20/fmt-module/build/dev/tests/find-package-test'
29-
1:
29+
1:
3030
1: Run Clean Command: /Users/clausklein/.local/bin/ninja clean
3131
1: [1/1] Cleaning all built files...
3232
1: Cleaning... 22 files.
33-
1:
33+
1:
3434
1: Run Build Command(s): /Users/clausklein/.local/bin/ninja
3535
1: [1/12] Scanning /usr/local/Cellar/gcc/15.2.0/include/c++/15/bits/std.compat.cc for CXX dependencies
3636
1: [2/12] Scanning /usr/local/Cellar/gcc/15.2.0/include/c++/15/bits/std.cc for CXX dependencies
@@ -44,7 +44,7 @@ test 1
4444
1: [10/12] Building CXX object 'CMakeFiles/fmt__fmt@synth_439f33eb51e5.dir/f6569b67b774.bmi'
4545
1: [11/12] Building CXX object CMakeFiles/module_header-only-test.dir/Users/clausklein/Workspace/cpp/cxx20/fmt-module/tests/header-only-test.cc.o
4646
1: [12/12] Linking CXX executable module_header-only-test
47-
1: FAILED: [code=1] module_header-only-test
47+
1: FAILED: [code=1] module_header-only-test
4848
1: : && /usr/local/bin/g++-15 -stdlib=libstdc++ -O3 -DNDEBUG -Wl,-search_paths_first -Wl,-headerpad_max_install_names -stdlib=libstdc++ CMakeFiles/module_header-only-test.dir/Users/clausklein/Workspace/cpp/cxx20/fmt-module/tests/header-only-test.cc.o -o module_header-only-test /Users/clausklein/Workspace/cpp/cxx20/fmt-module/stagedir/lib/libfmt.a && :
4949
1: Undefined symbols for architecture x86_64:
5050
1: "initializer for module std", referenced from:
@@ -54,7 +54,7 @@ test 1
5454
1: ld: symbol(s) not found for architecture x86_64
5555
1: collect2: error: ld returned 1 exit status
5656
1: ninja: build stopped: subcommand failed.
57-
1:
57+
1:
5858
1/1 Test #1: find-package-test ................***Failed 9.90 sec
5959
Internal cmake changing into directory: /Users/clausklein/Workspace/cpp/cxx20/fmt-module/build/dev/tests/find-package-test
6060
======== CMake output ======
@@ -88,7 +88,7 @@ Run Build Command(s): /Users/clausklein/.local/bin/ninja
8888
[10/12] Building CXX object 'CMakeFiles/fmt__fmt@synth_439f33eb51e5.dir/f6569b67b774.bmi'
8989
[11/12] Building CXX object CMakeFiles/module_header-only-test.dir/Users/clausklein/Workspace/cpp/cxx20/fmt-module/tests/header-only-test.cc.o
9090
[12/12] Linking CXX executable module_header-only-test
91-
FAILED: [code=1] module_header-only-test
91+
FAILED: [code=1] module_header-only-test
9292
: && /usr/local/bin/g++-15 -stdlib=libstdc++ -O3 -DNDEBUG -Wl,-search_paths_first -Wl,-headerpad_max_install_names -stdlib=libstdc++ CMakeFiles/module_header-only-test.dir/Users/clausklein/Workspace/cpp/cxx20/fmt-module/tests/header-only-test.cc.o -o module_header-only-test /Users/clausklein/Workspace/cpp/cxx20/fmt-module/stagedir/lib/libfmt.a && :
9393
Undefined symbols for architecture x86_64:
9494
"initializer for module std", referenced from:

.bumpversion.cfg

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ tag_name = v{new_version}
66
tag = False
77
current_version = 12.1.0-dev1
88
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)([-](?P<release>(dev|rc))+(?P<build>\d+))?
9-
serialize =
9+
serialize =
1010
{major}.{minor}.{patch}-{release}{build}
1111
{major}.{minor}.{patch}
1212

1313
[bumpversion:part:release]
1414
first_value = dev
1515
optional_value = ga
16-
values =
16+
values =
1717
dev
1818
rc
1919
ga
2020

2121
[bumpversion:file:CMakeLists.txt]
2222
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<build>\d+))?
23-
serialize =
23+
serialize =
2424
{major}.{minor}.{patch}.{build}
2525
{major}.{minor}.{patch}
2626

2727
[bumpversion:file:tests/CMakeLists.txt]
2828
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<build>\d+))?
29-
serialize =
29+
serialize =
3030
{major}.{minor}.{patch}.{build}
3131
{major}.{minor}.{patch}
3232

3333
[bumpversion:file:module/tests/CMakeLists.txt]
3434
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<build>\d+))?
35-
serialize =
35+
serialize =
3636
{major}.{minor}.{patch}.{build}
3737
{major}.{minor}.{patch}
3838

.bumpversion.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ bumpversion flow:
55
1.0.0 => 1.0.1-dev0 => 1.0.1-dev1 = > 1.0.1-rc0 => 1.0.1-rc1 => 1.0.1
66
patch build release build release
77

8-
98
## Details
109

1110
Start with an initial release, say `1.0.0`.
@@ -34,14 +33,12 @@ Start with an initial release, say `1.0.0`.
3433
git tag => v1.0.1-rc1
3534
CMake PROJECT_VERSION => 1.0.1.1
3635

37-
4. Finally, bump `release` to generate a final release for the current
38-
`major` / `minor` / `patch` version.
36+
5. Finally, bump `release` to generate a final release for the current `major` / `minor` / `patch` version.
3937

4038
$ bumpversion release --tag
4139
git tag => v1.0.1
4240
CMake PROJECT_VERSION => 1.0.1
4341

44-
4542
## Notes
4643

4744
* Once the final release has been reached, it is not possible to bump
@@ -52,12 +49,10 @@ Start with an initial release, say `1.0.0`.
5249

5350
bumpversion --new-version 12.1.0 release --no-commit --no-tag --allow-dirty
5451

55-
# Reference
52+
## Reference
5653

5754
To install bumpversion:
5855

59-
pip install --upgrade bump2version
60-
61-
https://github.com/c4urself/bump2version#installation
62-
https://cmake.org/cmake/help/latest/variable/PROJECT_VERSION.html#variable:PROJECT_VERSION
56+
pipx install bump2version
6357

58+
[cmke PROJECT_VERSION](https://cmake.org/cmake/help/latest/variable/PROJECT_VERSION.html#variable:PROJECT_VERSION)

.markdownlint.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# MD033/no-inline-html : Inline HTML : https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md033.md
2+
# Disable inline html linter is needed for <details> <summary>
3+
MD033: false
4+
5+
# MD013/line-length : Line length : https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md013.md
6+
# Conforms to .clang-format ColumnLimit
7+
# Update the comment in .clang-format if we no-longer tie these two column limits.
8+
MD013:
9+
line_length: 119
10+
code_blocks: false

.pre-commit-config.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v6.0.0
6+
hooks:
7+
- id: trailing-whitespace
8+
exclude: ^fmt\.(patch|diff)$
9+
- id: end-of-file-fixer
10+
- id: check-yaml
11+
exclude: ^\.clang-(format|tidy)$
12+
- id: check-added-large-files
13+
14+
# Clang-format for C++
15+
# This brings in a portable version of clang-format.
16+
# See also: https://github.com/ssciwr/clang-format-wheel
17+
- repo: https://github.com/pre-commit/mirrors-clang-format
18+
rev: v21.1.7
19+
hooks:
20+
- id: clang-format
21+
types_or: [c++, c, json]
22+
23+
# CMake linting and formatting
24+
- repo: https://github.com/BlankSpruce/gersemi
25+
rev: 0.23.2
26+
hooks:
27+
- id: gersemi
28+
name: CMake linting
29+
exclude: ^.*/tests/.*/data/ # Exclude test data directories
30+
31+
# Markdown linting
32+
# Config file: .markdownlint.yaml
33+
# Commented out to disable this by default. Uncomment to enable markdown linting.
34+
- repo: https://github.com/igorshubovych/markdownlint-cli
35+
rev: v0.46.0
36+
hooks:
37+
- id: markdownlint
38+
39+
- repo: https://github.com/codespell-project/codespell
40+
rev: v2.4.1
41+
hooks:
42+
- id: codespell
43+
args: ["--write"]
44+
45+
exclude: 'build/'

BUILDING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ variable to provide them to CMake during configuration.
3333
CMake supports building on Apple Silicon properly since 3.20.1. Make sure you
3434
have the [latest version][1] installed.
3535

36+
```sh
37+
CXX=c++ cmake -S . -B build -G Ninja -D CMAKE_CXX_SCAN_FOR_MODULES=NO -D CMAKE_BUILD_TYPE=Release -D FMT_DEVELOPER_MODE=YES --fresh
38+
ninja -C build all_verify_interface_header_sets
39+
ninja -C build build install
40+
ninja -C build build tests
41+
```
42+
3643
## Install
3744

3845
This project doesn't require any special command-line flags to install to keep

CMakeLists.txt

Lines changed: 43 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,19 @@ cmake_minimum_required(VERSION 3.30...4.2)
33

44
include(cmake/prelude.cmake)
55

6-
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
6+
option(
7+
CMAKE_CXX_SCAN_FOR_MODULES
8+
"Whether to scan C++ source files for module dependencies"
9+
ON
10+
)
11+
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
712

813
# Set experimental flag to enable `import std` support from CMake.
914
# This must be enabled before C++ language support.
1015
if(CMAKE_CXX_SCAN_FOR_MODULES)
1116
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
1217
"d0edc3af-4c50-42ea-a356-e2862fe7a444"
1318
)
14-
# if(APPLE AND $ENV{CXX} STREQUAL g++-15)
15-
# set(CMAKE_CXX_STDLIB_MODULES_JSON
16-
# $ENV{GCC_DIR}/lib/gcc/current/libstdc++.modules.json
17-
# )
18-
# else()
19-
# set(CMAKE_CXX_STDLIB_MODULES_JSON
20-
# $ENV{LLVM_DIR}/lib/c++/libc++.modules.json
21-
# )
22-
# endif()
2319
endif()
2420

2521
#==================================================
@@ -39,16 +35,12 @@ set(CMAKE_CXX_EXTENSIONS ON)
3935
set(CMAKE_CXX_STANDARD_REQUIRED ON)
4036

4137
set(CMAKE_DEBUG_POSTFIX D)
42-
# to prevent -Winclude-angled-in-module-purview in fmt/os.h
43-
# see /Users/clausklein/.cache/CPM/fmt/297020319ba1d5d14e1599714def59a1788711c5/include/fmt/os.h:33
44-
set(CPPdefinitions FMT_USE_FCNTL=0)
45-
set(ADD_STDLIB_MODULES)
38+
set(CMAKE_SKIP_TEST_ALL_DEPENDENCY OFF)
4639

47-
option(
48-
FMT_SEPARATE_COMPILATION
49-
"build fmt lib too"
50-
${CMAKE_CXX_SCAN_FOR_MODULES}
51-
)
40+
# FIXME: to prevent -Winclude-angled-in-module-purview in fmt/os.h
41+
# see /Users/clausklein/.cache/CPM/fmt/6226dc0d560c5dca8bcd81db09f7e2752ccb8cef/include/fmt/os.h:33
42+
set(CPPdefinitions FMT_USE_FCNTL=0)
43+
option(FMT_SEPARATE_COMPILATION "build fmt lib too" ${PROJECT_IS_TOP_LEVEL})
5244
option(
5345
FMT_USE_MODULES
5446
"Export a CXX_MODULE fmt if possible"
@@ -82,35 +74,6 @@ if(CMAKE_GENERATOR STREQUAL "Ninja" AND FMT_USE_MODULES)
8274
set(LLVM_DIR ${LLVM_DIR} CACHE PATH "")
8375
message(STATUS "LLVM_DIR=${LLVM_DIR}")
8476

85-
# if(LINUX AND EXISTS ${LLVM_LIBC_SOURCE}/std.cppm)
86-
# message(WARNING "LLVM_LIBC_SOURCE=${LLVM_LIBC_SOURCE}")
87-
# set(ADD_STDLIB_MODULES stdc++)
88-
# list(APPEND CMAKE_CXX_COMPILER_IMPORT_STD 23)
89-
# endif()
90-
91-
# Build the stdlib module
92-
function(add_stdlib_module NAME)
93-
add_library(${NAME})
94-
target_sources(
95-
${NAME}
96-
PUBLIC
97-
FILE_SET CXX_MODULES
98-
BASE_DIRS ${LLVM_LIBC_SOURCE}
99-
FILES
100-
${LLVM_LIBC_SOURCE}/std.cppm
101-
${LLVM_LIBC_SOURCE}/std.compat.cppm
102-
)
103-
target_compile_features(${NAME} PUBLIC cxx_std_23)
104-
target_compile_definitions(
105-
${NAME}
106-
PUBLIC _LIBCPP_HAS_NO_LOCALIZATION
107-
)
108-
target_compile_options(
109-
${NAME}
110-
PRIVATE -Wno-reserved-module-identifier
111-
)
112-
endfunction()
113-
11477
add_compile_options(-fexperimental-library)
11578
add_link_options(-L${LLVM_DIR}/lib/c++ -lc++experimental)
11679
add_compile_options(-stdlib=libc++)
@@ -129,7 +92,7 @@ if(CMAKE_GENERATOR STREQUAL "Ninja" AND FMT_USE_MODULES)
12992
set(CMAKE_CXX_MODULE_STD ON)
13093
endif()
13194

132-
if(CMAKE_CXX_MODULE_STD OR ADD_STDLIB_MODULES)
95+
if(CMAKE_CXX_MODULE_STD)
13396
list(APPEND CPPdefinitions FMT_IMPORT_STD)
13497
endif()
13598

@@ -141,31 +104,27 @@ if(CMAKE_GENERATOR STREQUAL "Ninja" AND FMT_USE_MODULES)
141104
message(STATUS "CMAKE_CXX_MODULE_STD=${CMAKE_CXX_MODULE_STD}")
142105
message(STATUS "CPPdefinitions=${CPPdefinitions}")
143106
else()
144-
set(CMAKE_VERIFY_INTERFACE_HEADER_SETS ${PROJECT_IS_TOP_LEVEL})
107+
option(CMAKE_VERIFY_INTERFACE_HEADER_SETS "" ${PROJECT_IS_TOP_LEVEL})
145108
endif()
146109

147-
#XXX if(MSVC)
148-
#XXX include(cmake/example.cmake)
149-
#XXX endif()
150-
151110
# ---- add dependency libraries ----
152111

153112
include(cmake/CPM.cmake)
154113

155-
# gersemi: off
156114
cpmaddpackage(
157115
NAME fmt
158116
GITHUB_REPOSITORY fmtlib/fmt
159117
GIT_TAG 12.1.0
160118
VERSION 12.1.0
161119
DOWNLOAD_ONLY ON
162-
# XXX PATCH_COMMAND git apply -p 1 ${CMAKE_CURRENT_SOURCE_DIR}/fmt.patch
120+
# NO! PATCH_COMMAND git apply -p 1 ${CMAKE_CURRENT_SOURCE_DIR}/fmt.patch
163121
)
164-
# gersemi: on
165122

166-
# ---- Declare library ----
123+
# -----------------------------------------
124+
# ---- Collect the fmt library sources ----
125+
# -----------------------------------------
167126

168-
# TODO: only if needed (compare) and possible!
127+
# TODO(CK): manually apply the patch if needed (compare) and possible!
169128
if(
170129
EXISTS ${fmt_SOURCE_DIR}/src/fmt.cc
171130
AND NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/module/fmt.cppm
@@ -187,13 +146,29 @@ configure_file(
187146
${CMAKE_CURRENT_SOURCE_DIR}/module/os.cc
188147
COPYONLY
189148
)
190-
file(GLOB_RECURSE _fmt_all_sources "module/*.cc")
191149

192-
# fmt interface library
150+
file(
151+
GLOB_RECURSE _fmt_all_sources
152+
CONFIGURE_DEPENDS
153+
RELATIVE ${CMAKE_CURRENT_LIST_DIR}
154+
module/*.cc
155+
)
156+
157+
# -----------------------------------------
158+
# -----------------------------------------
159+
160+
#
161+
# build the fmt interface library
162+
#
193163
add_library(fmt-header-only INTERFACE)
194164
add_library(fmt::fmt-header-only ALIAS fmt-header-only)
195165

196-
file(GLOB_RECURSE _fmt_public_header "${fmt_SOURCE_DIR}/include/fmt/*.h")
166+
file(
167+
GLOB_RECURSE _fmt_public_header
168+
CONFIGURE_DEPENDS
169+
# NO! RELATIVE ${fmt_SOURCE_DIR}/include
170+
${fmt_SOURCE_DIR}/include/fmt/*.h
171+
)
197172
target_sources(
198173
fmt-header-only
199174
INTERFACE
@@ -211,10 +186,11 @@ target_compile_options(
211186
INTERFACE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/utf-8>
212187
)
213188

189+
#
190+
# build the fmt library
191+
#
214192
if(FMT_SEPARATE_COMPILATION)
215-
# file(GLOB_RECURSE _fmt_all_sources "${fmt_SOURCE_DIR}/src/*.cc")
216-
217-
add_library(fmt STATIC)
193+
add_library(fmt)
218194
target_sources(
219195
fmt
220196
PUBLIC
@@ -244,10 +220,10 @@ if(FMT_SEPARATE_COMPILATION)
244220
)
245221
target_compile_definitions(fmt PUBLIC ${CPPdefinitions})
246222
else()
247-
message(FATAL_ERROR "FMT_USE_MODULES=${FMT_USE_MODULES}!")
223+
message(WARNING "Missing or disabled support for CXX_MODULES!")
248224
add_library(fmt::fmt ALIAS fmt)
249225
target_compile_definitions(fmt PUBLIC ${CPPdefinitions})
250-
target_sources(fmt PUBLIC ${_fmt_all_sources})
226+
target_sources(fmt PRIVATE ${_fmt_all_sources})
251227
endif()
252228

253229
if(FMT_WARNINGS_AS_ERRORS AND FMT_DEVELOPER_MODE AND UNIX)

0 commit comments

Comments
 (0)