Skip to content

Commit 7c33675

Browse files
committed
[acquire/tests/config_for_tests.h.in] Ensure all values here are properly set ; [cmake/FindLibBSD.cmake] Rewrite to work without warnings on macOS ; [*] Progress on getting build to succeed (extract now does; download has one missing symbol)
1 parent 4c3623f commit 7c33675

23 files changed

+392
-217
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ if (_GNU_SOURCE)
5151
add_definitions(-D_GNU_SOURCE)
5252
endif (_GNU_SOURCE)
5353

54-
function (gettempdir VARNAME)
54+
function(gettempdir VARNAME)
5555
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
5656
set(${VARNAME} "$ENV{TEMP}" PARENT_SCOPE)
5757
else ()
@@ -61,7 +61,7 @@ function (gettempdir VARNAME)
6161
set(${VARNAME} "/tmp" PARENT_SCOPE)
6262
endif (NOT ${VARNAME})
6363
endif ()
64-
endfunction (gettempdir)
64+
endfunction(gettempdir)
6565

6666
gettempdir(TMPDIR_DEFAULT)
6767
set(TMPDIR "${TMPDIR_DEFAULT}" CACHE PATH "Select tmpdir, will use default otherwise")

acquire/CMakeLists.txt

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if (LIBACQUIRE_HEADER_ONLY)
2020
set(lib_type "INTERFACE")
2121
else ()
2222
set(lib_type "PUBLIC")
23-
endif (LIBACQUIRE_HEADER_ONLY)
23+
endif ()
2424

2525
set(_Header_Files "")
2626

@@ -69,11 +69,10 @@ source_group("Header Files" FILES "${Header_Files}")
6969
option(DEBUG_TOKENISER "OFF")
7070

7171
function(generate_source_file_from_header_only filepath header_filepath source_filepath)
72-
# --- Initialization ---
7372
if (NOT EXISTS "${filepath}")
7473
message(FATAL_ERROR "Input file does not exist: ${filepath}")
7574
return()
76-
endif ()
75+
endif (NOT EXISTS "${filepath}")
7776

