From aaebe53a5af0e8fe10fcf764140ad9916f4b70ff Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Mon, 12 Apr 2021 18:34:31 +0200 Subject: [PATCH 1/5] cmake: make the jansson library mandatory for build the Director Without the library, the API 2 commands are not available. Implement find_package for Jansson, as otherwise Solaris would require special treatment. --- cmake/FindJansson.cmake | 99 +++++++++++++++++++++++ core/CMakeLists.txt | 8 +- core/cmake/BareosFindAllLibraries.cmake | 2 +- core/src/console/CMakeLists.txt | 11 +-- core/src/console/console_conf.cc | 2 +- core/src/dird/CMakeLists.txt | 16 ++-- core/src/filed/CMakeLists.txt | 6 +- core/src/filed/filed_conf.cc | 2 +- core/src/findlib/CMakeLists.txt | 2 +- core/src/findlib/unittests/CMakeLists.txt | 4 +- core/src/lib/CMakeLists.txt | 7 +- core/src/qt-tray-monitor/CMakeLists.txt | 16 ++-- core/src/qt-tray-monitor/tray_conf.cc | 2 +- core/src/stored/CMakeLists.txt | 39 ++------- core/src/tests/CMakeLists.txt | 19 ++--- core/src/tools/CMakeLists.txt | 17 ++-- 16 files changed, 155 insertions(+), 97 deletions(-) create mode 100644 cmake/FindJansson.cmake diff --git a/cmake/FindJansson.cmake b/cmake/FindJansson.cmake new file mode 100644 index 00000000000..cd44d0307cc --- /dev/null +++ b/cmake/FindJansson.cmake @@ -0,0 +1,99 @@ +# BAREOS® - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2021-2021 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or modify it under +# the terms of version three of the GNU Affero General Public License as +# published by the Free Software Foundation and included in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +# details. +# +# You should have received a copy of the GNU Affero General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +#[=======================================================================[.rst: +FindJansson +----------- + +Find Jansson headers and libraries. +` +IMPORTED Targets +^^^^^^^^^^^^^^^^ + +The following :prop_tgt:`IMPORTED` targets may be defined: + +``Jansson::Jansson`` + Jansson library. + +Result variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +``JANSSON_FOUND`` + True if Jansson found. +``JANSSON_INCLUDE_DIRS`` + Where to find jansson.h. +``JANSSON_LIBRARIES`` + List of libraries when using Jansson. +``JANSSON_VERSION_STRING`` + The version of Jansson found. +``HAVE_JANSSON`` + 1 if Jansson found. + +#]=======================================================================] + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_JANSSON QUIET jansson) + +find_path( + JANSSON_INCLUDE_DIR + NAMES jansson.h + HINTS ${PC_JANSSON_INCLUDEDIR} ${PC_JANSSON_INCLUDE_DIRS} +) + +find_library( + JANSSON_LIBRARY + NAMES jansson libjansson + HINTS ${PC_JANSSON_LIBDIR} ${PC_JANSSON_LIBRARY_DIRS} +) + +if(PC_JANSSON_VERSION) + set(JANSSON_VERSION_STRING ${PC_JANSSON_VERSION}) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + Jansson + REQUIRED_VARS JANSSON_LIBRARY JANSSON_INCLUDE_DIR + VERSION_VAR JANSSON_VERSION_STRING +) + +if(JANSSON_FOUND) + set(JANSSON_LIBRARIES ${JANSSON_LIBRARY}) + set(JANSSON_INCLUDE_DIRS ${JANSSON_INCLUDE_DIR}) + set(HAVE_JANSSON 1) +endif() + +mark_as_advanced(JANSSON_INCLUDE_DIR JANSSON_LIBRARY) + +if(JANSSON_FOUND AND NOT TARGET Jansson::Jansson) + add_library(Jansson::Jansson UNKNOWN IMPORTED) + set_target_properties( + Jansson::Jansson PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${JANSSON_INCLUDE_DIRS}" + ) + set_target_properties( + Jansson::Jansson PROPERTIES INTERFACE_COMPILE_OPTIONS + "${JANSSON_DEFINITIONS}" + ) + set_property( + TARGET Jansson::Jansson + APPEND + PROPERTY IMPORTED_LOCATION "${JANSSON_LIBRARY}" + ) +endif() diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 64fe4436385..a2460b15df7 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -852,16 +852,16 @@ message( " OpenSSL support: ${OPENSSL_FOUND} ${OPENSSL_VERSION} ${OPENSSL_INCLUDE_DIR} ${OPENSSL_LIBRARIES} " ) message( - " PAM support: ${PAM_FOUND} ${PAM_LIBRARIES} ${PAM_INCLUDE_DIRS} " + " PAM support: ${PAM_FOUND} ${PAM_INCLUDE_DIRS} ${PAM_LIBRARIES} " ) message( - " ZLIB support: ${ZLIB_FOUND} ${ZLIB_LIBRARIES} ${ZLIB_INCLUDE_DIRS} " + " ZLIB support: ${ZLIB_FOUND} ${ZLIB_INCLUDE_DIRS} ${ZLIB_LIBRARIES} " ) message( - " LZO2 support: ${LZO2_FOUND} ${LZO2_LIBRARIES} ${LZO2_INCLUDE_DIRS} " + " LZO2 support: ${LZO2_FOUND} ${LZO2_INCLUDE_DIRS} ${LZO2_LIBRARIES} " ) message( - " JANSSON support: ${JANSSON_FOUND} ${JANSSON_LIBRARIES} ${JANSSON_INCLUDE_DIRS} " + " JANSSON support: ${JANSSON_FOUND} ${JANSSON_VERSION_STRING} ${JANSSON_INCLUDE_DIRS} ${JANSSON_LIBRARIES}" ) message( " VIXDISKLIB support: ${VIXDISKLIB_FOUND} ${VIXDISKLIB_LIBRARIES} ${VIXDISKLIB_INCLUDE_DIRS} " diff --git a/core/cmake/BareosFindAllLibraries.cmake b/core/cmake/BareosFindAllLibraries.cmake index 7e784d894c6..0b0d3148277 100644 --- a/core/cmake/BareosFindAllLibraries.cmake +++ b/core/cmake/BareosFindAllLibraries.cmake @@ -164,7 +164,6 @@ elseif( ) endif() -bareosfindlibraryandheaders("jansson" "jansson.h" "") bareosfindlibraryandheaders("rados" "rados/librados.h" "") bareosfindlibraryandheaders("radosstriper" "radosstriper/libradosstriper.h" "") bareosfindlibraryandheaders("cephfs" "cephfs/libcephfs.h" "") @@ -204,4 +203,5 @@ if(${ZLIB_FOUND}) endif() find_package(Readline) +find_package(Jansson) include(thread) diff --git a/core/src/console/CMakeLists.txt b/core/src/console/CMakeLists.txt index 3e6242cda71..3ef53d7fc55 100644 --- a/core/src/console/CMakeLists.txt +++ b/core/src/console/CMakeLists.txt @@ -35,15 +35,8 @@ add_executable(bconsole console.cc) add_library(console_objects STATIC ${BCONSSRCS}) -if(HAVE_PAM) - set(CONSOLE_LINK_LIBRARIES console_objects bareos ${Readline_LIBRARY} - ${PAM_LIBRARIES} - ) -else() - set(CONSOLE_LINK_LIBRARIES console_objects bareos ${Readline_LIBRARY}) -endif() - -target_link_libraries(bconsole ${CONSOLE_LINK_LIBRARIES} ${JANSSON_LIBRARIES}) +target_link_libraries(console_objects PRIVATE bareos) +target_link_libraries(bconsole PRIVATE console_objects ${Readline_LIBRARY}) install( TARGETS bconsole diff --git a/core/src/console/console_conf.cc b/core/src/console/console_conf.cc index 75289d51ffe..9fcfa8cbdf3 100644 --- a/core/src/console/console_conf.cc +++ b/core/src/console/console_conf.cc @@ -3,7 +3,7 @@ Copyright (C) 2000-2009 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2020 Bareos GmbH & Co. KG + Copyright (C) 2013-2021 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public diff --git a/core/src/dird/CMakeLists.txt b/core/src/dird/CMakeLists.txt index 431b1539b5f..dac5a41b067 100644 --- a/core/src/dird/CMakeLists.txt +++ b/core/src/dird/CMakeLists.txt @@ -18,6 +18,8 @@ # 02110-1301, USA. message("Entering ${CMAKE_CURRENT_SOURCE_DIR}") +find_package(Jansson REQUIRED) + set(DIRDSRCS dird.cc) # DIRD_OBJECTS_SRCS also used in a separate library for unittests @@ -99,6 +101,7 @@ set(DIRD_OBJECTS_SRCS verify.cc pthread_detach_if_not_detached.cc ) + if(HAVE_WIN32) list(APPEND DIRD_OBJECTS_SRCS ../win32/dird/dirdres.rc) endif() @@ -145,15 +148,14 @@ set(DIRD_RESTYPES # dird_objects is also used as library for unittests add_library(dird_objects STATIC ${DIRD_OBJECTS_SRCS}) target_link_libraries( - dird_objects PRIVATE ${OPENSSL_LIBRARIES} Threads::Threads - ${JANSSON_LIBRARIES} + dird_objects PRIVATE bareos ${OPENSSL_LIBRARIES} Threads::Threads ) add_executable(bareos-dir) target_sources(bareos-dir PRIVATE dird.cc) target_link_libraries( - bareos-dir PRIVATE dird_objects bareos bareoscats bareossql bareosfind + bareos-dir PRIVATE dird_objects bareoscats bareossql bareosfind ) if(HAVE_WIN32) @@ -178,11 +180,11 @@ endif() add_subdirectory(dbcopy) add_executable(bareos-dbcheck ${DBCHKSRCS}) -set(DBCHECK_LIBRARIES bareossql bareos bareosfind bareoscats - ${OPENSSL_LIBRARIES} ${JANSSON_LIBRARIES} -) -target_link_libraries(bareos-dbcheck ${DBCHECK_LIBRARIES}) +target_link_libraries( + bareos-dbcheck PRIVATE bareossql bareos bareosfind bareoscats + ${OPENSSL_LIBRARIES} +) # is not built by default diff --git a/core/src/filed/CMakeLists.txt b/core/src/filed/CMakeLists.txt index ad0987e0110..08154e14cba 100644 --- a/core/src/filed/CMakeLists.txt +++ b/core/src/filed/CMakeLists.txt @@ -64,9 +64,7 @@ endif() include_directories(${OPENSSL_INCLUDE_DIR}) add_library(fd_objects STATIC ${FDSRCS}) -target_link_libraries( - fd_objects PUBLIC bareos bareosfastlz ${ZLIB_LIBRARIES} ${JANSSON_LIBRARIES} -) +target_link_libraries(fd_objects PRIVATE bareos bareosfastlz ${ZLIB_LIBRARIES}) if(HAVE_LMDB) target_link_libraries(fd_objects PRIVATE bareoslmdb) @@ -89,7 +87,7 @@ if(HAVE_WIN32) target_compile_definitions(bareos-fd PRIVATE ${FD_COMPILE_DEFINITIONS}) endif() -target_link_libraries(bareos-fd fd_objects ${BAREOS_FD_LIBRARIES}) +target_link_libraries(bareos-fd PRIVATE fd_objects ${BAREOS_FD_LIBRARIES}) if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set_target_properties( diff --git a/core/src/filed/filed_conf.cc b/core/src/filed/filed_conf.cc index 85f46565299..67057749a82 100644 --- a/core/src/filed/filed_conf.cc +++ b/core/src/filed/filed_conf.cc @@ -3,7 +3,7 @@ Copyright (C) 2000-2008 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2020 Bareos GmbH & Co. KG + Copyright (C) 2013-2021 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public diff --git a/core/src/findlib/CMakeLists.txt b/core/src/findlib/CMakeLists.txt index a99cd37f67d..f5efb32c6f4 100644 --- a/core/src/findlib/CMakeLists.txt +++ b/core/src/findlib/CMakeLists.txt @@ -43,7 +43,7 @@ include_directories(${OPENSSL_INCLUDE_DIR}) add_library(bareosfind SHARED ${BAREOSFIND_SRCS}) -target_link_libraries(bareosfind bareos ${ACL_LIBRARIES}) +target_link_libraries(bareosfind PRIVATE bareos ${ACL_LIBRARIES}) install( TARGETS bareosfind diff --git a/core/src/findlib/unittests/CMakeLists.txt b/core/src/findlib/unittests/CMakeLists.txt index 2cb442810c1..87ddc02850b 100644 --- a/core/src/findlib/unittests/CMakeLists.txt +++ b/core/src/findlib/unittests/CMakeLists.txt @@ -23,9 +23,7 @@ set(TEST_SRC # drivetype_test.cc ) add_executable(test_findlib ${TEST_SRC}) -target_link_libraries( - test_findlib bareosfind bareos ${JANSSON_LIBRARIES} GTest::gtest_main -) +target_link_libraries(test_findlib PRIVATE bareosfind bareos GTest::gtest_main) add_test(NAME test_findlib COMMAND "test_findlib") set_property( diff --git a/core/src/lib/CMakeLists.txt b/core/src/lib/CMakeLists.txt index d4b841051d3..f07da2786d2 100644 --- a/core/src/lib/CMakeLists.txt +++ b/core/src/lib/CMakeLists.txt @@ -154,10 +154,13 @@ set_target_properties(version-obj PROPERTIES POSITION_INDEPENDENT_CODE ON) target_link_libraries( bareos PRIVATE bareosfastlz ${OPENSSL_LIBRARIES} Threads::Threads ${ZLIB_LIBRARIES} - ${LZO2_LIBRARIES} ${CAP_LIBRARIES} ${JANSSON_LIBRARIES} - ${CAM_LIBRARIES} + ${LZO2_LIBRARIES} ${CAP_LIBRARIES} ${CAM_LIBRARIES} ) +if(TARGET Jansson::Jansson) + target_link_libraries(bareos PUBLIC Jansson::Jansson) +endif() + install(TARGETS bareos DESTINATION ${libdir}) set_target_properties( diff --git a/core/src/qt-tray-monitor/CMakeLists.txt b/core/src/qt-tray-monitor/CMakeLists.txt index 15e90557912..26e9be29c79 100644 --- a/core/src/qt-tray-monitor/CMakeLists.txt +++ b/core/src/qt-tray-monitor/CMakeLists.txt @@ -63,23 +63,21 @@ if(HAVE_WIN32) list(APPEND SOURCES ../win32/qt-tray-monitor/traymon.rc) endif() -if(Qt4_FOUND) - set(TRAYMON_LIBRARIES bareos-tray-monitor Qt4::QtGui bareos) -else() - set(TRAYMON_LIBRARIES bareos-tray-monitor bareos) -endif() - if(HAVE_WIN32) add_executable(bareos-tray-monitor WIN32 ${SOURCES} main.qrc) else() add_executable(bareos-tray-monitor ${SOURCES} main.qrc) endif() -if(Qt5Widgets_FOUND) - qt5_use_modules(bareos-tray-monitor Widgets) +target_link_libraries(bareos-tray-monitor PRIVATE bareos) + +if(Qt4_FOUND) + target_link_libraries(bareos-tray-monitor PRIVATE Qt4::QtGui) endif() -target_link_libraries(${TRAYMON_LIBRARIES} ${JANSSON_LIBRARIES}) +if(TARGET Qt5::Widgets) + target_link_libraries(bareos-tray-monitor PRIVATE Qt5::Widgets) +endif() install(TARGETS bareos-tray-monitor DESTINATION "${bindir}") diff --git a/core/src/qt-tray-monitor/tray_conf.cc b/core/src/qt-tray-monitor/tray_conf.cc index 80ad938769c..b34b25d6bca 100644 --- a/core/src/qt-tray-monitor/tray_conf.cc +++ b/core/src/qt-tray-monitor/tray_conf.cc @@ -3,7 +3,7 @@ Copyright (C) 2004-2011 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2020 Bareos GmbH & Co. KG + Copyright (C) 2013-2021 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public diff --git a/core/src/stored/CMakeLists.txt b/core/src/stored/CMakeLists.txt index babbdd61906..8547615f664 100644 --- a/core/src/stored/CMakeLists.txt +++ b/core/src/stored/CMakeLists.txt @@ -186,7 +186,6 @@ else() if(TARGET droplet) list(APPEND LIBBAREOSSD_LIBRARIES droplet) endif() - if(${HAVE_RADOS}) list(APPEND LIBBAREOSSD_LIBRARIES ${RADOS_LIBRARIES}) endif() @@ -196,9 +195,7 @@ else() if(${HAVE_GFAPI}) list(APPEND LIBBAREOSSD_LIBRARIES ${GFAPI_LIBRARIES}) endif() - set(LIBBAREOSSD_LIBRARIES bareos ${LIBBAREOSSD_LIBRARIES} - ${JANSSON_LIBRARIES} - ) + set(LIBBAREOSSD_LIBRARIES bareos ${LIBBAREOSSD_LIBRARIES}) message(STATUS "LIBBAREOSSD_LIBRARIES ARE ${LIBBAREOSSD_LIBRARIES}") endif() @@ -207,13 +204,10 @@ if(${HAVE_DYNAMIC_SD_BACKENDS}) endif() add_library(bareossd SHARED ${LIBBAREOSSD_SRCS}) +target_link_libraries(bareossd PRIVATE bareos Threads::Threads) if(NOT ${HAVE_DYNAMIC_SD_BACKENDS}) - target_link_libraries(bareossd ${LIBBAREOSSD_LIBRARIES}) -endif() - -if(HAVE_DARWIN_OS) - target_link_libraries(bareossd bareos) + target_link_libraries(bareossd PRIVATE ${LIBBAREOSSD_LIBRARIES}) endif() add_library(stored_objects STATIC ${SDSRCS}) @@ -228,9 +222,6 @@ if(HAVE_WIN32) target_sources(bareos-sd PRIVATE ../win32/generic/main.cc) target_link_libraries(bareos-sd PRIVATE comctl32) endif() -if(HAVE_FREEBSD_OS) - target_link_libraries(bareos-sd PRIVATE ${JANSSON_LIBRARIES}) -endif() if(HAVE_NDMP) target_link_libraries(stored_objects PRIVATE bareosndmp) target_link_libraries(bareos-sd PRIVATE bareosndmp) @@ -239,36 +230,20 @@ endif() add_executable(bls ${BLSSRCS}) target_link_libraries(bls PRIVATE bareos bareossd bareosfind) -if(HAVE_FREEBSD_OS) - target_link_libraries(bls PRIVATE Threads::Threads ${JANSSON_LIBRARIES}) -endif() - add_executable(bextract ${BEXTRACTSRS}) -target_link_libraries( - bextract bareossd bareosfind bareos - $<$:Threads::Threads> - $<$:${JANSSON_LIBRARIES}> -) +target_link_libraries(bextract PRIVATE bareossd bareosfind bareos) add_executable(bscan ${BSCANSRCS}) target_link_libraries( - bscan bareos bareossd bareosfind bareossql bareoscats - $<$:Threads::Threads> - $<$:${JANSSON_LIBRARIES}> + bscan PRIVATE bareos bareossd bareosfind bareossql bareoscats ) add_executable(btape ${BTAPESRCS}) -target_link_libraries( - btape bareossd bareos $<$:Threads::Threads> - $<$:${JANSSON_LIBRARIES}> -) +target_link_libraries(btape PRIVATE bareossd bareos) add_executable(bcopy ${BCOPYSRCS}) -target_link_libraries( - bcopy bareossd bareos $<$:Threads::Threads> - $<$:${JANSSON_LIBRARIES}> -) +target_link_libraries(bcopy PRIVATE bareossd bareos) install(TARGETS bareossd DESTINATION ${libdir}) diff --git a/core/src/tests/CMakeLists.txt b/core/src/tests/CMakeLists.txt index 6a246e4a7c0..0404731c653 100644 --- a/core/src/tests/CMakeLists.txt +++ b/core/src/tests/CMakeLists.txt @@ -104,7 +104,6 @@ set(LINK_LIBRARIES bareoscats bareossql bareosfind - ${JANSSON_LIBRARIES} GTest::gtest_main ) @@ -185,10 +184,7 @@ bareos_add_test( bareos_add_test(test_is_name_valid LINK_LIBRARIES bareos GTest::gtest_main) -bareos_add_test( - test_output_formatter LINK_LIBRARIES GTest::gtest_main ${JANSSON_LIBRARIES} - bareos -) +bareos_add_test(test_output_formatter LINK_LIBRARIES GTest::gtest_main bareos) if(NOT client-only) bareos_add_test( @@ -248,9 +244,8 @@ if(NOT client-only) endif() # NOT client-only bareos_add_test( - test_config_parser_console - LINK_LIBRARIES console_objects bareos bareosfind GTest::gtest_main - ${JANSSON_LIBRARIES} + test_config_parser_console LINK_LIBRARIES console_objects bareos bareosfind + GTest::gtest_main ) if(NOT client-only) @@ -268,9 +263,8 @@ bareos_add_test( if(NOT client-only) bareos_add_test( - test_config_parser_sd - LINK_LIBRARIES stored_objects bareossd bareos GTest::gtest_main - $<$:${JANSSON_LIBRARIES}> + test_config_parser_sd LINK_LIBRARIES stored_objects bareossd bareos + GTest::gtest_main ) endif() # NOT client-only @@ -339,8 +333,7 @@ if(NOT client-only) alist_test.cc bareos_test_sockets.cc bsys_test.cc dlist_test.cc htable_test.cc qualified_resource_name_type_converter_test.cc ${PROJECT_SOURCE_DIR}/src/filed/evaluate_job_command.cc - LINK_LIBRARIES stored_objects bareossd bareos ${JANSSON_LIBRARIES} - GTest::gtest_main + LINK_LIBRARIES stored_objects bareossd bareos GTest::gtest_main ) bareos_add_test( diff --git a/core/src/tools/CMakeLists.txt b/core/src/tools/CMakeLists.txt index 98f8cdf714c..7cac953441e 100644 --- a/core/src/tools/CMakeLists.txt +++ b/core/src/tools/CMakeLists.txt @@ -23,38 +23,37 @@ if(HAVE_WIN32) list(APPEND BSMTPSRCS ../win32/tools/bsmtpres.rc) endif() add_executable(bsmtp ${BSMTPSRCS}) -target_link_libraries(bsmtp bareos ${JANSSON_LIBRARIES}) +target_link_libraries(bsmtp bareos) add_executable(drivetype drivetype.cc) -target_link_libraries(drivetype bareos bareosfind ${JANSSON_LIBRARIES}) +target_link_libraries(drivetype bareos bareosfind) add_executable(fstype fstype.cc) -target_link_libraries(fstype bareos bareosfind ${JANSSON_LIBRARIES}) +target_link_libraries(fstype bareos bareosfind) set(BREGEXSRCS bregex.cc) if(HAVE_WIN32) list(APPEND BREGEXSRCS ../win32/tools/bregexres.rc) endif() add_executable(bregex ${BREGEXSRCS}) -target_link_libraries(bregex bareos bareosfind ${JANSSON_LIBRARIES}) +target_link_libraries(bregex bareos bareosfind) set(BWILDSRCS bwild.cc) if(HAVE_WIN32) list(APPEND BWILDSRCS ../win32/tools/bwildres.rc) endif() add_executable(bwild ${BWILDSRCS}) -target_link_libraries(bwild bareos ${JANSSON_LIBRARIES}) +target_link_libraries(bwild bareos) add_executable(bscrypto bscrypto.cc) -target_link_libraries(bscrypto bareos ${JANSSON_LIBRARIES}) +target_link_libraries(bscrypto bareos) if(NOT HAVE_WIN32) - add_executable(btestls btestls.cc) - target_link_libraries(btestls bareosfind bareos ${JANSSON_LIBRARIES}) + target_link_libraries(btestls bareosfind bareos) add_executable(bpluginfo bpluginfo.cc) - target_link_libraries(bpluginfo bareos ${DL_LIBRARIES} ${JANSSON_LIBRARIES}) + target_link_libraries(bpluginfo bareos ${DL_LIBRARIES}) endif() set(TOOLS_BIN bsmtp bwild bregex) From 5f92747caf617e9f0e6f9b9a9521dc9ecb03557e Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Wed, 14 Apr 2021 15:31:54 +0200 Subject: [PATCH 2/5] core: remove HAVE_JANSSON from Director jansson is a requirement when compiling the Director, so HAVE_JANSSON is no longer required. --- core/src/dird/dird_conf.cc | 11 +---------- core/src/dird/dird_conf.h | 4 +--- core/src/dird/inc_conf.cc | 5 ++--- core/src/dird/inc_conf.h | 2 -- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/core/src/dird/dird_conf.cc b/core/src/dird/dird_conf.cc index 58838043b72..496f23a27e0 100644 --- a/core/src/dird/dird_conf.cc +++ b/core/src/dird/dird_conf.cc @@ -3,7 +3,7 @@ Copyright (C) 2000-2011 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2020 Bareos GmbH & Co. KG + Copyright (C) 2013-2021 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -738,7 +738,6 @@ struct s_kw PoolTypes[] = {{"Backup", 0}, {"Copy", 0}, {"Cloned", 0}, {"Archive", 0}, {"Migration", 0}, {"Scratch", 0}, {NULL, 0}}; -#ifdef HAVE_JANSSON json_t* json_item(s_jl* item) { json_t* json = json_object(); @@ -945,14 +944,6 @@ bool PrintConfigSchemaJson(PoolMem& buffer) return true; } -#else -bool PrintConfigSchemaJson(PoolMem& buffer) -{ - PmStrcat(buffer, "{ \"success\": false, \"message\": \"not available\" }"); - - return false; -} -#endif static bool CmdlineItem(PoolMem* buffer, ResourceItem* item) { diff --git a/core/src/dird/dird_conf.h b/core/src/dird/dird_conf.h index 749cd56f639..4fb5e545c32 100644 --- a/core/src/dird/dird_conf.h +++ b/core/src/dird/dird_conf.h @@ -3,7 +3,7 @@ Copyright (C) 2000-2011 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2020 Bareos GmbH & Co. KG + Copyright (C) 2013-2021 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -722,9 +722,7 @@ bool print_datatype_schema_json(PoolMem& buffer, const int type, ResourceItem items[], const bool last = false); -#ifdef HAVE_JANSSON json_t* json_datatype(const int type, ResourceItem items[]); -#endif const char* AuthenticationProtocolTypeToString(uint32_t auth_protocol); const char* JobLevelToString(int level); extern "C" char* job_code_callback_director(JobControlRecord* jcr, const char*); diff --git a/core/src/dird/inc_conf.cc b/core/src/dird/inc_conf.cc index 7dea4b89508..8f329eeddce 100644 --- a/core/src/dird/inc_conf.cc +++ b/core/src/dird/inc_conf.cc @@ -3,7 +3,7 @@ Copyright (C) 2000-2009 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2020 Bareos GmbH & Co. KG + Copyright (C) 2013-2021 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -1066,7 +1066,6 @@ void StoreInc(LEX* lc, ResourceItem* item, int index, int pass) scan_err0(lc, _("Old style Include/Exclude not supported\n")); } -#ifdef HAVE_JANSSON json_t* json_incexc(const int type) { return json_datatype(type, newinc_items); @@ -1076,5 +1075,5 @@ json_t* json_options(const int type) { return json_datatype(type, options_items); } -#endif + } /* namespace directordaemon */ diff --git a/core/src/dird/inc_conf.h b/core/src/dird/inc_conf.h index 69eff66add5..b65cc6dbd89 100644 --- a/core/src/dird/inc_conf.h +++ b/core/src/dird/inc_conf.h @@ -41,10 +41,8 @@ bool print_options_schema_json(PoolMem& buffer, int level, const int type, const bool last = false); -#ifdef HAVE_JANSSON json_t* json_incexc(const int type); json_t* json_options(const int type); -#endif } /* namespace directordaemon */ From 8297eb24c74d59ccdd2d4d0dc3589d81a5c4c2e8 Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Mon, 12 Apr 2021 19:38:13 +0200 Subject: [PATCH 3/5] core: remove json.* files This files have been used to initialize jansson with a custom memory management. While this have been useful in the past, the memory management have now be identical to the default. Therefore, these initialization is no longer required. --- core/src/console/console_conf.cc | 3 -- core/src/dird/dird_conf.cc | 3 -- core/src/filed/filed_conf.cc | 2 -- core/src/include/bareos.h | 1 - core/src/lib/CMakeLists.txt | 1 - core/src/lib/json.cc | 46 --------------------------- core/src/lib/json.h | 26 --------------- core/src/lib/output_formatter.cc | 5 +-- core/src/qt-tray-monitor/tray_conf.cc | 2 -- core/src/stored/stored_conf.cc | 3 -- 10 files changed, 1 insertion(+), 91 deletions(-) delete mode 100644 core/src/lib/json.cc delete mode 100644 core/src/lib/json.h diff --git a/core/src/console/console_conf.cc b/core/src/console/console_conf.cc index 9fcfa8cbdf3..ff9cdc9ff77 100644 --- a/core/src/console/console_conf.cc +++ b/core/src/console/console_conf.cc @@ -28,7 +28,6 @@ #include "console/console_globals.h" #include "console/console_conf.h" #include "lib/alist.h" -#include "lib/json.h" #include "lib/resource_item.h" #include "lib/tls_resource_items.h" #include "lib/output_formatter.h" @@ -274,8 +273,6 @@ ConfigurationParser* InitConsConfig(const char* configfile, int exit_code) #ifdef HAVE_JANSSON bool PrintConfigSchemaJson(PoolMem& buffer) { - InitializeJson(); - json_t* json = json_object(); json_object_set_new(json, "format-version", json_integer(2)); json_object_set_new(json, "component", json_string("bconsole")); diff --git a/core/src/dird/dird_conf.cc b/core/src/dird/dird_conf.cc index 496f23a27e0..b013053bc3b 100644 --- a/core/src/dird/dird_conf.cc +++ b/core/src/dird/dird_conf.cc @@ -530,7 +530,6 @@ static ResourceItem counter_items[] = { }; #include "lib/messages_resource_items.h" -#include "lib/json.h" /** * This is the master resource definition. @@ -839,8 +838,6 @@ bool PrintConfigSchemaJson(PoolMem& buffer) DatatypeName* datatype; ResourceTable* resources = my_config->resources_; - InitializeJson(); - json_t* json = json_object(); json_object_set_new(json, "format-version", json_integer(2)); json_object_set_new(json, "component", json_string("bareos-dir")); diff --git a/core/src/filed/filed_conf.cc b/core/src/filed/filed_conf.cc index 67057749a82..5f921339c8c 100644 --- a/core/src/filed/filed_conf.cc +++ b/core/src/filed/filed_conf.cc @@ -282,8 +282,6 @@ bool PrintConfigSchemaJson(PoolMem& buffer) { ResourceTable* resources = my_config->resources_; - InitializeJson(); - json_t* json = json_object(); json_object_set_new(json, "format-version", json_integer(2)); json_object_set_new(json, "component", json_string("bareos-fd")); diff --git a/core/src/include/bareos.h b/core/src/include/bareos.h index e19f0bd0631..70be9e3adb2 100644 --- a/core/src/include/bareos.h +++ b/core/src/include/bareos.h @@ -192,7 +192,6 @@ extern "C" { #include "baconfig.h" #include "lib/lib.h" #include "lib/compression.h" -#include "lib/json.h" /** * For wx-console compiles, we undo some Bareos defines. diff --git a/core/src/lib/CMakeLists.txt b/core/src/lib/CMakeLists.txt index f07da2786d2..91abb4358bd 100644 --- a/core/src/lib/CMakeLists.txt +++ b/core/src/lib/CMakeLists.txt @@ -65,7 +65,6 @@ set(BAREOS_SRCS hmac.cc htable.cc jcr.cc - json.cc lockmgr.cc mem_pool.cc message.cc diff --git a/core/src/lib/json.cc b/core/src/lib/json.cc deleted file mode 100644 index 3ce7e5e18bb..00000000000 --- a/core/src/lib/json.cc +++ /dev/null @@ -1,46 +0,0 @@ -/* - BAREOS® - Backup Archiving REcovery Open Sourced - - Copyright (C) 2015-2019 Bareos GmbH & Co. KG - - This program is Free Software; you can redistribute it and/or - modify it under the terms of version three of the GNU Affero General Public - License as published by the Free Software Foundation and included - in the file LICENSE. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -/* - * JSON Glue layer. - * - * This file is the glue between JANSSON and BAREOS. - * - * Joerg Steffens, April 2015 - */ - -#define NEED_JANSSON_NAMESPACE 1 -#include "include/bareos.h" -#include "lib/output_formatter.h" - -#if HAVE_JANSSON -static pthread_once_t json_setup = PTHREAD_ONCE_INIT; - -static void* json_malloc(size_t size) { return malloc(size); } - -static void json_free(void* ptr) { free(ptr); } - -static void set_alloc_funcs() { json_set_alloc_funcs(json_malloc, json_free); } - -void InitializeJson() { pthread_once(&json_setup, set_alloc_funcs); } -#else -void InitializeJson() {} -#endif /* HAVE_JANSSON */ diff --git a/core/src/lib/json.h b/core/src/lib/json.h deleted file mode 100644 index e7e8df92d25..00000000000 --- a/core/src/lib/json.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - BAREOS® - Backup Archiving REcovery Open Sourced - - Copyright (C) 2018-2018 Bareos GmbH & Co. KG - - This program is Free Software; you can redistribute it and/or - modify it under the terms of version three of the GNU Affero General Public - License as published by the Free Software Foundation and included - in the file LICENSE. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ -#ifndef BAREOS_LIB_JSON_H_ -#define BAREOS_LIB_JSON_H_ - -void InitializeJson(); - -#endif // BAREOS_LIB_JSON_H_ diff --git a/core/src/lib/output_formatter.cc b/core/src/lib/output_formatter.cc index d8e5793b470..ce837d85a03 100644 --- a/core/src/lib/output_formatter.cc +++ b/core/src/lib/output_formatter.cc @@ -2,7 +2,7 @@ BAREOS® - Backup Archiving REcovery Open Sourced Copyright (C) 2016-2016 Planets Communications B.V. - Copyright (C) 2015-2020 Bareos GmbH & Co. KG + Copyright (C) 2015-2021 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -33,7 +33,6 @@ #include "include/bareos.h" #define NEED_JANSSON_NAMESPACE #include "lib/output_formatter.h" -#include "lib/json.h" const char* json_error_message_template = "{ " @@ -51,8 +50,6 @@ OutputFormatter::OutputFormatter(SEND_HANDLER* send_func_arg, void* filter_ctx_arg, int api_mode) { - InitializeJson(); - send_func = send_func_arg; filter_func = filter_func_arg; send_ctx = send_ctx_arg; diff --git a/core/src/qt-tray-monitor/tray_conf.cc b/core/src/qt-tray-monitor/tray_conf.cc index b34b25d6bca..763344a7076 100644 --- a/core/src/qt-tray-monitor/tray_conf.cc +++ b/core/src/qt-tray-monitor/tray_conf.cc @@ -404,8 +404,6 @@ bool PrintConfigSchemaJson(PoolMem& buffer) { ResourceTable* resources = my_config->resources_; - InitializeJson(); - json_t* json = json_object(); json_object_set_new(json, "format-version", json_integer(2)); json_object_set_new(json, "component", json_string("bareos-tray-monitor")); diff --git a/core/src/stored/stored_conf.cc b/core/src/stored/stored_conf.cc index 43956ef69cd..ba37f132e3b 100644 --- a/core/src/stored/stored_conf.cc +++ b/core/src/stored/stored_conf.cc @@ -45,7 +45,6 @@ #define NEED_JANSSON_NAMESPACE 1 #include "lib/output_formatter.h" #include "lib/output_formatter_resource.h" -#include "lib/json.h" #include "include/auth_types.h" #include "include/jcr.h" @@ -622,8 +621,6 @@ bool PrintConfigSchemaJson(PoolMem& buffer) { ResourceTable* resources = my_config->resources_; - InitializeJson(); - json_t* json = json_object(); json_object_set_new(json, "format-version", json_integer(2)); json_object_set_new(json, "component", json_string("bareos-sd")); From 2566a8f1b6f8b77d8b6dbcac5b7d698a9ec8d134 Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Wed, 14 Apr 2021 15:39:30 +0200 Subject: [PATCH 4/5] update CHANGELOG: mandatory jansson library #793 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab287b4ae64..7d93a53f3e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https: - added external repo bareos-contrib as subtree [PR #752] ### Changed +. core: Make the jansson library mandatory when compiling the Bareos Director [PR #793] - repaired or added all header guards in libdroplet [PR #765] - When using Python > 3.7 the postgres and libcloud plugins will cancel the job and write an error message [PR #769] - bstrncpy: workaround when used with overlapping strings [PR #736] From 3c2e57b75a8332626103a66ef0255ef84e164a5d Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Mon, 19 Apr 2021 13:58:40 +0200 Subject: [PATCH 5/5] cmake: fix typo The message mode parameter is case-sensitiv and must be written upper-case. --- core/CMakeLists.txt | 1 - core/src/CMakeLists.txt | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index a2460b15df7..a5ed9ea5230 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -870,7 +870,6 @@ message(" LMDB support: ${lmdb} ") message(" NDMP support: ${ndmp} ") message(" Build ndmjob binary: ${build_ndmjob} ") message(" enable-lockmgr: ${lockmgr} ") -message(" bat support: ${support_bat} ") message(" tray-monitor support: ${HAVE_TRAYMONITOR} ") message(" test-plugin support: ${HAVE_TEST_PLUGIN} ") message(" client-only: ${build_client_only} ") diff --git a/core/src/CMakeLists.txt b/core/src/CMakeLists.txt index b5eaa98c8fa..75caa5c3dd7 100644 --- a/core/src/CMakeLists.txt +++ b/core/src/CMakeLists.txt @@ -35,10 +35,10 @@ endif() if(RUN_SYSTEMTESTS_ON_INSTALLED_FILES) message( - status "Skipping unit tests as testing on installed files is requested" + STATUS "Skipping unit tests as testing on installed files is requested" ) elseif(NOT GTest_FOUND) - message(status "Skipping unit tests as gtest was not found") + message(STATUS "Skipping unit tests as gtest was not found") else() add_subdirectory(tests) endif()