-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindPLIB.cmake
63 lines (57 loc) · 1.98 KB
/
FindPLIB.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
# - Try to find PLIB
# Once done, this will define
#
# PLIB_FOUND : library found
# PLIB_INCLUDE_DIRS : include directories
# PLIB_LIBRARIES : libraries to link to
# PLIB_VERSION : version
#
# when listing components, list in the order below
# to ensure proper static linking
#
# macros
include(FindPackageHandleStandardArgs)
set(_PLIB_EXTRA_SEARCH_PATHS
/usr/local
/opt/local
)
# find the include directory
find_path(_PLIB_INCLUDE_DIR
NAMES plib/ul.h
PATHS ${_PLIB_EXTRA_SEARCH_PATHS}
PATH_SUFFIXES include
)
# read the version
if (EXISTS ${_PLIB_INCLUDE_DIR}/plib/ul.h)
file(READ ${_PLIB_INCLUDE_DIR}/plib/ul.h PLIB_VERSION_FILE)
string(REGEX MATCH "\#define PLIB_MAJOR_VERSION ([0-9]+)" _PLIB_VERSION_MATCH ${PLIB_VERSION_FILE})
set(_PLIB_MAJOR_VERSION ${CMAKE_MATCH_1})
string(REGEX MATCH "\#define PLIB_MINOR_VERSION[ ]+([0-9]+)" _PLIB_VERSION_MATCH ${PLIB_VERSION_FILE})
set(_PLIB_MINOR_VERSION ${CMAKE_MATCH_1})
string(REGEX MATCH "\#define PLIB_TINY_VERSION[ ]+([0-9]+)" _PLIB_VERSION_MATCH ${PLIB_VERSION_FILE})
set(_PLIB_TINY_VERSION ${CMAKE_MATCH_1})
set(PLIB_VERSION "${_PLIB_MAJOR_VERSION}.${_PLIB_MINOR_VERSION}.${_PLIB_TINY_VERSION}")
else()
set(PLIB_VERSION "")
endif()
# find components
set(PLIB_LIBRARIES "")
if ("${PLIB_FIND_COMPONENTS}" STREQUAL "")
message(FATAL_ERROR "FindPLIB: must specify a plib library as a component.")
endif()
foreach(component ${PLIB_FIND_COMPONENTS})
string(TOUPPER ${component} component_uc)
string(TOLOWER ${component} component_lc)
find_library(PLIB_${component_uc}
NAMES plib${component_lc} libplib${component_lc}.a
PATHS ${_PLIB_EXTRA_SEARCH_PATHS}
PATH_SUFFIXES lib
)
list(APPEND PLIB_LIBRARIES ${PLIB_${component_uc}})
endforeach()
# handle arguments
set(PLIB_INCLUDE_DIRS ${_PLIB_INCLUDE_DIR})
find_package_handle_standard_args(PLIB
REQUIRED_VARS PLIB_LIBRARIES PLIB_INCLUDE_DIRS PLIB_VERSION
VERSION_VAR PLIB_VERSION
)