Skip to content

Commit c515363

Browse files
Fix warnings and small issues (#1178)
try some things with no standard libraries Add arm64 and freebsd build and tests fix a discrepancy in the handling of chars on Arm processors --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 587129a commit c515363

File tree

10 files changed

+117
-30
lines changed

10 files changed

+117
-30
lines changed

.github/workflows/arm_mac_gcc.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: ARM GCC
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
7+
jobs:
8+
arm64_gcc:
9+
name: ARM64 GCC
10+
runs-on: ubuntu-24.04-arm
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Configure
15+
run: |
16+
cmake -S . -B build \
17+
-DCMAKE_CXX_STANDARD=17
18+
19+
- name: Build
20+
run: cmake --build build -j4
21+
22+
- name: Test
23+
run: |
24+
cd build
25+
ctest --output-on-failure

.github/workflows/freebsd.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: freebsd
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
name: run test on FreeBSD
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Test in FreeBSD
16+
id: test
17+
uses: vmactions/freebsd-vm@v1
18+
with:
19+
usesh: true
20+
prepare: |
21+
pkg install -y cmake pkgconf
22+
23+
run: |
24+
cmake -S . -B build \
25+
-DCMAKE_CXX_STANDARD=20
26+
cmake --build build -j4
27+
cd build
28+
ctest --output-on-failure

.github/workflows/tests.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
runs-on: ubuntu-latest
2020
strategy:
2121
matrix:
22-
std: ["11", "14", "17", "20"]
22+
std: ["14", "17", "20","23"]
2323
precompile: ["ON", "OFF"]
2424
steps:
2525
- uses: actions/checkout@v4
@@ -150,6 +150,22 @@ jobs:
150150
run: ctest --output-on-failure
151151
working-directory: build
152152

153+
sanitizer-build:
154+
name: sanitizer build
155+
runs-on: ubuntu-24.04
156+
steps:
157+
- uses: actions/checkout@v4
158+
with:
159+
submodules: true
160+
# this build step will fail
161+
- name: Configure
162+
run: cmake -S . -B build -DCLI11_SANITIZERS=ON
163+
- name: Build
164+
run: cmake --build build -j2
165+
- name: Run tests
166+
run: ctest --output-on-failure
167+
working-directory: build
168+
153169
meson-build:
154170
name: Meson build
155171
runs-on: ubuntu-latest
@@ -378,4 +394,12 @@ jobs:
378394
uses: ./.github/actions/quick_cmake
379395
with:
380396
cmake-version: "3.31"
397+
args: -DCLI11_SANITIZERS=ON -DCLI11_BUILD_EXAMPLES_JSON=ON
398+
if: success() || failure()
399+
400+
- name: Check CMake 4.0
401+
uses: ./.github/actions/quick_cmake
402+
with:
403+
cmake-version: "4.0"
404+
args: -DCLI11_BUILD_EXAMPLES_JSON=ON
381405
if: success() || failure()

CMakeLists.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
cmake_minimum_required(VERSION 3.10...3.31)
2-
# Note: this is a header only library. If you have an older CMake than 3.5,
1+
cmake_minimum_required(VERSION 3.10...4.0)
2+
# Note: this is a header only library. If you have an older CMake than 3.10,
33
# just add the CLI11/include directory and that's all you need to do.
44

55
set(VERSION_REGEX "#define CLI11_VERSION[ \t]+\"(.+)\"")
@@ -69,7 +69,7 @@ option(CLI11_WARNINGS_AS_ERRORS "Turn all warnings into errors (for CI)")
6969
option(CLI11_SINGLE_FILE "Generate a single header file")
7070
option(CLI11_PRECOMPILED "Generate a precompiled static library instead of a header-only" OFF)
7171
cmake_dependent_option(CLI11_SANITIZERS "Download the sanitizers CMake config" OFF
72-
"NOT CMAKE_VERSION VERSION_LESS 3.13" OFF)
72+
"NOT CMAKE_VERSION VERSION_LESS 3.15" OFF)
7373

7474
cmake_dependent_option(CLI11_BUILD_DOCS "Build CLI11 documentation" ON "${build-docs}" OFF)
7575

@@ -80,7 +80,7 @@ cmake_dependent_option(CLI11_BUILD_EXAMPLES "Build CLI11 examples" ON
8080
"CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME;${examples_EXIST}" OFF)
8181

