From 5e4318c15d742cb0fda26f441643409925d8ed34 Mon Sep 17 00:00:00 2001 From: Kazunobu Kuriyama Date: Mon, 7 Sep 2015 23:13:36 +0900 Subject: [PATCH] Fix Mac OS X iconv library linking failure Add a path to awesomeConfig.cmake for searching an iconv library and the corresponding header file automatically if the build system is on Mac OS X which needs to pass the header and library paths explicitly to the compiler to build Awesome successfully. Closes https://github.com/awesomeWM/awesome/pull/440. --- awesomeConfig.cmake | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/awesomeConfig.cmake b/awesomeConfig.cmake index ddf3cd78..4239f978 100644 --- a/awesomeConfig.cmake +++ b/awesomeConfig.cmake @@ -155,6 +155,43 @@ if(NOT AWESOME_REQUIRED_FOUND OR NOT AWESOME_COMMON_REQUIRED_FOUND) message(FATAL_ERROR) endif() +# On Mac OS X, the executable of Awesome has to be linked against libiconv +# explicitly. Unfortunately, libiconv doesn't have its pkg-config file, +# and CMake doesn't provide a module for looking up the library. Thus, we +# have to do everything for ourselves... +if(APPLE) + if(NOT DEFINED AWESOME_ICONV_SEARCH_PATHS) + set(AWESOME_ICONV_SEARCH_PATHS /opt/local /opt /usr/local /usr) + endif() + + if(NOT DEFINED AWESOME_ICONV_INCLUDE_DIR) + find_path(AWESOME_ICONV_INCLUDE_DIR + iconv.h + PATHS ${AWESOME_ICONV_SEARCH_PATHS} + PATH_SUFFIXES include + NO_CMAKE_SYSTEM_PATH) + endif() + + if(NOT DEFINED AWESOME_ICONV_LIBRARY_PATH) + get_filename_component(AWESOME_ICONV_BASE_DIRECTORY ${AWESOME_ICONV_INCLUDE_DIR} DIRECTORY) + find_library(AWESOME_ICONV_LIBRARY_PATH + NAMES iconv + HINTS ${AWESOME_ICONV_BASE_DIRECTORY} + PATH_SUFFIXES lib) + endif() + + if(NOT DEFINED AWESOME_ICONV_LIBRARY_PATH) + message(FATAL_ERROR "Looking for iconv library - not found.") + else() + message(STATUS "Looking for iconv library - found: ${AWESOME_ICONV_LIBRARY_PATH}") + endif() + + set(AWESOME_REQUIRED_LDFLAGS + ${AWESOME_REQUIRED_LDFLAGS} ${AWESOME_ICONV_LIBRARY_PATH}) + set(AWESOME_REQUIRED_INCLUDE_DIRS + ${AWESOME_REQUIRED_INCLUDE_DIRS} ${AWESOME_ICONV_INCLUDE_DIR}) +endif(APPLE) + macro(a_find_library variable library) find_library(${variable} ${library}) if(NOT ${variable})