Commit bf3509e2 authored by Johan Ström's avatar Johan Ström

Add detection of sqlite3 and openssl (optional)

parent 205d7fe0
......@@ -123,6 +123,13 @@ log_pkg_found(yamlcpp "${YAML_CPP_FOUND}" "${YAML_CPP_VERSION}" FATAL_ERROR "")
pkg_search_module(AUGEAS REQUIRED augeas)
log_pkg_found(augeas "${AUGEAS_FOUND}" "${AUGEAS_VERSION}" FATAL_ERROR "")
pkg_search_module(SQLITE REQUIRED sqlite3)
log_pkg_found(augeas "${SQLITE_FOUND}" "${SQLITE_VERSION}" FATAL_ERROR "")
# Mongoose may use openssl
pkg_search_module(OPENSSL openssl)
log_pkg_found(openssl "${OPENSSL_FOUND}" "${OPENSSL_VERSION}" STATUS ", building without https support")
# Linux/debian has lua5.x, FreeBSD has lua-5.x, fedora has just lua
pkg_search_module(LUA lua5.3 lua-5.3 lua5.2 lua-5.2 lua5.1 lua-5.1 lua)
log_pkg_found(lua "${LUA_FOUND}" "${LUA_VERSION}" WARNING ", parts of core will not be built")
......@@ -158,6 +165,11 @@ log_pkg_found(OpenLighting "${OpenLighting_FOUND}" "${OpenLighting_VERSION}" STA
include_directories(${Boost_INCLUDE_DIRS})
find_program(INTLTOOL_MERGE intltool-merge)
if(NOT INTLTOOL_MERGE)
message(FATAL_ERROR "Program 'intltool-merge' is required to build web UI")
endif()
# Fix for Boost < 1.56 built without C++, when we build with C++11
# https://stackoverflow.com/questions/35007134/c-boost-undefined-reference-to-boostfilesystemdetailcopy-file
# https://chaste.cs.ox.ac.uk/trac/wiki/ChasteGuides/ModernCpp#Boostscopedenumsforboost1.56
......@@ -171,7 +183,7 @@ if(Boost_VERSION VERSION_LESS 105600)
endif()
find_package(CppUnit)
log_pkg_found(CppUnit "${CPPUNIT_FOUND}" "${CPPUNIT_VERSION}" STATUS "not building unit-tests")
log_pkg_found(CppUnit "${CPPUNIT_FOUND}" "${CPPUNIT_VERSION}" STATUS ", not building unit-tests")
check_include_files("xlocale.h" HAVE_XLOCALE_H)
......
......@@ -797,8 +797,12 @@ void AgoRpc::setupApp() {
for(tokenizer::iterator gen=tok.begin(); gen != tok.end(); ++gen) {
std::string addr(*gen);
if(addr[addr.length() -1] == 's') {
#if MG_ENABLE_SSL
addr.assign(addr, 0, addr.length()-1);
agoHttp.addBinding(addr, certificate);
#else
throw ConfigurationError("Not compiled with https support, cannot use binding "+addr);
#endif
}else
agoHttp.addBinding(addr);
}
......
......@@ -404,8 +404,12 @@ void AgoImperiHome::setupApp() {
for (tokenizer::iterator gen = tok.begin(); gen != tok.end(); ++gen) {
std::string addr(*gen);
if (addr[addr.length() - 1] == 's') {
#if MG_ENABLE_SSL
addr.assign(addr, 0, addr.length() - 1);
agoHttp.addBinding(addr, certificate);
#else
throw ConfigurationError("Not compiled with https support, cannot use binding "+addr);
#endif
} else
agoHttp.addBinding(addr);
}
......
......@@ -14,18 +14,38 @@ set (AGOHTTP_LIBRARIES
${Boost_FILESYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY}
${CMAKE_THREAD_LIBS_INIT} # for pthread
ssl
crypto
${JSONCPP_LIBRARIES}
)
target_link_libraries (agohttp ${AGOHTTP_LIBRARIES})
if(OPENSSL_FOUND)
list(APPEND AGOHTTP_LIBRARIES
ssl
crypto
)
set(MG_ENABLE_SSL 1)
else()
set(MG_ENABLE_SSL 0)
endif()
# configure a header file to pass some of the CMake settings
# to the source code
# Note that MG_ flags must be set when building mongoose.c too
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/agohttp_config.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/agohttp_config.h"
@ONLY
)
# SSI fails to build on GCC 8, we dont use it anyway
# https://github.com/cesanta/mongoose/issues/929
set_property(
TARGET agohttp
PROPERTY COMPILE_DEFINITIONS
MG_ENABLE_SSL=1
TARGET agohttp
APPEND PROPERTY COMPILE_DEFINITIONS
MG_ENABLE_HTTP_SSI=0
MG_ENABLE_SSL=${MG_ENABLE_SSL}
)
target_link_libraries (agohttp ${AGOHTTP_LIBRARIES})
set_property(
TARGET agohttp
......
......@@ -460,18 +460,23 @@ void AgoHttp::addPrefixHandler(const std::string& path, agohttp_url_handler_fn h
urlPrefixHandlers[path] = handler;
}
void AgoHttp::addBinding(const std::string& address,
const boost::filesystem::path& certFile,
void AgoHttp::addBinding(const std::string& address
#if MG_ENABLE_SSL
, const boost::filesystem::path& certFile,
const boost::filesystem::path& keyFile,
const boost::filesystem::path& caCertFile) {
const boost::filesystem::path& caCertFile
#endif
) {
if(state != Stopped)
throw std::runtime_error("Cannot change settings when running");
HttpBindOptions opts;
opts.address = address;
#if MG_ENABLE_SSL
opts.sslCertFile = certFile.native();
opts.sslKeyFile = keyFile.native();
opts.sslCaCertFile = caCertFile.native();
#endif
bindings.push_back(opts);
}
......@@ -490,6 +495,7 @@ void AgoHttp::start() {
const char *err;
bindopts.error_string = &err;
#if MG_ENABLE_SSL
// If empty, they are ignored.
if(!opts.sslCertFile.empty())
bindopts.ssl_cert = opts.sslCertFile.c_str();
......@@ -497,6 +503,7 @@ void AgoHttp::start() {
bindopts.ssl_key = opts.sslKeyFile.c_str();
if(!opts.sslCaCertFile.empty())
bindopts.ssl_ca_cert = opts.sslCaCertFile.c_str();
#endif
AGO_INFO() << "Binding HTTP on " << opts.address;
struct mg_connection *lc = mg_bind_opt(&mongooseMgr, opts.address.c_str(),
......
......@@ -8,6 +8,8 @@
#include <boost/thread/mutex.hpp>
#include <json/json.h>
// Reference to binary dir
#include "agohttp/agohttp_config.h"
#include "mongoose.h"
namespace agocontrol {
......@@ -83,10 +85,14 @@ public:
// https://docs.cesanta.com/mongoose/master/#/c-api/net.h/mg_bind_opt.md/
// If SSL is desired on this particular port, specify certFile, and optionally keyFile & caCertFile.
// SSL files should be in PEM format, certFile may hold both key & cert.
void addBinding(const std::string& address,
const boost::filesystem::path& certFile = boost::filesystem::path(),
// SSL support requires openssl to be installed
void addBinding(const std::string& address
#if MG_ENABLE_SSL
, const boost::filesystem::path& certFile = boost::filesystem::path(),
const boost::filesystem::path& keyFile = boost::filesystem::path(),
const boost::filesystem::path& caCertFile = boost::filesystem::path());
const boost::filesystem::path& caCertFile = boost::filesystem::path()
#endif
);
// Set a document root to serve documents from, if no handler have been registered for path.
// If never called, we respond 404 to any unknown paths.
......
#ifndef AGOHTTP_CONFIG_H
#cmakedefine MG_ENABLE_SSL @MG_ENABLE_SSL@
#endif
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment