1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
10 Try to find the OpenSP library.
15 This will define the following variables:
18 True if (the requested version of) ``OpenSP`` is available
21 The version of ``OpenSP``
23 ``OpenSP_VERSION_MAJOR``
24 The major version of ``OpenSP``
26 ``OpenSP_VERSION_MINOR``
27 The minor version of ``OpenSP``
29 ``OpenSP_VERSION_PATCH``
30 The patch version of ``OpenSP``
32 ``OpenSP_INCLUDE_DIRS``
33 The include dirs of ``OpenSP`` with its headers
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
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
50 This module defines the :prop_tgt:`IMPORTED` target ``OpenSP::OpenSP``, if
51 OpenSP has been found.
56 The following cache variables may also be set:
58 ``OpenSP_INCLUDE_DIR``
59 the OpenSP include directory
62 the absolute path of the osp library
64 #]=======================================================================]
67 cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
69 find_package(PkgConfig QUIET)
71 pkg_check_modules(PC_OpenSP QUIET opensp)
74 if (NOT OpenSP_INCLUDE_DIR)
75 find_path(OpenSP_INCLUDE_DIR
76 NAMES ParserEventGeneratorKit.h
78 ${PC_OpenSP_INCLUDEDIRS}
79 ${PC_OpenSP_INCLUDE_DIRS}
80 PATH_SUFFIXES OpenSP opensp
81 DOC "The OpenSP include directory"
85 if (NOT OpenSP_LIBRARY)
86 find_library(OpenSP_LIBRARY_RELEASE
87 NAMES osp libosp opensp libopensp sp133 libsp
90 ${PC_OpenSP_LIBRARY_DIRS}
93 find_library(OpenSP_LIBRARY_DEBUG
94 NAMES ospd libospd openspd libopenspd sp133d libspd
97 ${PC_OpenSP_LIBRARY_DIRS}
100 include(SelectLibraryConfigurations)
101 select_library_configurations(OpenSP)
104 if (OpenSP_INCLUDE_DIR)
105 if (EXISTS "${OpenSP_INCLUDE_DIR}/config.h")
106 if (NOT OpenSP_VERSION)
107 file(STRINGS "${OpenSP_INCLUDE_DIR}/config.h" opensp_version_str REGEX "^#define[\t ]+SP_VERSION[\t ]+\".*\"")
108 string(REGEX REPLACE "^.*SP_VERSION[\t ]+\"([^\"]*)\".*$" "\\1" OpenSP_VERSION "${opensp_version_str}")
109 unset(opensp_version_str)
112 if (OpenSP_VERSION MATCHES [=[([0-9]+)\.([0-9]+)\.([0-9]+)]=])
113 set(OpenSP_VERSION_MAJOR "${CMAKE_MATCH_1}")
114 set(OpenSP_VERSION_MINOR "${CMAKE_MATCH_2}")
115 set(OpenSP_VERSION_PATCH "${CMAKE_MATCH_3}")
118 include(CheckCXXSymbolExists)
119 check_cxx_symbol_exists(SP_MULTI_BYTE "${OpenSP_INCLUDE_DIR}/config.h" OpenSP_MULTI_BYTE)
123 include(FindPackageHandleStandardArgs)
124 find_package_handle_standard_args(OpenSP
125 REQUIRED_VARS OpenSP_LIBRARY OpenSP_INCLUDE_DIR
126 VERSION_VAR OpenSP_VERSION
129 mark_as_advanced(OpenSP_INCLUDE_DIR OpenSP_LIBRARY OpenSP_MULTI_BYTE)
132 set(OpenSP_INCLUDE_DIRS ${OpenSP_INCLUDE_DIR})
133 if (NOT TARGET OpenSP::OpenSP)
134 add_library(OpenSP::OpenSP UNKNOWN IMPORTED)
135 if (EXISTS "${OpenSP_LIBRARY}")
136 set_target_properties(OpenSP::OpenSP PROPERTIES
137 IMPORTED_LOCATION "${OpenSP_LIBRARY}")
139 set_target_properties(OpenSP::OpenSP PROPERTIES
140 INTERFACE_INCLUDE_DIRECTORIES "${OpenSP_INCLUDE_DIRS}")
142 if (OpenSP_LIBRARY_RELEASE)
143 set_target_properties(OpenSP::OpenSP PROPERTIES
144 IMPORTED_LOCATION_RELEASE "${OpenSP_LIBRARY_RELEASE}")
145 set_property(TARGET OpenSP::OpenSP APPEND PROPERTY
146 IMPORTED_CONFIGURATIONS RELEASE)
149 if (OpenSP_LIBRARY_DEBUG)
150 set_target_properties(OpenSP::OpenSP PROPERTIES
151 IMPORTED_LOCATION_DEBUG "${OpenSP_LIBRARY_DEBUG}")
152 set_property(TARGET OpenSP::OpenSP APPEND PROPERTY
153 IMPORTED_CONFIGURATIONS DEBUG)
158 include(FeatureSummary)
159 set_package_properties(OpenSP PROPERTIES
160 URL "http://openjade.sourceforge.net/doc/index.htm"
161 DESCRIPTION "An SGML System Conforming to International Standard ISO 8879"