Files
CMake/Tests/RunCMake/CMP0156/CMP0156-Common.cmake
Marc Chevrier 7b99c42e57 Link step: Enable to configure deduplication of libraries
Some platforms, Apple or Windows for instance, do not require to duplicate
static libraries to resolve mutual dependencies. Moreover, Xcode version 15
emits a warning if a library is duplicated.
On Windows, enable a better control of libraries order.

Fixes: #20722, #25297
2023-11-09 19:20:40 +01:00

28 lines
912 B
CMake

enable_language(C)
# ensure link is successful in case of circular dependency
add_library(lib1 STATIC lib1.c)
add_library(lib2 STATIC lib2.c)
target_link_libraries(lib1 PRIVATE lib2)
target_link_libraries(lib2 PRIVATE lib1)
add_executable(main main.c)
target_link_libraries(main PRIVATE lib1)
if (APPLE_TEST)
target_link_options(main PRIVATE "LINKER:-fatal_warnings")
else()
target_link_options(main PRIVATE "$<$<AND:$<NOT:$<TARGET_POLICY:CMP0156>>,$<C_COMPILER_ID:AppleClang>,$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,15.0>>:LINKER:-no_warn_duplicate_libraries>")
endif()
add_library(lib3 SHARED lib3.c)
add_library(lib4 STATIC lib4.c)
target_link_libraries(lib4 PRIVATE lib3)
# link specifying a shared library not directly used by the target
# on Windows, with CMP0156=NEW, lib3 is specified before lib4 on link step
add_executable(main2 main2.c)
target_link_libraries(main2 PRIVATE lib3 lib4)