Fix a build regression on Solaris

Fix a regression introduced in commit aeb26da4cb64c0e75c8d.

On an Illumos test machine, running the GCC compiler and the Solaris
link editor, the CMake build failed with the following error:

    ld: fatal: unrecognized option '--version-script=/.../libpng.vers'

The fix consists in avoiding the use of CMAKE_SHARED_LIBRARY_C_FLAGS
in version script checks on Solaris.

Also clean up the surrounding code, as follows:
 * Rename CMAKE_REQUIRED_FLAGS_SAVE to _SAVED_CMAKE_REQUIRED_FLAGS.
   (The name of an internal variable should not begin with "CMAKE_".)
 * Reformat the version script to optimize the vertical space.
This commit is contained in:
Cosmin Truta 2023-06-21 21:08:40 +03:00
parent e6c5bf46c4
commit afc6c595bf

View File

@ -240,38 +240,36 @@ option(ld-version-script "Enable linker version script" ON)
if(ld-version-script AND NOT ANDROID AND NOT APPLE)
# Check if LD supports linker scripts.
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/conftest.map" "
VERS_1 {
global: sym1;
local: *;
};
VERS_2 {
global: sym2;
main;
} VERS_1;
VERS_1 { global: sym1; local: *; };
VERS_2 { global: sym2; main; } VERS_1;
")
set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS
${CMAKE_REQUIRED_FLAGS}
${CMAKE_SHARED_LIBRARY_C_FLAGS}
"-Wl,--version-script='${CMAKE_CURRENT_BINARY_DIR}/conftest.map'")
set(_SAVED_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
if(NOT CMAKE_HOST_SYSTEM_NAME MATCHES "^SunOS")
# Avoid using CMAKE_SHARED_LIBRARY_C_FLAGS in version script checks on
# Solaris, because of an incompatibility with the Solaris link editor.
list(APPEND CMAKE_REQUIRED_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
endif()
list(APPEND CMAKE_REQUIRED_FLAGS "-Wl,--version-script='${CMAKE_CURRENT_BINARY_DIR}/conftest.map'")
check_c_source_compiles("
void sym1(void) {}
void sym2(void) {}
int main(void) {return 0;}
int main(void) { return 0; }
" HAVE_LD_VERSION_SCRIPT)
if(NOT HAVE_LD_VERSION_SCRIPT)
set(CMAKE_REQUIRED_FLAGS
${CMAKE_REQUIRED_FLAGS_SAVE}
${CMAKE_SHARED_LIBRARY_C_FLAGS}
"-Wl,-M -Wl,${CMAKE_CURRENT_BINARY_DIR}/conftest.map")
check_c_source_compiles("
set(CMAKE_REQUIRED_FLAGS ${_SAVED_CMAKE_REQUIRED_FLAGS})
if(NOT CMAKE_HOST_SYSTEM_NAME MATCHES "^SunOS")
# Again, avoid using CMAKE_SHARED_LIBRARY_C_FLAGS in version script
# checks on Solaris.
list(APPEND CMAKE_REQUIRED_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
endif()
list(APPEND CMAKE_REQUIRED_FLAGS "-Wl,-M -Wl,${CMAKE_CURRENT_BINARY_DIR}/conftest.map")
check_c_source_compiles("
void sym1(void) {}
void sym2(void) {}
int main(void) {return 0;}
int main(void) { return 0; }
" HAVE_SOLARIS_LD_VERSION_SCRIPT)
endif()
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
set(CMAKE_REQUIRED_FLAGS ${_SAVED_CMAKE_REQUIRED_FLAGS})
file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/conftest.map")
endif()