From 40256933f8669c9c68bd67d4582f38af31464f8e Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Tue, 9 Apr 2024 12:26:19 -0400 Subject: [PATCH] COMP: Apple Clang 15 duplicate libraries Addresses: ld: warning: ignoring duplicate libraries: '-lm' With Apple Clang 15. This approach works with older CMake but based on: https://gitlab.kitware.com/cmake/cmake/-/commit/7b99c42e57b11afe818827ac537ca020c020addd --- CMake/ITKModuleHeaderTest.cmake | 1 + CMake/ITKModuleMacros.cmake | 1 + CMake/ITKModuleTest.cmake | 2 ++ Modules/Core/Common/test/CMakeLists.txt | 4 ++++ Modules/Core/TestKernel/src/CMakeLists.txt | 1 + Modules/Filtering/FFT/test/CMakeLists.txt | 1 + Modules/Nonunit/IntegratedTest/test/CMakeLists.txt | 4 ++++ 7 files changed, 14 insertions(+) diff --git a/CMake/ITKModuleHeaderTest.cmake b/CMake/ITKModuleHeaderTest.cmake index 67917cc07dd..555d4adac10 100644 --- a/CMake/ITKModuleHeaderTest.cmake +++ b/CMake/ITKModuleHeaderTest.cmake @@ -86,6 +86,7 @@ macro(itk_module_headertest _name) ${${_name}_SOURCE_DIR} ${${_name}_BINARY_DIR} ${MAXIMUM_NUMBER_OF_HEADERS} ${_test_num}) add_executable(${_test_name} ${_header_test_src}) target_link_libraries(${_test_name} PUBLIC ${${_name}_LIBRARIES} itksys) + target_link_options(${_test_name} PRIVATE "$<$,$,15.0>>:LINKER:-no_warn_duplicate_libraries>") add_dependencies(${_name}-all ${_test_name}) math(EXPR _test_num "${_test_num} + 1") diff --git a/CMake/ITKModuleMacros.cmake b/CMake/ITKModuleMacros.cmake index d0375b494a0..6c988b89923 100644 --- a/CMake/ITKModuleMacros.cmake +++ b/CMake/ITKModuleMacros.cmake @@ -492,6 +492,7 @@ macro(itk_module_add_library _name) endif() add_library(${_name} ${_LIBRARY_BUILD_TYPE} ${ARGN}) target_compile_features(${_name} PUBLIC cxx_std_${CMAKE_CXX_STANDARD}) + target_link_options(${_name} PRIVATE "$<$,$,15.0>>:LINKER:-no_warn_duplicate_libraries>") itk_module_link_dependencies() itk_module_target(${_name}) endmacro() diff --git a/CMake/ITKModuleTest.cmake b/CMake/ITKModuleTest.cmake index acd87fc5177..8659779c1dc 100644 --- a/CMake/ITKModuleTest.cmake +++ b/CMake/ITKModuleTest.cmake @@ -70,6 +70,7 @@ EM_ASM( LINK_PUBLIC ${KIT_LIBS} ${ITKTestKernel_LIBRARIES}) + target_link_options(${KIT}TestDriver PRIVATE "$<$,$,15.0>>:LINKER:-no_warn_duplicate_libraries>") itk_module_target_label(${KIT}TestDriver) endmacro() @@ -240,6 +241,7 @@ function( ${KIT_LIBS} GTest::GTest GTest::Main) + target_link_options(${exe} PRIVATE "$<$,$,15.0>>:LINKER:-no_warn_duplicate_libraries>") itk_module_target_label(${exe}) include(GoogleTest) diff --git a/Modules/Core/Common/test/CMakeLists.txt b/Modules/Core/Common/test/CMakeLists.txt index 8123e5a9f61..78846a40f49 100644 --- a/Modules/Core/Common/test/CMakeLists.txt +++ b/Modules/Core/Common/test/CMakeLists.txt @@ -209,6 +209,7 @@ set(BASELINE "${ITK_DATA_ROOT}/Baseline/Common") set(TEMP ${ITK_TEST_OUTPUT_DIR}) add_executable(itkMathTest itkMathTest.cxx) +target_link_options(itkMathTest PRIVATE "$<$,$,15.0>>:LINKER:-no_warn_duplicate_libraries>") itk_module_target_label(itkMathTest) target_link_libraries(itkMathTest LINK_PUBLIC ${ITKCommon_LIBRARIES}) itk_add_test( @@ -218,6 +219,7 @@ itk_add_test( itkMathTest) add_executable(itkSystemInformation itkSystemInformation.cxx) +target_link_options(itkSystemInformation PRIVATE "$<$,$,15.0>>:LINKER:-no_warn_duplicate_libraries>") itk_module_target_label(itkSystemInformation) target_link_libraries(itkSystemInformation LINK_PUBLIC ${ITKCommon_LIBRARIES}) itk_add_test( @@ -1767,6 +1769,7 @@ if(NOT ITK_BUILD_SHARED_LIBS ".*-static.*") macro(BuildSharedTestLibrary _name _type) add_library(SharedTestLibrary${_name} ${_type} SharedTestLibrary${_name}.cxx) + target_link_options(SharedTestLibrary${_name} PRIVATE "$<$,$,15.0>>:LINKER:-no_warn_duplicate_libraries>") itk_module_target_label(SharedTestLibrary${_name}) target_link_libraries(SharedTestLibrary${_name} LINK_PUBLIC ${ITKCommon_LIBRARIES}) set_property(TARGET SharedTestLibrary${_name} PROPERTY LIBRARY_OUTPUT_DIRECTORY ${ITK_TEST_OUTPUT_DIR}) @@ -1784,6 +1787,7 @@ if(NOT ITK_BUILD_SHARED_LIBS buildsharedtestlibrary(A SHARED) buildsharedtestlibrary(B SHARED) add_executable(itkObjectFactoryBasePrivateDestructor itkObjectFactoryBasePrivateDestructor.cxx) + target_link_options(itkObjectFactoryBasePrivateDestructor PRIVATE "$<$,$,15.0>>:LINKER:-no_warn_duplicate_libraries>") itk_module_target_label(itkObjectFactoryBasePrivateDestructor) target_link_libraries( itkObjectFactoryBasePrivateDestructor diff --git a/Modules/Core/TestKernel/src/CMakeLists.txt b/Modules/Core/TestKernel/src/CMakeLists.txt index e363d6431dc..5ae5b75de02 100644 --- a/Modules/Core/TestKernel/src/CMakeLists.txt +++ b/Modules/Core/TestKernel/src/CMakeLists.txt @@ -9,6 +9,7 @@ if(NOT DO_NOT_BUILD_ITK_TEST_DRIVER) ${ITKTestKernel_LIBRARIES}) itk_module_target_label(itkTestDriver) itk_module_target_export(itkTestDriver) + target_link_options(itkTestDriver PRIVATE "$<$,$,15.0>>:LINKER:-no_warn_duplicate_libraries>") if(NOT DO_NOT_INSTALL_ITK_TEST_DRIVER) # used only by vcpkg itk_module_target_install(itkTestDriver) diff --git a/Modules/Filtering/FFT/test/CMakeLists.txt b/Modules/Filtering/FFT/test/CMakeLists.txt index ca553cd16ea..bb742fca56a 100644 --- a/Modules/Filtering/FFT/test/CMakeLists.txt +++ b/Modules/Filtering/FFT/test/CMakeLists.txt @@ -440,6 +440,7 @@ endforeach() # Test header files circular dependencies add_executable(ITKFFTTestCircularDependency itkTestCircularDependency.cxx) +target_link_options(ITKFFTTestCircularDependency PRIVATE "$<$,$,15.0>>:LINKER:-no_warn_duplicate_libraries>") target_link_libraries(ITKFFTTestCircularDependency ${ITKFFT-Test_LIBRARIES}) itk_add_test( NAME diff --git a/Modules/Nonunit/IntegratedTest/test/CMakeLists.txt b/Modules/Nonunit/IntegratedTest/test/CMakeLists.txt index a4890ad145e..d9cde27e7a4 100644 --- a/Modules/Nonunit/IntegratedTest/test/CMakeLists.txt +++ b/Modules/Nonunit/IntegratedTest/test/CMakeLists.txt @@ -16,6 +16,7 @@ set(TEMP ${ITK_TEST_OUTPUT_DIR}) # temporary solution for all print tests. Each module should have its own print test later. add_executable(itkAlgorithmsPrintTest itkAlgorithmsPrintTest.cxx) +target_link_options(itkAlgorithmsPrintTest PRIVATE "$<$,$,15.0>>:LINKER:-no_warn_duplicate_libraries>") itk_module_target_label(itkAlgorithmsPrintTest) target_link_libraries(itkAlgorithmsPrintTest LINK_PUBLIC ${ITKIntegratedTest-Test_LIBRARIES}) itk_add_test( @@ -25,6 +26,7 @@ itk_add_test( itkAlgorithmsPrintTest) add_executable(itkAlgorithmsPrintTest2 itkAlgorithmsPrintTest2.cxx) +target_link_options(itkAlgorithmsPrintTest2 PRIVATE "$<$,$,15.0>>:LINKER:-no_warn_duplicate_libraries>") itk_module_target_label(itkAlgorithmsPrintTest2) target_link_libraries(itkAlgorithmsPrintTest2 LINK_PUBLIC ${ITKIntegratedTest-Test_LIBRARIES}) itk_add_test( @@ -34,6 +36,7 @@ itk_add_test( itkAlgorithmsPrintTest) add_executable(itkAlgorithmsPrintTest3 itkAlgorithmsPrintTest3.cxx) +target_link_options(itkAlgorithmsPrintTest3 PRIVATE "$<$,$,15.0>>:LINKER:-no_warn_duplicate_libraries>") itk_module_target_label(itkAlgorithmsPrintTest3) target_link_libraries(itkAlgorithmsPrintTest3 LINK_PUBLIC ${ITKIntegratedTest-Test_LIBRARIES}) itk_add_test( @@ -43,6 +46,7 @@ itk_add_test( itkAlgorithmsPrintTest) add_executable(itkAlgorithmsPrintTest4 itkAlgorithmsPrintTest4.cxx) +target_link_options(itkAlgorithmsPrintTest4 PRIVATE "$<$,$,15.0>>:LINKER:-no_warn_duplicate_libraries>") itk_module_target_label(itkAlgorithmsPrintTest4) target_link_libraries(itkAlgorithmsPrintTest4 LINK_PUBLIC ${ITKIntegratedTest-Test_LIBRARIES}) itk_add_test(