diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 48428d4ac..a48272a85 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,14 +52,6 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) set_property(GLOBAL PROPERTY USE_FOLDERS ON) ### Build Settings -if (BUILD_WITH_DOUBLE_SCALAR) - message(STATUS "Building with double precision") - add_definitions(-DMESHLAB_SCALAR=double) -else() - message(STATUS "Building with single precision") - add_definitions(-DMESHLAB_SCALAR=float) -endif() - if(WIN32) add_definitions(-DNOMINMAX) if(MSVC) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index e2dacb7e9..7ace25c0b 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -3,10 +3,20 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../../ML_VERSION") if (BUILD_WITH_DOUBLE_SCALAR) set(MESHLAB_VERSION "${MESHLAB_VERSION}d") endif() - add_definitions(-DMESHLAB_VERSION=${MESHLAB_VERSION}) + #add_definitions(-DMESHLAB_VERSION=${MESHLAB_VERSION}) message(STATUS "MeshLab version: ${MESHLAB_VERSION}") endif() +if (BUILD_WITH_DOUBLE_SCALAR) + message(STATUS "Building with double precision") + set(MESHLAB_SCALAR "double") + #add_definitions(-DMESHLAB_SCALAR=double) +else() + message(STATUS "Building with single precision") + set(MESHLAB_SCALAR "float") + #add_definitions(-DMESHLAB_SCALAR=float) +endif() + set(HEADERS globals.h plugins/interfaces/plugin_file_interface.h @@ -81,6 +91,11 @@ if(WIN32) endif() add_library(meshlab-common ${TARGET_TYPE} ${SOURCES} ${HEADERS} ${RESOURCES}) +target_compile_definitions(meshlab-common + PUBLIC + MESHLAB_VERSION=${MESHLAB_VERSION} + MESHLAB_SCALAR=${MESHLAB_SCALAR}) + target_include_directories(meshlab-common PRIVATE ${EXTERNAL_DIR}/easyexif/ diff --git a/src/common/globals.h b/src/common/globals.h index 2e1dd37b6..cd6010079 100644 --- a/src/common/globals.h +++ b/src/common/globals.h @@ -29,6 +29,13 @@ #include +#ifndef MESHLAB_VERSION +#error "MESHLAB_VERSION needs to be defined!" +#endif +#ifndef MESHLAB_SCALAR +#error "MESHLAB_SCALAR needs to be defined!" +#endif + class RichParameterList; class PluginManager; diff --git a/src/common/plugins/plugin_manager.cpp b/src/common/plugins/plugin_manager.cpp index e451f7ceb..3da550e4d 100644 --- a/src/common/plugins/plugin_manager.cpp +++ b/src/common/plugins/plugin_manager.cpp @@ -130,9 +130,20 @@ void PluginManager::loadPlugin(const QString& fileName) if (!ifp){ throw MLException(fin.fileName() + " is not a MeshLab plugin."); } - if (ifp && ifp->getMLVersion().second != MeshLabScalarTest::doublePrecision()) { + if (ifp->getMLVersion().second != MeshLabScalarTest::doublePrecision()) { throw MLException(fin.fileName() + " has different floating point precision from the running MeshLab version."); } + std::string mlVersionPlug = ifp->getMLVersion().first; + std::string majorVersionPlug = mlVersionPlug.substr(0, 4); //4 is the position of '.' in meshlab version + std::string majorVersionML = meshlab::meshlabVersion().substr(0, 4); + if (majorVersionML != majorVersionPlug){ + throw MLException(fin.fileName() + " has different major version from the running MeshLab version."); + } + std::string minorVersionPlug = mlVersionPlug.substr(5, mlVersionPlug.size()); + std::string minorVersionML = meshlab::meshlabVersion().substr(5, meshlab::meshlabVersion().size()); + if (std::stoi(minorVersionPlug) > std::stoi(minorVersionML)){ + throw MLException(fin.fileName() + " has greater version from the running MeshLab version. Please update MeshLab to use it."); + } //TODO: check in some way also the meshlab version of the plugin