Skip to content

Commit ce930d1

Browse files
committed
[cmake/FindLibBSD.cmake] Rewrite to use PkgConfig cmake module and expose a cmake package ; [acquire/tests/CMakeLists.txt] Hide chatting output behind a flag ; [acquire/tests/test_*.h] Resolve a lot of the warnings
1 parent 1949fa9 commit ce930d1

File tree

11 files changed

+112
-59
lines changed

11 files changed

+112
-59
lines changed

acquire/CMakeLists.txt

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ if (NOT HAS_STDBOOL AND NOT MSVC)
6161
endif (NOT HAS_STDBOOL AND NOT MSVC)
6262
source_group("Header Files" FILES "${Header_Files}")
6363

64+
option(DEBUG_TOKENISER "OFF")
65+
6466
function (generate_source_file_from_header_only filepath header_filepath source_filepath)
6567
# This function parses a header-only library file and creates a header and source file.
6668
# Care is taken so that the same conditions hold, e.g., #if FEATURE\n#include "s.h"\n#endif /* FEATURE */
@@ -172,8 +174,10 @@ function (generate_source_file_from_header_only filepath header_filepath source_
172174
OR prev_prev_char STREQUAL ":" # label (incl. case & default)
173175
))
174176
if (line_len)
175-
message(STATUS "full_line = \"${line}\"")
176-
message(STATUS "prev_prev_char = '${prev_prev_char}'; prev_char = '${prev_char}'; char = '${char}'")
177+
if (DEBUG_TOKENISER)
178+
message(STATUS "full_line = \"${line}\"")
179+
message(STATUS "prev_prev_char = '${prev_prev_char}'; prev_char = '${prev_char}'; char = '${char}'")
180+
endif (DEBUG_TOKENISER)
177181
math(EXPR line_no "${line_no} + 1")
178182
if (line MATCHES "^#.*endif")
179183
list(POP_BACK conditions)
@@ -182,9 +186,12 @@ function (generate_source_file_from_header_only filepath header_filepath source_
182186
list(APPEND end_impl "${line}")
183187
list(APPEND end_line_impl "${line_no}")
184188
list(SUBLIST "${contents}" "${start_line_impl}" "${end_line_impl}" new_contents_l)
185-
message(STATUS "start_line_impl = ${start_line_impl}")
186-
message(STATUS "end_line_impl = ${end_line_impl}")
187-
message(STATUS "new_contents_l = ${new_contents_l}")
189+
if (DEBUG_TOKENISER)
190+
message(STATUS "start_line_impl = ${start_line_impl}")
191+
message(STATUS "end_line_impl = ${end_line_impl}")
192+
message(STATUS "new_contents_l = ${new_contents_l}")
193+
endif (DEBUG_TOKENISER)
194+
188195
#string(SUBSTRING "${contents}" "${start_line_impl}" "${end_line_impl}" source_contents)
189196
set(eat_source "OFF")
190197
set(eat_header "ON")
@@ -193,12 +200,16 @@ function (generate_source_file_from_header_only filepath header_filepath source_
193200
elseif (line MATCHES "^#.*if")
194201
list(APPEND conditions "${line}")
195202
list(APPEND conditions_line "${line_no}")
196-
message(STATUS "[${line_no}] conditions = ${conditions}")
197-
message(STATUS "[${line_no}] conditions_line = ${conditions_line}")
203+
if (DEBUG_TOKENISER)
204+
message(STATUS "[${line_no}] conditions = ${conditions}")
205+
message(STATUS "[${line_no}] conditions_line = ${conditions_line}")
206+
endif (DEBUG_TOKENISER)
198207
if (line MATCHES ".*LIBACQUIRE_IMPLEMENTATION.*")
199208
list(APPEND start_impl "${line}")
200209
list(APPEND start_line_impl "${line_no}")
201-
message(STATUS "start_impl = ${start_impl}")
210+
if (DEBUG_TOKENISER)
211+
message(STATUS "start_impl = ${start_impl}")
212+
endif (DEBUG_TOKENISER)
202213
set(eat_from_line_no "${line_no}")
203214
set(eat_source "ON")
204215
set(eat_header "OFF")
@@ -252,11 +263,14 @@ else ()
252263

253264
add_library("${LIBRARY_NAME}_lib" SHARED "${gen_header_files}" "${gen_source_files}")
254265

255-
find_package(LibBSD)
256-
if (LibBSD_FOUND)
257-
target_link_directories("${LIBRARY_NAME}_lib" PUBLIC "${BSD_LIBRARY}")
258-
target_compile_definitions("${LIBRARY_NAME}_lib" PUBLIC HAVE_STRNSTR=1)
259-
endif (LibBSD_FOUND)
266+
if (NOT BSD)
267+
find_package(LibBSD)
268+
if (LibBSD_FOUND)
269+
target_link_directories("${LIBRARY_NAME}_lib" PUBLIC "${BSD_LIBRARY}")
270+
target_compile_definitions("${LIBRARY_NAME}_lib" PUBLIC HAVE_STRNSTR=1)
271+
target_compile_definitions("${LIBRARY_NAME}_lib" PUBLIC HAVE_LIBBSD=1)
272+
endif (LibBSD_FOUND)
273+
endif (NOT BSD)
260274

261275
message(STATUS "${LIBRARY_NAME}_lib::CMAKE_SOURCE_DIR = ${CMAKE_SOURCE_DIR}")
262276
target_include_directories(

acquire/acquire_libcurl.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#if !defined(LIBACQUIRE_LIBCURL_H) && defined(USE_LIBCURL) && \
2+
defined(LIBACQUIRE_IMPLEMENTATION)
3+
14
/*
25
* libcurl implementation of libacquire's download API
36
*
@@ -8,13 +11,13 @@
811
* - Elsewhere that curl supports (not tested, but shouldn't be an issue)
912
* */
1013

11-
#if !defined(LIBACQUIRE_LIBCURL_H) && defined(USE_LIBCURL) && \
12-
defined(LIBACQUIRE_IMPLEMENTATION)
1314
#define LIBACQUIRE_LIBCURL_H
1415

1516
#include <stdint.h>
1617
#include <stdlib.h>
1718

19+
#include <acquire_fileutils.h>
20+
1821
#include "acquire_common_defs.h"
1922
#include "acquire_string_extras.h"
2023

acquire/acquire_string_extras.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
#include <stdarg.h>
1010
#include <stdio.h>
11+
#ifdef HAVE_LIBBSD
12+
#include <bsd/string.h>
13+
#else
1114
#include <string.h>
15+
#endif /* HAVE_LIBBSD */
1216

1317
#include "libacquire_export.h"
1418

acquire/tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ set(All_Header_Files "${GREATEST_FILE}")
7171

7272
foreach (_library "HTTPS" "CRYPTO" "EXTRACT" "CHECKSUM")
7373
message(STATUS "[test_libacquire] ${_library}_LIB: \t${${_library}_LIB}")
74-
endforeach (_library "HTTPS" "CRYPTO" "EXTRACT")
74+
endforeach (_library "HTTPS" "CRYPTO" "EXTRACT" "CHECKSUM")
7575

7676
macro (test_wrapper)
7777
target_include_directories(

acquire/tests/test_amalgamation.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef TEST_AMALGAMATION_H
2+
#define TEST_AMALGAMATION_H
3+
14
#include <greatest.h>
25
#include <stdbool.h>
36

@@ -21,3 +24,5 @@ TEST x_test_file_downloads(void) {
2124

2225
/* Suites can group multiple tests with common setup. */
2326
SUITE(downloads_suite) { RUN_TEST(x_test_file_downloads); }
27+
28+
#endif /* !TEST_AMALGAMATION_H */

acquire/tests/test_checksum.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef TEST_CHECKSUM_H
2+
#define TEST_CHECKSUM_H
3+
14
#include <greatest.h>
25
#include <stdbool.h>
36

@@ -20,15 +23,15 @@
2023
#endif
2124

2225
#ifdef _MSC_VER
23-
#define NUM_FORMAT "%zu"
26+
#define NUM_FORMAT "zu"
27+
#define BOOL_FORMAT NUM_FORMAT
2428
#elif defined(__linux__) || defined(linux) || defined(__linux)
25-
#define NUM_FORMAT "%d"
26-
#else
27-
#define NUM_FORMAT "%lu"
29+
#define NUM_FORMAT "d"
30+
#define BOOL_FORMAT "lu"
2831
#endif
2932

3033
TEST x_test_crc32c_should_be_true(void) {
31-
printf("crc32c(GREATEST_FILE, \"%s\"): " NUM_FORMAT "\n", GREATEST_CRC32C,
34+
printf("crc32c(GREATEST_FILE, \"%s\"): %" BOOL_FORMAT "\n", GREATEST_CRC32C,
3235
crc32c(GREATEST_FILE, GREATEST_CRC32C));
3336
ASSERT_FALSE(!crc32c(GREATEST_FILE, GREATEST_CRC32C));
3437
PASS();
@@ -50,3 +53,5 @@ SUITE(checksums_suite) {
5053
RUN_TEST(x_test_sha256_should_be_true);
5154
RUN_TEST(x_test_sha256_file_should_be_false);
5255
}
56+
57+
#endif /* !TEST_CHECKSUM_H */

acquire/tests/test_download.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef TEST_DOWNLOAD_H
2+
#define TEST_DOWNLOAD_H
3+
14
#include <greatest.h>
25

36
#include <acquire_common_defs.h>
@@ -35,3 +38,5 @@ TEST x_test_file_downloads(void) {
3538

3639
/* Suites can group multiple tests with common setup. */
3740
SUITE(downloads_suite) { RUN_TEST(x_test_file_downloads); }
41+
42+
#endif /* !TEST_DOWNLOAD_H */

acquire/tests/test_extract.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
#define PATH_SEP "/"
1414
#endif /* defined(_MSC_VER) && !defined(__INTEL_COMPILER) */
1515

16-
#include <acquire_common_defs.h>
17-
#include <acquire_config.h>
18-
#include <acquire_extract.h>
19-
#include <config_for_tests.h>
20-
2116
#define LIBACQUIRE_IMPLEMENTATION
2217
#include <acquire_fileutils.h>
2318
#include ARCHIVE_LIB_NAME
2419
#undef LIBACQUIRE_IMPLEMENTATION
2520

21+
#include <acquire_common_defs.h>
22+
#include <acquire_config.h>
23+
#include <acquire_extract.h>
24+
#include <config_for_tests.h>
25+
2626
TEST x_test_extract_archive(void) {
2727
#define EXTRACT_DIR DOWNLOAD_DIR PATH_SEP "extract" PATH_SEP ARCHIVE_LIB
2828
puts("\"test_extract.h\" for ARCHIVE_LIB: \"" ARCHIVE_LIB

acquire/tests/test_fileutils.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1+
#ifndef TEST_FILEUTILS_H
2+
#define TEST_FILEUTILS_H
3+
4+
#define LIBACQUIRE_IMPLEMENTATION
15
#include <acquire_fileutils.h>
6+
#undef LIBACQUIRE_IMPLEMENTATION
7+
28
#include <config_for_tests.h>
39
#include <greatest.h>
4-
#include <stdbool.h>
510

611
#ifdef _MSC_VER
7-
#define NUM_FORMAT "%zu"
12+
#define NUM_FORMAT "zu"
813
typedef size_t num_type;
914
#elif defined(__linux__) || defined(linux) || defined(__linux)
10-
#define NUM_FORMAT "%d"
15+
#define NUM_FORMAT "d"
1116
typedef int num_type;
1217
#else
13-
#define NUM_FORMAT "%lu"
18+
#define NUM_FORMAT "lu"
1419
typedef unsigned long num_type;
1520
#endif /* _MSC_VER */
1621

1722
TEST x_is_directory_should_be_true(void) {
1823
const bool x = is_directory(CMAKE_CURRENT_SOURCE_DIR);
19-
ASSERT_EQ_FMT((num_type) true, x, NUM_FORMAT);
24+
ASSERT_EQ_FMT((bool)true, x, "%" BOOL_FORMAT);
2025
PASS();
2126
}
2227

@@ -30,7 +35,7 @@ TEST x_is_directory_should_be_false(void) {
3035

3136
TEST x_is_file_should_be_true(void) {
3237
const bool x = is_file(CMAKE_CURRENT_LIST_FILE);
33-
ASSERT_EQ_FMT((num_type) true, x, NUM_FORMAT);
38+
ASSERT_EQ_FMT((bool)true, x, "%" BOOL_FORMAT);
3439
PASS();
3540
}
3641

@@ -45,8 +50,8 @@ TEST x_is_file_should_be_false(void) {
4550
TEST x_exists_should_be_true(void) {
4651
const bool x = exists(CMAKE_CURRENT_SOURCE_DIR);
4752
const bool y = exists(CMAKE_CURRENT_LIST_FILE);
48-
ASSERT_EQ_FMT((num_type) true, x, NUM_FORMAT);
49-
ASSERT_EQ_FMT((num_type) true, y, NUM_FORMAT);
53+
ASSERT_EQ_FMT((bool)true, x, "%" BOOL_FORMAT);
54+
ASSERT_EQ_FMT((bool)true, y, "%" BOOL_FORMAT);
5055
PASS();
5156
}
5257

@@ -102,3 +107,5 @@ SUITE(fileutils_suite) {
102107
/* RUN_TEST(x_parse_out_extension_should_be_include_both_dots_when_whole_filename_is_extension);
103108
*/
104109
}
110+
111+
#endif /* !TEST_FILEUTILS_H */

acquire/tests/test_string_extras.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef TEST_STRING_EXTRAS_H
2+
#define TEST_STRING_EXTRAS_H
3+
14
#include "config_for_tests.h"
25
#include <acquire_string_extras.h>
36
#include <greatest.h>
@@ -20,3 +23,5 @@ SUITE(strnstr_suite) {
2023
RUN_TEST(x_strnstr_should_succeed);
2124
RUN_TEST(x_strnstr_should_fail);
2225
}
26+
27+
#endif /* !TEST_STRING_EXTRAS_H */

0 commit comments

Comments
 (0)