mirror of
https://github.com/QuasarApp/LIEF.git
synced 2025-05-07 01:09:33 +00:00
Make JSON related API optional
This commit is contained in:
parent
8ad708414e
commit
3a76b8dddc
@ -54,6 +54,7 @@ option(LIEF_COVERAGE "Perform code coverage" OFF)
|
||||
option(LIEF_USE_CCACHE "Use ccache to speed up compilation" ON)
|
||||
option(LIEF_EXTRA_WARNINGS "Enable extra warning from the compiler" OFF)
|
||||
option(LIEF_LOGGING "Enable logging" ON)
|
||||
option(LIEF_ENABLE_JSON "Enable JSON-related APIs" ON)
|
||||
|
||||
option(LIEF_ELF "Build LIEF with ELF module" ON)
|
||||
option(LIEF_PE "Build LIEF with PE module" ON)
|
||||
@ -74,17 +75,23 @@ endif()
|
||||
|
||||
# Json
|
||||
# ----
|
||||
set(LIBJSON_GIT_URL "https://github.com/nlohmann/json.git" CACHE STRING "URL to the JSON lib repo")
|
||||
ExternalProject_Add(lief_libjson
|
||||
GIT_REPOSITORY ${LIBJSON_GIT_URL}
|
||||
GIT_TAG v2.0.8
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND "")
|
||||
|
||||
ExternalProject_get_property(lief_libjson SOURCE_DIR)
|
||||
set(LIBJSON_SOURCE_DIR "${SOURCE_DIR}")
|
||||
if (LIEF_ENABLE_JSON)
|
||||
set(LIBJSON_GIT_URL "https://github.com/nlohmann/json.git" CACHE STRING "URL to the JSON lib repo")
|
||||
ExternalProject_Add(lief_libjson
|
||||
GIT_REPOSITORY ${LIBJSON_GIT_URL}
|
||||
GIT_TAG v2.0.8
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND "")
|
||||
|
||||
ExternalProject_get_property(lief_libjson SOURCE_DIR)
|
||||
set(LIBJSON_SOURCE_DIR "${SOURCE_DIR}")
|
||||
message(STATUS "Enable JSON support")
|
||||
set(ENABLE_JSON_SUPPORT 1)
|
||||
else()
|
||||
message(STATUS "Disable JSON support")
|
||||
set(ENABLE_JSON_SUPPORT 0)
|
||||
endif()
|
||||
|
||||
# Rang
|
||||
# ----
|
||||
@ -330,6 +337,12 @@ configure_file(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/version.h"
|
||||
)
|
||||
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/config.h.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/config.h"
|
||||
@ONLY
|
||||
)
|
||||
|
||||
set (LIEF_PUBLIC_INCLUDE_DIR
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include/"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/"
|
||||
@ -375,8 +388,10 @@ target_include_directories(LIB_LIEF_SHARED
|
||||
PRIVATE "${LIEF_PRIVATE_INCLUDE_DIR}")
|
||||
|
||||
|
||||
add_dependencies(LIB_LIEF_STATIC lief_libjson)
|
||||
add_dependencies(LIB_LIEF_SHARED lief_libjson)
|
||||
if (LIEF_ENABLE_JSON)
|
||||
add_dependencies(LIB_LIEF_STATIC lief_libjson)
|
||||
add_dependencies(LIB_LIEF_SHARED lief_libjson)
|
||||
endif()
|
||||
|
||||
add_dependencies(LIB_LIEF_STATIC lief_easyloggingpp)
|
||||
add_dependencies(LIB_LIEF_SHARED lief_easyloggingpp)
|
||||
|
@ -54,13 +54,20 @@ set(PYBIND11_SOURCE_DIR "${SOURCE_DIR}")
|
||||
set(LIEF_PYTHON_BASIC_SRC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/pyLIEF.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/pyUtils.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/pyJson.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/pyIterators.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/pyExceptions.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/pyLogger.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/encoding.cpp"
|
||||
)
|
||||
|
||||
if (LIEF_ENABLE_JSON)
|
||||
set(LIEF_PYTHON_BASIC_SRC
|
||||
$(LIEF_PYTHON_BASIC_SRC)
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/pyJson.cpp"
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
set(LIEF_PYTHON_ABSTRACT_SRC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/Abstract/init.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects"
|
||||
|
@ -51,7 +51,10 @@ PYBIND11_PLUGIN(_pylief) {
|
||||
// Init util functions
|
||||
init_utils_functions(LIEF_module);
|
||||
|
||||
|
||||
#if defined(LIEF_JSON_SUPPORT)
|
||||
init_json_functions(LIEF_module);
|
||||
#endif
|
||||
|
||||
return LIEF_module.ptr();
|
||||
}
|
||||
|
@ -21,10 +21,14 @@
|
||||
#include <pybind11/operators.h>
|
||||
#include <functional>
|
||||
|
||||
#include <LIEF/config.h>
|
||||
|
||||
#include "encoding.hpp"
|
||||
|
||||
#include "pyIterators.hpp"
|
||||
|
||||
#define RST_CLASS_REF(X) ":class:`~"#X"`"
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
using namespace pybind11::literals;
|
||||
@ -36,8 +40,10 @@ void init_ELF_module(py::module&);
|
||||
void init_PE_module(py::module&);
|
||||
void init_MachO_module(py::module&);
|
||||
void init_utils_functions(py::module&);
|
||||
void init_json_functions(py::module&);
|
||||
|
||||
#define RST_CLASS_REF(X) ":class:`~"#X"`"
|
||||
#if defined(LIEF_JSON_SUPPORT)
|
||||
void init_json_functions(py::module&);
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
24
include/LIEF/config.h.in
Normal file
24
include/LIEF/config.h.in
Normal file
@ -0,0 +1,24 @@
|
||||
/* Copyright 2017 A. Guinet
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LIEF_CONFIG_H_
|
||||
#define LIEF_CONFIG_H_
|
||||
|
||||
#if @ENABLE_JSON_SUPPORT@
|
||||
#define LIEF_JSON_SUPPORT
|
||||
#endif
|
||||
|
||||
#endif
|
@ -15,8 +15,13 @@
|
||||
*/
|
||||
#ifndef LIEF_JSON_H_
|
||||
#define LIEF_JSON_H_
|
||||
|
||||
#include <LIEF/config.h>
|
||||
|
||||
#ifdef LIEF_JSON_SUPPORT
|
||||
#include <json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -16,6 +16,10 @@
|
||||
#ifndef LIEF_TO_JSON_H_
|
||||
#define LIEF_TO_JSON_H_
|
||||
|
||||
#include "LIEF/config.h"
|
||||
|
||||
#ifdef LIEF_JSON_SUPPORT
|
||||
|
||||
#include "LIEF/json.hpp"
|
||||
|
||||
#include "LIEF/visitors/json.hpp"
|
||||
@ -41,4 +45,6 @@ std::string to_json_str(const T& obj) {
|
||||
|
||||
} // namespace LIEF
|
||||
|
||||
#endif // LIEF_JSON_SUPPORT
|
||||
|
||||
#endif
|
||||
|
@ -16,6 +16,10 @@
|
||||
#ifndef LIEF_ELF_VISITOR_JSONS_H_
|
||||
#define LIEF_ELF_VISITOR_JSONS_H_
|
||||
|
||||
#include "LIEF/config.h"
|
||||
|
||||
#ifdef LIEF_JSON_SUPPORT
|
||||
|
||||
#include "LIEF/visibility.h"
|
||||
#include "LIEF/visitors/json.hpp"
|
||||
|
||||
@ -59,5 +63,6 @@ class DLL_PUBLIC JsonVisitor : public LIEF::JsonVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
#endif // LIEF_JSON_SUPPORT
|
||||
|
||||
#endif
|
||||
|
@ -16,6 +16,10 @@
|
||||
#ifndef LIEF_VISITOR_JSONS_H_
|
||||
#define LIEF_VISITOR_JSONS_H_
|
||||
|
||||
#include "LIEF/config.h"
|
||||
|
||||
#ifdef LIEF_JSON_SUPPORT
|
||||
|
||||
#include "LIEF/visibility.h"
|
||||
#include "LIEF/Visitor.hpp"
|
||||
#include "LIEF/json.hpp"
|
||||
@ -46,5 +50,6 @@ class DLL_PUBLIC JsonVisitor : public Visitor {
|
||||
|
||||
}
|
||||
|
||||
#endif // LIEF_JSON_SUPPORT
|
||||
|
||||
#endif
|
||||
|
@ -19,6 +19,10 @@
|
||||
#include "LIEF/visibility.h"
|
||||
#include "LIEF/visitors/json.hpp"
|
||||
|
||||
#include "LIEF/config.h"
|
||||
|
||||
#ifdef LIEF_JSON_SUPPORT
|
||||
|
||||
namespace LIEF {
|
||||
namespace PE {
|
||||
class DLL_PUBLIC JsonVisitor : public LIEF::JsonVisitor {
|
||||
@ -72,5 +76,6 @@ class DLL_PUBLIC JsonVisitor : public LIEF::JsonVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
#endif // LIEF_JSON_SUPPORT
|
||||
|
||||
#endif
|
||||
|
@ -13,6 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "LIEF/config.h"
|
||||
|
||||
#ifdef LIEF_JSON_SUPPORT
|
||||
|
||||
#include "LIEF/visitors/elf_json.hpp"
|
||||
#include "LIEF/ELF.hpp"
|
||||
namespace LIEF {
|
||||
@ -411,3 +416,5 @@ void JsonVisitor::visit(const LIEF::Section& section) {
|
||||
|
||||
} // namespace ELF
|
||||
} // namespace LIEF
|
||||
|
||||
#endif // LIEF_JSON_SUPPORT
|
||||
|
@ -16,6 +16,11 @@
|
||||
#include "LIEF/Abstract/Abstract.hpp"
|
||||
#include "LIEF/visitors/json.hpp"
|
||||
#include "LIEF/Abstract/EnumToString.hpp"
|
||||
|
||||
#include "LIEF/config.h"
|
||||
|
||||
#ifdef LIEF_JSON_SUPPORT
|
||||
|
||||
namespace LIEF {
|
||||
|
||||
JsonVisitor::JsonVisitor(void) :
|
||||
@ -92,3 +97,5 @@ const json& JsonVisitor::get(void) const {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // LIEF_JSON_SUPPORT
|
||||
|
@ -13,6 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "LIEF/config.h"
|
||||
|
||||
#ifdef LIEF_JSON_SUPPORT
|
||||
|
||||
#include "LIEF/visitors/pe_json.hpp"
|
||||
#include "LIEF/visitors/Hash.hpp"
|
||||
#include "LIEF/PE.hpp"
|
||||
@ -661,3 +666,5 @@ void JsonVisitor::visit(const LIEF::Section& section) {
|
||||
|
||||
} // namespace PE
|
||||
} // namespace LIEF
|
||||
|
||||
#endif // LIEF_JSON_SUPPORT
|
||||
|
Loading…
x
Reference in New Issue
Block a user