Imported Upstream version 0.7.4
[platform/upstream/libsolv.git] / cmake / modules / FindLibSolv.cmake
1 # FindLibSolv - Find libsolv headers and libraries.
2 #
3 # Sample:
4 #
5 #   SET( LibSolv_USE_STATIC_LIBS OFF )
6 #   FIND_PACKAGE( LibSolv REQUIRED ext )
7 #   IF( LibSolv_FOUND )
8 #      INCLUDE_DIRECTORIES( ${LibSolv_INCLUDE_DIRS} )
9 #      TARGET_LINK_LIBRARIES( ... ${LibSolv_LIBRARIES} )
10 #   ENDIF()
11 #
12 # Variables used by this module need to be set before calling find_package
13 # (not that they are cmale cased like the modiulemane itself):
14 #
15 #   LibSolv_USE_STATIC_LIBS     Can be set to ON to force the use of the static
16 #                               libsolv libraries. Defaults to OFF.
17 #
18 # Supported components:
19 #
20 #   ext                         Also include libsolvext
21 #
22 # Variables provided by this module:
23 #
24 #   LibSolv_FOUND               Include dir, libsolv and all extra libraries
25 #                               specified in the COMPONENTS list were found.
26 #
27 #   LibSolv_LIBRARIES           Link to these to use all the libraries you specified.
28 #
29 #   LibSolv_INCLUDE_DIRS        Include directories.
30 #
31 # For each component you specify in find_package(), the following (UPPER-CASE)
32 # variables are set to pick and choose components instead of just using LibSolv_LIBRARIES:
33 #
34 #   LIBSOLV_FOUND                       TRUE if libsolv was found
35 #   LIBSOLV_LIBRARY                     libsolv libraries
36 #
37 #   LIBSOLV_${COMPONENT}_FOUND          TRUE if the library component was found
38 #   LIBSOLV_${COMPONENT}_LIBRARY        The libraries for the specified component
39 #
40
41 # Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
42 IF(LibSolv_USE_STATIC_LIBS)
43     SET( _ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
44     SET(CMAKE_FIND_LIBRARY_SUFFIXES .a )
45 ENDIF()
46
47 # Look for the header files
48 UNSET(LibSolv_INCLUDE_DIRS CACHE)
49 FIND_PATH(LibSolv_INCLUDE_DIRS NAMES solv/solvable.h)
50
51 # Look for the core library
52 UNSET(LIBSOLV_LIBRARY CACHE)
53 FIND_LIBRARY(LIBSOLV_LIBRARY NAMES solv)
54 FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibSolv DEFAULT_MSG LIBSOLV_LIBRARY LibSolv_INCLUDE_DIRS)
55 MARK_AS_ADVANCED(
56     LIBSOLV_FOUND
57     LIBSOLV_LIBRARY
58 )
59
60 # Prepare return values and collectiong more components
61 SET(LibSolv_FOUND ${LIBSOLV_FOUND})
62 SET(LibSolv_LIBRARIES ${LIBSOLV_LIBRARY})
63 MARK_AS_ADVANCED(
64     LibSolv_FOUND
65     LibSolv_LIBRARIES
66     LibSolv_INCLUDE_DIRS
67 )
68
69 # Look for components
70 FOREACH(COMPONENT ${LibSolv_FIND_COMPONENTS})
71     STRING(TOUPPER ${COMPONENT} _UPPERCOMPONENT)
72     UNSET(LIBSOLV_${_UPPERCOMPONENT}_LIBRARY CACHE)
73     FIND_LIBRARY(LIBSOLV_${_UPPERCOMPONENT}_LIBRARY NAMES solv${COMPONENT})
74     SET(LibSolv_${COMPONENT}_FIND_REQUIRED ${LibSolv_FIND_REQUIRED})
75     SET(LibSolv_${COMPONENT}_FIND_QUIETLY ${LibSolv_FIND_QUIETLY})
76     FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibSolv_${COMPONENT} DEFAULT_MSG LIBSOLV_${_UPPERCOMPONENT}_LIBRARY)
77     MARK_AS_ADVANCED(
78         LIBSOLV_${_UPPERCOMPONENT}_FOUND
79         LIBSOLV_${_UPPERCOMPONENT}_LIBRARY
80     )
81     IF(LIBSOLV_${_UPPERCOMPONENT}_FOUND)
82         SET(LibSolv_LIBRARIES ${LibSolv_LIBRARIES} ${LIBSOLV_${_UPPERCOMPONENT}_LIBRARY})
83     ELSE()
84         SET(LibSolv_FOUND FALSE)
85     ENDIF()
86 ENDFOREACH()
87
88 # restore CMAKE_FIND_LIBRARY_SUFFIXES
89 IF(Solv_USE_STATIC_LIBS)
90     SET(CMAKE_FIND_LIBRARY_SUFFIXES ${_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES} )
91 ENDIF()
92
93 IF(LibSolv_FOUND AND NOT LibSolv_FIND_QUIETLY)
94     MESSAGE(STATUS "Found LibSolv: ${LibSolv_INCLUDE_DIRS} ${LibSolv_LIBRARIES}")
95 ENDIF()