Commit 7b1678c1 authored by Tobias WEBER's avatar Tobias WEBER
Browse files

started with plugins

parent 5fba96b6
......@@ -8,6 +8,8 @@
project(pol)
cmake_minimum_required(VERSION 3.0)
set(BUILD_LIB TRUE)
find_package(Boost REQUIRED)
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets OpenGL)
......@@ -17,9 +19,19 @@ set(CMAKE_AUTOMOC TRUE)
set(CMAKE_CXX_STANDARD 17)
add_definitions(-std=c++17 -fconcepts)
add_definitions(${Boost_CXX_FLAGS})
include_directories("${PROJECT_SOURCE_DIR}" "${Boost_INCLUDE_DIRS}/.." "../..")
add_executable(pol pol.cpp
../glplot/glplot.cpp ../glplot/glplot.h)
if(BUILD_LIB)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
add_definitions(-DBUILD_LIB)
add_library(pol SHARED
pol.cpp ../glplot/glplot.cpp ../glplot/glplot.h)
else()
add_executable(pol
pol.cpp ../glplot/glplot.cpp ../glplot/glplot.h)
endif()
target_link_libraries(pol ${Boost_LIBRARIES})
qt5_use_modules(pol Core Gui Widgets OpenGL)
......@@ -521,6 +521,9 @@ static inline void set_locales()
}
#ifndef BUILD_LIB // build application
int main(int argc, char** argv)
{
set_gl_format(1, _GL_MAJ_VER, _GL_MIN_VER, 8);
......@@ -532,4 +535,26 @@ int main(int argc, char** argv)
return app->exec();
}
#else // build library
#include <boost/dll/alias.hpp>
std::shared_ptr<QDialog>
//QDialog*
create(QWidget *pParent)
{
//std::cout << "In " << __FUNCTION__ << std::endl;
set_gl_format(1, _GL_MAJ_VER, _GL_MIN_VER, 8);
//return new PolDlg(pParent);
return std::make_shared<PolDlg>(pParent);
}
BOOST_DLL_ALIAS(create, create);
#endif
// ----------------------------------------------------------------------------
/**
* directly executes a plugin module
* @author Tobias Weber <tweber@ill.fr>
* @date Nov-2018
* @license GPLv3, see 'LICENSE' file
*
* g++-8 -std=c++17 -I/usr/local/include -L/usr/local/lib -o runplugin runplugin.cpp -F/usr/local/opt/qt5/lib -framework QtCore -framework QtWidgets -lboost_filesystem -lboost_system
*/
#include <QtWidgets/QApplication>
#include <QtWidgets/QDialog>
#include <iostream>
#include <memory>
#include <boost/dll/shared_library.hpp>
static inline void set_locales()
{
std::ios_base::sync_with_stdio(false);
::setlocale(LC_ALL, "C");
std::locale::global(std::locale("C"));
QLocale::setDefault(QLocale::C);
}
int main(int argc, char** argv)
{
set_locales();
if(argc <= 1)
{
std::cerr << "Specify a plugin library." << std::endl;
return -1;
}
const char *dllfile = argv[1];
auto dll = std::make_shared<boost::dll::shared_library>(dllfile);
if(!dll || !dll->is_loaded())
{
std::cerr << "Could not load plugin." << std::endl;
return -1;
}
std::cerr << "Plugin " << dll->location() << " loaded." << std::endl;
if(!dll->has("create"))
{
std::cerr << "Plugin does not have the \"create\" function." << std::endl;
return -1;
}
auto app = std::make_unique<QApplication>(argc, argv);
//auto createDlg = dll->get<QDialog*(*)(QWidget*)>("create");
auto createDlg = dll->get<std::shared_ptr<QDialog>(*)(QWidget*)>("create");
auto dlg = createDlg(nullptr);
if(dlg)
dlg->show();
return app->exec();
}
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