From 899458ab20876aeea915a59e9bfb459d92d264de Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 20 Aug 2015 10:37:18 -0400 Subject: [PATCH] Tests: Cover NO_SONAME property for SHARED libraries This property was added by commit v2.8.9~204^2~2 (Support building shared libraries or modules without soname, 2012-04-22). A test for using the property on MODULE libraries was added by commit v2.8.9~204^2~1 (Test NO_SONAME property, 2012-04-23). Add such a test for SHARED libraries too. --- Tests/ExportImport/Export/CMakeLists.txt | 5 +++ Tests/ExportImport/Export/testLibNoSONAME.c | 7 +++ Tests/ExportImport/Import/A/CMakeLists.txt | 44 +++++++++++++++++++ .../Import/A/check_lib_nosoname.cmake | 7 +++ .../Import/A/check_lib_soname.cmake | 7 +++ 5 files changed, 70 insertions(+) create mode 100644 Tests/ExportImport/Export/testLibNoSONAME.c create mode 100644 Tests/ExportImport/Import/A/check_lib_nosoname.cmake create mode 100644 Tests/ExportImport/Import/A/check_lib_soname.cmake diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt index 7fdfaa847..2b9e8442c 100644 --- a/Tests/ExportImport/Export/CMakeLists.txt +++ b/Tests/ExportImport/Export/CMakeLists.txt @@ -127,6 +127,9 @@ target_link_libraries(testLibCycleA testLibCycleB) target_link_libraries(testLibCycleB testLibCycleA) set_property(TARGET testLibCycleA PROPERTY LINK_INTERFACE_MULTIPLICITY 3) +add_library(testLibNoSONAME SHARED testLibNoSONAME.c) +set_property(TARGET testLibNoSONAME PROPERTY NO_SONAME 1) + # Test exporting dependent libraries into different exports add_library(testLibRequired testLibRequired.c) add_library(testLibDepends testLibDepends.c) @@ -467,6 +470,7 @@ install( testExe2lib testLib4lib testLib4libdbg testLib4libopt testLib6 testLib7 testLibCycleA testLibCycleB + testLibNoSONAME cmp0022NEW cmp0022OLD systemlib EXPORT exp @@ -527,6 +531,7 @@ export(TARGETS testExe1 testLib1 testLib2 testLib3 export(TARGETS testExe2 testLib4 testLib5 testLib6 testLib7 testExe3 testExe4 testExe2lib testLib4lib testLib4libdbg testLib4libopt testLibCycleA testLibCycleB + testLibNoSONAME testLibPerConfigDest NAMESPACE bld_ APPEND FILE ExportBuildTree.cmake diff --git a/Tests/ExportImport/Export/testLibNoSONAME.c b/Tests/ExportImport/Export/testLibNoSONAME.c new file mode 100644 index 000000000..2193e1f53 --- /dev/null +++ b/Tests/ExportImport/Export/testLibNoSONAME.c @@ -0,0 +1,7 @@ +#if defined(_WIN32) || defined(__CYGWIN__) +# define testLibNoSONAME_EXPORT __declspec(dllexport) +#else +# define testLibNoSONAME_EXPORT +#endif + +testLibNoSONAME_EXPORT int testLibNoSONAME(void) { return 0; } diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt index 0f56495d5..5ce962861 100644 --- a/Tests/ExportImport/Import/A/CMakeLists.txt +++ b/Tests/ExportImport/Import/A/CMakeLists.txt @@ -90,6 +90,50 @@ add_custom_target(check_testLib1_genex ALL -P ${CMAKE_CURRENT_SOURCE_DIR}/check_testLib1_genex.cmake ) +if(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG AND + "${CMAKE_C_CREATE_SHARED_MODULE}" MATCHES "SONAME_FLAG") + foreach(ns exp bld) + get_property(configs TARGET ${ns}_testLib5 PROPERTY IMPORTED_CONFIGURATIONS) + foreach(c ${configs}) + string(TOUPPER "${c}" CONFIG) + get_property(soname TARGET ${ns}_testLib5 PROPERTY IMPORTED_NO_SONAME_${CONFIG}) + if(soname) + message(SEND_ERROR "${ns}_testLib5 has IMPORTED_NO_SONAME_${CONFIG} but should:\n ${soname}") + else() + message(STATUS "${ns}_testLib5 does not have IMPORTED_NO_SONAME_${CONFIG} as expected") + endif() + endforeach() + + get_property(configs TARGET ${ns}_testLibNoSONAME PROPERTY IMPORTED_CONFIGURATIONS) + foreach(c ${configs}) + string(TOUPPER "${c}" CONFIG) + get_property(soname TARGET ${ns}_testLibNoSONAME PROPERTY IMPORTED_NO_SONAME_${CONFIG}) + if(soname) + message(STATUS "${ns}_testLibNoSONAME has IMPORTED_NO_SONAME_${CONFIG} as expected") + else() + message(SEND_ERROR "${ns}_testLibNoSONAME 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_${ns}_testLib5_soname ALL COMMAND + ${CMAKE_COMMAND} -Dreadelf=${READELF_EXE} + -Dlib=$ + -P ${CMAKE_CURRENT_SOURCE_DIR}/check_lib_soname.cmake + ) + add_custom_target(check_${ns}_testLibNoSONAME_soname ALL COMMAND + ${CMAKE_COMMAND} -Dreadelf=${READELF_EXE} + -Dlib=$ + -P ${CMAKE_CURRENT_SOURCE_DIR}/check_lib_nosoname.cmake + ) + endif() + endif() + endforeach() +endif() + add_executable(cmp0022OLD_test cmp0022OLD_test_vs6_1.cpp) target_link_libraries(cmp0022OLD_test bld_cmp0022OLD) add_executable(cmp0022NEW_test cmp0022NEW_test_vs6_1.cpp) diff --git a/Tests/ExportImport/Import/A/check_lib_nosoname.cmake b/Tests/ExportImport/Import/A/check_lib_nosoname.cmake new file mode 100644 index 000000000..6261ff42b --- /dev/null +++ b/Tests/ExportImport/Import/A/check_lib_nosoname.cmake @@ -0,0 +1,7 @@ +execute_process(COMMAND ${readelf} -d ${lib} OUTPUT_FILE ${lib}.readelf.txt) +file(STRINGS ${lib}.readelf.txt soname REGEX "\\(SONAME\\)") +if(soname) + message(FATAL_ERROR "${lib} has soname but should not:\n ${soname}") +else() + message(STATUS "${lib} has no soname as expected:\n ${soname}") +endif() diff --git a/Tests/ExportImport/Import/A/check_lib_soname.cmake b/Tests/ExportImport/Import/A/check_lib_soname.cmake new file mode 100644 index 000000000..7794e8011 --- /dev/null +++ b/Tests/ExportImport/Import/A/check_lib_soname.cmake @@ -0,0 +1,7 @@ +execute_process(COMMAND ${readelf} -d ${lib} OUTPUT_FILE ${lib}.readelf.txt) +file(STRINGS ${lib}.readelf.txt soname REGEX "\\(SONAME\\)") +if(soname) + message(STATUS "${lib} has soname as expected:\n ${soname}") +else() + message(FATAL_ERROR "${lib} has no soname but should:\n ${soname}") +endif()