(cmake) new python code is optional and enabled at cmake time with -DUSE_PYTHON=1

This commit is contained in:
Benjamin Sergeant
2020-06-25 10:05:02 -07:00
parent f8b8799799
commit 68c97da518
8 changed files with 62 additions and 44 deletions

View File

@ -36,7 +36,10 @@ if (NOT JSONCPP_FOUND)
set(JSONCPP_INCLUDE_DIRS ../third_party/jsoncpp)
endif()
find_package(Python COMPONENTS Development)
if (USE_PYTHON)
target_compile_definitions(ixbots PUBLIC IXBOTS_USE_PYTHON)
find_package(Python COMPONENTS Development)
endif()
set(IXBOTS_INCLUDE_DIRS
.
@ -47,7 +50,10 @@ set(IXBOTS_INCLUDE_DIRS
../ixredis
../ixsentry
${JSONCPP_INCLUDE_DIRS}
${SPDLOG_INCLUDE_DIRS}
${Python_INCLUDE_DIRS})
${SPDLOG_INCLUDE_DIRS})
if (USE_PYTHON)
set(IXBOTS_INCLUDE_DIRS ${IXBOTS_INCLUDE_DIRS} ${Python_INCLUDE_DIRS})
endif()
target_include_directories( ixbots PUBLIC ${IXBOTS_INCLUDE_DIRS} )

View File

@ -23,18 +23,18 @@
// (linking error about missing debug build)
//
#ifndef _WIN32
#ifdef IXBOTS_USE_PYTHON
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#endif
#ifndef _WIN32
#ifdef IXBOTS_USE_PYTHON
namespace
{
//
// This function is unused at this point. It produce a correct output,
// but triggers memory leaks when called repeateadly, as the reference counting
// Python functions are not used properly
// but triggers memory leaks when called repeateadly, as I cannot figure out how to
// make the reference counting Python functions to work properly (Py_DECREF and friends)
//
PyObject* jsonToPythonObject(const Json::Value& val)
{
@ -104,8 +104,9 @@ namespace ix
StatsdClient& statsdClient,
const std::string& scriptPath)
{
#ifdef _WIN32
CoreLogger::error("Command is disabled on Windows.");
#ifndef IXBOTS_USE_PYTHON
CoreLogger::error("Command is disabled. "
"Needs to be configured with USE_PYTHON=1");
return -1;
#else
CobraBot bot;