8282
cmake_dependent_option(CLI11_BUILD_EXAMPLES_JSON "Build CLI11 json example" OFF
83-
"CLI11_BUILD_EXAMPLES;NOT CMAKE_VERSION VERSION_LESS 3.11" OFF)
83+
"CLI11_BUILD_EXAMPLES;NOT CMAKE_VERSION VERSION_LESS 3.15" OFF)
8484

8585
cmake_dependent_option(CLI11_SINGLE_FILE_TESTS "Duplicate all the tests for a single file build"
8686
OFF "BUILD_TESTING;CLI11_SINGLE_FILE" OFF)
@@ -113,12 +113,15 @@ if(NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)
113113
set(CMAKE_CXX_STANDARD_REQUIRED ON)
114114
endif()
115115

116+
include(CLI11Warnings)
117+
116118
# Allow IDE's to group targets into folders
117119
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
118120
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
119-
endif()
120121

121-
include(CLI11Warnings)
122+
set(CMAKE_CXX_STANDARD_LIBRARIES_INIT "")
123+
set(CMAKE_CXX_STANDARD_LIBRARIES "")
124+
endif()
122125

123126
# Sources
124127

examples/CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,14 @@ function(add_cli_exe T)
1010
endif()
1111
endfunction()
1212

13-
if(CLI11_BUILD_EXAMPLES_JSON)
13+
if(CLI11_BUILD_EXAMPLES_JSON AND CMAKE_VERSION VERSION_GREATER "3.14.7")
1414
message(STATUS "Using nlohmann/json")
1515
FetchContent_Declare(
1616
json
1717
URL https://github.com/nlohmann/json/releases/download/v3.7.3/include.zip
1818
URL_HASH "SHA256=87b5884741427220d3a33df1363ae0e8b898099fbc59f1c451113f6732891014")
1919

20-
FetchContent_GetProperties(json)
21-
if(NOT json_POPULATED)
22-
FetchContent_Populate(json)
23-
endif()
20+
FetchContent_MakeAvailable(json)
2421

2522
add_cli_exe(json json.cpp)
2623
target_include_directories(json PUBLIC SYSTEM "${json_SOURCE_DIR}/single_include")

include/CLI/StringTools.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ CLI11_INLINE bool valid_name_string(const std::string &str);
165165

166166
/// Verify an app name
167167
inline bool valid_alias_name_string(const std::string &str) {
168-
static const std::string badChars(std::string("\n") + '\0');
168+
static const std::string badChars{'\n', '\0'};
169169
return (str.find_first_of(badChars) == std::string::npos);
170170
}
171171

include/CLI/TypeTools.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,14 @@ bool lexical_cast(const std::string &input, T &output) {
11301130
output = static_cast<T>(input[0]);
11311131
return true;
11321132
}
1133-
return integral_conversion(input, output);
1133+
std::int8_t res{0};
1134+
// we do it this way as some systems have char as signed and not, this ensures consistency in the way things are
1135+
// handled
1136+
bool result = integral_conversion(input, res);
1137+
if(result) {
1138+
output = static_cast<T>(res);
1139+
}
1140+
return result;
11341141
}
11351142

11361143
/// Boolean values

tests/CMakeLists.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
if(CLI11_SANITIZERS AND ${CMAKE_VERSION} VERSION_GREATER "3.13.0")
1+
if(CLI11_SANITIZERS AND ${CMAKE_VERSION} VERSION_GREATER "3.15.0")
22
message(STATUS "Using arsenm/sanitizers-cmake")
33
FetchContent_Declare(
44
sanitizers
55
GIT_REPOSITORY https://github.com/arsenm/sanitizers-cmake.git
66
GIT_SHALLOW 1
77
GIT_TAG 0573e2e)
88

9-
FetchContent_GetProperties(sanitizers)
10-
11-
if(NOT sanitizers_POPULATED)
12-
FetchContent_Populate(sanitizers)
13-
endif()
9+
FetchContent_MakeAvailable(sanitizers)
1410

1511
list(APPEND CMAKE_MODULE_PATH "${sanitizers_SOURCE_DIR}/cmake")
1612

@@ -119,6 +115,7 @@ foreach(DATA_FILE IN LISTS DATA_FILES)
119115
VERBATIM)
120116
endforeach()
121117
add_custom_target(cli11_test_data DEPENDS ${DATA_FILES})
118+
set_target_properties(cli11_test_data PROPERTIES FOLDER "Tests/Apps")
122119

