Commit 7776ce98 authored by Brad King's avatar Brad King
Browse files

Tests: Add cases for usage requirements of linked object libs

Add tests to cover transitive usage requirements on installation and
export of targets that link to object libraries.

Issue: #14778
parent bafe655b
Pipeline #93062 passed with stage
......@@ -88,7 +88,17 @@ else()
set(maybe_OBJECTS_DESTINATION "")
endif()
add_library(testLib9Obj OBJECT testLib9Obj.c)
cmake_policy(PUSH)
cmake_policy(SET CMP0022 NEW)
add_library(testLib9ObjPub OBJECT testLib9ObjPub.c)
target_compile_definitions(testLib9ObjPub INTERFACE testLib9ObjPub_USED)
add_library(testLib9ObjPriv OBJECT testLib9ObjPriv.c)
target_compile_definitions(testLib9ObjPriv INTERFACE testLib9ObjPriv_USED)
add_library(testLib9ObjIface OBJECT testLib9ObjIface.c)
target_compile_definitions(testLib9ObjIface INTERFACE testLib9ObjIface_USED)
add_library(testLib9 STATIC testLib9.c)
target_link_libraries(testLib9 INTERFACE testLib9ObjIface PUBLIC testLib9ObjPub PRIVATE testLib9ObjPriv)
cmake_policy(POP)
# Test using the target_link_libraries command to set the
# LINK_INTERFACE_LIBRARIES* properties. We construct two libraries
......@@ -486,6 +496,7 @@ install(
testExe1 testLib1 testLib2 testExe2 testLib3 testLib4 testExe3 testExe4
testExe2lib testLib4lib testLib4libdbg testLib4libopt
testLib6 testLib7 testLib8
testLib9
testLibCycleA testLibCycleB
testLibNoSONAME
cmp0022NEW cmp0022OLD
......@@ -500,7 +511,7 @@ install(
)
install(
TARGETS
testLib9Obj
testLib9ObjPub testLib9ObjPriv testLib9ObjIface
EXPORT exp
)
if (APPLE)
......@@ -553,7 +564,7 @@ export(TARGETS testExe1 testLib1 testLib2 testLib3
)
export(TARGETS testExe2 testLib4 testLib5 testLib6 testLib7 testExe3 testExe4 testExe2lib
testLib8
testLib9Obj
testLib9 testLib9ObjPub testLib9ObjPriv testLib9ObjIface
testLib4lib testLib4libdbg testLib4libopt
testLibCycleA testLibCycleB
testLibNoSONAME
......
#ifndef testLib9ObjPub_USED
#error "testLib9ObjPub_USED not defined!"
#endif
#ifndef testLib9ObjPriv_USED
#error "testLib9ObjPriv_USED not defined!"
#endif
#ifdef testLib9ObjIface_USED
#error "testLib9ObjIface_USED defined but should not be!"
#endif
int testLib9ObjPub(void);
int testLib9ObjPriv(void);
int testLib9(void)
{
return (testLib9ObjPub() + testLib9ObjPriv());
}
/* Duplicate symbols from other sources to verify that this source
is not included when the object library is used. */
int testLib9ObjMissing(void);
int testLib9ObjPub(void)
{
return testLib9ObjMissing();
}
int testLib9ObjPriv(void)
{
return testLib9ObjMissing();
}
int testLib9ObjPriv(void)
{
return 0;
}
......@@ -231,26 +231,41 @@ target_link_libraries(imp_lib1b bld_testLib2)
if(NOT CMAKE_GENERATOR STREQUAL "Xcode" OR NOT CMAKE_OSX_ARCHITECTURES MATCHES "[;$]")
set(bld_objlib_type OBJECT_LIBRARY)
# Create a executable that is using objects imported from the install tree
add_executable(imp_testLib8 imp_testLib8.c $<TARGET_OBJECTS:exp_testLib8>)
# Create executables using objects imported from the install tree
add_executable(imp_testLib8_src imp_testLib8.c $<TARGET_OBJECTS:exp_testLib8>)
add_executable(imp_testLib8_link imp_testLib8.c)
target_link_libraries(imp_testLib8_link exp_testLib8)
if(NOT CMAKE_GENERATOR STREQUAL "Xcode" OR NOT XCODE_VERSION VERSION_LESS 5)
# Create a executable that is using objects imported from the build tree
add_executable(imp_testLib8b imp_testLib8.c $<TARGET_OBJECTS:bld_testLib8>)
# Create executables using objects imported from the build tree
add_executable(imp_testLib8b_src imp_testLib8.c $<TARGET_OBJECTS:bld_testLib8>)
add_executable(imp_testLib8b_link imp_testLib8.c)
target_link_libraries(imp_testLib8b_link bld_testLib8)
endif()
else()
set(bld_objlib_type INTERFACE_LIBRARY)
endif()
# Create an executable that uses a library imported from the install tree
# that itself was built using an object library. Verify we get the usage
# requirements.
add_executable(imp_testLib9 imp_testLib9.c)
target_link_libraries(imp_testLib9 exp_testLib9)
# Similarly for importing from the build tree.
add_executable(imp_testLib9b imp_testLib9.c)
target_link_libraries(imp_testLib9b bld_testLib9)
# Check that object libraries were transformed on export as expected.
get_property(type TARGET exp_testLib9Obj PROPERTY TYPE)
if(NOT type STREQUAL INTERFACE_LIBRARY)
message(FATAL_ERROR "exp_testLib9Obj type is '${type}', not 'INTERFACE_LIBRARY'")
endif()
get_property(type TARGET bld_testLib9Obj PROPERTY TYPE)
if(NOT type STREQUAL "${bld_objlib_type}")
message(FATAL_ERROR "bld_testLib9Obj type is '${type}', not '${bld_objlib_type}'")
endif()
foreach(vis Pub Priv Iface)
get_property(type TARGET exp_testLib9Obj${vis} PROPERTY TYPE)
if(NOT type STREQUAL INTERFACE_LIBRARY)
message(FATAL_ERROR "exp_testLib9Obj${vis} type is '${type}', not 'INTERFACE_LIBRARY'")
endif()
get_property(type TARGET bld_testLib9Obj${vis} PROPERTY TYPE)
if(NOT type STREQUAL "${bld_objlib_type}")
message(FATAL_ERROR "bld_testLib9Obj${vis} type is '${type}', not '${bld_objlib_type}'")
endif()
endforeach()
#-----------------------------------------------------------------------------
# Test that handling imported targets, including transitive dependencies,
......
#ifndef testLib9ObjPub_USED
#error "testLib9ObjPub_USED not defined!"
#endif
#ifdef testLib9ObjPriv_USED
#error "testLib9ObjPriv_USED defined but should not be!"
#endif
#ifndef testLib9ObjIface_USED
#error "testLib9ObjIface_USED not defined!"
#endif
int testLib9(void);
int main()
{
return testLib9();
}
CMake Error: install\(EXPORT "exp" ...\) includes target "UseA" which requires target "A" that is not in the export set.
add_library(A OBJECT a.c)
add_library(UseA STATIC)
target_link_libraries(UseA PUBLIC A)
install(TARGETS UseA EXPORT exp ARCHIVE DESTINATION lib)
install(EXPORT exp DESTINATION lib/cmake/exp)
add_library(A OBJECT a.c)
add_library(UseA STATIC)
target_link_libraries(UseA PUBLIC A)
install(TARGETS UseA A EXPORT exp ARCHIVE DESTINATION lib)
install(EXPORT exp DESTINATION lib/cmake/exp)
......@@ -11,6 +11,8 @@ if(RunCMake_GENERATOR STREQUAL "Xcode" AND "$ENV{CMAKE_OSX_ARCHITECTURES}" MATCH
else()
run_cmake(Import)
run_cmake(Install)
run_cmake(InstallLinkedObj1)
run_cmake(InstallLinkedObj2)
endif()
run_cmake(Export)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment