Better way to wrap pkg-config (IMNSHO)
authorPierre Habouzit <madcoder@debian.org>
Sat, 18 Aug 2007 16:38:37 +0000 (18:38 +0200)
committerPierre Habouzit <madcoder@debian.org>
Sat, 18 Aug 2007 16:38:37 +0000 (18:38 +0200)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
CMakeLists.txt

index 67bede3..33cd4f6 100644 (file)
@@ -20,7 +20,7 @@ SET(PKGDATADIR "${CMAKE_INSTALL_PREFIX}/share/madmutt")
 SET(PKGDOCDIR  "${CMAKE_INSTALL_PREFIX}/share/doc/madmutt")
 SET(SYSCONFDIR "${CMAKE_INSTALL_PREFIX}/etc")
 SET(VERSION    "devel")
-SET(MUTTLIBS   "")
+SET(MUTTLIBS)
 
 ADD_DEFINITIONS("-DBINDIR=\\\"${BINDIR}\\\"")
 ADD_DEFINITIONS("-DPKGDATADIR=\\\"${PKGDATADIR}\\\"")
@@ -116,17 +116,17 @@ CHECK_FUNCTION_EXISTS(nl_langinfo HAVE_LANGINFO_CODESET)
 # }}}
 # libraries {{{
 INCLUDE(CheckLibraryExists)
-INCLUDE(UsePkgConfig)
+INCLUDE(FindPkgConfig)
 
 IF(HAVE_NCURSESW_NCURSES_H)
     SET(CMAKE_REQUIRED_INCLUDES "ncursesw/ncurses.h")
-    SET(MUTTLIBS "${MUTTLIBS} -lncursesw")
+    LIST(APPEND MUTTLIBS -lncursesw)
 ELSEIF(HAVE_NCURSES_H)
     SET(CMAKE_REQUIRED_INCLUDES "ncurses.h")
-    SET(MUTTLIBS "${MUTTLIBS} -lncurses")
+    LIST(APPEND MUTTLIBS  -lncurses)
 ELSEIF(HAVE_NCURSES_H OR HAVE_NCURSES_NCURSES_H)
     SET(CMAKE_REQUIRED_INCLUDES "ncurses/ncurses.h")
-    SET(MUTTLIBS "${MUTTLIBS} -lncurses")
+    LIST(APPEND MUTTLIBS  -lncurses)
 ELSE(HAVE_NCURSESW_NCURSES_H)
     MESSAGE(FATAL_ERROR "could not find ncurses.h")
 ENDIF(HAVE_NCURSESW_NCURSES_H)
@@ -135,17 +135,15 @@ CHECK_FUNCTION_EXISTS(resizeterm         HAVE_RESIZETERM)
 SET(CMAKE_REQUIRED_LIBRARIES)
 SET(CMAKE_REQUIRED_INCLUDES)
 
-PKGCONFIG(lua5.1 lua_INCDIR lua_LINKDIR lua_LDFLAGS lua_CFLAGS)
-MESSAGE(STATUS "found lua5.1 at: INCDIR ${lua_INCDIR}")
-INCLUDE_DIRECTORIES(${lua_INCDIR})
-ADD_DEFINITIONS(${lua_CFLAGS})
-SET(MUTTLIBS "${MUTTLIBS} ${lua_LDFLAGS}")
+pkg_search_module(LUA REQUIRED lua5.1)
+ADD_DEFINITIONS(${LUA_CFLAGS})
+LIST(APPEND MUTTLIBS ${LUA_LDFLAGS})
 
 IF(WITH_GPGME)
     XCONFIG(gpgme-config gpgme_INCDIR gpgme_LINKDIR gpgme_LDFLAGS gpgme_CFLAGS)
     INCLUDE_DIRECTORIES(${gpgme_INCDIR})
     ADD_DEFINITIONS(${gpgme_CFLAGS})
-    SET(MUTTLIBS "${MUTTLIBS} ${gpgme_LDFLAGS}")
+    LIST(APPEND MUTTLIBS ${gpgme_LDFLAGS})
     SET(HAVE_GPGME 1)
 ENDIF(WITH_GPGME)
 
@@ -153,17 +151,17 @@ XCONFIG(libgnutls-config gnutls_INCDIR gnutls_LINKDIR gnutls_LDFLAGS gnutls_CFLA
 INCLUDE_DIRECTORIES(${gnutls_INCDIR})
 ADD_DEFINITIONS(${gnutls_CFLAGS})
 CHECK_INCLUDE_FILE(gnutls/openssl.h  HAVE_GNUTLS_OPENSSL_H)
-SET(MUTTLIBS "${MUTTLIBS} ${gnutls_LDFLAGS}")
+LIST(APPEND MUTTLIBS ${gnutls_LDFLAGS})
 
 CHECK_LIBRARY_EXISTS(sasl2 sasl_client_init "" WITH_SASL)
 IF(NOT WITH_SASL)
     MESSAGE(FATAL_ERROR "sasl2 not found")
 ENDIF(NOT WITH_SASL)
-SET(MUTTLIBS "${MUTTLIBS} -lsasl2")
+LIST(APPEND MUTTLIBS -lsasl2)
 
 IF(WITH_IDN)
-    PKGCONFIG(libidn idn_INCDIR idn_LINKDIR idn_LDFLAGS idn_CFLAGS)
-    SET(MUTTLIBS "${MUTTLIBS} ${idn_LDFLAGS}")
+    pkg_search_module(IDN REQUIRED libidn)
+    LIST(APPEND MUTTLIBS ${IDN_LDFLAGS})
     SET(HAVE_LIBIDN 1)
 ENDIF(WITH_IDN)
 
@@ -171,7 +169,7 @@ CHECK_LIBRARY_EXISTS(lockfile lockfile_create "" WITH_LOCKFILE)
 IF(NOT WITH_LOCKFILE)
     MESSAGE(FATAL_ERROR "lockfile not found")
 ENDIF(NOT WITH_LOCKFILE)
-SET(MUTTLIBS "${MUTTLIBS} -llockfile")
+LIST(APPEND MUTTLIBS -llockfile)
 
 IF(USE_HCACHE)
     OPTION(WITH_QDBM "Use qdbm for header caching [default: on]" ON)
@@ -179,15 +177,11 @@ IF(USE_HCACHE)
     SET(USE_HCACHE)
 
     IF(WITH_QDBM)
-        PKGCONFIG(qdbm qdbm_INCDIR qdbm_LINKDIR qdbm_LDFLAGS qdbm_CFLAGS)
-        IF(qdbm_LDFLAGS)
-            MESSAGE(STATUS "qdbm found")
-        ELSE(qdbm_LDFLAGS)
-            MESSAGE(FATAL_ERROR "qdbm not found")
-        ENDIF(qdbm_LDFLAGS)
-        INCLUDE_DIRECTORIES(${qdbm_INCDIR})
-        ADD_DEFINITIONS(${qdbm_CFLAGS})
-        SET(MUTTLIBS "${MUTTLIBS} ${qdbm_LDFLAGS}")
+        pkg_search_module(QDBM REQUIRED qdbm)
+        ADD_DEFINITIONS(${QDBM_CFLAGS})
+        SET(QDBM_LDFLAGS "${QDBM_LDFLAGS}")
+        # LIST(APPEND MUTTLIBS ${QDBM_LDFLAGS})
+        LIST(APPEND MUTTLIBS -lqdbm)
         SET(USE_HCACHE 1)
         SET(HAVE_QDBM 1)
     ENDIF(WITH_QDBM)
@@ -197,7 +191,7 @@ IF(USE_HCACHE)
         IF(NOT GDBM)
             MESSAGE(FATAL_ERROR "gdbm not found")
         ENDIF(NOT GDBM)
-        SET(MUTTLIBS "${MUTTLIBS} -lgdbm")
+        LIST(APPEND MUTTLIBS -lgdbm)
         SET(USE_HCACHE 1)
         SET(HAVE_GDBM 1)
     ENDIF(NOT USE_HCACHE AND WITH_GDBM)
@@ -317,9 +311,10 @@ IF(WITH_NNTP)
     )
 ENDIF(WITH_NNTP)
 
+STRING(REGEX REPLACE ";" " " MUTTLIBS "${MUTTLIBS}")
 ADD_EXECUTABLE(madmutt ${madmuttsrc})
 TARGET_LINK_LIBRARIES(madmutt mime sys mx lua imap ui lib)
-SET_TARGET_PROPERTIES(madmutt PROPERTIES LINK_FLAGS ${MUTTLIBS})
+SET_TARGET_PROPERTIES(madmutt PROPERTIES LINK_FLAGS "${MUTTLIBS}")
 
 # generate_files hack {{{