diff options
author | Cosmin Truta <ctruta@gmail.com> | 2023-06-21 21:08:40 +0300 |
---|---|---|
committer | Cosmin Truta <ctruta@gmail.com> | 2023-06-21 21:08:40 +0300 |
commit | afc6c595bf24340432ccbffba310eec3bd8b32fc (patch) | |
tree | e90d0f2d5965693f1abe61ff93b443318c4aa130 | |
parent | e6c5bf46c4fa3e3738a2ed0896ce33fc270e0cac (diff) | |
download | libpng-afc6c595bf24340432ccbffba310eec3bd8b32fc.tar.gz |
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.
-rw-r--r-- | CMakeLists.txt | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 90b53f37c..fa65509af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() |