blob: 25d0e6fb781130488fca817ac7de460e7f68cfd2 [file] [log] [blame]
Dawid Wróbele706da52022-07-12 16:39:58 +02001# 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:
5FindOpenSP
6----------
7
Dawid Wróbele706da52022-07-12 16:39:58 +02008.. versionadded:: 3.25
9
Brad King286a40c2022-10-07 11:29:00 -040010Try to find the OpenSP library.
11
Dawid Wróbele706da52022-07-12 16:39:58 +020012Result Variables
13^^^^^^^^^^^^^^^^
14
15This 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
47IMPORTED Targets
48^^^^^^^^^^^^^^^^
49
50This module defines the :prop_tgt:`IMPORTED` target ``OpenSP::OpenSP``, if
51OpenSP has been found.
52
53Cache variables
54^^^^^^^^^^^^^^^
55
56The 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
Kefu Chai3b1c19f2022-12-20 11:38:27 +080066find_package(PkgConfig QUIET)
67if (PkgConfig_FOUND)
68 pkg_check_modules(PC_OpenSP QUIET opensp)
Dawid Wróbele706da52022-07-12 16:39:58 +020069endif ()
70
71if (NOT OpenSP_INCLUDE_DIR)
72 find_path(OpenSP_INCLUDE_DIR
73 NAMES ParserEventGeneratorKit.h
Kefu Chai3b1c19f2022-12-20 11:38:27 +080074 HINTS
75 ${PC_OpenSP_INCLUDEDIRS}
76 ${PC_OpenSP_INCLUDE_DIRS}
Dawid Wróbele706da52022-07-12 16:39:58 +020077 PATH_SUFFIXES OpenSP opensp
78 DOC "The OpenSP include directory"
79 )
80endif ()
81
82if (NOT OpenSP_LIBRARY)
83 find_library(OpenSP_LIBRARY_RELEASE
84 NAMES osp libosp opensp libopensp sp133 libsp
Kefu Chai3b1c19f2022-12-20 11:38:27 +080085 HINTS
86 ${PC_OpenSP_LIBDIR}
87 ${PC_OpenSP_LIBRARY_DIRS}
Dawid Wróbele706da52022-07-12 16:39:58 +020088 )
89
90 find_library(OpenSP_LIBRARY_DEBUG
91 NAMES ospd libospd openspd libopenspd sp133d libspd
Kefu Chai3b1c19f2022-12-20 11:38:27 +080092 HINTS
93 ${PC_OpenSP_LIBDIR}
94 ${PC_OpenSP_LIBRARY_DIRS}
Dawid Wróbele706da52022-07-12 16:39:58 +020095 )
96
97 include(SelectLibraryConfigurations)
98 select_library_configurations(OpenSP)
99endif ()
100
Kefu Chai3b1c19f2022-12-20 11:38:27 +0800101if (OpenSP_INCLUDE_DIR)
Dawid Wróbele706da52022-07-12 16:39:58 +0200102 if (EXISTS "${OpenSP_INCLUDE_DIR}/config.h")
103 if (NOT OpenSP_VERSION)
104 file(STRINGS "${OpenSP_INCLUDE_DIR}/config.h" opensp_version_str REGEX "^#define[\t ]+SP_VERSION[\t ]+\".*\"")
105 string(REGEX REPLACE "^.*SP_VERSION[\t ]+\"([^\"]*)\".*$" "\\1" OpenSP_VERSION "${opensp_version_str}")
106 unset(opensp_version_str)
107 endif ()
108
109 if (OpenSP_VERSION MATCHES [=[([0-9]+)\.([0-9]+)\.([0-9]+)]=])
110 set(OpenSP_VERSION_MAJOR "${CMAKE_MATCH_1}")
111 set(OpenSP_VERSION_MINOR "${CMAKE_MATCH_2}")
112 set(OpenSP_VERSION_PATCH "${CMAKE_MATCH_3}")
113 endif ()
114
115 include(CheckCXXSymbolExists)
116 check_cxx_symbol_exists(SP_MULTI_BYTE "${OpenSP_INCLUDE_DIR}/config.h" OpenSP_MULTI_BYTE)
117 endif ()
Dawid Wróbele706da52022-07-12 16:39:58 +0200118endif ()
119
120include(FindPackageHandleStandardArgs)
121find_package_handle_standard_args(OpenSP
122 FOUND_VAR OpenSP_FOUND
123 REQUIRED_VARS OpenSP_LIBRARY OpenSP_INCLUDE_DIR
124 VERSION_VAR OpenSP_VERSION
125 )
126
127mark_as_advanced(OpenSP_INCLUDE_DIR OpenSP_LIBRARY OpenSP_MULTI_BYTE)
128
Kefu Chai3b1c19f2022-12-20 11:38:27 +0800129if (OpenSP_FOUND)
130 set(OpenSP_INCLUDE_DIRS ${OpenSP_INCLUDE_DIR})
131 if (NOT TARGET OpenSP::OpenSP)
132 add_library(OpenSP::OpenSP UNKNOWN IMPORTED)
133 if (EXISTS "${OpenSP_LIBRARY}")
134 set_target_properties(OpenSP::OpenSP PROPERTIES
135 IMPORTED_LOCATION "${OpenSP_LIBRARY}")
136 endif ()
137 set_target_properties(OpenSP::OpenSP PROPERTIES
138 INTERFACE_INCLUDE_DIRECTORIES "${OpenSP_INCLUDE_DIRS}")
139
140 if (OpenSP_LIBRARY_RELEASE)
141 set_target_properties(OpenSP::OpenSP PROPERTIES
142 IMPORTED_LOCATION_RELEASE "${OpenSP_LIBRARY_RELEASE}")
143 set_property(TARGET OpenSP::OpenSP APPEND PROPERTY
144 IMPORTED_CONFIGURATIONS RELEASE)
145 endif ()
146
147 if (OpenSP_LIBRARY_DEBUG)
148 set_target_properties(OpenSP::OpenSP PROPERTIES
149 IMPORTED_LOCATION_DEBUG "${OpenSP_LIBRARY_DEBUG}")
150 set_property(TARGET OpenSP::OpenSP APPEND PROPERTY
151 IMPORTED_CONFIGURATIONS DEBUG)
152 endif ()
153 endif ()
154endif ()
155
Dawid Wróbele706da52022-07-12 16:39:58 +0200156include(FeatureSummary)
157set_package_properties(OpenSP PROPERTIES
158 URL "http://openjade.sourceforge.net/doc/index.htm"
159 DESCRIPTION "An SGML System Conforming to International Standard ISO 8879"
160 )