Permalink
Browse files

Adding POPT CMake lib finder.

Utilities in the tools/ directory will now be built if
the popt library is found
  • Loading branch information...
1 parent 7715ad8 commit 89db105a5a7596bfdf00824911a5cba97d0e6668 @alanxz alanxz committed Nov 1, 2011
Showing with 130 additions and 6 deletions.
  1. +7 −0 CMakeLists.txt
  2. +18 −0 cmake/FindPOPT.cmake
  3. +99 −0 cmake/LibFindMacros.cmake
  4. +6 −6 tools/CMakeLists.txt
View
@@ -60,7 +60,14 @@ endif (FETCH_CODEGEN_FROM_GIT)
mark_as_advanced(AMQP_CODEGEN_DIR)
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
+
+find_package(POPT)
add_subdirectory(librabbitmq)
add_subdirectory(examples)
+if (POPT_FOUND)
+ add_subdirectory(tools)
+endif (POPT_FOUND)
+
View
@@ -0,0 +1,18 @@
+INCLUDE(LibFindMacros)
+
+# Find the include directories
+FIND_PATH(POPT_INCLUDE_DIR
+ NAMES popt.h
+ HINTS ${POPT_PREFIX}/include
+ )
+
+FIND_LIBRARY(POPT_LIBRARY
+ NAMES popt
+ HINTS ${POPT_PREFIX}/lib
+ )
+
+SET(POPT_PROCESS_INCLUDES POPT_INCLUDE_DIR)
+SET(POPT_PROCESS_LIBS POPT_LIBRARY)
+
+LIBFIND_PROCESS(POPT)
+
View
@@ -0,0 +1,99 @@
+# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments
+# used for the current package. For this to work, the first parameter must be the
+# prefix of the current package, then the prefix of the new package etc, which are
+# passed to find_package.
+macro (libfind_package PREFIX)
+ set (LIBFIND_PACKAGE_ARGS ${ARGN})
+ if (${PREFIX}_FIND_QUIETLY)
+ set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET)
+ endif (${PREFIX}_FIND_QUIETLY)
+ if (${PREFIX}_FIND_REQUIRED)
+ set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED)
+ endif (${PREFIX}_FIND_REQUIRED)
+ find_package(${LIBFIND_PACKAGE_ARGS})
+endmacro (libfind_package)
+
+# CMake developers made the UsePkgConfig system deprecated in the same release (2.6)
+# where they added pkg_check_modules. Consequently I need to support both in my scripts
+# to avoid those deprecated warnings. Here's a helper that does just that.
+# Works identically to pkg_check_modules, except that no checks are needed prior to use.
+macro (libfind_pkg_check_modules PREFIX PKGNAME)
+ if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
+ include(UsePkgConfig)
+ pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS)
+ else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
+ find_package(PkgConfig)
+ if (PKG_CONFIG_FOUND)
+ pkg_check_modules(${PREFIX} ${PKGNAME})
+ endif (PKG_CONFIG_FOUND)
+ endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
+endmacro (libfind_pkg_check_modules)
+
+# Do the final processing once the paths have been detected.
+# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain
+# all the variables, each of which contain one include directory.
+# Ditto for ${PREFIX}_PROCESS_LIBS and library files.
+# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES.
+# Also handles errors in case library detection was required, etc.
+macro (libfind_process PREFIX)
+ # Skip processing if already processed during this run
+ if (NOT ${PREFIX}_FOUND)
+ # Start with the assumption that the library was found
+ set (${PREFIX}_FOUND TRUE)
+
+ # Process all includes and set _FOUND to false if any are missing
+ foreach (i ${${PREFIX}_PROCESS_INCLUDES})
+ if (${i})
+ set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
+ mark_as_advanced(${i})
+ else (${i})
+ set (${PREFIX}_FOUND FALSE)
+ endif (${i})
+ endforeach (i)
+
+ # Process all libraries and set _FOUND to false if any are missing
+ foreach (i ${${PREFIX}_PROCESS_LIBS})
+ if (${i})
+ set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
+ mark_as_advanced(${i})
+ else (${i})
+ set (${PREFIX}_FOUND FALSE)
+ endif (${i})
+ endforeach (i)
+
+ # Print message and/or exit on fatal error
+ if (${PREFIX}_FOUND)
+ if (NOT ${PREFIX}_FIND_QUIETLY)
+ message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
+ endif (NOT ${PREFIX}_FIND_QUIETLY)
+ else (${PREFIX}_FOUND)
+ if (${PREFIX}_FIND_REQUIRED)
+ foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS})
+ message("${i}=${${i}}")
+ endforeach (i)
+ message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.")
+ endif (${PREFIX}_FIND_REQUIRED)
+ endif (${PREFIX}_FOUND)
+ endif (NOT ${PREFIX}_FOUND)
+endmacro (libfind_process)
+
+macro(libfind_library PREFIX basename)
+ set(TMP "")
+ if(MSVC80)
+ set(TMP -vc80)
+ endif(MSVC80)
+ if(MSVC90)
+ set(TMP -vc90)
+ endif(MSVC90)
+ set(${PREFIX}_LIBNAMES ${basename}${TMP})
+ if(${ARGC} GREATER 2)
+ set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2})
+ string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES})
+ set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP})
+ endif(${ARGC} GREATER 2)
+ find_library(${PREFIX}_LIBRARY
+ NAMES ${${PREFIX}_LIBNAMES}
+ PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS}
+ )
+endmacro(libfind_library)
+
View
@@ -1,4 +1,4 @@
-include_directories(${librabbitmq_SOURCE_DIR} ${librabbitmq_BINARY_DIR})
+include_directories(${librabbitmq_SOURCE_DIR} ${librabbitmq_BINARY_DIR} ${POPT_INCLUDE_DIRS})
if (WIN32)
set(PLATFORM_DIR win32)
@@ -18,17 +18,17 @@ set(COMMON_SRCS
)
add_executable(amqp-publish publish.c ${COMMON_SRCS})
-target_link_libraries(amqp-publish rabbitmq)
+target_link_libraries(amqp-publish rabbitmq ${POPT_LIBRARY})
add_executable(amqp-get get.c ${COMMON_SRCS})
-target_link_libraries(amqp-get rabbitmq)
+target_link_libraries(amqp-get rabbitmq ${POPT_LIBRARY})
add_executable(amqp-consume consume.c ${PLATFORM_DIR}/process.c ${COMMON_SRCS})
-target_link_libraries(amqp-consume rabbitmq)
+target_link_libraries(amqp-consume rabbitmq ${POPT_LIBRARY})
add_executable(amqp-declare-queue declare_queue.c ${COMMON_SRCS})
-target_link_libraries(amqp-declare-queue rabbitmq)
+target_link_libraries(amqp-declare-queue rabbitmq ${POPT_LIBRARY})
add_executable(amqp-delete-queue delete_queue.c ${COMMON_SRCS})
-target_link_libraries(amqp-delete-queue rabbitmq)
+target_link_libraries(amqp-delete-queue rabbitmq ${POPT_LIBRARY})

0 comments on commit 89db105

Please sign in to comment.