Skip to content

Commit 94b3903

Browse files
committed
build: replace if-blocks with genexps, fix REUSE
REUSE 5.x requires `override` precedence for third-party code and `closest` for project code. Obfuscate SPDX-License-Identifier in .clang-format to prevent false-positive parsing. Signed-off-by: Yuming He <ComixHe1895@outlook.com>
1 parent 69cc8ce commit 94b3903

7 files changed

Lines changed: 75 additions & 60 deletions

File tree

.clang-format

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ ColumnLimit: 100
2727
# Disable reflow of some specific comments
2828
# qdoc comments: indentation rules are different.
2929
# Translation comments and SPDX license identifiers are also excluded.
30-
CommentPragmas: "^!|^:|^ SPDX-License-Identifier:"
30+
#
31+
# NOTE: '[I]' is used here to obfuscate the 'SPDX-License-Identifier' keyword.
32+
# Regular 'I' would cause the REUSE compliance tool to misinterpret this configuration
33+
# line as a valid license expression, leading to a linter parsing error.
34+
CommentPragmas: "^!|^:|^ SPDX-License-[I]dentifier:"
3135

3236
PointerAlignment: Right
3337

CMakeLists.txt

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,11 @@ set(linyaps-box_ACTIVE_LOG_LEVEL
9292

9393
set(linyaps-box_ENABLE_CPM
9494
OFF
95-
CACHE BOOL "enable CPM"
96-
)
95+
CACHE BOOL "enable CPM")
9796

9897
set(linyaps-box_HARDENING
9998
ON
100-
CACHE BOOL "enable hardening"
101-
)
99+
CACHE BOOL "enable hardening")
102100

103101
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
104102

@@ -111,8 +109,7 @@ endif()
111109
# if just want to try local packages at first set CPM_USE_LOCAL_PACKAGES ON
112110
set(linyaps-box_CPM_LOCAL_PACKAGES_ONLY
113111
OFF
114-
CACHE BOOL "use local packages only"
115-
)
112+
CACHE BOOL "use local packages only")
116113

117114
# ==============================================================================
118115

@@ -122,10 +119,8 @@ if(linyaps-box_HARDENING)
122119
"${CMAKE_EXE_LINKER_FLAGS} -pie -Wl,-z,relro -Wl,-z,now")
123120
add_compile_options(-fstack-protector-strong)
124121

125-
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
126-
message(STATUS "Non-Debug build, enabling FORTIFY_SOURCE")
127-
add_compile_definitions(_FORTIFY_SOURCE=2)
128-
endif()
122+
message(STATUS "Non-Debug build, enabling FORTIFY_SOURCE")
123+
add_compile_definitions("$<$<NOT:$<CONFIG:Debug>>:_FORTIFY_SOURCE=2>")
129124
endif()
130125

131126
set(linyaps-box_LIBRARY linyaps-box)
@@ -295,11 +290,11 @@ if(linyaps-box_ENABLE_CPM)
295290
EXCLUDE_FROM_ALL ON
296291
OPTIONS "BUILD_TESTING OFF")
297292
CPMFindPackage(
298-
NAME fmt
299-
VERSION 10.1.0
300-
GITHUB_REPOSITORY fmtlib/fmt
301-
GIT_TAG 12.2.0
302-
EXCLUDE_FROM_ALL ON)
293+
NAME fmt
294+
VERSION 10.1.0
295+
GITHUB_REPOSITORY fmtlib/fmt
296+
GIT_TAG 12.2.0
297+
EXCLUDE_FROM_ALL ON)
303298
endif()
304299

305300
# find minimal version
@@ -329,13 +324,11 @@ endif()
329324

330325
list(APPEND linyaps-box_LIBRARY_LINK_LIBRARIES CLI11::CLI11)
331326

332-
set(FMT_TARGET fmt::fmt)
333-
if(linyaps-box_STATIC)
334-
set(FMT_TARGET fmt::fmt-header-only)
335-
endif()
327+
set(FMT_TARGET
328+
"$<IF:$<BOOL:${linyaps-box_STATIC}>,fmt::fmt-header-only,fmt::fmt>")
336329

