ctkLinkerAsNeededFlagCheck.cmake 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. ###########################################################################
  2. #
  3. # Library: CTK
  4. #
  5. # Copyright (c) Kitware Inc.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0.txt
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. ###########################################################################
  20. #
  21. # Linker --as-needed flag check
  22. #
  23. # Check if the linker will resolve symbols of underlinked libraries
  24. #
  25. # This script set the variable CTK_LINKER_NO_AS_NEEDED_FLAG_REQUIRED
  26. # to either TRUE or FALSE.
  27. #
  28. if(NOT DEFINED CTK_LINKER_NO_AS_NEEDED_FLAG_REQUIRED)
  29. message(STATUS "Checking if --no-as-needed linker flag is required")
  30. set(LINK_TEST_SOURCE_DIR ${CTK_CMAKE_DIR}/ctkLinkerAsNeededFlagCheck)
  31. set(LINK_TEST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ctkLinkerAsNeededFlagCheck)
  32. execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory ${LINK_TEST_BINARY_DIR})
  33. try_compile(CTK_LINKER_LINKS_UNDERLINKED_LIBS
  34. ${LINK_TEST_BINARY_DIR}
  35. ${LINK_TEST_SOURCE_DIR}
  36. LINK_TEST
  37. )
  38. if(CTK_LINKER_LINKS_UNDERLINKED_LIBS)
  39. set(CTK_LINKER_NO_AS_NEEDED_FLAG_REQUIRED FALSE CACHE INTERNAL "Test CTK_LINKER_NO_AS_NEEDED_FLAG_REQUIRED")
  40. message(STATUS "Checking if --no-as-needed linker flag is required - no")
  41. else()
  42. try_compile(CTK_LINKER_NO_AS_NEEDED_LINKS_UNDERLINKED_LIBS
  43. ${LINK_TEST_BINARY_DIR}
  44. ${LINK_TEST_SOURCE_DIR}
  45. LINK_TEST_FLAGS
  46. CMAKE_FLAGS -DCMAKE_EXE_LINKER_FLAGS=-Wl,--no-as-needed
  47. )
  48. if(CTK_LINKER_NO_AS_NEEDED_LINKS_UNDERLINKED_LIBS)
  49. set(CTK_LINKER_NO_AS_NEEDED_FLAG_REQUIRED TRUE CACHE INTERNAL "Test CTK_LINKER_NO_AS_NEEDED_FLAG_REQUIRED")
  50. message(STATUS "Checking if --no-as-needed linker flag is required - yes")
  51. else()
  52. message(STATUS "Checking if --no-as-needed linker flag is required - failed.")
  53. message(WARNING "Could not compile test code."
  54. "Linker could fail trying to resolve symbols for underlinked libraries."
  55. "See issue 2321 (http://na-mic.org/Mantis/view.php?id=2321) for more details.")
  56. endif()
  57. endif()
  58. endif()