Debian Codegraph @

cmake/modules/FindIcecream.cmake

raw
1 # Try to find the Icecream library
2 #
3 # Once done this defines:
4 # Icecream_FOUND - system has libicecream
5 # Icecream_INCLUDE_DIR - the libicecream include directory
6 # Icecream_LIBRARIES - Link these to use libicecream
7 # Icecream_VERSION - the libicecream version, if available
8
9 #=============================================================================
10 # Copyright 2015 Kevin Funk <[email protected]>
11 #
12 # Distributed under the OSI-approved BSD License (the "License");
13 # see accompanying file Copyright.txt for details.
14 #
15 # This software is distributed WITHOUT ANY WARRANTY; without even the
16 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 # See the License for more information.
18 #=============================================================================
19
20 if (Icecream_INCLUDE_DIR AND Icecream_LIBRARY AND Icecream_LIB_EXTRA)
21 # in cache already
22 set(Icecream_FOUND TRUE)
23 else ()
24 set(extraLibs)
25
26 if(NOT WIN32)
27 # use pkg-config to get the directories and then use these values
28 # in the FIND_PATH() and FIND_LIBRARY() calls
29 find_package(PkgConfig REQUIRED)
30 pkg_check_modules(PC_ICECC icecc>=1.3 REQUIRED)
31 # The icecream lib may optionally need linking to -lcap-ng, so dig it out
32 # of pkg-config data.
33 # Somewhat hackish, but I can't find a simpler way to do this with CMake.
34 foreach(lib ${PC_ICECC_STATIC_LIBRARIES})
35 if(NOT ${lib} STREQUAL "icecc")
36 list(APPEND extraLibs "-l${lib}")
37 endif()
38 endforeach()
39 set(Icecream_VERSION "${PC_ICECC_VERSION}")
40 endif()
41
42 list(APPEND extraLibs ${CMAKE_DL_LIBS})
43
44 set(Icecream_LIB_EXTRA ${extraLibs} CACHE INTERNAL "The library dependencies for libicecream")
45
46 find_path(Icecream_INCLUDE_DIR icecc/comm.h
47 HINTS
48 ${PC_ICECC_INCLUDEDIR}
49 ${PC_ICECC_INCLUDE_DIRS}
50 /opt/icecream/include
51 )
52
53 find_library(Icecream_LIBRARY NAMES icecc
54 HINTS
55 ${PC_ICECC_LIBDIR}
56 ${PC_ICECC_LIBRARY_DIRS}
57 /opt/icecream/lib
58 )
59
60 include(FindPackageHandleStandardArgs)
61 find_package_handle_standard_args(Icecream
62 REQUIRED_VARS Icecream_LIBRARY Icecream_INCLUDE_DIR
63 VERSION_VAR Icecream_VERSION
64 )
65
66 mark_as_advanced(
67 Icecream_INCLUDE_DIR Icecream_LIBRARIES Icecream_LIB_EXTRA
68 )
69 set(Icecream_FOUND ${ICECREAM_FOUND}) # CMake bug: Does not set Icecream_FOUND
70 endif()
71
72 if (Icecream_FOUND)
73 set(Icecream_LIBRARIES ${Icecream_LIBRARY} ${Icecream_LIB_EXTRA})
74
75 add_library(Icecream UNKNOWN IMPORTED)
76 set_target_properties(Icecream PROPERTIES
77 IMPORTED_LOCATION ${Icecream_LIBRARY}
78 INTERFACE_INCLUDE_DIRECTORIES ${Icecream_INCLUDE_DIR}
79 INTERFACE_LINK_LIBRARIES "${Icecream_LIB_EXTRA}"
80 )
81 endif()