FindOpenSP.cmake 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. find_package(PkgConfig QUIET)
  46. if (PkgConfig_FOUND)
  47. pkg_check_modules(PC_OpenSP QUIET opensp)
  48. endif ()
  49. if (NOT OpenSP_INCLUDE_DIR)
  50. find_path(OpenSP_INCLUDE_DIR
  51. NAMES ParserEventGeneratorKit.h
  52. HINTS
  53. ${PC_OpenSP_INCLUDEDIRS}
  54. ${PC_OpenSP_INCLUDE_DIRS}
  55. PATH_SUFFIXES OpenSP opensp
  56. DOC "The OpenSP include directory"
  57. )
  58. endif ()
  59. if (NOT OpenSP_LIBRARY)
  60. find_library(OpenSP_LIBRARY_RELEASE
  61. NAMES osp libosp opensp libopensp sp133 libsp
  62. HINTS
  63. ${PC_OpenSP_LIBDIR}
  64. ${PC_OpenSP_LIBRARY_DIRS}
  65. )
  66. find_library(OpenSP_LIBRARY_DEBUG
  67. NAMES ospd libospd openspd libopenspd sp133d libspd
  68. HINTS
  69. ${PC_OpenSP_LIBDIR}
  70. ${PC_OpenSP_LIBRARY_DIRS}
  71. )
  72. include(SelectLibraryConfigurations)
  73. select_library_configurations(OpenSP)
  74. endif ()
  75. if (OpenSP_INCLUDE_DIR)
  76. if (EXISTS "${OpenSP_INCLUDE_DIR}/config.h")
  77. if (NOT OpenSP_VERSION)
  78. file(STRINGS "${OpenSP_INCLUDE_DIR}/config.h" opensp_version_str REGEX "^#define[\t ]+SP_VERSION[\t ]+\".*\"")
  79. string(REGEX REPLACE "^.*SP_VERSION[\t ]+\"([^\"]*)\".*$" "\\1" OpenSP_VERSION "${opensp_version_str}")
  80. unset(opensp_version_str)
  81. endif ()
  82. if (OpenSP_VERSION MATCHES [=[([0-9]+)\.([0-9]+)\.([0-9]+)]=])
  83. set(OpenSP_VERSION_MAJOR "${CMAKE_MATCH_1}")
  84. set(OpenSP_VERSION_MINOR "${CMAKE_MATCH_2}")
  85. set(OpenSP_VERSION_PATCH "${CMAKE_MATCH_3}")
  86. endif ()
  87. include(CheckCXXSymbolExists)
  88. check_cxx_symbol_exists(SP_MULTI_BYTE "${OpenSP_INCLUDE_DIR}/config.h" OpenSP_MULTI_BYTE)
  89. endif ()
  90. endif ()
  91. include(FindPackageHandleStandardArgs)
  92. find_package_handle_standard_args(OpenSP
  93. FOUND_VAR OpenSP_FOUND
  94. REQUIRED_VARS OpenSP_LIBRARY OpenSP_INCLUDE_DIR
  95. VERSION_VAR OpenSP_VERSION
  96. )
  97. mark_as_advanced(OpenSP_INCLUDE_DIR OpenSP_LIBRARY OpenSP_MULTI_BYTE)
  98. if (OpenSP_FOUND)
  99. set(OpenSP_INCLUDE_DIRS ${OpenSP_INCLUDE_DIR})
  100. if (NOT TARGET OpenSP::OpenSP)
  101. add_library(OpenSP::OpenSP UNKNOWN IMPORTED)
  102. if (EXISTS "${OpenSP_LIBRARY}")
  103. set_target_properties(OpenSP::OpenSP PROPERTIES
  104. IMPORTED_LOCATION "${OpenSP_LIBRARY}")
  105. endif ()
  106. set_target_properties(OpenSP::OpenSP PROPERTIES
  107. INTERFACE_INCLUDE_DIRECTORIES "${OpenSP_INCLUDE_DIRS}")
  108. if (OpenSP_LIBRARY_RELEASE)
  109. set_target_properties(OpenSP::OpenSP PROPERTIES
  110. IMPORTED_LOCATION_RELEASE "${OpenSP_LIBRARY_RELEASE}")
  111. set_property(TARGET OpenSP::OpenSP APPEND PROPERTY
  112. IMPORTED_CONFIGURATIONS RELEASE)
  113. endif ()
  114. if (OpenSP_LIBRARY_DEBUG)
  115. set_target_properties(OpenSP::OpenSP PROPERTIES
  116. IMPORTED_LOCATION_DEBUG "${OpenSP_LIBRARY_DEBUG}")
  117. set_property(TARGET OpenSP::OpenSP APPEND PROPERTY
  118. IMPORTED_CONFIGURATIONS DEBUG)
  119. endif ()
  120. endif ()
  121. endif ()
  122. include(FeatureSummary)
  123. set_package_properties(OpenSP PROPERTIES
  124. URL "http://openjade.sourceforge.net/doc/index.htm"
  125. DESCRIPTION "An SGML System Conforming to International Standard ISO 8879"
  126. )