FindSword.cmake 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #Taken from BibleTime Project, and preserved verbatim below
  2. #
  3. # In the name of the Father, and of the Son, and of the Holy Spirit.
  4. #
  5. # This file is part of BibleTime's source code, http://www.bibletime.info/.
  6. #
  7. # Copyright 1999-2014 by the BibleTime developers.
  8. # The BibleTime source code is licensed under the GNU General Public License version 2.0.
  9. #
  10. # This module looks for the Sword library by the Crosswire Bible Society
  11. #
  12. # It might define the following values similarly to pkg_search_module()
  13. # Sword_FOUND
  14. # Sword_LIBRARIES
  15. # Sword_LIBRARY_DIRS
  16. # Sword_LDFLAGS
  17. # Sword_LDFLAGS_OTHER
  18. # Sword_INCLUDE_DIRS
  19. # Sword_CFLAGS
  20. # Sword_CFLAGS_OTHER
  21. # Sword_VERSION
  22. MACRO(FindSword_unset_all)
  23. UNSET(Sword_FOUND)
  24. UNSET(Sword_LIBRARIES)
  25. UNSET(Sword_LIBRARY_DIRS)
  26. UNSET(Sword_LDFLAGS)
  27. UNSET(Sword_LDFLAGS_OTHER)
  28. UNSET(Sword_INCLUDE_DIRS)
  29. UNSET(Sword_CFLAGS)
  30. UNSET(Sword_CFLAGS_OTHER)
  31. UNSET(Sword_VERSION)
  32. ENDMACRO()
  33. FindSword_unset_all()
  34. INCLUDE(FindPkgConfig)
  35. IF(PKG_CONFIG_FOUND)
  36. # Workaround PKG_CONFIG_PATH set to include CMAKE_PREFIX_PATH paths:
  37. IF(WIN32)
  38. SET(FindSword_s ";")
  39. ELSE()
  40. SET(FindSword_s ":")
  41. ENDIF()
  42. FOREACH(d IN LISTS CMAKE_PREFIX_PATH)
  43. SET(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}${FindSword_s}${d}/lib/pkgconfig${FindSword_s}${d}/share/pkgconfig${FindSword_s}${d}/lib32/pkgconfig${FindSword_s}${d}/lib64/pkgconfig")
  44. ENDFOREACH()
  45. UNSET(FindSword_s)
  46. IF(Sword_FIND_VERSION_EXACT)
  47. SET(FindSword_Version_Comp "=")
  48. ELSE()
  49. SET(FindSword_Version_Comp ">=")
  50. ENDIF()
  51. pkg_search_module(Sword QUIET
  52. "sword${FindSword_Version_Comp}${Sword_FIND_VERSION}"
  53. "sword-${Sword_FIND_VERSION_MAJOR}${FindSword_Version_Comp}${Sword_FIND_VERSION}"
  54. "sword-${Sword_FIND_VERSION_MAJOR}.${Sword_FIND_VERSION_MINOR}${FindSword_Version_Comp}${Sword_FIND_VERSION}"
  55. "sword${Sword_FIND_VERSION_MAJOR}${FindSword_Version_Comp}${Sword_FIND_VERSION}"
  56. "sword${Sword_FIND_VERSION_MAJOR}.${Sword_FIND_VERSION_MINOR}${FindSword_Version_Comp}${Sword_FIND_VERSION}")
  57. UNSET(FindSword_Version_Comp)
  58. ENDIF()
  59. # If pkg-config fails we try this:
  60. IF(NOT Sword_FOUND)
  61. IF(NOT Sword_FIND_QUIETLY)
  62. MESSAGE(WARNING "Falling back to manual Sword detection...")
  63. ENDIF()
  64. FIND_LIBRARY(FindSword_LIBS NAMES sword libsword)
  65. IF(FindSword_LIBS)
  66. FIND_PATH(FindSword_INCS NAMES "sword/swmgr.h")
  67. IF(FindSword_INCS)
  68. SET(FindSword_INCS "${FindSword_INCS}/sword")
  69. TRY_RUN(RUN_RESULT COMPILE_RESULT
  70. "${CMAKE_CURRENT_BINARY_DIR}"
  71. "${CMAKE_CURRENT_SOURCE_DIR}/cmake/sword_version_print.cpp"
  72. CMAKE_FLAGS
  73. "-DINCLUDE_DIRECTORIES:STRING=${FindSword_INCS}"
  74. COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT
  75. RUN_OUTPUT_VARIABLE RUN_OUTPUT)
  76. IF(NOT COMPILE_RESULT)
  77. IF(NOT Sword_FIND_QUIETLY)
  78. MESSAGE(WARNING "Failed to compile Sword version check: ${COMPILE_OUTPUT}")
  79. ENDIF()
  80. ELSEIF(RUN_RESULT)
  81. IF(NOT Sword_FIND_QUIETLY)
  82. MESSAGE(WARNING "Failed to run Sword version check: ${COMPILE_OUTPUT}")
  83. ENDIF()
  84. ELSE()
  85. SET(Sword_FOUND TRUE)
  86. SET(Sword_VERSION "${RUN_OUTPUT}")
  87. GET_FILENAME_COMPONENT(Sword_LIBRARY_DIRS "${FindSword_LIBS}" PATH)
  88. SET(Sword_LIBRARIES "sword")
  89. SET(Sword_LDFLAGS "-L${Sword_LIBRARY_DIRS};-l${Sword_LIBRARIES}")
  90. SET(Sword_INCLUDE_DIRS "${FindSword_INCS}")
  91. SET(Sword_CFLAGS "-I${Sword_INCLUDE_DIRS}")
  92. ENDIF()
  93. ENDIF()
  94. UNSET(FindSword_INCS)
  95. ENDIF()
  96. UNSET(FindSword_LIBS)
  97. ENDIF()
  98. IF(Sword_FOUND)
  99. SET(FindSword_Sword_FOUND "YES")
  100. ENDIF()
  101. INCLUDE(FindPackageHandleStandardArgs)
  102. IF(CMAKE_VERSION VERSION_LESS 2.8.11)
  103. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Sword
  104. REQUIRED_VARS FindSword_Sword_FOUND
  105. VERSION_VAR Sword_VERSION)
  106. IF(SWORD_FOUND)
  107. SET(Sword_FOUND TRUE)
  108. ENDIF()
  109. UNSET(SWORD_FOUND)
  110. ELSE()
  111. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Sword
  112. FOUND_VAR Sword_FOUND
  113. REQUIRED_VARS FindSword_Sword_FOUND
  114. VERSION_VAR Sword_VERSION)
  115. ENDIF()
  116. UNSET(FindSword_Sword_FOUND)
  117. IF(Sword_FOUND AND NOT Sword_FIND_QUIETLY)
  118. MESSAGE(STATUS "Sword ${Sword_VERSION} details:")
  119. MESSAGE(STATUS " CFLAGS: ${Sword_CFLAGS}")
  120. MESSAGE(STATUS " INCLUDE_DIRS: ${Sword_INCLUDE_DIRS}")
  121. MESSAGE(STATUS " CFLAGS_OTHER: ${Sword_CFLAGS_OTHER}")
  122. MESSAGE(STATUS " LDFLAGS: ${Sword_LDFLAGS}")
  123. MESSAGE(STATUS " LIBRARIES: ${Sword_LIBRARIES}")
  124. MESSAGE(STATUS " LIBRARY_DIRS: ${Sword_LIBRARY_DIRS}")
  125. MESSAGE(STATUS " LDFLAGS_OTHER: ${Sword_LDFLAGS_OTHER}")
  126. ENDIF()