337330
find_package(fmt 10.1.0 QUIET)
338-
if (NOT fmt_FOUND)
331+
if(NOT fmt_FOUND)
339332
# if fmt is not found in local system. just use fmt::fmt with static linkage
340333
# for boosting compiling speed.
341334
set(FMT_TARGET fmt::fmt)
@@ -393,10 +386,9 @@ target_compile_definitions(
393386
"LINYAPS_BOX_ACTIVE_LOG_LEVEL=${linyaps-box_ACTIVE_LOG_LEVEL}")
394387
target_compile_options("${linyaps-box_LIBRARY}"
395388
PRIVATE -fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.)
396-
if(linyaps-box_STATIC)
397-
target_compile_definitions("${linyaps-box_LIBRARY}"
398-
PUBLIC "LINYAPS_BOX_STATIC_LINK")
399-
endif()
389+
target_compile_definitions(
390+
"${linyaps-box_LIBRARY}"
391+
PUBLIC "$<$<BOOL:${linyaps-box_STATIC}>:LINYAPS_BOX_STATIC_LINK>")
400392

401393
if(linyaps-box_ENABLE_SECCOMP)
402394
target_compile_definitions("${linyaps-box_LIBRARY}"
@@ -413,18 +405,22 @@ if(linyaps-box_ENABLE_CAP)
413405
endif()
414406

415407
if(linyaps-box_ENABLE_COVERAGE)
416-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
417-
target_compile_options("${linyaps-box_LIBRARY}"
418-
PRIVATE -fprofile-instr-generate -fcoverage-mapping)
419-
target_link_options("${linyaps-box_LIBRARY}" PUBLIC
420-
-fprofile-instr-generate -fcoverage-mapping)
421-
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
422-
target_compile_options("${linyaps-box_LIBRARY}" PRIVATE --coverage)
423-
target_link_options("${linyaps-box_LIBRARY}" PUBLIC --coverage)
424-
else()
408+
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_ID
409+
STREQUAL "GNU")
425410
message(
426411
FATAL_ERROR "Coverage is not supported for ${CMAKE_CXX_COMPILER_ID}.")
427412
endif()
413+
target_compile_options(
414+
"${linyaps-box_LIBRARY}"
415+
PRIVATE "$<$<CXX_COMPILER_ID:Clang,AppleClang>:-fprofile-instr-generate>"
416+
"$<$<CXX_COMPILER_ID:Clang,AppleClang>:-fcoverage-mapping>"
417+
"$<$<CXX_COMPILER_ID:GNU>:--coverage>")
418+
target_link_options(
419+
"${linyaps-box_LIBRARY}"
420+
PUBLIC
421+
"$<$<CXX_COMPILER_ID:Clang,AppleClang>:-fprofile-instr-generate>"
422+
"$<$<CXX_COMPILER_ID:Clang,AppleClang>:-fcoverage-mapping>"
423+
"$<$<CXX_COMPILER_ID:GNU>:--coverage>")
428424
endif()
429425

430426
# ==============================================================================
@@ -439,10 +435,10 @@ add_executable("${linyaps-box_APP}" ${linyaps-box_APP_SOURCE})
439435
target_include_directories("${linyaps-box_APP}"
440436
${linyaps-box_APP_SOURCE_INCLUDE_DIRS})
441437
target_link_libraries("${linyaps-box_APP}" ${linyaps-box_APP_LINK_LIBRARIES})
442-
if(linyaps-box_STATIC)
443-
target_link_options("${linyaps-box_APP}" PRIVATE -static -static-libgcc
444-
-static-libstdc++)
445-
endif()
438+
target_link_options(
439+
"${linyaps-box_APP}" PRIVATE "$<$<BOOL:${linyaps-box_STATIC}>:-static>"
440+
"$<$<BOOL:${linyaps-box_STATIC}>:-static-libgcc>"
441+
"$<$<BOOL:${linyaps-box_STATIC}>:-static-libstdc++>")
446442
target_compile_features("${linyaps-box_APP}" PRIVATE cxx_std_17)
447443
set_property(TARGET "${linyaps-box_APP}" PROPERTY CXX_STANDARD 17)
448444
set_property(TARGET "${linyaps-box_APP}" PROPERTY CXX_EXTENSIONS OFF)

REUSE.toml

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
version = 1
22
SPDX-PackageName = "linyaps-box"
3-
SPDX-PackageSupplier = "UnionTech Software Technology Co., Ltd. <>"
3+
SPDX-PackageSupplier = "UnionTech Software Technology Co., Ltd."
44
SPDX-PackageDownloadLocation = "https://github.com/OpenAtom-Linyaps/linyaps-box"
55

