From 6fa3f563190107571408739f903bab4bb8a8ecde Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 11 May 2015 14:17:15 +0100 Subject: Another iteration of libraries detection rework. --- CMakeLists.txt | 144 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 101 insertions(+), 43 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index bd35976a9..80df09ba8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,55 +194,106 @@ ENDFUNCTION(INSTALL_IF_NOT_EXISTS) # Process required package by using FindPackage and calling for INCLUDE_DIRECTORIES and # setting list of required libraries MACRO(ProcessPackage var _name0) - PKG_SEARCH_MODULE(${var} "${_name0}" ${ARGN}) - IF(${var}_FOUND) - SET(WITH_${var} 1) - IF(ENABLE_STATIC MATCHES "ON") - SET(_XPREFIX "${var}_STATIC") - ELSE(ENABLE_STATIC MATCHES "ON") - SET(_XPREFIX "${var}") - ENDIF(ENABLE_STATIC MATCHES "ON") - FOREACH(_arg ${${_XPREFIX}_INCLUDE_DIRS}) - INCLUDE_DIRECTORIES("${_arg}") - SET(${var}_INCLUDE_DIR "${_arg}") - ENDFOREACH(_arg ${${_XPREFIX}_INCLUDE_DIRS}) - FOREACH(_arg ${${_XPREFIX}_LIBRARY_DIRS}) - LINK_DIRECTORIES("${_arg}") - ENDFOREACH(_arg ${${_XPREFIX}_LIBRARY_DIRS}) - # Handle other CFLAGS and LDFLAGS - FOREACH(_arg ${${_XPREFIX}_CFLAGS_OTHER}) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_arg}") - ENDFOREACH(_arg ${${_XPREFIX}_CFLAGS_OTHER}) - FOREACH(_arg ${${_XPREFIX}_LDFLAGS_OTHER}) - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_arg}") - ENDFOREACH(_arg ${${_XPREFIX}_LDFLAGS_OTHER}) - LIST(APPEND RSPAMD_REQUIRED_LIBRARIES "${${_XPREFIX}_LIBRARIES}") - ELSE(${var}_FOUND) - # Try some more heuristic + IF(NOT RSPAMD_SEARCH_PATH) + PKG_SEARCH_MODULE(${var} "${_name0}" ${ARGN}) + IF(${var}_FOUND) + SET(WITH_${var} 1) + IF(ENABLE_STATIC MATCHES "ON") + SET(_XPREFIX "${var}_STATIC") + ELSE(ENABLE_STATIC MATCHES "ON") + SET(_XPREFIX "${var}") + ENDIF(ENABLE_STATIC MATCHES "ON") + FOREACH(_arg ${${_XPREFIX}_INCLUDE_DIRS}) + INCLUDE_DIRECTORIES("${_arg}") + SET(${var}_INCLUDE_DIR "${_arg}") + ENDFOREACH(_arg ${${_XPREFIX}_INCLUDE_DIRS}) + FOREACH(_arg ${${_XPREFIX}_LIBRARY_DIRS}) + LINK_DIRECTORIES("${_arg}") + ENDFOREACH(_arg ${${_XPREFIX}_LIBRARY_DIRS}) + # Handle other CFLAGS and LDFLAGS + FOREACH(_arg ${${_XPREFIX}_CFLAGS_OTHER}) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_arg}") + ENDFOREACH(_arg ${${_XPREFIX}_CFLAGS_OTHER}) + FOREACH(_arg ${${_XPREFIX}_LDFLAGS_OTHER}) + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_arg}") + ENDFOREACH(_arg ${${_XPREFIX}_LDFLAGS_OTHER}) + LIST(APPEND RSPAMD_REQUIRED_LIBRARIES "${${_XPREFIX}_LIBRARIES}") + ELSE(${var}_FOUND) + # Try some more heuristic + FIND_LIBRARY(_lib NAMES "${_name0}" ${ARGN} + HINTS + "${RSPAMD_SEARCH_PATH}" + PATH_SUFFIXES lib64 lib + PATHS ${RSPAMD_DEFAULT_LIBRARY_PATHS}) + IF(NOT _lib) + MESSAGE(FATAL_ERROR "Packages ${_name0} ${ARGN} could not be found, no library") + ENDIF(NOT _lib) + + + FIND_PATH(_incl "${_name0}.h" + HINTS "${RSPAMD_SEARCH_PATH}" + PATH_SUFFIXES "include" "include/${_name0}" ${ARGN} + PATHS ${RSPAMD_DEFAULT_INCLUDE_PATHS}) + IF(NOT _incl) + MESSAGE(FATAL_ERROR "Packages ${_name0} ${ARGN} could not be found, no header") + ENDIF(NOT _incl) + GET_FILENAME_COMPONENT(_lib_path "${_lib}" PATH) + INCLUDE_DIRECTORIES("${_incl}") + LINK_DIRECTORIES("${_lib_path}") + MESSAGE(STATUS "Found ${_name0} ${ARGN} in '${_lib_path}' (library) and '${_incl}' (include).") + ENDIF(${var}_FOUND) + ELSE(NOT RSPAMD_SEARCH_PATH) + # Try heuristic first FIND_LIBRARY(_lib NAMES "${_name0}" ${ARGN} HINTS "${RSPAMD_SEARCH_PATH}" PATH_SUFFIXES lib64 lib PATHS ${RSPAMD_DEFAULT_LIBRARY_PATHS}) - IF(NOT _lib) - MESSAGE(FATAL_ERROR "Packages ${_name0} ${ARGN} could not be found, no library") - ENDIF(NOT _lib) + IF(_lib) + FIND_PATH(_incl "${_name0}.h" + HINTS "${RSPAMD_SEARCH_PATH}" + PATH_SUFFIXES "include" "include/${_name0}" ${ARGN} + PATHS ${RSPAMD_DEFAULT_INCLUDE_PATHS}) + IF(_incl) + GET_FILENAME_COMPONENT(_lib_path "${_lib}" PATH) + INCLUDE_DIRECTORIES("${_incl}") + LINK_DIRECTORIES("${_lib_path}") + MESSAGE(STATUS "Found ${_name0} ${ARGN} in '${_lib_path}' (library) and '${_incl}' (include).") + ENDIF(_incl) + ENDIF(_lib) - - FIND_PATH(_incl "${_name0}.h" - HINTS "${RSPAMD_SEARCH_PATH}" - PATH_SUFFIXES "include" "include/${_name0}" ${ARGN} - PATHS ${RSPAMD_DEFAULT_INCLUDE_PATHS}) - IF(NOT _incl) - MESSAGE(FATAL_ERROR "Packages ${_name0} ${ARGN} could not be found, no header") - ENDIF(NOT _incl) - GET_FILENAME_COMPONENT(_lib_path "${_lib}" PATH) - INCLUDE_DIRECTORIES("${_incl}") - LINK_DIRECTORIES("${_lib_path}") - MESSAGE(STATUS "Found ${_name0} ${ARGN} in '${_lib_path}' (library) and '${_incl}' (include).") - UNSET(_lib CACHE) - UNSET(_incl CACHE) - ENDIF(${var}_FOUND) + IF(NOT _incl OR NOT _lib) + PKG_SEARCH_MODULE(${var} "${_name0}" ${ARGN}) + IF(${var}_FOUND) + SET(WITH_${var} 1) + IF(ENABLE_STATIC MATCHES "ON") + SET(_XPREFIX "${var}_STATIC") + ELSE(ENABLE_STATIC MATCHES "ON") + SET(_XPREFIX "${var}") + ENDIF(ENABLE_STATIC MATCHES "ON") + FOREACH(_arg ${${_XPREFIX}_INCLUDE_DIRS}) + INCLUDE_DIRECTORIES("${_arg}") + SET(${var}_INCLUDE_DIR "${_arg}") + ENDFOREACH(_arg ${${_XPREFIX}_INCLUDE_DIRS}) + FOREACH(_arg ${${_XPREFIX}_LIBRARY_DIRS}) + LINK_DIRECTORIES("${_arg}") + ENDFOREACH(_arg ${${_XPREFIX}_LIBRARY_DIRS}) + # Handle other CFLAGS and LDFLAGS + FOREACH(_arg ${${_XPREFIX}_CFLAGS_OTHER}) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_arg}") + ENDFOREACH(_arg ${${_XPREFIX}_CFLAGS_OTHER}) + FOREACH(_arg ${${_XPREFIX}_LDFLAGS_OTHER}) + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_arg}") + ENDFOREACH(_arg ${${_XPREFIX}_LDFLAGS_OTHER}) + LIST(APPEND RSPAMD_REQUIRED_LIBRARIES "${${_XPREFIX}_LIBRARIES}") + ELSE(${var}_FOUND) + MESSAGE(FATAL_ERROR "Packages ${_name0} ${ARGN} could not be found") + ENDIF(${var}_FOUND) + ENDIF(NOT _incl OR NOT _lib) + ENDIF(NOT RSPAMD_SEARCH_PATH) + # Cleanup + UNSET(_lib CACHE) + UNSET(_incl CACHE) ENDMACRO(ProcessPackage name) MACRO(ADD_PRECOMPILED_HEADER _target _input) @@ -395,6 +446,13 @@ ENDIF(CMAKE_SYSTEM_NAME STREQUAL "SunOS") IF(ENABLE_LUAJIT MATCHES "ON") ProcessPackage(LUAJIT luajit) SET(WITH_LUA 1) + FindLua(5 1) + IF(NOT LUA_FOUND) + MESSAGE(FATAL_ERROR "Lua not found, lua support is required for working") + ELSE(NOT LUA_FOUND) + SET(WITH_LUA 1) + INCLUDE_DIRECTORIES("${LUA_INCLUDE_DIR}") + ENDIF(NOT LUA_FOUND) ELSE(ENABLE_LUAJIT MATCHES "ON") FindLua(5 2) IF(NOT LUA_FOUND) -- cgit v1.2.3