mirror of
https://github.com/pocoproject/poco.git
synced 2025-12-09 00:07:35 +01:00
fix(SharedLibrary): disable shared lib tests in static build #5069
This commit is contained in:
@@ -62,46 +62,51 @@ set_target_properties(TestApp PROPERTIES
|
|||||||
)
|
)
|
||||||
target_link_libraries(TestApp PUBLIC Poco::Foundation)
|
target_link_libraries(TestApp PUBLIC Poco::Foundation)
|
||||||
|
|
||||||
# TestLibrary
|
add_dependencies(Foundation-testrunner TestApp)
|
||||||
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 ""
|
|
||||||
)
|
|
||||||
|
|
||||||
# The test is run in the runtime directory. So the TestLibrary is built there too because it is used by the tests
|
# TestLibrary and related shared libraries - only for shared library builds
|
||||||
set_target_properties(TestLibrary PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
# SharedLibrary and ClassLoader tests require dynamically loadable libraries
|
||||||
target_link_libraries(TestLibrary PUBLIC Poco::Foundation)
|
if(BUILD_SHARED_LIBS)
|
||||||
|
add_library(TestLibrary SHARED src/TestLibrary.cpp src/TestPlugin.cpp src/TestPlugin.h)
|
||||||
add_dependencies(Foundation-testrunner TestApp TestLibrary)
|
set_target_properties(TestLibrary PROPERTIES
|
||||||
|
DEBUG_POSTFIX "d"
|
||||||
# TestLibraryMissingDeps - a library with missing dependencies for testing findMissingDependencies
|
# The test requires the library named TestLibrary. By default it is prefixed with lib.
|
||||||
# Build a stub library that TestLibraryMissingDeps links against
|
PREFIX ""
|
||||||
# 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)
|
# 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(TestLibraryMissingDeps PROPERTIES
|
set_target_properties(TestLibrary PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||||
DEBUG_POSTFIX "d"
|
target_link_libraries(TestLibrary PUBLIC Poco::Foundation)
|
||||||
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)
|
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()
|
||||||
|
|||||||
@@ -49,6 +49,10 @@ template class ClassLoader<TestPlugin>;
|
|||||||
|
|
||||||
void ClassLoaderTest::testClassLoader1()
|
void ClassLoaderTest::testClassLoader1()
|
||||||
{
|
{
|
||||||
|
#ifdef POCO_STATIC
|
||||||
|
return; // Skip test in static builds where TestLibrary is not built
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string libraryPath = getFullName("TestLibrary");
|
std::string libraryPath = getFullName("TestLibrary");
|
||||||
ClassLoader<TestPlugin> cl;
|
ClassLoader<TestPlugin> cl;
|
||||||
|
|
||||||
@@ -88,6 +92,10 @@ void ClassLoaderTest::testClassLoader1()
|
|||||||
|
|
||||||
void ClassLoaderTest::testClassLoader2()
|
void ClassLoaderTest::testClassLoader2()
|
||||||
{
|
{
|
||||||
|
#ifdef POCO_STATIC
|
||||||
|
return; // Skip test in static builds where TestLibrary is not built
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string libraryPath = getFullName("TestLibrary");
|
std::string libraryPath = getFullName("TestLibrary");
|
||||||
ClassLoader<TestPlugin> cl;
|
ClassLoader<TestPlugin> cl;
|
||||||
cl.loadLibrary(libraryPath);
|
cl.loadLibrary(libraryPath);
|
||||||
@@ -176,6 +184,10 @@ void ClassLoaderTest::testClassLoader2()
|
|||||||
|
|
||||||
void ClassLoaderTest::testClassLoader3()
|
void ClassLoaderTest::testClassLoader3()
|
||||||
{
|
{
|
||||||
|
#ifdef POCO_STATIC
|
||||||
|
return; // Skip test in static builds where TestLibrary is not built
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string libraryPath = getFullName("TestLibrary");
|
std::string libraryPath = getFullName("TestLibrary");
|
||||||
ClassLoader<TestPlugin> cl;
|
ClassLoader<TestPlugin> cl;
|
||||||
cl.loadLibrary(libraryPath);
|
cl.loadLibrary(libraryPath);
|
||||||
|
|||||||
@@ -50,6 +50,10 @@ SharedLibraryTest::~SharedLibraryTest()
|
|||||||
|
|
||||||
void SharedLibraryTest::testSharedLibrary1()
|
void SharedLibraryTest::testSharedLibrary1()
|
||||||
{
|
{
|
||||||
|
#ifdef POCO_STATIC
|
||||||
|
return; // Skip test in static builds where TestLibrary is not built
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string libraryPath = getFullName("TestLibrary");
|
std::string libraryPath = getFullName("TestLibrary");
|
||||||
SharedLibrary sl;
|
SharedLibrary sl;
|
||||||
assertTrue (!sl.isLoaded());
|
assertTrue (!sl.isLoaded());
|
||||||
@@ -83,6 +87,10 @@ void SharedLibraryTest::testSharedLibrary1()
|
|||||||
|
|
||||||
void SharedLibraryTest::testSharedLibrary2()
|
void SharedLibraryTest::testSharedLibrary2()
|
||||||
{
|
{
|
||||||
|
#ifdef POCO_STATIC
|
||||||
|
return; // Skip test in static builds where TestLibrary is not built
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string libraryPath = getFullName("TestLibrary");
|
std::string libraryPath = getFullName("TestLibrary");
|
||||||
SharedLibrary sl(libraryPath);
|
SharedLibrary sl(libraryPath);
|
||||||
assertTrue (sl.getPath() == libraryPath);
|
assertTrue (sl.getPath() == libraryPath);
|
||||||
@@ -98,6 +106,10 @@ void SharedLibraryTest::testSharedLibrary2()
|
|||||||
|
|
||||||
void SharedLibraryTest::testSharedLibrary3()
|
void SharedLibraryTest::testSharedLibrary3()
|
||||||
{
|
{
|
||||||
|
#ifdef POCO_STATIC
|
||||||
|
return; // Skip test in static builds where TestLibrary is not built
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string libraryPath = "NonexistentLibrary";
|
std::string libraryPath = "NonexistentLibrary";
|
||||||
libraryPath.append(libraryPath);
|
libraryPath.append(libraryPath);
|
||||||
SharedLibrary sl;
|
SharedLibrary sl;
|
||||||
@@ -140,9 +152,12 @@ void SharedLibraryTest::testSharedLibrary3()
|
|||||||
|
|
||||||
void SharedLibraryTest::testMissingDependencies()
|
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)
|
// Test with a valid library - should return empty list (all dependencies found)
|
||||||
std::string libraryPath = getFullName("TestLibrary");
|
std::string libraryPath = getFullName("TestLibrary");
|
||||||
assertTrue (File(libraryPath).exists());
|
|
||||||
std::vector<std::string> missing = SharedLibrary::findMissingDependencies(libraryPath);
|
std::vector<std::string> missing = SharedLibrary::findMissingDependencies(libraryPath);
|
||||||
// TestLibrary should have all its dependencies available
|
// TestLibrary should have all its dependencies available
|
||||||
for (const auto& dep : missing)
|
for (const auto& dep : missing)
|
||||||
|
|||||||
Reference in New Issue
Block a user