FindOpenSP.cmake 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindOpenSP
  5. ----------
  6. .. versionadded:: 3.25
  7. Try to find the OpenSP library.
  8. Result Variables
  9. ^^^^^^^^^^^^^^^^
  10. This will define the following variables:
  11. ``OpenSP_FOUND``
  12. True if (the requested version of) ``OpenSP`` is available
  13. ``OpenSP_VERSION``
  14. The version of ``OpenSP``
  15. ``OpenSP_VERSION_MAJOR``
  16. The major version of ``OpenSP``
  17. ``OpenSP_VERSION_MINOR``
  18. The minor version of ``OpenSP``
  19. ``OpenSP_VERSION_PATCH``
  20. The patch version of ``OpenSP``
  21. ``OpenSP_INCLUDE_DIRS``
  22. The include dirs of ``OpenSP`` with its headers
  23. ``OpenSP_LIBRARIES``
  24. The OpenSP library for use with target_link_libraries().
  25. This can be passed to target_link_libraries() instead of
  26. the :prop_tgt:`IMPORTED` ``OpenSP::OpenSP`` target
  27. ``OpenSP_MULTI_BYTE``
  28. True if ``SP_MULTI_BYTE`` was found to be defined in OpenSP's ``config.h``
  29. header file, which indicates that the ``OpenSP`` library was compiled with
  30. support for multi-byte characters. The consuming target needs to define the
  31. ``SP_MULTI_BYTE`` to match this value in order to avoid issues with character
  32. decoding.
  33. IMPORTED Targets
  34. ^^^^^^^^^^^^^^^^
  35. This module defines the :prop_tgt:`IMPORTED` target ``OpenSP::OpenSP``, if
  36. OpenSP has been found.
  37. Cache variables
  38. ^^^^^^^^^^^^^^^
  39. The following cache variables may also be set:
  40. ``OpenSP_INCLUDE_DIR``
  41. the OpenSP include directory
  42. ``OpenSP_LIBRARY``
  43. the absolute path of the osp library
  44. #]=======================================================================]
  45. cmake_policy(PUSH)
  46. cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
  47. find_package(PkgConfig QUIET)
  48. if (PkgConfig_FOUND)
  49. pkg_check_modules(PC_OpenSP QUIET opensp)
  50. endif ()
  51. if (NOT OpenSP_INCLUDE_DIR)
  52. find_path(OpenSP_INCLUDE_DIR
  53. NAMES ParserEventGeneratorKit.h
  54. HINTS
  55. ${PC_OpenSP_INCLUDEDIRS}
  56. ${PC_OpenSP_INCLUDE_DIRS}
  57. PATH_SUFFIXES OpenSP opensp
  58. DOC "The OpenSP include directory"
  59. )
  60. endif ()
  61. if (NOT OpenSP_LIBRARY)
  62. find_library(OpenSP_LIBRARY_RELEASE
  63. NAMES osp libosp opensp libopensp sp133 libsp
  64. HINTS
  65. ${PC_OpenSP_LIBDIR}
  66. ${PC_OpenSP_LIBRARY_DIRS}
  67. )
  68. find_library(OpenSP_LIBRARY_DEBUG
  69. NAMES ospd libospd openspd libopenspd sp133d libspd
  70. HINTS
  71. ${PC_OpenSP_LIBDIR}
  72. ${PC_OpenSP_LIBRARY_DIRS}
  73. )
  74. include(SelectLibraryConfigurations)
  75. select_library_configurations(OpenSP)
  76. endif ()
  77. if (OpenSP_INCLUDE_DIR)
  78. if (EXISTS "${OpenSP_INCLUDE_DIR}/config.h")
  79. if (NOT OpenSP_VERSION)
  80. file(STRINGS "${OpenSP_INCLUDE_DIR}/config.h" opensp_version_str REGEX "^#define[\t ]+SP_VERSION[\t ]+\".*\"")
  81. string(REGEX REPLACE "^.*SP_VERSION[\t ]+\"([^\"]*)\".*$" "\\1" OpenSP_VERSION "${opensp_version_str}")
  82. unset(opensp_version_str)
  83. endif ()
  84. if (OpenSP_VERSION MATCHES [=[([0-9]+)\.([0-9]+)\.([0-9]+)]=])
  85. set(OpenSP_VERSION_MAJOR "${CMAKE_MATCH_1}")
  86. set(OpenSP_VERSION_MINOR "${CMAKE_MATCH_2}")
  87. set(OpenSP_VERSION_PATCH "${CMAKE_MATCH_3}")
  88. endif ()
  89. include(CheckCXXSymbolExists)
  90. check_cxx_symbol_exists(SP_MULTI_BYTE "${OpenSP_INCLUDE_DIR}/config.h" OpenSP_MULTI_BYTE)
  91. endif ()
  92. endif ()
  93. include(FindPackageHandleStandardArgs)
  94. find_package_handle_standard_args(OpenSP
  95. REQUIRED_VARS OpenSP_LIBRARY OpenSP_INCLUDE_DIR
  96. VERSION_VAR OpenSP_VERSION
  97. )
  98. mark_as_advanced(OpenSP_INCLUDE_DIR OpenSP_LIBRARY OpenSP_MULTI_BYTE)
  99. if (OpenSP_FOUND)
  100. set(OpenSP_INCLUDE_DIRS ${OpenSP_INCLUDE_DIR})
  101. if (NOT TARGET OpenSP::OpenSP)
  102. add_library(OpenSP::OpenSP UNKNOWN IMPORTED)
  103. if (EXISTS "${OpenSP_LIBRARY}")
  104. set_target_properties(OpenSP::OpenSP PROPERTIES
  105. IMPORTED_LOCATION "${OpenSP_LIBRARY}")
  106. endif ()
  107. set_target_properties(OpenSP::OpenSP PROPERTIES
  108. INTERFACE_INCLUDE_DIRECTORIES "${OpenSP_INCLUDE_DIRS}")
  109. if (OpenSP_LIBRARY_RELEASE)
  110. set_target_properties(OpenSP::OpenSP PROPERTIES
  111. IMPORTED_LOCATION_RELEASE "${OpenSP_LIBRARY_RELEASE}")
  112. set_property(TARGET OpenSP::OpenSP APPEND PROPERTY
  113. IMPORTED_CONFIGURATIONS RELEASE)
  114. endif ()
  115. if (OpenSP_LIBRARY_DEBUG)
  116. set_target_properties(OpenSP::OpenSP PROPERTIES
  117. IMPORTED_LOCATION_DEBUG "${OpenSP_LIBRARY_DEBUG}")
  118. set_property(TARGET OpenSP::OpenSP APPEND PROPERTY
  119. IMPORTED_CONFIGURATIONS DEBUG)
  120. endif ()
  121. endif ()
  122. endif ()
  123. include(FeatureSummary)
  124. set_package_properties(OpenSP PROPERTIES
  125. URL "http://openjade.sourceforge.net/doc/index.htm"
  126. DESCRIPTION "An SGML System Conforming to International Standard ISO 8879"
  127. )
  128. cmake_policy(POP)