FindOpenSP.cmake 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindOpenSP
  5. ----------
  6. .. versionadded:: 3.25
  7. Finds the OpenSP library:
  8. .. code-block:: cmake
  9. find_package(OpenSP [<version>] [...])
  10. OpenSP is an open-source implementation of the SGML (Standard Generalized
  11. Markup Language) parser.
  12. Imported Targets
  13. ^^^^^^^^^^^^^^^^
  14. This module provides the following :ref:`Imported Targets`:
  15. ``OpenSP::OpenSP``
  16. Target encapsulating the OpenSP library usage requirements, available only if
  17. the OpenSP is found.
  18. Result Variables
  19. ^^^^^^^^^^^^^^^^
  20. This module defines the following variables:
  21. ``OpenSP_FOUND``
  22. Boolean indicating whether (the requested version of) OpenSP is available.
  23. ``OpenSP_VERSION``
  24. The version of found OpenSP.
  25. ``OpenSP_VERSION_MAJOR``
  26. The major version of OpenSP.
  27. ``OpenSP_VERSION_MINOR``
  28. The minor version of OpenSP.
  29. ``OpenSP_VERSION_PATCH``
  30. The patch version of OpenSP.
  31. ``OpenSP_INCLUDE_DIRS``
  32. The include directories containing headers needed to use the OpenSP library.
  33. ``OpenSP_LIBRARIES``
  34. Libraries required to link against to use OpenSP. These can be passed to the
  35. :command:`target_link_libraries` command when not using the ``OpenSP::OpenSP``
  36. imported target.
  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. ``OpenSP_MULTI_BYTE``
  45. True if ``SP_MULTI_BYTE`` was found to be defined in OpenSP's ``config.h``
  46. header file, which indicates that the OpenSP library was compiled with support
  47. for multi-byte characters. The consuming target needs to define the
  48. ``SP_MULTI_BYTE`` preprocessor macro to match this value in order to avoid
  49. issues with character decoding.
  50. Examples
  51. ^^^^^^^^
  52. Finding the OpenSP library and linking it to a project target:
  53. .. code-block:: cmake
  54. find_package(OpenSP)
  55. target_link_libraries(project_target PRIVATE OpenSP::OpenSP)
  56. #]=======================================================================]
  57. cmake_policy(PUSH)
  58. cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
  59. find_package(PkgConfig QUIET)
  60. if (PkgConfig_FOUND)
  61. pkg_check_modules(PC_OpenSP QUIET opensp)
  62. endif ()
  63. if (NOT OpenSP_INCLUDE_DIR)
  64. find_path(OpenSP_INCLUDE_DIR
  65. NAMES ParserEventGeneratorKit.h
  66. HINTS
  67. ${PC_OpenSP_INCLUDEDIRS}
  68. ${PC_OpenSP_INCLUDE_DIRS}
  69. PATH_SUFFIXES OpenSP opensp
  70. DOC "The OpenSP include directory"
  71. )
  72. endif ()
  73. if (NOT OpenSP_LIBRARY)
  74. find_library(OpenSP_LIBRARY_RELEASE
  75. NAMES osp libosp opensp libopensp sp133 libsp
  76. HINTS
  77. ${PC_OpenSP_LIBDIR}
  78. ${PC_OpenSP_LIBRARY_DIRS}
  79. )
  80. find_library(OpenSP_LIBRARY_DEBUG
  81. NAMES ospd libospd openspd libopenspd sp133d libspd
  82. HINTS
  83. ${PC_OpenSP_LIBDIR}
  84. ${PC_OpenSP_LIBRARY_DIRS}
  85. )
  86. include(SelectLibraryConfigurations)
  87. select_library_configurations(OpenSP)
  88. endif ()
  89. if (OpenSP_INCLUDE_DIR)
  90. if (EXISTS "${OpenSP_INCLUDE_DIR}/config.h")
  91. if (NOT OpenSP_VERSION)
  92. file(STRINGS "${OpenSP_INCLUDE_DIR}/config.h" opensp_version_str REGEX "^#define[\t ]+SP_VERSION[\t ]+\".*\"")
  93. string(REGEX REPLACE "^.*SP_VERSION[\t ]+\"([^\"]*)\".*$" "\\1" OpenSP_VERSION "${opensp_version_str}")
  94. unset(opensp_version_str)
  95. endif ()
  96. if (OpenSP_VERSION MATCHES [=[([0-9]+)\.([0-9]+)\.([0-9]+)]=])
  97. set(OpenSP_VERSION_MAJOR "${CMAKE_MATCH_1}")
  98. set(OpenSP_VERSION_MINOR "${CMAKE_MATCH_2}")
  99. set(OpenSP_VERSION_PATCH "${CMAKE_MATCH_3}")
  100. endif ()
  101. include(CheckCXXSymbolExists)
  102. check_cxx_symbol_exists(SP_MULTI_BYTE "${OpenSP_INCLUDE_DIR}/config.h" OpenSP_MULTI_BYTE)
  103. endif ()
  104. endif ()
  105. include(FindPackageHandleStandardArgs)
  106. find_package_handle_standard_args(OpenSP
  107. REQUIRED_VARS OpenSP_LIBRARY OpenSP_INCLUDE_DIR
  108. VERSION_VAR OpenSP_VERSION
  109. )
  110. mark_as_advanced(OpenSP_INCLUDE_DIR OpenSP_LIBRARY OpenSP_MULTI_BYTE)
  111. if (OpenSP_FOUND)
  112. set(OpenSP_INCLUDE_DIRS ${OpenSP_INCLUDE_DIR})
  113. if (NOT TARGET OpenSP::OpenSP)
  114. add_library(OpenSP::OpenSP UNKNOWN IMPORTED)
  115. if (EXISTS "${OpenSP_LIBRARY}")
  116. set_target_properties(OpenSP::OpenSP PROPERTIES
  117. IMPORTED_LOCATION "${OpenSP_LIBRARY}")
  118. endif ()
  119. set_target_properties(OpenSP::OpenSP PROPERTIES
  120. INTERFACE_INCLUDE_DIRECTORIES "${OpenSP_INCLUDE_DIRS}")
  121. if (OpenSP_LIBRARY_RELEASE)
  122. set_target_properties(OpenSP::OpenSP PROPERTIES
  123. IMPORTED_LOCATION_RELEASE "${OpenSP_LIBRARY_RELEASE}")
  124. set_property(TARGET OpenSP::OpenSP APPEND PROPERTY
  125. IMPORTED_CONFIGURATIONS RELEASE)
  126. endif ()
  127. if (OpenSP_LIBRARY_DEBUG)
  128. set_target_properties(OpenSP::OpenSP PROPERTIES
  129. IMPORTED_LOCATION_DEBUG "${OpenSP_LIBRARY_DEBUG}")
  130. set_property(TARGET OpenSP::OpenSP APPEND PROPERTY
  131. IMPORTED_CONFIGURATIONS DEBUG)
  132. endif ()
  133. endif ()
  134. endif ()
  135. include(FeatureSummary)
  136. set_package_properties(OpenSP PROPERTIES
  137. URL "https://openjade.sourceforge.net/doc/index.htm"
  138. DESCRIPTION "An SGML System Conforming to International Standard ISO 8879"
  139. )
  140. cmake_policy(POP)