diff --git a/.cmake/CheckDependencies.cmake b/.cmake/CheckDependencies.cmake index b8dc6a68d..73bd65fd5 100644 --- a/.cmake/CheckDependencies.cmake +++ b/.cmake/CheckDependencies.cmake @@ -1,10 +1,17 @@ function(ensure_library_exists libname) - unset(__TEMP_ENSURE_LIBRARY CACHE) - find_library(__TEMP_ENSURE_LIBRARY ${libname}) - if(NOT __TEMP_ENSURE_LIBRARY) - message(FATAL_ERROR "\n\n[check-dependencies] ${libname} not found\n\n") - else() - message(STATUS "[check-dependencies] ${libname} found at ${__TEMP_ENSURE_LIBRARY}") - endif() - unset(__TEMP_ENSURE_LIBRARY CACHE) + get_property(ALL_LINK_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY LINK_DIRECTORIES) + foreach(CURRENT_LINK_DIR ${ALL_LINK_DIRS}) + unset(__TEMP_ENSURE_LIBRARY CACHE) + find_library( + __TEMP_ENSURE_LIBRARY + NAMES ${libname} + PATHS ${CURRENT_LINK_DIR}) + if(NOT __TEMP_ENSURE_LIBRARY) + #message(STATUS "[check-dependencies] ${libname} not found") + else() + message(STATUS "[check-dependencies] ${libname} found at ${__TEMP_ENSURE_LIBRARY}") + return() + endif() + endforeach() + message(FATAL_ERROR "\n\n[check-dependencies] ${libname} not found\n\n") endfunction(ensure_library_exists) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e3229ff3..c69e19b4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,12 +38,22 @@ link_directories ("${musikcube_SOURCE_DIR}/bin/plugins") # custom include/library directories for BSDs if (CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "OpenBSD") - link_directories ("/usr/local/lib") - link_directories ("/usr/local/opt/openssl/lib") - link_directories ("/usr/local/opt/ncurses/lib") - include_directories("/usr/local/include") - include_directories("/usr/local/opt/openssl/include") - include_directories("/usr/local/opt/ncurses/include") + set(BSD_PATH_PREFIX "/usr/local") + if (CMAKE_SYSTEM_NAME MATCHES "Darwin") + execute_process( + COMMAND brew config + COMMAND grep -i HOMEBREW_PREFIX + COMMAND awk "{print $2}" + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE BSD_PATH_PREFIX) + endif() + message(STATUS "resolved BSD_PATH_PREFIX to: '${BSD_PATH_PREFIX}'") + link_directories ("${BSD_PATH_PREFIX}/lib") + link_directories ("${BSD_PATH_PREFIX}/opt/openssl/lib") + link_directories ("${BSD_PATH_PREFIX}/opt/ncurses/lib") + include_directories("${BSD_PATH_PREFIX}/include") + include_directories("${BSD_PATH_PREFIX}/opt/openssl/include") + include_directories("${BSD_PATH_PREFIX}/opt/ncurses/include") endif () if (${LINK_STATICALLY} MATCHES "true")