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.
This commit is contained in:
Kazunobu Kuriyama 2015-09-07 23:13:36 +09:00 committed by Daniel Hahler
parent 19ae63cf13
commit 5e4318c15d
1 changed files with 37 additions and 0 deletions

View File

@ -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})