From 4adc9d705b911af6f6204cdcd087118f342160d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 27 Jan 2017 07:28:57 +0200 Subject: [PATCH] Build Jansson if library not found If the Jansson JSON library is not found on the system, it is built from source. --- CMakeLists.txt | 6 ++++++ avro/CMakeLists.txt | 2 +- cmake/BuildJansson.cmake | 20 +++++++++++++++++++ server/modules/filter/cache/CMakeLists.txt | 2 +- .../storage/storage_rocksdb/CMakeLists.txt | 2 +- .../modules/filter/cache/test/CMakeLists.txt | 2 +- server/modules/filter/masking/CMakeLists.txt | 2 +- .../filter/masking/test/CMakeLists.txt | 2 +- 8 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 cmake/BuildJansson.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 87f7e261f..e2fc3a227 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,12 @@ if(NOT MARIADB_CONNECTOR_FOUND) include(cmake/BuildMariaDBConnector.cmake) endif() +if(NOT JANSSON_FOUND) + message(STATUS "Building Jansson from source.") + include(cmake/BuildJansson.cmake) + include_directories(${JANSSON_INCLUDE_DIR}) +endif() + # You can find the variables set by this in the FindCURL.cmake file # which is a default module in CMake. diff --git a/avro/CMakeLists.txt b/avro/CMakeLists.txt index cb6df2eed..cef0e2e05 100644 --- a/avro/CMakeLists.txt +++ b/avro/CMakeLists.txt @@ -1,7 +1,7 @@ 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) + target_link_libraries(maxavro maxscale-common ${JANSSON_LIBRARIES}) add_executable(maxavrocheck maxavrocheck.c) target_link_libraries(maxavrocheck maxavro) diff --git a/cmake/BuildJansson.cmake b/cmake/BuildJansson.cmake new file mode 100644 index 000000000..91fa99799 --- /dev/null +++ b/cmake/BuildJansson.cmake @@ -0,0 +1,20 @@ +# If the Jansson library is not found, download it and build it from source. + +set(JANSSON_REPO "https://github.com/akheron/jansson.git" CACHE STRING "Jansson Git repository") + +# Release 2.9 of Jansson +set(JANSSON_TAG "v2.9" CACHE STRING "Jansson Git tag") + +ExternalProject_Add(jansson + GIT_REPOSITORY ${JANSSON_REPO} + GIT_TAG ${JANSSON_TAG} + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/jansson/install -DCMAKE_C_FLAGS=-fPIC + BINARY_DIR ${CMAKE_BINARY_DIR}/jansson + INSTALL_DIR ${CMAKE_BINARY_DIR}/jansson/install + UPDATE_COMMAND "") + +set(JANSSON_FOUND TRUE CACHE INTERNAL "") +set(JANSSON_STATIC_FOUND TRUE CACHE INTERNAL "") +set(JANSSON_INCLUDE_DIR ${CMAKE_BINARY_DIR}/jansson/install/include CACHE INTERNAL "") +set(JANSSON_STATIC_LIBRARIES ${CMAKE_BINARY_DIR}/jansson/install/lib/libjansson.a CACHE INTERNAL "") +set(JANSSON_LIBRARIES ${JANSSON_STATIC_LIBRARIES} CACHE INTERNAL "") diff --git a/server/modules/filter/cache/CMakeLists.txt b/server/modules/filter/cache/CMakeLists.txt index 830a78aa0..6c767beb7 100644 --- a/server/modules/filter/cache/CMakeLists.txt +++ b/server/modules/filter/cache/CMakeLists.txt @@ -17,7 +17,7 @@ if (JANSSON_FOUND) storagefactory.cc storagereal.cc ) - target_link_libraries(cache maxscale-common jansson) + target_link_libraries(cache maxscale-common ${JANSSON_LIBRARIES}) set_target_properties(cache PROPERTIES VERSION "1.0.0") set_target_properties(cache PROPERTIES LINK_FLAGS -Wl,-z,defs) install_module(cache core) diff --git a/server/modules/filter/cache/storage/storage_rocksdb/CMakeLists.txt b/server/modules/filter/cache/storage/storage_rocksdb/CMakeLists.txt index ff5095c6a..b406d2b20 100644 --- a/server/modules/filter/cache/storage/storage_rocksdb/CMakeLists.txt +++ b/server/modules/filter/cache/storage/storage_rocksdb/CMakeLists.txt @@ -17,7 +17,7 @@ if (ROCKSDB_BUILT) storage_rocksdb.cc ) add_dependencies(storage_rocksdb RocksDB) - target_link_libraries(storage_rocksdb maxscale-common jansson ${ROCKSDB_LIB} ${ROCKSDB_LINK_LIBS}) + target_link_libraries(storage_rocksdb maxscale-common ${JANSSON_LIBRARIES} ${ROCKSDB_LIB} ${ROCKSDB_LINK_LIBS}) set_target_properties(storage_rocksdb PROPERTIES VERSION "1.0.0") set_target_properties(storage_rocksdb PROPERTIES LINK_FLAGS -Wl,-z,defs) install_module(storage_rocksdb experimental) diff --git a/server/modules/filter/cache/test/CMakeLists.txt b/server/modules/filter/cache/test/CMakeLists.txt index 21ac53d76..2b1c94b65 100644 --- a/server/modules/filter/cache/test/CMakeLists.txt +++ b/server/modules/filter/cache/test/CMakeLists.txt @@ -10,7 +10,7 @@ add_library(cachetester ) add_executable(testrules testrules.cc ../rules.cc) -target_link_libraries(testrules maxscale-common jansson) +target_link_libraries(testrules maxscale-common ${JANSSON_LIBRARIES}) add_executable(testkeygeneration testkeygeneration.cc diff --git a/server/modules/filter/masking/CMakeLists.txt b/server/modules/filter/masking/CMakeLists.txt index 147305c3e..fcd432774 100644 --- a/server/modules/filter/masking/CMakeLists.txt +++ b/server/modules/filter/masking/CMakeLists.txt @@ -6,7 +6,7 @@ if (JANSSON_FOUND) maskingrules.cc ) - target_link_libraries(masking maxscale-common jansson) + target_link_libraries(masking maxscale-common ${JANSSON_LIBRARIES}) set_target_properties(masking PROPERTIES VERSION "1.0.0") set_target_properties(masking PROPERTIES LINK_FLAGS -Wl,-z,defs) install_module(masking core) diff --git a/server/modules/filter/masking/test/CMakeLists.txt b/server/modules/filter/masking/test/CMakeLists.txt index 6cac31090..5fc64f7c7 100644 --- a/server/modules/filter/masking/test/CMakeLists.txt +++ b/server/modules/filter/masking/test/CMakeLists.txt @@ -1,6 +1,6 @@ include_directories(..) add_executable(masking_testrules testrules.cc ../maskingrules.cc) -target_link_libraries(masking_testrules maxscale-common jansson) +target_link_libraries(masking_testrules maxscale-common ${JANSSON_LIBRARIES}) add_test(TestMasking_rules masking_testrules)