From 05d642f69d815a120709c8032b00315cb9a0ee3e Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 27 Oct 2014 12:42:57 +0100 Subject: [PATCH] Use system-provided version of YAJL where available fixes #7454 --- CMakeLists.txt | 8 ++++++++ INSTALL.md | 1 + cmake/FindYAJL.cmake | 28 ++++++++++++++++++++++++++++ debian/control | 1 + lib/base/CMakeLists.txt | 5 +---- third-party/CMakeLists.txt | 5 ++++- 6 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 cmake/FindYAJL.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e13d08856..4946db376 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,14 @@ include_directories(${Boost_INCLUDE_DIRS}) find_package(OpenSSL REQUIRED) include_directories(${OPENSSL_INCLUDE_DIR}) +find_package(YAJL) + +if(NOT YAJL_FOUND) + include_directories(${icinga2_BINARY_DIR}/third-party/yajl/include) + link_directories(${icinga2_BINARY_DIR}/third-party/yajl) + set(YAJL_LIBRARIES "yajl") +endif() + include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/lib ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/lib diff --git a/INSTALL.md b/INSTALL.md index a3019fe39..0ee1f828c 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -28,6 +28,7 @@ parentheses): * recommended: libexecinfo on FreeBSD * optional: MySQL (mysql-devel on RHEL, libmysqlclient-dev on Debian) * optional: PostgreSQL (postgresql-devel on RHEL, libpq-dev on Debian) +* optional: YAJL (yajl-devel on RHEL, libyajl-dev on Debian) Note: RHEL5 ships an ancient flex version. Updated packages are available for example from the repoforge buildtools repository. diff --git a/cmake/FindYAJL.cmake b/cmake/FindYAJL.cmake new file mode 100644 index 000000000..b7d773273 --- /dev/null +++ b/cmake/FindYAJL.cmake @@ -0,0 +1,28 @@ +# - Try to find libyajl +# Once done this will define +# YAJL_FOUND - System has YAJL +# YAJL_INCLUDE_DIRS - The YAJL include directories +# YAJL_LIBRARIES - The libraries needed to use YAJL +# YAJL_DEFINITIONS - Compiler switches required for using YAJL + +find_package(PkgConfig) +pkg_check_modules(PC_YAJL QUIET yajl) +set(YAJL_DEFINITIONS ${PC_YAJL_CFLAGS_OTHER}) + +find_path(YAJL_INCLUDE_DIR yajl/yajl_parse.h + HINTS ${PC_YAJL_INCLUDEDIR} ${PC_YAJL_INCLUDE_DIRS} + PATH_SUFFIXES libyajl) + +find_library(YAJL_LIBRARY NAMES yajl libyajl + HINTS ${PC_YAJL_LIBDIR} ${PC_YAJL_LIBRARY_DIRS}) + +set(YAJL_LIBRARIES ${YAJL_LIBRARY} ) +set(YAJL_INCLUDE_DIRS ${YAJL_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set YAJL_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args(yajl DEFAULT_MSG + YAJL_LIBRARY YAJL_INCLUDE_DIR) + +mark_as_advanced(YAJL_INCLUDE_DIR YAJL_LIBRARY) diff --git a/debian/control b/debian/control index ba6f639d7..b5817b509 100644 --- a/debian/control +++ b/debian/control @@ -19,6 +19,7 @@ Build-Depends: bison, libmysqlclient-dev, libpq-dev, libssl-dev, + libyajl-dev, make (>= 3.81), po-debconf Standards-Version: 3.9.5 diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt index 40a1d7961..5947e73a2 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -41,7 +41,7 @@ endif() add_library(base SHARED ${base_SOURCES}) -target_link_libraries(base ${CMAKE_DL_LIBS} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} mmatch yajl) +target_link_libraries(base ${CMAKE_DL_LIBS} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${YAJL_LIBRARIES} mmatch) if(HAVE_LIBEXECINFO) target_link_libraries(base execinfo) @@ -56,9 +56,6 @@ link_directories(${icinga2_BINARY_DIR}/third-party/execvpe) include_directories(${icinga2_SOURCE_DIR}/third-party/mmatch) link_directories(${icinga2_BINARY_DIR}/third-party/mmatch) -include_directories(${icinga2_BINARY_DIR}/third-party/yajl/include) -link_directories(${icinga2_BINARY_DIR}/third-party/yajl) - if(UNIX OR CYGWIN) target_link_libraries(base execvpe) endif() diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 41fc705c5..dba21182a 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -16,7 +16,10 @@ # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. add_subdirectory(mmatch) -add_subdirectory(yajl) + +if(NOT YAJL_FOUND) + add_subdirectory(yajl) +endif() if(UNIX OR CYGWIN) add_subdirectory(execvpe)