Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adding POPT CMake lib finder.

Utilities in the tools/ directory will now be built if
the popt library is found
  • Loading branch information...
commit 89db105a5a7596bfdf00824911a5cba97d0e6668 1 parent 7715ad8
Alan Antonuk authored
7  CMakeLists.txt
@@ -60,7 +60,14 @@ endif (FETCH_CODEGEN_FROM_GIT)
60 60
 
61 61
 mark_as_advanced(AMQP_CODEGEN_DIR)
62 62
 
  63
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
  64
+
  65
+find_package(POPT)
63 66
 
64 67
 add_subdirectory(librabbitmq)
65 68
 add_subdirectory(examples)
66 69
 
  70
+if (POPT_FOUND)
  71
+    add_subdirectory(tools)
  72
+endif (POPT_FOUND)
  73
+
18  cmake/FindPOPT.cmake
... ...
@@ -0,0 +1,18 @@
  1
+INCLUDE(LibFindMacros)
  2
+
  3
+# Find the include directories
  4
+FIND_PATH(POPT_INCLUDE_DIR
  5
+    NAMES popt.h
  6
+    HINTS ${POPT_PREFIX}/include
  7
+    )
  8
+
  9
+FIND_LIBRARY(POPT_LIBRARY
  10
+    NAMES popt
  11
+    HINTS ${POPT_PREFIX}/lib
  12
+    )
  13
+
  14
+SET(POPT_PROCESS_INCLUDES POPT_INCLUDE_DIR)
  15
+SET(POPT_PROCESS_LIBS POPT_LIBRARY)
  16
+
  17
+LIBFIND_PROCESS(POPT)
  18
+
99  cmake/LibFindMacros.cmake
... ...
@@ -0,0 +1,99 @@
  1
+# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments
  2
+# used for the current package. For this to work, the first parameter must be the
  3
+# prefix of the current package, then the prefix of the new package etc, which are
  4
+# passed to find_package.
  5
+macro (libfind_package PREFIX)
  6
+  set (LIBFIND_PACKAGE_ARGS ${ARGN})
  7
+  if (${PREFIX}_FIND_QUIETLY)
  8
+    set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET)
  9
+  endif (${PREFIX}_FIND_QUIETLY)
  10
+  if (${PREFIX}_FIND_REQUIRED)
  11
+    set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED)
  12
+  endif (${PREFIX}_FIND_REQUIRED)
  13
+  find_package(${LIBFIND_PACKAGE_ARGS})
  14
+endmacro (libfind_package)
  15
+
  16
+# CMake developers made the UsePkgConfig system deprecated in the same release (2.6)
  17
+# where they added pkg_check_modules. Consequently I need to support both in my scripts
  18
+# to avoid those deprecated warnings. Here's a helper that does just that.
  19
+# Works identically to pkg_check_modules, except that no checks are needed prior to use.
  20
+macro (libfind_pkg_check_modules PREFIX PKGNAME)
  21
+  if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
  22
+    include(UsePkgConfig)
  23
+    pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS)
  24
+  else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
  25
+    find_package(PkgConfig)
  26
+    if (PKG_CONFIG_FOUND)
  27
+      pkg_check_modules(${PREFIX} ${PKGNAME})
  28
+    endif (PKG_CONFIG_FOUND)
  29
+  endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
  30
+endmacro (libfind_pkg_check_modules)
  31
+
  32
+# Do the final processing once the paths have been detected.
  33
+# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain
  34
+# all the variables, each of which contain one include directory.
  35
+# Ditto for ${PREFIX}_PROCESS_LIBS and library files.
  36
+# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES.
  37
+# Also handles errors in case library detection was required, etc.
  38
+macro (libfind_process PREFIX)
  39
+  # Skip processing if already processed during this run
  40
+  if (NOT ${PREFIX}_FOUND)
  41
+    # Start with the assumption that the library was found
  42
+    set (${PREFIX}_FOUND TRUE)
  43
+
  44
+    # Process all includes and set _FOUND to false if any are missing
  45
+    foreach (i ${${PREFIX}_PROCESS_INCLUDES})
  46
+      if (${i})
  47
+        set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
  48
+        mark_as_advanced(${i})
  49
