From 48b1583830c11e5866422d4df82911029090f31e Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Sun, 9 Oct 2016 13:20:31 +0300 Subject: [PATCH] Add FindJansson.cmake Added find_package module for CMake which locates the Jansson libraries and headers. This will make dependency checking easier and prevents build failures due to missing dependencies. --- CMakeLists.txt | 1 + avro/CMakeLists.txt | 2 +- cmake/FindJansson.cmake | 16 ++++++++++++++++ server/modules/filter/cache/CMakeLists.txt | 20 ++++++++++++-------- server/modules/routing/avro/CMakeLists.txt | 7 ++++--- 5 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 cmake/FindJansson.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f5e3f833..2ed799c0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ find_package(Git) find_package(CURL) find_package(RabbitMQ) find_package(LibUUID) +find_package(Jansson) find_package(Avro) find_package(GSSAPI) diff --git a/avro/CMakeLists.txt b/avro/CMakeLists.txt index 1e86df41d..cb6df2eed 100644 --- a/avro/CMakeLists.txt +++ b/avro/CMakeLists.txt @@ -1,4 +1,4 @@ -if (AVRO_FOUND) +if (AVRO_FOUND AND JANSSON_FOUND) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_library(maxavro maxavro.c maxavro_schema.c maxavro_record.c maxavro_file.c) target_link_libraries(maxavro maxscale-common jansson) diff --git a/cmake/FindJansson.cmake b/cmake/FindJansson.cmake new file mode 100644 index 000000000..c0322975e --- /dev/null +++ b/cmake/FindJansson.cmake @@ -0,0 +1,16 @@ +# This CMake file locates the Jansson libraries and headers +# +# The following variables are set: +# JANSSON_FOUND - If the Avro C library was found +# JANSSON_LIBRARIES - Path to the static library +# JANSSON_INCLUDE_DIR - Path to Avro headers + +find_path(JANSSON_INCLUDE_DIR jansson.h) +find_library(JANSSON_LIBRARIES NAMES libjansson.a libjansson.so) + +if (JANSSON_INCLUDE_DIR AND JANSSON_LIBRARIES) + message(STATUS "Found Jansson: ${JANSSON_LIBRARIES}") + set(JANSSON_FOUND TRUE) +else() + message(STATUS "Could not find Jansson") +endif() diff --git a/server/modules/filter/cache/CMakeLists.txt b/server/modules/filter/cache/CMakeLists.txt index 89db9c15b..3977cfbb0 100644 --- a/server/modules/filter/cache/CMakeLists.txt +++ b/server/modules/filter/cache/CMakeLists.txt @@ -1,11 +1,15 @@ -add_library(cache SHARED cache.c rules.c storage.c) -target_link_libraries(cache maxscale-common jansson) -set_target_properties(cache PROPERTIES VERSION "1.0.0") -set_target_properties(cache PROPERTIES LINK_FLAGS -Wl,-z,defs) -install_module(cache experimental) +if (JANSSON_FOUND) + add_library(cache SHARED cache.c rules.c storage.c) + target_link_libraries(cache maxscale-common jansson) + set_target_properties(cache PROPERTIES VERSION "1.0.0") + set_target_properties(cache PROPERTIES LINK_FLAGS -Wl,-z,defs) + install_module(cache experimental) -add_subdirectory(storage) + add_subdirectory(storage) -if(BUILD_TESTS) - add_subdirectory(test) + if(BUILD_TESTS) + add_subdirectory(test) + endif() +else() + message(STATUS "No Jansson libraries found, not building cache filter.") endif() diff --git a/server/modules/routing/avro/CMakeLists.txt b/server/modules/routing/avro/CMakeLists.txt index 4fcb896b6..0fed40b78 100644 --- a/server/modules/routing/avro/CMakeLists.txt +++ b/server/modules/routing/avro/CMakeLists.txt @@ -1,10 +1,11 @@ -if(AVRO_FOUND) +if(AVRO_FOUND AND JANSSON_FOUND) include_directories(${AVRO_INCLUDE_DIR}) + include_directories(${JANSSON_INCLUDE_DIR}) add_library(avrorouter SHARED avro.c ../binlog/binlog_common.c avro_client.c avro_schema.c avro_rbr.c avro_file.c avro_index.c) set_target_properties(avrorouter PROPERTIES VERSION "1.0.0") set_target_properties(avrorouter PROPERTIES LINK_FLAGS -Wl,-z,defs) - target_link_libraries(avrorouter maxscale-common jansson ${AVRO_LIBRARIES} maxavro sqlite3 lzma) + target_link_libraries(avrorouter maxscale-common ${JANSSON_LIBRARIES} ${AVRO_LIBRARIES} maxavro sqlite3 lzma) install_module(avrorouter core) else() - message(STATUS "Avro C libraries were not found, avrorouter will not be built.") + message(STATUS "No Avro C or Jansson libraries found, not building avrorouter.") endif()