summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/portaudio/cmake/modules/FindRegex.cmake
blob: 8793de613c768f97eb1df89c2102e23e3d2280c7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#[=======================================================================[.rst:
FindRegex
--------

Finds an implementation of POSIX regular expressions. It first checks if the
standard regex.h POSIX header is available. If not, it looks for the TRE library.
MinGW does not come with regex.h, so TRE is useful with MinGW.

Imported Targets
^^^^^^^^^^^^^^^^

This module provides the following imported targets, if found:

``Regex::regex``
  The POSIX regular expression implementation

#]=======================================================================]

include(FindPackageHandleStandardArgs)
include(CheckIncludeFile)

set(CMAKE_REQUIRED_QUIET TRUE)
check_include_file(regex.h REGEX_H)
set(CMAKE_REQUIRED_QUIET FALSE)

if(REGEX_H)
  # No need to add any include directories or link any libraries;
  # simply provide a dummy target.
  if(NOT TARGET Regex::regex)
    add_library(Regex::regex INTERFACE IMPORTED)
  endif()

  # check_include_file sets the variable to "1" which looks odd in the output
  # of find_package_handle_standard_args, so show the user what was actually found.
  set(REGEX_H "POSIX regex.h")
  find_package_handle_standard_args(
    Regex
    DEFAULT_MSG
    REGEX_H
  )
else()
  # MinGW does not include regex.h but this can be supplied by the TRE library.
  find_path(TRE_REGEX_H NAMES tre/regex.h)
  if(TRE_REGEX_H)
    # The POSIX #include is simply <regex.h> but the tre regex.h is at <tre/regex.h>,
    # so add the directory containing tre's headers to the include path.
    set(TRE_INCLUDE_DIR "${TRE_REGEX_H}/tre")
  endif()
  find_library(TRE_LIBRARY NAMES tre)
  if(TRE_REGEX_H AND TRE_LIBRARY)
    message(STATUS "Found regex.h from TRE")
  else()
    message(STATUS "regex.h POSIX header NOT found and NOT available from TRE")
  endif()

  if(NOT TARGET Regex::regex)
    add_library(Regex::regex INTERFACE IMPORTED)
    target_include_directories(Regex::regex INTERFACE "${TRE_INCLUDE_DIR}")
    target_link_libraries(Regex::regex INTERFACE "${TRE_LIBRARY}")
  endif()

  find_package_handle_standard_args(
    Regex
    DEFAULT_MSG
    TRE_INCLUDE_DIR
    TRE_LIBRARY
  )
endif()