+      else (${i})
  50
+        set (${PREFIX}_FOUND FALSE)
  51
+      endif (${i})
  52
+    endforeach (i)
  53
+
  54
+    # Process all libraries and set _FOUND to false if any are missing
  55
+    foreach (i ${${PREFIX}_PROCESS_LIBS})
  56
+      if (${i})
  57
+        set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
  58
+        mark_as_advanced(${i})
  59
+      else (${i})
  60
+        set (${PREFIX}_FOUND FALSE)
  61
+      endif (${i})
  62
+    endforeach (i)
  63
+
  64
+    # Print message and/or exit on fatal error
  65
+    if (${PREFIX}_FOUND)
  66
+      if (NOT ${PREFIX}_FIND_QUIETLY)
  67
+        message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
  68
+      endif (NOT ${PREFIX}_FIND_QUIETLY)
  69
+    else (${PREFIX}_FOUND)
  70
+      if (${PREFIX}_FIND_REQUIRED)
  71
+        foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS})
  72
+          message("${i}=${${i}}")
  73
+        endforeach (i)
  74
+        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.")
  75
+      endif (${PREFIX}_FIND_REQUIRED)
  76
+    endif (${PREFIX}_FOUND)
  77
+  endif (NOT ${PREFIX}_FOUND)
  78
+endmacro (libfind_process)
  79
+
  80
+macro(libfind_library PREFIX basename)
  81
+  set(TMP "")
  82
+  if(MSVC80)
  83
+    set(TMP -vc80)
  84
+  endif(MSVC80)
  85
+  if(MSVC90)
  86
+    set(TMP -vc90)
  87
+  endif(MSVC90)
  88
+  set(${PREFIX}_LIBNAMES ${basename}${TMP})
  89
+  if(${ARGC} GREATER 2)
  90
+    set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2})
  91
+    string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES})
  92
+    set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP})
  93
+  endif(${ARGC} GREATER 2)
  94
+  find_library(${PREFIX}_LIBRARY
  95
+    NAMES ${${PREFIX}_LIBNAMES}
  96
+    PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS}
  97
+  )
  98
+endmacro(libfind_library)
  99
+
12  tools/CMakeLists.txt
... ...
@@ -1,4 +1,4 @@
1  
-include_directories(${librabbitmq_SOURCE_DIR} ${librabbitmq_BINARY_DIR})
  1
+include_directories(${librabbitmq_SOURCE_DIR} ${librabbitmq_BINARY_DIR} ${POPT_INCLUDE_DIRS})
2 2
 
3 3
 if (WIN32)
4 4
     set(PLATFORM_DIR win32)
@@ -18,17 +18,17 @@ set(COMMON_SRCS
18 18
     )
19 19
 
20 20
 add_executable(amqp-publish publish.c ${COMMON_SRCS})
21  
-target_link_libraries(amqp-publish rabbitmq)
  21
+target_link_libraries(amqp-publish rabbitmq ${POPT_LIBRARY})
22 22
 
23 23
 add_executable(amqp-get get.c ${COMMON_SRCS})
24  
-target_link_libraries(amqp-get rabbitmq)
  24
+target_link_libraries(amqp-get rabbitmq ${POPT_LIBRARY})
25 25
 
26 26
 add_executable(amqp-consume consume.c ${PLATFORM_DIR}/process.c ${COMMON_SRCS})
27  
-target_link_libraries(amqp-consume rabbitmq)
  27
+target_link_libraries(amqp-consume rabbitmq ${POPT_LIBRARY})
28 28
 
29 29
 add_executable(amqp-declare-queue declare_queue.c ${COMMON_SRCS})
30  
-target_link_libraries(amqp-declare-queue rabbitmq)
  30
+target_link_libraries(amqp-declare-queue rabbitmq ${POPT_LIBRARY})
31 31
 
32 32
 add_executable(amqp-delete-queue delete_queue.c ${COMMON_SRCS})
33  
-target_link_libraries(amqp-delete-queue rabbitmq)
  33
+target_link_libraries(amqp-delete-queue rabbitmq ${POPT_LIBRARY})
34 34
 

0 notes on commit 89db105

Please sign in to comment.
Something went wrong with that request. Please try again.