Skip to content

Commit

Permalink
Merge pull request #793
Browse files Browse the repository at this point in the history
Make the jansson library mandatory.
  • Loading branch information
arogge committed Apr 22, 2021
2 parents ee04f78 + 3c2e57b commit 3bc9255
Show file tree
Hide file tree
Showing 27 changed files with 163 additions and 209 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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]
Expand Down
99 changes: 99 additions & 0 deletions 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()
9 changes: 4 additions & 5 deletions core/CMakeLists.txt
Expand Up @@ -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} "
Expand All @@ -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} ")
Expand Down
2 changes: 1 addition & 1 deletion core/cmake/BareosFindAllLibraries.cmake
Expand Up @@ -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" "")
Expand Down Expand Up @@ -204,4 +203,5 @@ if(${ZLIB_FOUND})
endif()

find_package(Readline)
find_package(Jansson)
include(thread)
4 changes: 2 additions & 2 deletions core/src/CMakeLists.txt
Expand Up @@ -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()
Expand Down
11 changes: 2 additions & 9 deletions core/src/console/CMakeLists.txt
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions core/src/console/console_conf.cc
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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"));
Expand Down
16 changes: 9 additions & 7 deletions core/src/dird/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
14 changes: 1 addition & 13 deletions core/src/dird/dird_conf.cc
Expand Up @@ -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
Expand Down Expand Up @@ -530,7 +530,6 @@ static ResourceItem counter_items[] = {
};

#include "lib/messages_resource_items.h"
#include "lib/json.h"

/**
* This is the master resource definition.
Expand Down Expand Up @@ -738,7 +737,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();
Expand Down Expand Up @@ -840,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"));
Expand Down Expand Up @@ -945,14 +941,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)
{
Expand Down
4 changes: 1 addition & 3 deletions core/src/dird/dird_conf.h
Expand Up @@ -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
Expand Down Expand Up @@ -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*);
Expand Down
5 changes: 2 additions & 3 deletions core/src/dird/inc_conf.cc
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -1076,5 +1075,5 @@ json_t* json_options(const int type)
{
return json_datatype(type, options_items);
}
#endif

} /* namespace directordaemon */
2 changes: 0 additions & 2 deletions core/src/dird/inc_conf.h
Expand Up @@ -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 */

Expand Down
6 changes: 2 additions & 4 deletions core/src/filed/CMakeLists.txt
Expand Up @@ -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)
Expand All @@ -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(
Expand Down
4 changes: 1 addition & 3 deletions core/src/filed/filed_conf.cc
Expand Up @@ -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
Expand Down Expand Up @@ -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"));
Expand Down

0 comments on commit 3bc9255

Please sign in to comment.