Merge topic 'cuda_add_12.8_new_sm_support'
[kiteware-cmake.git] / Modules / FindOpenSP.cmake
blob8f6d50aa31c5984def09753982dc2534be73f151
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:
5 FindOpenSP
6 ----------
8 .. versionadded:: 3.25
10 Try to find the OpenSP library.
12 Result Variables
13 ^^^^^^^^^^^^^^^^
15 This will define the following variables:
17 ``OpenSP_FOUND``
18   True if (the requested version of) ``OpenSP`` is available
20 ``OpenSP_VERSION``
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
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
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.
47 Imported Targets
48 ^^^^^^^^^^^^^^^^
50 This module defines the :prop_tgt:`IMPORTED` target ``OpenSP::OpenSP``, if
51 OpenSP has been found.
53 Cache variables
54 ^^^^^^^^^^^^^^^
56 The following cache variables may also be set:
58 ``OpenSP_INCLUDE_DIR``
59   the OpenSP include directory
61 ``OpenSP_LIBRARY``
62   the absolute path of the osp library
64 #]=======================================================================]
66 cmake_policy(PUSH)
67 cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
69 find_package(PkgConfig QUIET)
70 if (PkgConfig_FOUND)
71   pkg_check_modules(PC_OpenSP QUIET opensp)
72 endif ()
74 if (NOT OpenSP_INCLUDE_DIR)
75   find_path(OpenSP_INCLUDE_DIR
76     NAMES ParserEventGeneratorKit.h
77     HINTS
78     ${PC_OpenSP_INCLUDEDIRS}
79     ${PC_OpenSP_INCLUDE_DIRS}
80     PATH_SUFFIXES OpenSP opensp
81     DOC "The OpenSP include directory"
82     )
83 endif ()
85 if (NOT OpenSP_LIBRARY)
86   find_library(OpenSP_LIBRARY_RELEASE
87     NAMES osp libosp opensp libopensp sp133 libsp
88     HINTS
89     ${PC_OpenSP_LIBDIR}
90     ${PC_OpenSP_LIBRARY_DIRS}
91     )
93   find_library(OpenSP_LIBRARY_DEBUG
94     NAMES ospd libospd openspd libopenspd sp133d libspd
95     HINTS
96     ${PC_OpenSP_LIBDIR}
97     ${PC_OpenSP_LIBRARY_DIRS}
98     )
100   include(SelectLibraryConfigurations)
101   select_library_configurations(OpenSP)
102 endif ()
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)
110     endif ()
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}")
116     endif ()
118     include(CheckCXXSymbolExists)
119     check_cxx_symbol_exists(SP_MULTI_BYTE "${OpenSP_INCLUDE_DIR}/config.h" OpenSP_MULTI_BYTE)
120   endif ()
121 endif ()
123 include(FindPackageHandleStandardArgs)
124 find_package_handle_standard_args(OpenSP
125   REQUIRED_VARS OpenSP_LIBRARY OpenSP_INCLUDE_DIR
126   VERSION_VAR OpenSP_VERSION
127   )
129 mark_as_advanced(OpenSP_INCLUDE_DIR OpenSP_LIBRARY OpenSP_MULTI_BYTE)
131 if (OpenSP_FOUND)
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}")
138     endif ()
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)
147     endif ()
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)
154     endif ()
155   endif ()
156 endif ()
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"
162   )
164 cmake_policy(POP)