66
[[annotations]]
77
path = [
8-
"**/CMakeLists.txt",
9-
"**/CMakePresets.json",
10-
"**/.gitignore",
8+
"CMakeLists.txt",
9+
"src/**/CMakeLists.txt",
10+
"tests/**/CMakeLists.txt",
11+
"CMakePresets.json",
12+
".gitignore",
13+
"tests/**/.gitignore",
1114
".clang-format",
1215
".cmake-format.py",
13-
"cmake.external/**",
14-
"external/*/CMakeLists.txt",
16+
"cmake.external/CLI11/**",
17+
"cmake.external/nlohmann_json/**",
18+
"cmake.external/zeus_expected/**",
19+
"external/CLI11/CMakeLists.txt",
20+
"external/nlohmann_json/CMakeLists.txt",
21+
"external/zeus_expected/CMakeLists.txt",
1522
]
16-
precedence = "aggregate"
23+
precedence = "closest"
1724
SPDX-FileCopyrightText = "UnionTech Software Technology Co., Ltd."
1825
SPDX-License-Identifier = "CC0-1.0"
1926

@@ -28,45 +35,42 @@ path = [
2835
]
2936

3037
exclude = ["**/cmake_test_discovery_*.json"]
31-
precedence = "aggregate"
38+
precedence = "closest"
3239
SPDX-FileCopyrightText = "UnionTech Software Technology Co., Ltd."
3340
SPDX-License-Identifier = "CC0-1.0"
3441

3542
[[annotations]]
3643
path = ["README.md", "README.zh_CN.md"]
37-
precedence = "aggregate"
44+
precedence = "closest"
3845
SPDX-FileCopyrightText = "UnionTech Software Technology Co., Ltd."
3946
SPDX-License-Identifier = "CC-BY-4.0"
4047

4148
[[annotations]]
4249
path = ["cmake/CPM.cmake"]
43-
precedence = "aggregate"
50+
precedence = "override"
4451
SPDX-FileCopyrightText = "2019-2023 Lars Melchior and contributors"
4552
SPDX-License-Identifier = "MIT"
4653

4754
[[annotations]]
4855
path = ["external/nlohmann_json/include/**"]
49-
precedence = "aggregate"
56+
precedence = "override"
5057
SPDX-FileCopyrightText = "2013-2025 Niels Lohmann <https://nlohmann.me>"
5158
SPDX-License-Identifier = "MIT"
5259

5360
[[annotations]]
5461
path = ["external/CLI11/include/**"]
55-
precedence = "aggregate"
62+
precedence = "override"
5663
SPDX-FileCopyrightText = "2017-2026 University of Cincinnati, developed by Henry Schreiner under NSF AWARD 1414736."
5764
SPDX-License-Identifier = "BSD-3-Clause"
5865

5966
[[annotations]]
6067
path = ["external/zeus_expected/include/**"]
61-
precedence = "aggregate"
68+
precedence = "override"
6269
SPDX-FileCopyrightText = "2024 zeus-cpp"
6370
SPDX-License-Identifier = "MIT"
6471

6572
[[annotations]]
66-
path = [
67-
"external/fmt/**",
68-
"cmake.external/fmt/**"
69-
]
70-
precedence = "aggregate"
73+
path = ["external/fmt/**", "cmake.external/fmt/JoinPaths.py"]
74+
precedence = "override"
7175
SPDX-FileCopyrightText = "2012 - present, Victor Zverovich and {fmt} contributors"
7276
SPDX-License-Identifier = "MIT"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SPDX-FileCopyrightText: None
2+
#
3+
# SPDX-License-Identifier: CC0-1.0
4+
5+
with section("format"):
6+
disable = True

external/CLI11/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
add_library(CLI11 INTERFACE)
22
add_library(CLI11::CLI11 ALIAS CLI11)
3-
target_include_directories(CLI11 INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include/")
3+
target_include_directories(CLI11 INTERFACE
4+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
5+
)

external/nlohmann_json/CMakeLists.txt

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

33
add_library(nlohmann_json INTERFACE)
44
add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json)
5-
target_include_directories(nlohmann_json INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include/")
5+
target_include_directories(nlohmann_json INTERFACE
6+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
7+
)
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_library(zeus_expected INTERFACE)
22
add_library(zeus::expected ALIAS zeus_expected)
3-
target_include_directories(zeus_expected
4-
INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include/")
3+
target_include_directories(zeus_expected INTERFACE
4+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
5+
)

0 commit comments

Comments
 (0)