-
Notifications
You must be signed in to change notification settings - Fork 299
/
Findcxxopts.cmake
74 lines (62 loc) · 2.82 KB
/
Findcxxopts.cmake
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
69
70
71
72
73
74
# Find the cxxopts headers
# Behavior is to first look for config files, such as the one installed by some package
# managers who provides their own cmake files.
# Most of them and official sources does not provide cmake finders, so if no config files
# were found, this tries to find the library by looking at headers file.
#
# Defines:
# cxxopts_FOUND : True if cxxopts is found
# cxxopts_VERSION : cxxopts version if found
#
# Provides both target cxxopts::cxxopts.
find_package(cxxopts NO_MODULE QUIET HINTS ${cxxopts_DIR})
macro(_cxxopts_check_version)
if(EXISTS "${cxxopts_INCLUDE_DIR}/cxxopts.hpp")
file(READ "${cxxopts_INCLUDE_DIR}/cxxopts.hpp" _cxxopts_version_header)
endif()
string(REGEX MATCH "define[ \t]+CXXOPTS__VERSION_MAJOR[ \t]+([0-9]+)" _cxxopts_major_version_match "${_cxxopts_version_header}")
set(cxxopts_VERSION_MAJOR "${CMAKE_MATCH_1}")
string(REGEX MATCH "define[ \t]+CXXOPTS__VERSION_MINOR[ \t]+([0-9]+)" _cxxopts_minor_version_match "${_cxxopts_version_header}")
set(cxxopts_VERSION_MINOR "${CMAKE_MATCH_1}")
string(REGEX MATCH "define[ \t]+CXXOPTS__VERSION_PATCH[ \t]+([0-9]+)" _cxxopts_patch_version_match "${_cxxopts_version_header}")
set(cxxopts_VERSION_PATCH "${CMAKE_MATCH_1}")
set(cxxopts_VERSION ${cxxopts_VERSION_MAJOR}.${cxxopts_VERSION_MINOR}.${cxxopts_VERSION_PATCH})
set(cxxopts_VERSION_OK TRUE)
if(${cxxopts_VERSION} VERSION_LESS ${cxxopts_FIND_VERSION})
set(cxxopts_VERSION_OK FALSE)
message(SEND_ERROR "cxxopts version ${cxxopts_VERSION} found in ${cxxopts_INCLUDE_DIR}/cxxopts.hpp, "
"but at least version ${cxxopts_FIND_VERSION} is required")
endif()
if(${cxxopts_FIND_VERSION_EXACT} AND NOT ${cxxopts_VERSION} VERSION_EQUAL ${cxxopts_FIND_VERSION})
set(cxxopts_VERSION_OK FALSE)
message(SEND_ERROR "cxxopts version ${cxxopts_VERSION} found in ${cxxopts_INCLUDE_DIR}, "
"but exact version ${cxxopts_FIND_VERSION_EXACT} is required")
endif()
endmacro()
if(NOT TARGET cxxopts::cxxopts)
if(NOT cxxopts_INCLUDE_DIR)
find_path(cxxopts_INCLUDE_DIR
NAMES cxxopts.hpp
PATH_SUFFIXES include
)
endif()
if(cxxopts_INCLUDE_DIR)
_cxxopts_check_version()
set(cxxopts_FOUND ${cxxopts_VERSION_OK})
endif()
if(cxxopts_FOUND)
set(cxxopts_INCLUDE_DIRS ${cxxopts_INCLUDE_DIR})
if(NOT cxxopts_FIND_QUIETLY)
message(STATUS "Found cxxopts version ${cxxopts_VERSION} from ${cxxopts_INCLUDE_DIR}/cxxopts.hpp)")
endif()
if(NOT TARGET cxxopts::cxxopts)
add_library(cxxopts::cxxopts INTERFACE IMPORTED)
set_property(TARGET cxxopts::cxxopts PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${cxxopts_INCLUDE_DIR}")
endif()
else()
endif()
mark_as_advanced(cxxopts_INCLUDE_DIR)
endif()
if(NOT cxxopts_FOUND AND cxxopts_FIND_REQUIRED)
message(FATAL_ERROR "Cannot find cxxopts")
endif()