summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorDavid Cole <david.cole@kitware.com>2012-05-01 18:09:59 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2012-05-01 18:09:59 (GMT)
commit8df7aa54f0f78d48e4ed91001ac9ac9d39dbf535 (patch)
treecfde4039510819e096c2bf197cfdc6e7827b6b0d /Tests
parentd05e12bc166d4285ccd5e961bd48cc6eb95bc77f (diff)
parentfdb3f878fec158ab284130a55849ada9edbd6fd1 (diff)
downloadCMake-8df7aa54f0f78d48e4ed91001ac9ac9d39dbf535.zip
CMake-8df7aa54f0f78d48e4ed91001ac9ac9d39dbf535.tar.gz
CMake-8df7aa54f0f78d48e4ed91001ac9ac9d39dbf535.tar.bz2
Merge topic 'module-no-soname'
fdb3f87 Test NO_SONAME property (#13155) e1409ac Support building shared libraries or modules without soname (#13155)
Diffstat (limited to 'Tests')
-rw-r--r--Tests/Plugin/CMakeLists.txt44
-rw-r--r--Tests/Plugin/check_mod_soname.cmake14
2 files changed, 58 insertions, 0 deletions
diff --git a/Tests/Plugin/CMakeLists.txt b/Tests/Plugin/CMakeLists.txt
index b0942c0..31ca59c 100644
--- a/Tests/Plugin/CMakeLists.txt
+++ b/Tests/Plugin/CMakeLists.txt
@@ -39,6 +39,50 @@ TARGET_LINK_LIBRARIES(example_exe kwsys)
ADD_LIBRARY(example_mod_1 MODULE src/example_mod_1.c)
TARGET_LINK_LIBRARIES(example_mod_1 example_exe)
+
+IF(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG AND
+ "${CMAKE_C_CREATE_SHARED_MODULE}" MATCHES "SONAME_FLAG")
+ # Add a second plugin that should not have any soname.
+ ADD_LIBRARY(example_mod_2 MODULE src/example_mod_1.c)
+ TARGET_LINK_LIBRARIES(example_mod_2 example_exe)
+ SET_PROPERTY(TARGET example_mod_2 PROPERTY NO_SONAME 1)
+
+ # Verify that targets export with proper IMPORTED SONAME properties.
+ EXPORT(TARGETS example_mod_1 example_mod_2 NAMESPACE exp_
+ FILE ${CMAKE_CURRENT_BINARY_DIR}/mods.cmake)
+ INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/mods.cmake)
+ GET_PROPERTY(configs TARGET exp_example_mod_1 PROPERTY IMPORTED_CONFIGURATIONS)
+ FOREACH(c ${configs})
+ STRING(TOUPPER "${c}" CONFIG)
+ GET_PROPERTY(soname1 TARGET exp_example_mod_1 PROPERTY IMPORTED_SONAME_${CONFIG})
+ GET_PROPERTY(soname2 TARGET exp_example_mod_2 PROPERTY IMPORTED_NO_SONAME_${CONFIG})
+ IF(soname1)
+ MESSAGE(STATUS "exp_example_mod_1 has IMPORTED_SONAME_${CONFIG} as expected: ${soname1}")
+ ELSE()
+ MESSAGE(SEND_ERROR "exp_example_mod_1 does not have IMPORTED_SONAME_${CONFIG} but should")
+ ENDIF()
+ IF(soname2)
+ MESSAGE(STATUS "exp_example_mod_2 has IMPORTED_NO_SONAME_${CONFIG} as expected: ${soname2}")
+ ELSE()
+ MESSAGE(SEND_ERROR "exp_example_mod_2 does not have IMPORTED_NO_SONAME_${CONFIG} but should")
+ ENDIF()
+ ENDFOREACH()
+
+ # Parse the binary to check for SONAME if possible.
+ IF("${CMAKE_EXECUTABLE_FORMAT}" MATCHES "ELF")
+ FIND_PROGRAM(READELF_EXE readelf)
+ IF(READELF_EXE)
+ ADD_CUSTOM_TARGET(check_mod_soname ALL COMMAND
+ ${CMAKE_COMMAND} -Dreadelf=${READELF_EXE}
+ -Dmod1=$<TARGET_FILE:example_mod_1>
+ -Dmod2=$<TARGET_FILE:example_mod_2>
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/check_mod_soname.cmake
+ )
+ ADD_DEPENDENCIES(check_mod_soname example_mod_1 example_mod_2)
+ ENDIF()
+ ENDIF()
+ENDIF()
+
# TODO:
# - create a plugin that links to a static lib
# - create a plugin that links to a shared lib
diff --git a/Tests/Plugin/check_mod_soname.cmake b/Tests/Plugin/check_mod_soname.cmake
new file mode 100644
index 0000000..3737b45
--- /dev/null
+++ b/Tests/Plugin/check_mod_soname.cmake
@@ -0,0 +1,14 @@
+execute_process(COMMAND ${readelf} -d ${mod1} OUTPUT_FILE ${mod1}.readelf.txt)
+execute_process(COMMAND ${readelf} -d ${mod2} OUTPUT_FILE ${mod2}.readelf.txt)
+file(STRINGS ${mod1}.readelf.txt soname1 REGEX "\\(SONAME\\)")
+file(STRINGS ${mod2}.readelf.txt soname2 REGEX "\\(SONAME\\)")
+if(soname1)
+ message(STATUS "${mod1} has soname as expected: ${soname1}")
+else()
+ message(FATAL_ERROR "${mod1} has no soname but should:\n ${soname1}")
+endif()
+if(soname2)
+ message(FATAL_ERROR "${mod2} has soname but should not:\n ${soname2}")
+else()
+ message(STATUS "${mod2} has no soname as expected")
+endif()