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