@@ -20,7 +20,7 @@ if (LIBACQUIRE_HEADER_ONLY)
2020 set (lib_type "INTERFACE" )
2121else ()
2222 set (lib_type "PUBLIC" )
23- endif (LIBACQUIRE_HEADER_ONLY )
23+ endif ()
2424
2525set (_Header_Files "" )
2626
@@ -69,11 +69,10 @@ source_group("Header Files" FILES "${Header_Files}")
6969option (DEBUG_TOKENISER "OFF" )
7070
7171function (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
306307if (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} " )
461464endif ()
462465
463466include (GNUInstallDirs)
@@ -483,7 +486,6 @@ endif (DEFINED LIBACQUIRE_INCLUDE_DIR)
483486foreach (_lib ${LIBACQUIRE_LIBRARIES} )
484487 target_link_libraries_once("${LIBRARY_NAME} " "${lib_vis} " "${_lib} " )
485488endforeach (_lib ${LIBACQUIRE_LIBRARIES} )
486- message (STATUS "${LIBRARY_NAME} linked_libs = ${linked_libs} " )
487489target_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
523525option (BUILD_OPENBSD_FTP "Build `ftp` binary from OpenBSD" OFF )
524526if (BUILD_OPENBSD_FTP)
0 commit comments