@@ -3,6 +3,7 @@ set(LIBRARY_NAME "${PROJECT_NAME}")
33
44include ("${CMAKE_SOURCE_DIR} /cmake/FindCurlCustom.cmake" )
55include ("${CMAKE_SOURCE_DIR} /cmake/lib${PROJECT_NAME} _helpers.cmake" )
6+ include ("${CMAKE_SOURCE_DIR} /cmake/target_link_libraries_once.cmake" )
67
78include (GNUInstallDirs)
89set (installable_libs "" )
@@ -316,10 +317,10 @@ else ()
316317 "acquire_download.h"
317318 "acquire_extract.h"
318319 "acquire_fileutils.h"
320+ "acquire_librhash.h"
319321 "acquire_net_common.h"
320322 "acquire_string_extras.h"
321323 "acquire_url_utils.h"
322- "acquire_librhash.h"
323324 )
324325
325326 foreach (header_file IN LISTS header_impls)
@@ -336,17 +337,17 @@ else ()
336337 if (EXISTS "${gen_header_file} " )
337338 list (APPEND gen_header_files "${gen_header_file} " )
338339 message (STATUS "Generated header: ${gen_header_file} " )
339- else ()
340+ else ()
340341 message (WARNING "Missing generated header: ${gen_header_file} " )
341- endif ()
342+ endif ()
342343
343344 if (EXISTS "${gen_source_file} " )
344345 list (APPEND gen_source_files "${gen_source_file} " )
345346 message (STATUS "Generated source: ${gen_source_file} " )
346- else ()
347+ else ()
347348 message (WARNING "Missing generated source: ${gen_source_file} " )
348- endif ()
349- endforeach ()
349+ endif ()
350+ endforeach ()
350351
351352 # Implement the internal implementation library as STATIC
352353 add_library ("${LIBRARY_NAME} _impl" STATIC ${gen_header_files} ${gen_source_files} )
@@ -370,57 +371,65 @@ else ()
370371 set_source_files_properties (${src} PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;USE_WININET=1" )
371372 elseif (USE_OPENBSD_FTP)
372373 set_source_files_properties (${src} PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;USE_OPENBSD_FTP=1" )
373- else ()
374+ else ()
374375 set_source_files_properties (${src} PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;USE_LIBCURL=1" )
375- endif ()
376+ endif ()
376377 elseif (src MATCHES "/gen_acquire_extract.c$" )
377378 # For extract, could detect MINIZ or LIBARCHIVE
378379 if (USE_MINIZ)
379380 set_source_files_properties (${src} PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;USE_MINIZ=1" )
380381 elseif (USE_LIBARCHIVE)
381382 set_source_files_properties (${src} PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION;USE_LIBARCHIVE=1" )
382- else ()
383+ else ()
383384 set_source_files_properties (${src} PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION" )
384- endif ()
385+ endif ()
385386 elseif (src MATCHES "/gen_acquire_net_common.c$" )
386387 set_source_files_properties (${src} PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION" )
387388 elseif (src MATCHES "/gen_acquire_string_extras.c$" )
388389 set_source_files_properties (${src} PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION" )
389390 elseif (src MATCHES "/gen_acquire_url_utils.c$" )
390391 set_source_files_properties (${src} PROPERTIES COMPILE_DEFINITIONS "LIBACQUIRE_IMPLEMENTATION" )
391- else ()
392+ else ()
392393 set_source_files_properties (${src} PROPERTIES COMPILE_DEFINITIONS "" )
393- endif ()
394- endforeach ()
394+ endif ()
395+ endforeach ()
395396
396397 if (USE_LIBRHASH)
397398 message (STATUS "[libacquire] Using LibRHash for checksums" )
399+
398400 find_package (LibRHash REQUIRED)
399- target_include_directories ("${LIBRARY_NAME} _impl" PUBLIC "${LibRHash_INCLUDE_DIRS} " )
400- list (REMOVE_DUPLICATES LibRHash_LIBRARIES)
401- target_link_libraries ("${LIBRARY_NAME} _impl" PUBLIC "${LibRHash_LIBRARIES} " )
402401 target_compile_definitions ("${LIBRARY_NAME} _impl" PRIVATE USE_LIBRHASH=1)
402+
403+ get_target_property (linked_libs "${LIBRARY_NAME} _impl" LINK_LIBRARIES )
404+ list (FIND linked_libs "${_lib} " lib_index)
405+ if (lib_index EQUAL -1)
406+ target_include_directories ("${LIBRARY_NAME} _impl" PUBLIC "${LibRHash_INCLUDE_DIRS} " )
407+ list (REMOVE_DUPLICATES LibRHash_LIBRARIES)
408+ target_link_libraries ("${LIBRARY_NAME} _impl" PUBLIC "${LibRHash_LIBRARIES} " )
409+ else ()
410+ message (STATUS "${LIBRARY_NAME} _impl already linked with '${_lib} '" )
411+ endif (lib_index EQUAL -1)
403412 elseif (USE_CRC32C)
404413 message (STATUS "[libacquire] Using internal CRC32C implementation" )
405414 target_compile_definitions ("${LIBRARY_NAME} _impl" PRIVATE USE_CRC32C=1)
406- else ()
415+ else ()
407416 message (FATAL_ERROR "No checksum implementation selected: define USE_LIBRHASH or USE_CRC32C" )
408- endif ()
417+ endif ()
409418
410419 if (NOT BSD)
411420 find_package (LibBSD)
412421 if (LibBSD_FOUND)
413422 if (NOT DEFINED LibBSD_LIBRARIES)
414423 set (LibBSD_LIBRARIES "${BSD_LIBRARY} " )
415- endif ()
424+ endif ()
416425 target_link_directories ("${LIBRARY_NAME} _impl" PUBLIC "${LibBSD_LIBRARIES} " )
417426 if (DEFINED LibBSD_INCLUDEDIR)
418427 target_include_directories ("${LIBRARY_NAME} _impl" PUBLIC "${LibBSD_INCLUDEDIR} " )
419- endif ()
428+ endif ()
420429 target_compile_definitions ("${LIBRARY_NAME} _impl" PUBLIC HAVE_STRNSTR=1)
421430 target_compile_definitions ("${LIBRARY_NAME} _impl" PUBLIC HAVE_LIBBSD=1)
422- endif ()
423- endif ()
431+ endif ()
432+ endif ()
424433
425434 target_include_directories (
426435 "${LIBRARY_NAME} _impl"
@@ -446,16 +455,10 @@ else ()
446455 set (lib_vis "PUBLIC" )
447456
448457 foreach (_lib ${LIBACQUIRE_LIBRARIES} )
449- get_target_property (linked_libs "${LIBRARY_NAME} " LINK_LIBRARIES )
450- list (FIND linked_libs "${_lib} " lib_index)
451- if (lib_index EQUAL -1)
452- target_link_libraries ("${LIBRARY_NAME} " "${lib_vis} " "${_lib} " )
453- else ()
454- message (STATUS "${LIBRARY_NAME} already linked with '${_lib} '" )
455- endif ()
458+ target_link_libraries_once("${LIBRARY_NAME} " "${lib_vis} " "${_lib} " )
456459 endforeach (_lib ${LIBACQUIRE_LIBRARIES} )
457460 message (STATUS "${LIBRARY_NAME} linked_libs = ${linked_libs} " )
458- endif ()
461+ endif ()
459462
460463include (GNUInstallDirs)
461464if (LIBACQUIRE_HEADER_ONLY)
@@ -478,13 +481,7 @@ if (DEFINED LIBACQUIRE_INCLUDE_DIR)
478481endif (DEFINED LIBACQUIRE_INCLUDE_DIR)
479482
480483foreach (_lib ${LIBACQUIRE_LIBRARIES} )
481- get_target_property (linked_libs "${LIBRARY_NAME} " LINK_LIBRARIES )
482- list (FIND linked_libs "${_lib} " lib_index)
483- if (lib_index EQUAL -1)
484- target_link_libraries ("${LIBRARY_NAME} " "${lib_vis} " "${_lib} " )
485- else ()
486- message (STATUS "${LIBRARY_NAME} already linked with '${_lib} '" )
487- endif ()
484+ target_link_libraries_once("${LIBRARY_NAME} " "${lib_vis} " "${_lib} " )
488485endforeach (_lib ${LIBACQUIRE_LIBRARIES} )
489486message (STATUS "${LIBRARY_NAME} linked_libs = ${linked_libs} " )
490487target_link_libraries (
@@ -521,7 +518,7 @@ if (NOT LIBACQUIRE_HEADER_ONLY)
521518 C
522519 OUTPUT_NAME "${PROJECT_NAME} "
523520 )
524- endif ()
521+ endif ()
525522
526523option (BUILD_OPENBSD_FTP "Build `ftp` binary from OpenBSD" OFF )
527524if (BUILD_OPENBSD_FTP)
@@ -538,8 +535,8 @@ endif (BUILD_FREEBSD_LIBFETCH OR USE_MY_LIBFETCH)
538535#######################################
539536
540537# setup the version numbering
541- set_property (TARGET "${LIBRARY_NAME} " PROPERTY VERSION "1.0.0 " )
542- set_property (TARGET "${LIBRARY_NAME} " PROPERTY SOVERSION "1 " )
538+ set_property (TARGET "${LIBRARY_NAME} " PROPERTY VERSION "${ ${PROJECT_NAME} _VERSION} " )
539+ set_property (TARGET "${LIBRARY_NAME} " PROPERTY SOVERSION "${ ${PROJECT_NAME} _VERSION_MAJOR} " )
543540
544541# install rules
545542list (APPEND installable_libs "${LIBRARY_NAME} " "${PROJECT_NAME} _compiler_flags" )
0 commit comments