fix(SharedLibrary): disable shared lib tests in static build #5069

This commit is contained in:
Alex Fabijanic
2025-12-05 15:47:17 -06:00
parent 4904acd257
commit 709601dfa0
3 changed files with 72 additions and 40 deletions

View File

@@ -62,46 +62,51 @@ set_target_properties(TestApp PROPERTIES
)
target_link_libraries(TestApp PUBLIC Poco::Foundation)
# TestLibrary
add_library(TestLibrary SHARED src/TestLibrary.cpp src/TestPlugin.cpp src/TestPlugin.h)
set_target_properties(TestLibrary PROPERTIES
DEBUG_POSTFIX "d"
# The test requires the library named TestLibrary. By default it is prefixed with lib.
PREFIX ""
)
add_dependencies(Foundation-testrunner TestApp)
# The test is run in the runtime directory. So the TestLibrary is built there too because it is used by the tests
set_target_properties(TestLibrary PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
target_link_libraries(TestLibrary PUBLIC Poco::Foundation)
add_dependencies(Foundation-testrunner TestApp TestLibrary)
# TestLibraryMissingDeps - a library with missing dependencies for testing findMissingDependencies
# Build a stub library that TestLibraryMissingDeps links against
# The test will delete it at runtime to simulate a missing dependency
add_library(NonExistentLibrary SHARED src/NonExistentStub.c)
set_target_properties(NonExistentLibrary PROPERTIES
DEBUG_POSTFIX "d"
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
)
# For multi-config generators (Visual Studio), set per-configuration archive output
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG_UPPER)
set_target_properties(NonExistentLibrary PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER}}
# TestLibrary and related shared libraries - only for shared library builds
# SharedLibrary and ClassLoader tests require dynamically loadable libraries
if(BUILD_SHARED_LIBS)
add_library(TestLibrary SHARED src/TestLibrary.cpp src/TestPlugin.cpp src/TestPlugin.h)
set_target_properties(TestLibrary PROPERTIES
DEBUG_POSTFIX "d"
# The test requires the library named TestLibrary. By default it is prefixed with lib.
PREFIX ""
)
endforeach()
add_library(TestLibraryMissingDeps SHARED src/TestLibraryMissingDeps.cpp)
set_target_properties(TestLibraryMissingDeps PROPERTIES
DEBUG_POSTFIX "d"
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
target_link_libraries(TestLibraryMissingDeps PUBLIC Poco::Foundation NonExistentLibrary)
add_dependencies(TestLibraryMissingDeps NonExistentLibrary)
# The test is run in the runtime directory. So the TestLibrary is built there too because it is used by the tests
set_target_properties(TestLibrary PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
target_link_libraries(TestLibrary PUBLIC Poco::Foundation)
add_dependencies(Foundation-testrunner TestLibraryMissingDeps)
add_dependencies(Foundation-testrunner TestLibrary)
# TestLibraryMissingDeps - a library with missing dependencies for testing findMissingDependencies
# Build a stub library that TestLibraryMissingDeps links against
# The test will delete it at runtime to simulate a missing dependency
add_library(NonExistentLibrary SHARED src/NonExistentStub.c)
set_target_properties(NonExistentLibrary PROPERTIES
DEBUG_POSTFIX "d"
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
)
# For multi-config generators (Visual Studio), set per-configuration archive output
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG_UPPER)
set_target_properties(NonExistentLibrary PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER}}
)
endforeach()
add_library(TestLibraryMissingDeps SHARED src/TestLibraryMissingDeps.cpp)
set_target_properties(TestLibraryMissingDeps PROPERTIES
DEBUG_POSTFIX "d"
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
target_link_libraries(TestLibraryMissingDeps PUBLIC Poco::Foundation NonExistentLibrary)
add_dependencies(TestLibraryMissingDeps NonExistentLibrary)
add_dependencies(Foundation-testrunner TestLibraryMissingDeps)
endif()

View File

@@ -49,6 +49,10 @@ template class ClassLoader<TestPlugin>;
void ClassLoaderTest::testClassLoader1()
{
#ifdef POCO_STATIC
return; // Skip test in static builds where TestLibrary is not built
#endif
std::string libraryPath = getFullName("TestLibrary");
ClassLoader<TestPlugin> cl;
@@ -88,6 +92,10 @@ void ClassLoaderTest::testClassLoader1()
void ClassLoaderTest::testClassLoader2()
{
#ifdef POCO_STATIC
return; // Skip test in static builds where TestLibrary is not built
#endif
std::string libraryPath = getFullName("TestLibrary");
ClassLoader<TestPlugin> cl;
cl.loadLibrary(libraryPath);
@@ -176,6 +184,10 @@ void ClassLoaderTest::testClassLoader2()
void ClassLoaderTest::testClassLoader3()
{
#ifdef POCO_STATIC
return; // Skip test in static builds where TestLibrary is not built
#endif
std::string libraryPath = getFullName("TestLibrary");
ClassLoader<TestPlugin> cl;
cl.loadLibrary(libraryPath);

View File

@@ -50,6 +50,10 @@ SharedLibraryTest::~SharedLibraryTest()
void SharedLibraryTest::testSharedLibrary1()
{
#ifdef POCO_STATIC
return; // Skip test in static builds where TestLibrary is not built
#endif
std::string libraryPath = getFullName("TestLibrary");
SharedLibrary sl;
assertTrue (!sl.isLoaded());
@@ -83,6 +87,10 @@ void SharedLibraryTest::testSharedLibrary1()
void SharedLibraryTest::testSharedLibrary2()
{
#ifdef POCO_STATIC
return; // Skip test in static builds where TestLibrary is not built
#endif
std::string libraryPath = getFullName("TestLibrary");
SharedLibrary sl(libraryPath);
assertTrue (sl.getPath() == libraryPath);
@@ -98,6 +106,10 @@ void SharedLibraryTest::testSharedLibrary2()
void SharedLibraryTest::testSharedLibrary3()
{
#ifdef POCO_STATIC
return; // Skip test in static builds where TestLibrary is not built
#endif
std::string libraryPath = "NonexistentLibrary";
libraryPath.append(libraryPath);
SharedLibrary sl;
@@ -140,9 +152,12 @@ void SharedLibraryTest::testSharedLibrary3()
void SharedLibraryTest::testMissingDependencies()
{
#ifdef POCO_STATIC
return; // Skip test in static builds where TestLibrary is not built
#endif
// Test with a valid library - should return empty list (all dependencies found)
std::string libraryPath = getFullName("TestLibrary");
assertTrue (File(libraryPath).exists());
std::vector<std::string> missing = SharedLibrary::findMissingDependencies(libraryPath);
// TestLibrary should have all its dependencies available
for (const auto& dep : missing)