Skip to content

Commit

Permalink
COMP: Apple Clang 15 duplicate libraries
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thewtex committed Apr 9, 2024
1 parent 50d44dc commit 4025693
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMake/ITKModuleHeaderTest.cmake
Expand Up @@ -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 "$<$<AND:$<C_COMPILER_ID:AppleClang>,$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,15.0>>:LINKER:-no_warn_duplicate_libraries>")

add_dependencies(${_name}-all ${_test_name})
math(EXPR _test_num "${_test_num} + 1")
Expand Down
1 change: 1 addition & 0 deletions CMake/ITKModuleMacros.cmake
Expand Up @@ -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 "$<$<AND:$<C_COMPILER_ID:AppleClang>,$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,15.0>>:LINKER:-no_warn_duplicate_libraries>")
itk_module_link_dependencies()
itk_module_target(${_name})
endmacro()
2 changes: 2 additions & 0 deletions CMake/ITKModuleTest.cmake
Expand Up @@ -70,6 +70,7 @@ EM_ASM(
LINK_PUBLIC
${KIT_LIBS}
${ITKTestKernel_LIBRARIES})
target_link_options(${KIT}TestDriver PRIVATE "$<$<AND:$<C_COMPILER_ID:AppleClang>,$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,15.0>>:LINKER:-no_warn_duplicate_libraries>")
itk_module_target_label(${KIT}TestDriver)
endmacro()

Expand Down Expand Up @@ -240,6 +241,7 @@ function(
${KIT_LIBS}
GTest::GTest
GTest::Main)
target_link_options(${exe} PRIVATE "$<$<AND:$<C_COMPILER_ID:AppleClang>,$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,15.0>>:LINKER:-no_warn_duplicate_libraries>")
itk_module_target_label(${exe})

include(GoogleTest)
Expand Down
4 changes: 4 additions & 0 deletions Modules/Core/Common/test/CMakeLists.txt
Expand Up @@ -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 "$<$<AND:$<C_COMPILER_ID:AppleClang>,$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,15.0>>:LINKER:-no_warn_duplicate_libraries>")
itk_module_target_label(itkMathTest)
target_link_libraries(itkMathTest LINK_PUBLIC ${ITKCommon_LIBRARIES})
itk_add_test(
Expand All @@ -218,6 +219,7 @@ itk_add_test(
itkMathTest)

add_executable(itkSystemInformation itkSystemInformation.cxx)
target_link_options(itkSystemInformation PRIVATE "$<$<AND:$<C_COMPILER_ID:AppleClang>,$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,15.0>>:LINKER:-no_warn_duplicate_libraries>")
itk_module_target_label(itkSystemInformation)
target_link_libraries(itkSystemInformation LINK_PUBLIC ${ITKCommon_LIBRARIES})
itk_add_test(
Expand Down Expand Up @@ -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 "$<$<AND:$<C_COMPILER_ID:AppleClang>,$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,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})
Expand All @@ -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 "$<$<AND:$<C_COMPILER_ID:AppleClang>,$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,15.0>>:LINKER:-no_warn_duplicate_libraries>")
itk_module_target_label(itkObjectFactoryBasePrivateDestructor)
target_link_libraries(
itkObjectFactoryBasePrivateDestructor
Expand Down
1 change: 1 addition & 0 deletions Modules/Core/TestKernel/src/CMakeLists.txt
Expand Up @@ -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 "$<$<AND:$<C_COMPILER_ID:AppleClang>,$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,15.0>>:LINKER:-no_warn_duplicate_libraries>")

if(NOT DO_NOT_INSTALL_ITK_TEST_DRIVER) # used only by vcpkg
itk_module_target_install(itkTestDriver)
Expand Down
1 change: 1 addition & 0 deletions Modules/Filtering/FFT/test/CMakeLists.txt
Expand Up @@ -440,6 +440,7 @@ endforeach()

# Test header files circular dependencies
add_executable(ITKFFTTestCircularDependency itkTestCircularDependency.cxx)
target_link_options(ITKFFTTestCircularDependency PRIVATE "$<$<AND:$<C_COMPILER_ID:AppleClang>,$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,15.0>>:LINKER:-no_warn_duplicate_libraries>")
target_link_libraries(ITKFFTTestCircularDependency ${ITKFFT-Test_LIBRARIES})
itk_add_test(
NAME
Expand Down
4 changes: 4 additions & 0 deletions Modules/Nonunit/IntegratedTest/test/CMakeLists.txt
Expand Up @@ -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 "$<$<AND:$<C_COMPILER_ID:AppleClang>,$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,15.0>>:LINKER:-no_warn_duplicate_libraries>")
itk_module_target_label(itkAlgorithmsPrintTest)
target_link_libraries(itkAlgorithmsPrintTest LINK_PUBLIC ${ITKIntegratedTest-Test_LIBRARIES})
itk_add_test(
Expand All @@ -25,6 +26,7 @@ itk_add_test(
itkAlgorithmsPrintTest)

add_executable(itkAlgorithmsPrintTest2 itkAlgorithmsPrintTest2.cxx)
target_link_options(itkAlgorithmsPrintTest2 PRIVATE "$<$<AND:$<C_COMPILER_ID:AppleClang>,$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,15.0>>:LINKER:-no_warn_duplicate_libraries>")
itk_module_target_label(itkAlgorithmsPrintTest2)
target_link_libraries(itkAlgorithmsPrintTest2 LINK_PUBLIC ${ITKIntegratedTest-Test_LIBRARIES})
itk_add_test(
Expand All @@ -34,6 +36,7 @@ itk_add_test(
itkAlgorithmsPrintTest)

add_executable(itkAlgorithmsPrintTest3 itkAlgorithmsPrintTest3.cxx)
target_link_options(itkAlgorithmsPrintTest3 PRIVATE "$<$<AND:$<C_COMPILER_ID:AppleClang>,$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,15.0>>:LINKER:-no_warn_duplicate_libraries>")
itk_module_target_label(itkAlgorithmsPrintTest3)
target_link_libraries(itkAlgorithmsPrintTest3 LINK_PUBLIC ${ITKIntegratedTest-Test_LIBRARIES})
itk_add_test(
Expand All @@ -43,6 +46,7 @@ itk_add_test(
itkAlgorithmsPrintTest)

add_executable(itkAlgorithmsPrintTest4 itkAlgorithmsPrintTest4.cxx)
target_link_options(itkAlgorithmsPrintTest4 PRIVATE "$<$<AND:$<C_COMPILER_ID:AppleClang>,$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,15.0>>:LINKER:-no_warn_duplicate_libraries>")
itk_module_target_label(itkAlgorithmsPrintTest4)
target_link_libraries(itkAlgorithmsPrintTest4 LINK_PUBLIC ${ITKIntegratedTest-Test_LIBRARIES})
itk_add_test(
Expand Down

0 comments on commit 4025693

Please sign in to comment.