From 1fc11eb24407b0b5d4417cde1c43c5c22282dcbc Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Thu, 6 Oct 2011 14:21:54 +0200 Subject: [PATCH] Provide a FindLibSolv.cmake file --- CMakeLists.txt | 1 + cmake/modules/FindLibSolv.cmake | 95 +++++++++++++++++++++++++++++++++ package/libsolv.spec.in | 23 ++++---- 3 files changed, 108 insertions(+), 11 deletions(-) create mode 100644 cmake/modules/FindLibSolv.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 70d8d0cb2..ad1fa2599 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ SET (BIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/bin") # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked SET (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) +INSTALL( FILES ${CMAKE_MODULE_PATH}/FindLibSolv.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules ) INCLUDE (${CMAKE_SOURCE_DIR}/VERSION.cmake) diff --git a/cmake/modules/FindLibSolv.cmake b/cmake/modules/FindLibSolv.cmake new file mode 100644 index 000000000..166e79dcd --- /dev/null +++ b/cmake/modules/FindLibSolv.cmake @@ -0,0 +1,95 @@ +# FindLibSolv - Find libsolv headers and libraries. +# +# Sample: +# +# SET( LibSolv_USE_STATIC_LIBS OFF ) +# FIND_PACKAGE( LibSolv REQUIRED ext ) +# IF( LibSolv_FOUND ) +# INCLUDE_DIRECTORIES( ${LibSolv_INCLUDE_DIRS} ) +# TARGET_LINK_LIBRARIES( ... ${LibSolv_LIBRARIES} ) +# ENDIF() +# +# Variables used by this module need to be set before calling find_package +# (not that they are cmale cased like the modiulemane itself): +# +# LibSolv_USE_STATIC_LIBS Can be set to ON to force the use of the static +# libsolv libraries. Defaults to OFF. +# +# Supported components: +# +# ext Also include libsolvext +# +# Variables provided by this module: +# +# LibSolv_FOUND Include dir, libsolv and all extra libraries +# specified in the COMPONENTS list were found. +# +# LibSolv_LIBRARIES Link to these to use all the libraries you specified. +# +# LibSolv_INCLUDE_DIRS Include directories. +# +# For each component you specify in find_package(), the following (UPPER-CASE) +# variables are set to pick and choose components instead of just using LibSolv_LIBRARIES: +# +# LIBSOLV_FOUND TRUE if libsolv was found +# LIBSOLV_LIBRARY libsolv libraries +# +# LIBSOLV_${COMPONENT}_FOUND TRUE if the library component was found +# LIBSOLV_${COMPONENT}_LIBRARY The libraries for the specified component +# + +# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES +IF(LibSolv_USE_STATIC_LIBS) + SET( _ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + SET(CMAKE_FIND_LIBRARY_SUFFIXES .a ) +ENDIF() + +# Look for the header files +UNSET(LibSolv_INCLUDE_DIRS CACHE) +FIND_PATH(LibSolv_INCLUDE_DIRS NAMES solv/solvable.h) + +# Look for the core library +UNSET(LIBSOLV_LIBRARY CACHE) +FIND_LIBRARY(LIBSOLV_LIBRARY NAMES solv) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibSolv DEFAULT_MSG LIBSOLV_LIBRARY LibSolv_INCLUDE_DIRS) +MARK_AS_ADVANCED( + LIBSOLV_FOUND + LIBSOLV_LIBRARY +) + +# Prepare return values and collectiong more components +SET(LibSolv_FOUND ${LIBSOLV_FOUND}) +SET(LibSolv_LIBRARIES ${LIBSOLV_LIBRARY}) +MARK_AS_ADVANCED( + LibSolv_FOUND + LibSolv_LIBRARIES + LibSolv_INCLUDE_DIRS +) + +# Look for components +FOREACH(COMPONENT ${LibSolv_FIND_COMPONENTS}) + STRING(TOUPPER ${COMPONENT} _UPPERCOMPONENT) + UNSET(LIBSOLV_${_UPPERCOMPONENT}_LIBRARY CACHE) + FIND_LIBRARY(LIBSOLV_${_UPPERCOMPONENT}_LIBRARY NAMES solv${COMPONENT}) + SET(LibSolv_${COMPONENT}_FIND_REQUIRED ${LibSolv_FIND_REQUIRED}) + SET(LibSolv_${COMPONENT}_FIND_QUIETLY ${LibSolv_FIND_QUIETLY}) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibSolv_${COMPONENT} DEFAULT_MSG LIBSOLV_${_UPPERCOMPONENT}_LIBRARY) + MARK_AS_ADVANCED( + LIBSOLV_${_UPPERCOMPONENT}_FOUND + LIBSOLV_${_UPPERCOMPONENT}_LIBRARY + ) + IF(LIBSOLV_${_UPPERCOMPONENT}_FOUND) + SET(LibSolv_LIBRARIES ${LibSolv_LIBRARIES} ${LIBSOLV_${_UPPERCOMPONENT}_LIBRARY}) + ELSE() + SET(LibSolv_FOUND FALSE) + ENDIF() +ENDFOREACH() + +# restore CMAKE_FIND_LIBRARY_SUFFIXES +IF(Solv_USE_STATIC_LIBS) + SET(CMAKE_FIND_LIBRARY_SUFFIXES ${_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES} ) +ENDIF() + +IF(LibSolv_FOUND AND NOT LibSolv_FIND_QUIETLY) + MESSAGE(STATUS "Found LibSolv: ${LibSolv_INCLUDE_DIRS} ${LibSolv_LIBRARIES}") +ENDIF() diff --git a/package/libsolv.spec.in b/package/libsolv.spec.in index deec7b396..2209d1f65 100644 --- a/package/libsolv.spec.in +++ b/package/libsolv.spec.in @@ -184,7 +184,7 @@ cmake $CMAKE_FLAGS \ %{?with_python_binding:-DENABLE_PYTHON=1} \ %{?with_ruby_binding:-DENABLE_RUBY=1} \ -DUSE_VENDORDIRS=1 \ - -DCMAKE_SKIP_RPATH=1 + -DCMAKE_SKIP_RPATH=1 make %{?jobs:-j %jobs} %install @@ -211,26 +211,27 @@ rm -rf "$RPM_BUILD_ROOT" %files -n libsolv@LIBSOLV_SOVERSION@ %defattr(-,root,root) %doc LICENSE* -%_libdir/libsolv.so.* -%_libdir/libsolvext.so.* +%{_libdir}/libsolv.so.* +%{_libdir}/libsolvext.so.* %endif %files tools %defattr(-,root,root) -%exclude /usr/bin/helix2solv -%exclude /usr/bin/solv -/usr/bin/* +%exclude %{_bindir}/helix2solv +%exclude %{_bindir}/solv +%{_bindir}/* %files devel %defattr(-,root,root) -%_libdir/libsolv.so -%_libdir/libsolvext.so -/usr/include/solv -/usr/bin/helix2solv +%{_libdir}/libsolv.so +%{_libdir}/libsolvext.so +%{_includedir}/solv +%{_bindir}/helix2solv +%{_datadir}/cmake/Modules/* %files demo %defattr(-,root,root) -/usr/bin/solv +%{_bindir}/solv %if %{with perl_binding} %files -n perl-solv