7877
get_filename_component(header_basename "${header_filepath}" NAME)
7978
set(header_contents "")
@@ -146,11 +145,11 @@ function(generate_source_file_from_header_only filepath header_filepath source_f
146145
elseif (state STREQUAL "BLOCK_COMMENT")
147146
if (char STREQUAL "/" AND prev_char STREQUAL "*")
148147
set(state "CODE")
149-
endif ()
148+
endif (char STREQUAL "/" AND prev_char STREQUAL "*")
150149
elseif (state STREQUAL "LINE_COMMENT")
151150
if (char STREQUAL "\n")
152151
set(state "CODE")
153-
endif ()
152+
endif (char STREQUAL "\n")
154153
elseif (state STREQUAL "STRING")
155154
if (escape_next_char)
156155
set(escape_next_char OFF)
@@ -218,10 +217,10 @@ function(generate_source_file_from_header_only filepath header_filepath source_f
218217
set(directive_type "IF")
219218
if (line_for_match MATCHES "^[ \t]*#[ \t]*ifdef")
220219
set(directive_type "IFDEF")
221-
endif ()
220+
endif (line_for_match MATCHES "^[ \t]*#[ \t]*ifdef")
222221
if (line_for_match MATCHES "^[ \t]*#[ \t]*ifndef")
223222
set(directive_type "IFNDEF")
224-
endif ()
223+
endif (line_for_match MATCHES "^[ \t]*#[ \t]*ifndef")
225224

226225
list(APPEND pp_conditions_stack "${directive_type};${condition_str}")
227226

@@ -230,9 +229,9 @@ function(generate_source_file_from_header_only filepath header_filepath source_f
230229
set(in_implementation_block ON)
231230
set(append_to_header OFF)
232231
set(append_to_source ON)
233-
endif ()
232+
endif (implementation_block_depth EQUAL 0)
234233
math(EXPR implementation_block_depth "${implementation_block_depth} + 1")
235-
endif ()
234+
endif (condition_str MATCHES "LIBACQUIRE_IMPLEMENTATION")
236235

237236
elseif (line_for_match MATCHES "^[ \t]*#[ \t]*else")
238237
# pass through
@@ -244,22 +243,22 @@ function(generate_source_file_from_header_only filepath header_filepath source_f
244243
if (line_for_match MATCHES "LIBACQUIRE_IMPLEMENTATION")
245244
if (implementation_block_depth GREATER 0)
246245
set(is_impl_endif ON)
247-
endif ()
248-
endif ()
246+
endif (implementation_block_depth GREATER 0)
247+
endif (line_for_match MATCHES "LIBACQUIRE_IMPLEMENTATION")
249248
if (is_impl_endif)
250249
math(EXPR implementation_block_depth "${implementation_block_depth} - 1")
251250
if (implementation_block_depth EQUAL 0)
252251
set(in_implementation_block OFF)
253252
set(append_to_header OFF)
254253
set(append_to_source ON)
255-
endif ()
256-
endif ()
254+
endif (implementation_block_depth EQUAL 0)
255+
endif (is_impl_endif)
257256
list(POP_BACK pp_conditions_stack)
258257
else ()
259258
message(WARNING "Unmatched #endif encountered: ${current_line}")
260259
endif ()
261260
endif ()
262-
endif ()
261+
endif (line_for_match MATCHES "^[ \t]*#")
263262

264263
if (append_to_source)
265264
string(APPEND source_contents "${current_line}")
@@ -274,34 +273,36 @@ function(generate_source_file_from_header_only filepath header_filepath source_f
274273
set(rbrace 0)
275274
set(lsquare 0)
276275
set(rsquare 0)
277-
endif ()
278-
endforeach ()
276+
endif (process_line)
277+
endforeach (char_index RANGE ${last_index})
279278

280279
if (NOT state STREQUAL "CODE")
281280
message(WARNING "File ended while in state: ${state}")
282-
endif ()
281+
endif (NOT state STREQUAL "CODE")
283282
if (NOT lparen EQUAL rparen OR NOT lsquare EQUAL rsquare)
284283
message(WARNING "File ended with unbalanced parentheses/brackets")
285-
endif ()
284+
endif (NOT lparen EQUAL rparen OR NOT lsquare EQUAL rsquare)
286285
if (pp_conditions_stack)
287286
message(WARNING "File ended with unbalanced preprocessor directives. Stack: ${pp_conditions_stack}")
288-
endif ()
287+
endif (pp_conditions_stack)
289288
if (NOT implementation_block_depth EQUAL 0)
290289
message(WARNING "File ended with unbalanced LIBACQUIRE_IMPLEMENTATION blocks. Depth: ${implementation_block_depth}")
291-
endif ()
290+
endif (NOT implementation_block_depth EQUAL 0)
292291

293292
file(WRITE "${header_filepath}" "${header_contents}")
294-
message(STATUS "Generated header (via character-by-character): ${header_filepath}")
293+
string(REGEX REPLACE "^${CMAKE_BINARY_DIR}." "" header_filepath_rel "${header_filepath}")
294+
message(STATUS "Generated header (via character-by-character): ${header_filepath_rel}")
295295

296+
string(REGEX REPLACE "^${CMAKE_BINARY_DIR}." "" source_filepath_rel "${source_filepath}")
296297
if (source_contents OR in_implementation_block)
297298
set(final_source_content "#include \"${header_basename}\"\n\n${source_contents}")
298299
file(WRITE "${source_filepath}" "${final_source_content}")
299-
message(STATUS "Generated source (via character-by-character): ${source_filepath}")
300+
message(STATUS "Generated source (via character-by-character): ${source_filepath_rel}")
300301
else ()
301-
message(STATUS "No implementation content found for source (via character-by-character): ${source_filepath}")
302+
message(STATUS "Failed to source gen (character-by-character): ${source_filepath_rel}")
302303
endif ()
303304

304-
endfunction()
305+
endfunction(generate_source_file_from_header_only filepath header_filepath source_filepath)
305306

306307
if (LIBACQUIRE_HEADER_ONLY)
307308
add_library("${LIBRARY_NAME}" INTERFACE "${_Header_Files}" "${Header_Files}")
@@ -336,18 +337,20 @@ else ()
336337

337338
if (EXISTS "${gen_header_file}")
338339
list(APPEND gen_header_files "${gen_header_file}")
339-
message(STATUS "Generated header: ${gen_header_file}")
340+
string(REGEX REPLACE "^${CMAKE_BINARY_DIR}." "" gen_header_file_rel "${gen_header_file}")
341+
message(STATUS "Generated header: ${gen_header_file_rel}")
340342
else ()
341343
message(WARNING "Missing generated header: ${gen_header_file}")
342344
endif ()
343345

344346
if (EXISTS "${gen_source_file}")
345347
list(APPEND gen_source_files "${gen_source_file}")
346-
message(STATUS "Generated source: ${gen_source_file}")
348+
string(REGEX REPLACE "^${CMAKE_BINARY_DIR}." "" gen_source_file_rel "${gen_source_file}")
349+
message(STATUS "Generated source: ${gen_source_file_rel}")
347350
else ()
348351
message(WARNING "Missing generated source: ${gen_source_file}")
349352
endif ()
350-
endforeach ()
353+
endforeach (header_file IN LISTS header_impls)
351354

352355
# Implement the internal implementation library as STATIC
353356
add_library("${LIBRARY_NAME}_impl" STATIC ${gen_header_files} ${gen_source_files})
@@ -364,15 +367,20 @@ else ()
364367
set_source_files_properties(${src} PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION")
365368
elseif (src MATCHES "/gen_acquire_download.c$")
366369
if (USE_LIBCURL)
367-
set_source_files_properties(${src} PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;USE_LIBCURL=1")
370+
set_source_files_properties(${src}
371+
PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;DOWNLOAD_IMPL;USE_LIBCURL=1")
368372
elseif (USE_LIBFETCH)
369-
set_source_files_properties(${src} PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;USE_LIBFETCH=1")
373+
set_source_files_properties(${src}
374+
PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;DOWNLOAD_IMPL;USE_LIBFETCH=1")
370375
elseif (USE_WININET)
371-
set_source_files_properties(${src} PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;USE_WININET=1")
376+
set_source_files_properties(${src}
377+
PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;DOWNLOAD_IMPL;USE_WININET=1")
372378
elseif (USE_OPENBSD_FTP)
373-
set_source_files_properties(${src} PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;USE_OPENBSD_FTP=1")
379+
set_source_files_properties(${src}
380+
PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;DOWNLOAD_IMPL;USE_OPENBSD_FTP=1")
374381
else ()
375-
set_source_files_properties(${src} PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;USE_LIBCURL=1")
382+
set_source_files_properties(${src}
383+
PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;DOWNLOAD_IMPL;USE_LIBCURL=1")
376384
endif ()
377385
elseif (src MATCHES "/gen_acquire_extract.c$")
378386
# For extract, could detect MINIZ or LIBARCHIVE
@@ -386,13 +394,14 @@ else ()
386394
elseif (src MATCHES "/gen_acquire_net_common.c$")
387395
set_source_files_properties(${src} PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION")
388396
elseif (src MATCHES "/gen_acquire_string_extras.c$")
389-
set_source_files_properties(${src} PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION")
397+
set_source_files_properties(${src}
398+
PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;STRCASESTR_IMPL;STRERRORLEN_IMPL")
390399
elseif (src MATCHES "/gen_acquire_url_utils.c$")
391400
set_source_files_properties(${src} PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION")
392401
else ()
393402
set_source_files_properties(${src} PROPERTIES COMPILE_DEFINITIONS "")
394403
endif ()
395-
endforeach ()
404+
endforeach (src IN LISTS gen_source_files)
396405

397406
if (USE_LIBRHASH)
398407
message(STATUS "[libacquire] Using LibRHash for checksums")
@@ -419,17 +428,12 @@ else ()
419428
if (NOT BSD)
420429
find_package(LibBSD)
421430
if (LibBSD_FOUND)
422-
if (NOT DEFINED LibBSD_LIBRARIES)
423-
set(LibBSD_LIBRARIES "${BSD_LIBRARY}")
424-
endif ()
425-
target_link_directories("${LIBRARY_NAME}_impl" PUBLIC "${LibBSD_LIBRARIES}")
426-
if (DEFINED LibBSD_INCLUDEDIR)
427-
target_include_directories("${LIBRARY_NAME}_impl" PUBLIC "${LibBSD_INCLUDEDIR}")
428-
endif ()
429-
target_compile_definitions("${LIBRARY_NAME}_impl" PUBLIC HAVE_STRNSTR=1)
430-
target_compile_definitions("${LIBRARY_NAME}_impl" PUBLIC HAVE_LIBBSD=1)
431-
endif ()
432-
endif ()
431+
target_link_libraries("${LIBRARY_NAME}_impl" PUBLIC LibBSD::LibBSD)
432+
target_compile_definitions(
433+
"${LIBRARY_NAME}_impl" PUBLIC HAVE_STRNSTR=1 HAVE_LIBBSD=1
434+
)
435+
endif (LibBSD_FOUND)
436+
endif (NOT BSD)
433437

434438
target_include_directories(
435439
"${LIBRARY_NAME}_impl"
@@ -457,7 +461,6 @@ else ()
457461
foreach (_lib ${LIBACQUIRE_LIBRARIES})
458462
target_link_libraries_once("${LIBRARY_NAME}" "${lib_vis}" "${_lib}")
459463
endforeach (_lib ${LIBACQUIRE_LIBRARIES})
460-
message(STATUS "${LIBRARY_NAME} linked_libs = ${linked_libs}")
461464
endif ()
462465

463466
include(GNUInstallDirs)
@@ -483,7 +486,6 @@ endif (DEFINED LIBACQUIRE_INCLUDE_DIR)
483486
foreach (_lib ${LIBACQUIRE_LIBRARIES})
484487
target_link_libraries_once("${LIBRARY_NAME}" "${lib_vis}" "${_lib}")
485488
endforeach (_lib ${LIBACQUIRE_LIBRARIES})
486-
message(STATUS "${LIBRARY_NAME} linked_libs = ${linked_libs}")
487489
target_link_libraries(
488490
"${LIBRARY_NAME}"
489491
"${lib_vis}"
@@ -518,7 +520,7 @@ if (NOT LIBACQUIRE_HEADER_ONLY)
518520
C
519521
OUTPUT_NAME "${PROJECT_NAME}"
520522
)
521-
endif ()
523+
endif (NOT LIBACQUIRE_HEADER_ONLY)
522524

523525
option(BUILD_OPENBSD_FTP "Build `ftp` binary from OpenBSD" OFF)
524526
if (BUILD_OPENBSD_FTP)

acquire/acquire_common_defs.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
* log level definitions, and other common values.
1010
*/
1111

12-
#ifdef __cplusplus
13-
extern "C" {
14-
#endif /* __cplusplus */
15-
1612
#ifdef __cplusplus
1713
extern "C" {
1814
#elif defined(HAS_STDBOOL) && !defined(bool)
@@ -73,7 +69,7 @@ extern "C" {
7369
#define NAME_MAX 4096
7470
#endif /* PATH_MAX */
7571

76-
#endif /* NAME_MAX */
72+
#endif /* !NAME_MAX */
7773

7874
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
7975
#define PATH_SEP "\\"

acquire/acquire_libcurl.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
#if !defined(LIBACQUIRE_LIBCURL_H) && defined(USE_LIBCURL) && \
2-
defined(LIBACQUIRE_IMPLEMENTATION)
1+
#ifndef LIBACQUIRE_LIBCURL_H
2+
#define LIBACQUIRE_LIBCURL_H
3+
4+
#if defined(USE_LIBCURL) && defined(LIBACQUIRE_IMPLEMENTATION)
35

46
/*
57
* libcurl implementation of libacquire's download API
@@ -11,10 +13,8 @@
1113
* - Elsewhere that curl supports (not tested, but shouldn't be an issue)
1214
* */
1315

14-
#define LIBACQUIRE_LIBCURL_H
15-
1616
#ifdef __cplusplus
17-
}
17+
extern "C" {
1818
#endif /* __cplusplus */
1919

2020
#include <stdint.h>
@@ -175,6 +175,7 @@ size_t write_cb(const void *buffer, const size_t sz, size_t nmemb,
175175
return 0;
176176
}
177177

178+
#if defined(LIBACQUIRE_IMPLEMENTATION) && defined(DOWNLOAD_IMPL)
178179
int download(const char *url, enum Checksum checksum, const char *hash,
179180
const char target_location[NAME_MAX], bool follow, size_t retry,
180181
size_t verbosity) {
@@ -325,6 +326,7 @@ int download(const char *url, enum Checksum checksum, const char *hash,
325326

326327
#undef handle_curl_error
327328
}
329+
#endif /* LIBACQUIRE_IMPLEMENTATION && DOWNLOAD_IMPL */
328330

329331
int download_many(const char *url[], const char *hashes[],
330332
enum Checksum checksums[], const char *target_location,
@@ -333,8 +335,9 @@ int download_many(const char *url[], const char *hashes[],
333335
}
334336

335337
#ifdef __cplusplus
336-
}
338+
} /* extern "C" */
337339
#endif /* __cplusplus */
338340

339-
#endif /* !defined(LIBACQUIRE_LIBCURL_H) && defined(USE_LIBCURL) && \
340-
defined(LIBACQUIRE_IMPLEMENTATION) */
341+
#endif /* defined(USE_LIBCURL) && defined(LIBACQUIRE_IMPLEMENTATION) */
342+
343+
#endif /* LIBACQUIRE_LIBCURL_H */

acquire/acquire_libfetch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ static int fetch(char *URL, const char *path) {
794794
const char *get_download_dir(void) { return ".downloads"; }
795795
#endif /* !DOWNLOAD_DIR_IMPL */
796796

797+
#ifdef DOWNLOAD_IMPL
797798
int download(const char *url, enum Checksum checksum, const char *hash,
798799
const char target_location[NAME_MAX], bool follow, size_t retry,
799800
size_t verbosity) {
@@ -823,6 +824,7 @@ int download(const char *url, enum Checksum checksum, const char *hash,
823824

824825
return result;
825826
}
827+
#endif /* DOWNLOAD_IMPL */
826828

827829
#ifdef __cplusplus
828830
}

acquire/acquire_openbsd_ftp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ extern "C" {
1818
const char *get_download_dir(void) { return ".downloads"; }
1919
#endif /* !DOWNLOAD_DIR_IMPL */
2020

21+
#ifdef DOWNLOAD_IMPL
2122
int download(const char *url, enum Checksum checksum, const char *hash,
2223
const char target_location[NAME_MAX], bool follow, size_t retry,
2324
size_t verbosity) {
2425
sendrequest();
2526
}
27+
#endif /* DOWNLOAD_IMPL */
2628

2729
#ifdef __cplusplus
2830
}

0 commit comments

Comments
 (0)