This is an automated email from the ASF dual-hosted git repository.
pengzheng pushed a commit to branch feature/refactor_bundle_cache
in repository https://gitbox.apache.org/repos/asf/celix.git
The following commit(s) were added to refs/heads/feature/refactor_bundle_cache
by this push:
new f7416656 Link the code under test statically into the testing
executable to make error injector work.
f7416656 is described below
commit f74166568baab84b47d05c6f3fde99466fc4c50d
Author: PengZheng <[email protected]>
AuthorDate: Tue Feb 7 13:30:48 2023 +0800
Link the code under test statically into the testing executable to make
error injector work.
---
libs/error_injector/README.md | 2 +-
libs/framework/CMakeLists.txt | 26 +++++++++++++++-----------
libs/framework/gtest/CMakeLists.txt | 4 ++--
3 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/libs/error_injector/README.md b/libs/error_injector/README.md
index 4f63431f..651fcddd 100644
--- a/libs/error_injector/README.md
+++ b/libs/error_injector/README.md
@@ -30,7 +30,7 @@ As its name suggests, Celix Error Injector enables you to
inject arbitrary error
You only have to:
1. Implement a simple stub module for your target API under this folder.
-2. Link it into your test executable.
+2. Link it into your test executable **statically**. Check
`test_framework_with_ei` for a way of doing this with minimal CMake duplication.
3. Specify the target function call you want to injector specific error into
with a single function call before the code under test runs.
4. Disable error injector during the TearDown phase of the test. Forgetting
this step may interrupt other tests.
diff --git a/libs/framework/CMakeLists.txt b/libs/framework/CMakeLists.txt
index a837e6d8..5e75eb88 100644
--- a/libs/framework/CMakeLists.txt
+++ b/libs/framework/CMakeLists.txt
@@ -35,27 +35,31 @@ set(SOURCES
src/celix_bundle_state.c
src/celix_framework_utils.c
src/celix_module_private.h)
-add_library(framework SHARED ${SOURCES})
-set_target_properties(framework PROPERTIES OUTPUT_NAME "celix_framework")
-target_include_directories(framework PUBLIC
+add_library(framework_obj OBJECT ${SOURCES})
+target_include_directories(framework_obj PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
-)
-target_compile_options(framework PRIVATE -DUSE_FILE32API)
-target_compile_options(framework PRIVATE -Wno-deprecated-declarations) #note
part of the api is deprecated, ignore this warning on own api
-set_target_properties(framework PROPERTIES "SOVERSION" ${CELIX_MAJOR})
+ )
+target_compile_options(framework_obj PRIVATE -DUSE_FILE32API)
+target_compile_options(framework_obj PRIVATE -Wno-deprecated-declarations)
#note part of the api is deprecated, ignore this warning on own api
+target_link_libraries(framework_obj PUBLIC Celix::utils Celix::dfi
${CELIX_OPTIONAL_EXTRA_LIBS})
+target_link_libraries(framework_obj PUBLIC libuuid::libuuid CURL::libcurl
ZLIB::ZLIB)
+target_link_libraries(framework_obj PRIVATE ${CMAKE_DL_LIBS})
+celix_deprecated_utils_headers(framework_obj)
-target_link_libraries(framework PUBLIC Celix::utils Celix::dfi
${CELIX_OPTIONAL_EXTRA_LIBS})
-target_link_libraries(framework PUBLIC libuuid::libuuid CURL::libcurl
ZLIB::ZLIB)
-target_link_libraries(framework PRIVATE ${CMAKE_DL_LIBS})
+add_library(framework SHARED)
+target_link_libraries(framework PUBLIC framework_obj)
+set_target_properties(framework PROPERTIES OUTPUT_NAME "celix_framework")
+set_target_properties(framework PROPERTIES "SOVERSION" ${CELIX_MAJOR})
celix_deprecated_utils_headers(framework)
-install(TARGETS framework EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT framework
+install(TARGETS framework framework_obj EXPORT celix LIBRARY DESTINATION
${CMAKE_INSTALL_LIBDIR} COMPONENT framework
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix
COMPONENT framework)
#Alias setup to match external usage
add_library(Celix::framework ALIAS framework)
+add_library(Celix::framework_obj ALIAS framework_obj)
if (ENABLE_TESTING AND CELIX_CXX17) #framework tests are C++17
add_subdirectory(gtest)
diff --git a/libs/framework/gtest/CMakeLists.txt
b/libs/framework/gtest/CMakeLists.txt
index 08e15735..5df62ae5 100644
--- a/libs/framework/gtest/CMakeLists.txt
+++ b/libs/framework/gtest/CMakeLists.txt
@@ -125,9 +125,9 @@ if (LINKER_WRAP_SUPPORTED)
add_celix_bundle_dependencies(test_framework_with_ei simple_test_bundle1)
celix_deprecated_utils_headers(test_framework_with_ei)
target_link_libraries(test_framework_with_ei PRIVATE
- Celix::framework
- GTest::gtest GTest::gtest_main
+ Celix::framework_obj
Celix::malloc_ei
+ GTest::gtest GTest::gtest_main
)
add_test(NAME test_framework_with_ei COMMAND test_framework_with_ei)