123120
# Make a shim if we are building single file tests
124121
if(CLI11_SINGLE_FILE AND CLI11_INSTALL_PACKAGE_TESTS)
@@ -132,13 +129,18 @@ set(CLI11_DEPENDENT_APPLICATIONS ensure_utf8 ensure_utf8_twice)
132129
foreach(APP IN LISTS CLI11_DEPENDENT_APPLICATIONS)
133130
add_executable(${APP} applications/${APP}.cpp)
134131
target_include_directories(${APP} PRIVATE ${CMAKE_SOURCE_DIR}/include)
132+
set_target_properties(${APP} PROPERTIES FOLDER "Tests/Apps")
135133
endforeach()
136134

137135
function(add_dependent_application_definitions TARGET)
138136
foreach(APP IN LISTS CLI11_DEPENDENT_APPLICATIONS)
139137
string(TOUPPER ${APP} APP_UPPERCASE)
140138
target_compile_definitions(${TARGET}
141139
PRIVATE CLI11_${APP_UPPERCASE}_EXE="$<TARGET_FILE:${APP}>")
140+
141+
if(WIN32)
142+
target_link_libraries(${APP} PRIVATE Shell32)
143+
endif()
142144
endforeach()
143145
endfunction()
144146

@@ -246,6 +248,7 @@ if(CLI11_FORCE_LIBCXX)
246248
PROPERTY LINK_FLAGS -stdlib=libc++)
247249
endif()
248250

251+
set_target_properties(informational PROPERTIES FOLDER "Tests/Apps")
249252
# Force this to be in a standard location so CTest can find it
250253
set_target_properties(
251254
informational

tests/HelpersTest.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ TEST_CASE("StringTools: binaryEscapeConversion", "[helpers]") {
274274
testString2.push_back(0);
275275
testString2.push_back(static_cast<char>(197));
276276
testString2.push_back(78);
277-
testString2.push_back(-34);
277+
testString2.push_back(static_cast<char>(-34));
278278

279279
rstring = CLI::detail::extract_binary_string(CLI::detail::binary_escape_string(testString2));
280280
CHECK(rstring == testString2);
@@ -294,8 +294,8 @@ TEST_CASE("StringTools: binaryEscapeConversion2", "[helpers]") {
294294
testString.push_back(0);
295295
testString.push_back(0);
296296
testString.push_back(56);
297-
testString.push_back(-112);
298-
testString.push_back(-112);
297+
testString.push_back(static_cast<char>(-112));
298+
testString.push_back(static_cast<char>(-112));
299299
testString.push_back(39);
300300
testString.push_back(97);
301301
std::string estring = CLI::detail::binary_escape_string(testString);
@@ -310,8 +310,8 @@ TEST_CASE("StringTools: binaryEscapeConversion_withX", "[helpers]") {
310310
testString.push_back(0);
311311
testString.push_back(0);
312312
testString.push_back(56);
313-
testString.push_back(-112);
314-
testString.push_back(-112);
313+
testString.push_back(static_cast<char>(-112));
314+
testString.push_back(static_cast<char>(-112));
315315
testString.push_back(39);
316316
testString.push_back(97);
317317
std::string estring = CLI::detail::binary_escape_string(testString);
@@ -324,12 +324,12 @@ TEST_CASE("StringTools: binaryEscapeConversion_withBrackets", "[helpers]") {
324324

325325
std::string vstr = R"raw('B"([\xb0\x0a\xb0/\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0\xb0])"')raw";
326326
std::string testString("[");
327-
testString.push_back(-80);
327+
testString.push_back(static_cast<char>(-80));
328328
testString.push_back('\n');
329-
testString.push_back(-80);
329+
testString.push_back(static_cast<char>(-80));
330330
testString.push_back('/');
331331
for(int ii = 0; ii < 13; ++ii) {
332-
testString.push_back(-80);
332+
testString.push_back(static_cast<char>(-80));
333333
}
334334
testString.push_back(']');
335335

tests/app_helper.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ CLI11_INLINE void check_identical_files(const char *path1, const char *path2) {
112112
file1.seekg(0);
113113
file2.seekg(0);
114114

115-
std::array<uint8_t, 10240> buffer1;
116-
std::array<uint8_t, 10240> buffer2;
115+
static std::array<uint8_t, 10240> buffer1;
116+
static std::array<uint8_t, 10240> buffer2;
117117

118118
for(size_t ibuffer = 0; file1.good(); ++ibuffer) {
119119
// Flawfinder: ignore

0 commit comments

Comments
 (0)