SgABIComplianceChecker.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #.rst:
  2. # SgABIComplianceChecker
  3. # ----------------------
  4. #
  5. # Check backward API/ABI compatibility.
  6. #
  7. # A CMake script for checking backward API/ABI compatibility of the Sagui
  8. # library.
  9. #
  10. # ::
  11. #
  12. # SG_OLD_LIB_DIR - Absolute path of the old Sagui library.
  13. # SG_OLD_LIB_VERSION - Version of the old Sagui library.
  14. # _
  15. # ___ __ _ __ _ _ _(_)
  16. # / __|/ _` |/ _` | | | | |
  17. # \__ \ (_| | (_| | |_| | |
  18. # |___/\__,_|\__, |\__,_|_|
  19. # |___/
  20. #
  21. # Cross-platform library which helps to develop web servers or frameworks.
  22. #
  23. # Copyright (C) 2016-2019 Silvio Clecio <[email protected]>
  24. #
  25. # Sagui library is free software; you can redistribute it and/or
  26. # modify it under the terms of the GNU Lesser General Public
  27. # License as published by the Free Software Foundation; either
  28. # version 2.1 of the License, or (at your option) any later version.
  29. #
  30. # Sagui library is distributed in the hope that it will be useful,
  31. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  33. # Lesser General Public License for more details.
  34. #
  35. # You should have received a copy of the GNU Lesser General Public
  36. # License along with Sagui library; if not, write to the Free Software
  37. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  38. #
  39. #TODO: download latest Sagui from Github releases and delete SG_OLD_LIB_DIR
  40. if(__SG_ABI_COMPLIANCE_CHECKER_INCLUDED)
  41. return()
  42. endif()
  43. set(__SG_ABI_COMPLIANCE_CHECKER_INCLUDED ON)
  44. option(SG_ABI_COMPLIANCE_CHECKER "Enable ABI compliance checker" OFF)
  45. if(SG_ABI_COMPLIANCE_CHECKER)
  46. if(NOT SG_OLD_LIB_DIR)
  47. message(
  48. FATAL_ERROR
  49. "You must to specify SG_OLD_LIB_DIR for ABI compliance checking")
  50. endif()
  51. if(NOT EXISTS ${SG_OLD_LIB_DIR})
  52. message(FATAL_ERROR "${SG_OLD_LIB_DIR} not found")
  53. endif()
  54. if(NOT SG_OLD_LIB_VERSION)
  55. message(
  56. FATAL_ERROR
  57. "You must to specify SG_OLD_LIB_VERSION for ABI compliance checking")
  58. endif()
  59. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Og")
  60. find_program(_abi_comp_checker abi-compliance-checker)
  61. if(NOT _abi_comp_checker)
  62. message(
  63. FATAL_ERROR
  64. "abi-compliance-checker tool is required for ABI compliance checking")
  65. endif()
  66. find_program(_abi_dumper abi-dumper)
  67. if(NOT _abi_dumper)
  68. message(
  69. FATAL_ERROR "abi-dumper tool is required for ABI compliance checking")
  70. endif()
  71. file(TO_CMAKE_PATH "${SG_OLD_LIB_DIR}/build" _old_lib_build_dir)
  72. file(REMOVE_RECURSE "${_old_lib_build_dir}")
  73. file(MAKE_DIRECTORY "${_old_lib_build_dir}")
  74. add_custom_target(
  75. abi_compliance_checker
  76. COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS=-Og
  77. -DBUILD_SHARED_LIBS=ON -DSG_HTTPS_SUPPORT=ON ".."
  78. COMMAND ${CMAKE_COMMAND} --build "${_old_lib_build_dir}" --target
  79. ${PROJECT_NAME}
  80. WORKING_DIRECTORY ${_old_lib_build_dir}
  81. COMMENT "Compiling the old Sagui library for ABI compliance checking"
  82. DEPENDS ${PROJECT_NAME}
  83. VERBATIM)
  84. set(_old_lib_name "libsagui.so.${SG_OLD_LIB_VERSION}")
  85. set(_old_lib "${_old_lib_build_dir}/src/${_old_lib_name}")
  86. set(_new_lib_name libsagui.so.${VERSION})
  87. set(_new_lib "${CMAKE_BINARY_DIR}/src/${_new_lib_name}")
  88. file(REMOVE "${_old_lib}.dump")
  89. file(REMOVE "${_new_lib}.dump")
  90. add_custom_command(
  91. TARGET abi_compliance_checker POST_BUILD
  92. COMMAND ${_abi_dumper} "${_old_lib}" -o "${_old_lib}.dump" -lver
  93. "${SG_OLD_LIB_VERSION}"
  94. COMMAND ${_abi_dumper} "${_new_lib}" -o "${_new_lib}.dump" -lver
  95. "${VERSION}"
  96. COMMAND
  97. ${_abi_comp_checker} -l "${PROJECT_NAME}" -old "${_old_lib}.dump" -new
  98. "${_new_lib}.dump"
  99. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  100. COMMENT "Checking ABI compliance"
  101. VERBATIM)
  102. unset(_abi_dumper)
  103. unset(_abi_comp_checker)
  104. unset(_old_lib_build_dir)
  105. unset(_old_lib_name)
  106. unset(_old_lib)
  107. unset(_new_lib_name)
  108. unset(_new_lib)
  109. unset(_old_lib)
  110. endif()