@@ -0,0 +1,34 | |||
|
1 | #ifndef SCIQLOP_PLUGINMANAGER_H | |
|
2 | #define SCIQLOP_PLUGINMANAGER_H | |
|
3 | ||
|
4 | #include <Common/spimpl.h> | |
|
5 | ||
|
6 | #include <QLoggingCategory> | |
|
7 | ||
|
8 | class QDir; | |
|
9 | ||
|
10 | Q_DECLARE_LOGGING_CATEGORY(LOG_PluginManager) | |
|
11 | ||
|
12 | /** | |
|
13 | * @brief The PluginManager class aims to handle the plugins loaded dynamically into SciQLop. | |
|
14 | */ | |
|
15 | class PluginManager { | |
|
16 | public: | |
|
17 | explicit PluginManager(); | |
|
18 | ||
|
19 | /** | |
|
20 | * Loads plugins into SciQlop. The loaded plugins are those located in the directory passed in | |
|
21 | * parameter | |
|
22 | * @param pluginDir the directory containing the plugins | |
|
23 | */ | |
|
24 | void loadPlugins(const QDir &pluginDir); | |
|
25 | ||
|
26 | /// @returns the number of plugins loaded | |
|
27 | int nbPluginsLoaded() const noexcept; | |
|
28 | ||
|
29 | private: | |
|
30 | class PluginManagerPrivate; | |
|
31 | spimpl::unique_impl_ptr<PluginManagerPrivate> impl; | |
|
32 | }; | |
|
33 | ||
|
34 | #endif // SCIQLOP_PLUGINMANAGER_H |
@@ -0,0 +1,118 | |||
|
1 | #include <Plugin/PluginManager.h> | |
|
2 | ||
|
3 | #include <Plugin/IPlugin.h> | |
|
4 | ||
|
5 | #include <QDir> | |
|
6 | #include <QLibrary> | |
|
7 | #include <QPluginLoader> | |
|
8 | ||
|
9 | Q_LOGGING_CATEGORY(LOG_PluginManager, "PluginManager") | |
|
10 | ||
|
11 | namespace { | |
|
12 | ||
|
13 | /// Key for retrieving metadata of the plugin | |
|
14 | const auto PLUGIN_METADATA_KEY = QStringLiteral("MetaData"); | |
|
15 | ||
|
16 | /// Key for retrieving the name of the plugin in its metadata | |
|
17 | const auto PLUGIN_NAME_KEY = QStringLiteral("name"); | |
|
18 | ||
|
19 | /// Helper to state the plugin loading operation | |
|
20 | struct LoadPluginState { | |
|
21 | explicit LoadPluginState(const QString &pluginPath) | |
|
22 | : m_PluginPath{pluginPath}, m_Valid{true}, m_ErrorMessage{} | |
|
23 | { | |
|
24 | } | |
|
25 | ||
|
26 | void log() const | |
|
27 | { | |
|
28 | if (m_Valid) { | |
|
29 | qCDebug(LOG_PluginManager()) | |
|
30 | << QObject::tr("File '%1' has been loaded as a plugin").arg(m_PluginPath); | |
|
31 | } | |
|
32 | else { | |
|
33 | qCWarning(LOG_PluginManager()) | |
|
34 | << QObject::tr("File '%1' can't be loaded as a plugin: %2") | |
|
35 | .arg(m_PluginPath) | |
|
36 | .arg(m_ErrorMessage); | |
|
37 | } | |
|
38 | } | |
|
39 | ||
|
40 | void setError(const QString &errorMessage) | |
|
41 | { | |
|
42 | m_Valid = false; | |
|
43 | m_ErrorMessage = errorMessage; | |
|
44 | } | |
|
45 | ||
|
46 | QString m_PluginPath; | |
|
47 | bool m_Valid; | |
|
48 | QString m_ErrorMessage; | |
|
49 | }; | |
|
50 | ||
|
51 | } // namespace | |
|
52 | ||
|
53 | struct PluginManager::PluginManagerPrivate { | |
|
54 | /** | |
|
55 | * Loads a single plugin into SciQlop. The method has no effect if the plugin is malformed (e.g. | |
|
56 | * wrong library type, missing metadata, etc.) | |
|
57 | * @param pluginPath the path to the plugin library. | |
|
58 | */ | |
|
59 | void loadPlugin(const QString &pluginPath) | |
|
60 | { | |
|
61 | qCDebug(LOG_PluginManager()) | |
|
62 | << QObject::tr("Attempting to load file '%1' as a plugin").arg(pluginPath); | |
|
63 | ||
|
64 | LoadPluginState loadState{pluginPath}; | |
|
65 | ||
|
66 | if (QLibrary::isLibrary(pluginPath)) { | |
|
67 | QPluginLoader pluginLoader{pluginPath}; | |
|
68 | ||
|
69 | // Retrieving the plugin name to check if it can be loaded (i.e. no plugin with the same | |
|
70 | // name has been registered yet) | |
|
71 | auto metadata = pluginLoader.metaData().value(PLUGIN_METADATA_KEY).toObject(); | |
|
72 | auto pluginName = metadata.value(PLUGIN_NAME_KEY).toString(); | |
|
73 | ||
|
74 | if (pluginName.isEmpty()) { | |
|
75 | loadState.setError(QObject::tr("empty file name")); | |
|
76 | } | |
|
77 | else if (m_RegisteredPlugins.contains(pluginName)) { | |
|
78 | loadState.setError(QObject::tr("name '%1' already registered").arg(pluginName)); | |
|
79 | } | |
|
80 | else { | |
|
81 | if (auto pluginInstance = qobject_cast<IPlugin *>(pluginLoader.instance())) { | |
|
82 | pluginInstance->initialize(); | |
|
83 | m_RegisteredPlugins.insert(pluginName, pluginPath); | |
|
84 | } | |
|
85 | else { | |
|
86 | loadState.setError(QObject::tr("the file is not a Sciqlop plugin")); | |
|
87 | } | |
|
88 | } | |
|
89 | } | |
|
90 | else { | |
|
91 | loadState.setError(QObject::tr("the file is not a library")); | |
|
92 | } | |
|
93 | ||
|
94 | // Log loading result | |
|
95 | loadState.log(); | |
|
96 | } | |
|
97 | ||
|
98 | /// Registered plugins (key: plugin name, value: plugin path) | |
|
99 | QHash<QString, QString> m_RegisteredPlugins; | |
|
100 | }; | |
|
101 | ||
|
102 | PluginManager::PluginManager() : impl{spimpl::make_unique_impl<PluginManagerPrivate>()} | |
|
103 | { | |
|
104 | } | |
|
105 | ||
|
106 | void PluginManager::loadPlugins(const QDir &pluginDir) | |
|
107 | { | |
|
108 | // Load plugins | |
|
109 | auto pluginInfoList = pluginDir.entryInfoList(QDir::Files, QDir::Name); | |
|
110 | for (auto pluginInfo : qAsConst(pluginInfoList)) { | |
|
111 | impl->loadPlugin(pluginInfo.absoluteFilePath()); | |
|
112 | } | |
|
113 | } | |
|
114 | ||
|
115 | int PluginManager::nbPluginsLoaded() const noexcept | |
|
116 | { | |
|
117 | return impl->m_RegisteredPlugins.size(); | |
|
118 | } |
|
1 | NO CONTENT: new file 100644, binary diff hidden |
|
1 | NO CONTENT: new file 100644, binary diff hidden |
|
1 | NO CONTENT: new file 100644 |
|
1 | NO CONTENT: new file 100644, binary diff hidden |
|
1 | NO CONTENT: new file 100644, binary diff hidden |
|
1 | NO CONTENT: new file 100644, binary diff hidden |
|
1 | NO CONTENT: new file 100644, binary diff hidden |
|
1 | NO CONTENT: new file 100644, binary diff hidden |
@@ -0,0 +1,81 | |||
|
1 | #include <Plugin/PluginManager.h> | |
|
2 | ||
|
3 | #include <QObject> | |
|
4 | #include <QtTest> | |
|
5 | ||
|
6 | #include <QtDebug> | |
|
7 | ||
|
8 | namespace { | |
|
9 | ||
|
10 | /// Path for the tests | |
|
11 | const auto TESTS_RESOURCES_PATH = QFileInfo{ | |
|
12 | QString{SCQCORE_TESTS_RESOURCES_PATH}, | |
|
13 | "Plugin/TestPluginManager"}.absoluteFilePath(); | |
|
14 | ||
|
15 | QString pluginDirPath(const QString &pluginDirName) | |
|
16 | { | |
|
17 | return QFileInfo{TESTS_RESOURCES_PATH, pluginDirName}.absoluteFilePath(); | |
|
18 | } | |
|
19 | ||
|
20 | } // namespace | |
|
21 | ||
|
22 | class TestPluginManager : public QObject { | |
|
23 | Q_OBJECT | |
|
24 | private slots: | |
|
25 | /// Defines data for plugin loading | |
|
26 | /// @sa testLoadPlugin() | |
|
27 | void testLoadPlugin_data(); | |
|
28 | ||
|
29 | /// Tests plugin loading | |
|
30 | void testLoadPlugin(); | |
|
31 | }; | |
|
32 | ||
|
33 | void TestPluginManager::testLoadPlugin_data() | |
|
34 | { | |
|
35 | // ////////////// // | |
|
36 | // Test structure // | |
|
37 | // ////////////// // | |
|
38 | ||
|
39 | // Name of directory containing the plugins | |
|
40 | QTest::addColumn<QString>("pluginDirName"); | |
|
41 | // Number of loaded plugins expected | |
|
42 | QTest::addColumn<int>("nbPluginsLoaded"); | |
|
43 | ||
|
44 | // ////////// // | |
|
45 | // Test cases // | |
|
46 | // ////////// // | |
|
47 | ||
|
48 | QTest::newRow("Valid plugin") << QStringLiteral("Test_ValidPlugin") << 1; | |
|
49 | ||
|
50 | // Two different plugins | |
|
51 | QTest::newRow("Valid plugins") << QStringLiteral("Test_ValidPlugins") << 2; | |
|
52 | ||
|
53 | // Two plugins with the same name: we expect that only one is loaded | |
|
54 | QTest::newRow("Duplicated plugins") << QStringLiteral("Test_DuplicatedPlugins") << 1; | |
|
55 | ||
|
56 | QTest::newRow("Invalid plugin (not a DLL)") << QStringLiteral("Test_InvalidFileType") << 0; | |
|
57 | QTest::newRow("Invalid plugin (not a SciQlop DLL)") | |
|
58 | << QStringLiteral("Test_NotSciqlopDll") << 0; | |
|
59 | QTest::newRow("Invalid plugin (missing metadata)") | |
|
60 | << QStringLiteral("Test_MissingPluginMetadata") << 0; | |
|
61 | } | |
|
62 | ||
|
63 | void TestPluginManager::testLoadPlugin() | |
|
64 | { | |
|
65 | QFETCH(QString, pluginDirName); | |
|
66 | QFETCH(int, nbPluginsLoaded); | |
|
67 | ||
|
68 | // Generates plugin dir | |
|
69 | auto pluginDir = QDir{pluginDirPath(pluginDirName)}; | |
|
70 | QVERIFY(pluginDir.exists()); | |
|
71 | ||
|
72 | // Load plugins | |
|
73 | PluginManager pluginManager{}; | |
|
74 | pluginManager.loadPlugins(pluginDir); | |
|
75 | ||
|
76 | // Check the number of plugins loaded | |
|
77 | QCOMPARE(pluginManager.nbPluginsLoaded(), nbPluginsLoaded); | |
|
78 | } | |
|
79 | ||
|
80 | QTEST_MAIN(TestPluginManager) | |
|
81 | #include "TestPluginManager.moc" |
@@ -0,0 +1,45 | |||
|
1 | ## plugin - CMakeLists.txt | |
|
2 | STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX) | |
|
3 | SET(SQPPLUGIN_LIBRARY_NAME "${LIBRARY_PREFFIX}_plugin${DEBUG_SUFFIX}") | |
|
4 | SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") | |
|
5 | ||
|
6 | # Include plugin directory | |
|
7 | INCLUDE_DIRECTORIES("${INCLUDES_DIR}") | |
|
8 | ||
|
9 | # | |
|
10 | # Find Qt modules | |
|
11 | # | |
|
12 | SCIQLOP_FIND_QT(Core) | |
|
13 | ||
|
14 | # | |
|
15 | # Compile the library | |
|
16 | # | |
|
17 | FILE (GLOB_RECURSE MODULE_SOURCES | |
|
18 | ${INCLUDES_DIR}/*.h) | |
|
19 | ||
|
20 | ADD_LIBRARY(${SQPPLUGIN_LIBRARY_NAME} ${MODULE_SOURCES}) | |
|
21 | ||
|
22 | # Add the files to the list of files to be analyzed | |
|
23 | LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES}) | |
|
24 | SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES) | |
|
25 | # Vera++ exclusion files | |
|
26 | #LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/path/to/exclusionFiles.tcl) | |
|
27 | SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES) | |
|
28 | ||
|
29 | # | |
|
30 | # Set the files that must be formatted by clang-format. | |
|
31 | # | |
|
32 | LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES}) | |
|
33 | SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES) | |
|
34 | ||
|
35 | # | |
|
36 | # Set the directories that doxygen must browse to generate the | |
|
37 | # documentation. | |
|
38 | # | |
|
39 | # Source directories: | |
|
40 | LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs") | |
|
41 | LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include") | |
|
42 | SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS) | |
|
43 | # Source directories to exclude from the documentation generation | |
|
44 | #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*") | |
|
45 | SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS) |
@@ -0,0 +1,12 | |||
|
1 | # - Try to find sciqlop-plugin | |
|
2 | # Once done this will define | |
|
3 | # SCIQLOP-PLUGIN_FOUND - System has sciqlop-plugin | |
|
4 | # SCIQLOP-PLUGIN_INCLUDE_DIR - The sciqlop-plugin include directories | |
|
5 | ||
|
6 | if(SCIQLOP-PLUGIN_FOUND) | |
|
7 | return() | |
|
8 | endif(SCIQLOP-PLUGIN_FOUND) | |
|
9 | ||
|
10 | set(SCIQLOP-PLUGIN_INCLUDE_DIR ${sciqlop-plugin_DIR}/../include) | |
|
11 | ||
|
12 | set(SCIQLOP-PLUGIN_FOUND TRUE) |
@@ -0,0 +1,20 | |||
|
1 | #ifndef SCIQLOP_IPLUGIN_H | |
|
2 | #define SCIQLOP_IPLUGIN_H | |
|
3 | ||
|
4 | #include <QString> | |
|
5 | #include <QtPlugin> | |
|
6 | ||
|
7 | /** | |
|
8 | * @brief Interface for a plugin | |
|
9 | */ | |
|
10 | class IPlugin { | |
|
11 | public: | |
|
12 | virtual ~IPlugin() = default; | |
|
13 | ||
|
14 | /// Initializes the plugin | |
|
15 | virtual void initialize() = 0; | |
|
16 | }; | |
|
17 | ||
|
18 | Q_DECLARE_INTERFACE(IPlugin, "sciqlop.plugin.IPlugin") | |
|
19 | ||
|
20 | #endif // SCIQLOP_IPLUGIN_H |
@@ -1,56 +1,60 | |||
|
1 | 1 | # |
|
2 | 2 | # Sciqlop_modules.cmake |
|
3 | 3 | # |
|
4 | 4 | # Set ouptut directories |
|
5 | 5 | # |
|
6 | 6 | SET (EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist) |
|
7 | 7 | SET (LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist) |
|
8 | 8 | IF (UNIX) |
|
9 | 9 | SET (CONFIG_OUTPUT_PATH $ENV{HOME}/.config/QtProject) |
|
10 | 10 | ELSEIF(WIN32) |
|
11 | 11 | SET (CONFIG_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist/app/QtProject) |
|
12 | 12 | ELSE() |
|
13 | 13 | SET (CONFIG_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist) |
|
14 | 14 | ENDIF() |
|
15 | 15 | |
|
16 | 16 | if(BUILD_TESTS) |
|
17 | 17 | INCLUDE ("cmake/sciqlop_code_coverage.cmake") |
|
18 | 18 | APPEND_COVERAGE_COMPILER_FLAGS() |
|
19 | 19 | endif(BUILD_TESTS) |
|
20 | 20 | |
|
21 | 21 | # |
|
22 | 22 | # Compile the diffents modules |
|
23 | 23 | # |
|
24 | set(sciqlop-plugin_DIR "${CMAKE_SOURCE_DIR}/plugin/cmake") | |
|
25 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-plugin_DIR}") | |
|
26 | ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/plugin") | |
|
27 | ||
|
24 | 28 | set(sciqlop-core_DIR "${CMAKE_SOURCE_DIR}/core/cmake") |
|
25 | 29 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-core_DIR}") |
|
26 | 30 | ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/core") |
|
27 | 31 | |
|
28 | 32 | set(sciqlop-gui_DIR "${CMAKE_SOURCE_DIR}/gui/cmake") |
|
29 | 33 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-gui_DIR}") |
|
30 | 34 | ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/gui") |
|
31 | 35 | |
|
32 | 36 | ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/app") |
|
33 | 37 | |
|
34 | 38 | # LOGGER |
|
35 | 39 | set(QTLOGGING_INI_FILE "${CMAKE_SOURCE_DIR}/config/QtProject/qtlogging.ini") |
|
36 | 40 | FILE(COPY ${QTLOGGING_INI_FILE} DESTINATION ${CONFIG_OUTPUT_PATH}) |
|
37 | 41 | |
|
38 | 42 | |
|
39 | 43 | # |
|
40 | 44 | # Code formatting |
|
41 | 45 | # |
|
42 | 46 | # Vera++ exclusion files |
|
43 | 47 | LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/formatting/vera-exclusions/exclusions.txt) |
|
44 | 48 | #SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES) |
|
45 | 49 | INCLUDE ("cmake/sciqlop_formatting.cmake") |
|
46 | 50 | |
|
47 | 51 | # |
|
48 | 52 | # Documentation generation |
|
49 | 53 | # |
|
50 | 54 | INCLUDE ("cmake/sciqlop_doxygen.cmake") |
|
51 | 55 | |
|
52 | 56 | # |
|
53 | 57 | # Source code analysis |
|
54 | 58 | # |
|
55 | 59 | INCLUDE ("cmake/sciqlop_code_analysis.cmake") |
|
56 | 60 | INCLUDE ("cmake/sciqlop_code_cppcheck.cmake") |
@@ -1,141 +1,149 | |||
|
1 | 1 | |
|
2 | 2 | ## core - CMakeLists.txt |
|
3 | 3 | STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX) |
|
4 | 4 | SET(SQPCORE_LIBRARY_NAME "${LIBRARY_PREFFIX}_core${DEBUG_SUFFIX}") |
|
5 | 5 | SET(SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/") |
|
6 | 6 | SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/") |
|
7 | 7 | |
|
8 | 8 | # Include core directory |
|
9 | 9 | include_directories("${INCLUDES_DIR}") |
|
10 | 10 | |
|
11 | 11 | # Set a variable to display a warning in the version files. |
|
12 | 12 | SET(SCIQLOP_CMAKE_GENERATION_WARNING "DON'T CHANGE THIS FILE. AUTOGENERATED BY CMAKE.") |
|
13 | 13 | # Generate the version file from the cmake version variables. The version |
|
14 | 14 | # variables are defined in the cmake/sciqlop_version.cmake file. |
|
15 | 15 | CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/resources/Version.h.in" |
|
16 | 16 | "${INCLUDES_DIR}/Version.h") |
|
17 | 17 | CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/resources/Version.cpp.in" |
|
18 | 18 | "${SOURCES_DIR}/Version.cpp") |
|
19 | ||
|
19 | ||
|
20 | # Find dependent modules | |
|
21 | find_package(sciqlop-plugin) | |
|
22 | INCLUDE_DIRECTORIES(${SCIQLOP-PLUGIN_INCLUDE_DIR}) | |
|
23 | ||
|
20 | 24 | # |
|
21 | 25 | # Find Qt modules |
|
22 | 26 | # |
|
23 | 27 | SCIQLOP_FIND_QT(Core) |
|
24 | 28 | |
|
25 | 29 | # |
|
26 | 30 | # Compile the library library |
|
27 | 31 | # |
|
28 | 32 | FILE (GLOB_RECURSE MODULE_SOURCES |
|
29 | 33 | ${INCLUDES_DIR}/*.h |
|
30 | 34 | ${SOURCES_DIR}/*.c |
|
31 | 35 | ${SOURCES_DIR}/*.cpp |
|
32 | 36 | ${SOURCES_DIR}/*.h) |
|
33 | 37 | |
|
34 | 38 | ADD_LIBRARY(${SQPCORE_LIBRARY_NAME} ${MODULE_SOURCES}) |
|
35 | 39 | set_property(TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY CXX_STANDARD 14) |
|
36 | 40 | set_property(TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) |
|
37 | 41 | TARGET_LINK_LIBRARIES(${SQPCORE_LIBRARY_NAME}) |
|
38 | 42 | qt5_use_modules(${SQPCORE_LIBRARY_NAME} Core) |
|
39 | 43 | |
|
40 | 44 | # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html |
|
41 | 45 | # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order. |
|
42 | 46 | # The DEFINE_SYMBOL target property is also added as a compile definition as a special convenience case for SHARED and MODULE library targets |
|
43 | 47 | IF(BUILD_SHARED_LIBS) |
|
44 | 48 | SET_TARGET_PROPERTIES(${SQPCORE_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT") |
|
45 | 49 | ELSE() |
|
46 | 50 | TARGET_COMPILE_DEFINITIONS(${SQPCORE_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES") |
|
47 | 51 | ENDIF() |
|
48 | 52 | |
|
49 | 53 | # Set the variable to parent scope so that the other projects can copy the |
|
50 | 54 | # dependent shared libraries |
|
51 | 55 | SCIQLOP_SET_TO_PARENT_SCOPE(SQPCORE_LIBRARY_NAME) |
|
52 | 56 | |
|
53 | 57 | # Copy extern shared libraries to the lib folder |
|
54 | 58 | SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPCORE_LIBRARY_NAME} ${EXTERN_SHARED_LIBRARIES}) |
|
55 | 59 | |
|
56 | 60 | # Add the files to the list of files to be analyzed |
|
57 | 61 | LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES}) |
|
58 | 62 | SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES) |
|
59 | 63 | # Vera++ exclusion files |
|
60 | 64 | LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt) |
|
61 | 65 | SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES) |
|
62 | 66 | |
|
63 | 67 | # |
|
64 | 68 | # Compile the tests |
|
65 | 69 | # |
|
66 | 70 | IF(BUILD_TESTS) |
|
67 | 71 | INCLUDE_DIRECTORIES(${SOURCES_DIR}) |
|
68 | 72 | FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp) |
|
69 | 73 | FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h) |
|
70 | 74 | SET( TEST_LIBRARIES ${SQPCORE_LIBRARY_NAME}) |
|
71 | 75 | |
|
76 | # Set tests resources path | |
|
77 | SET(RESOURCES_PATH ${CMAKE_CURRENT_SOURCE_DIR}/tests-resources/) | |
|
78 | add_definitions(-DSCQCORE_TESTS_RESOURCES_PATH="${RESOURCES_PATH}") | |
|
79 | ||
|
72 | 80 | SET(TARGETS_COV) |
|
73 | 81 | FOREACH( testFile ${TESTS_SOURCES} ) |
|
74 | 82 | GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY ) |
|
75 | 83 | GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE ) |
|
76 | 84 | |
|
77 | 85 | # Add to the list of sources files all the sources in the same |
|
78 | 86 | # directory that aren't another test |
|
79 | 87 | FILE (GLOB currentTestSources |
|
80 | 88 | ${testDirectory}/*.c |
|
81 | 89 | ${testDirectory}/*.cpp |
|
82 | 90 | ${testDirectory}/*.h) |
|
83 | 91 | LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES}) |
|
84 | 92 | # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS}) |
|
85 | 93 | |
|
86 | 94 | ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources}) |
|
87 | 95 | set_property(TARGET ${testName} PROPERTY CXX_STANDARD 14) |
|
88 | 96 | set_property(TARGET ${testName} PROPERTY CXX_STANDARD_REQUIRED ON) |
|
89 | 97 | TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} ) |
|
90 | 98 | qt5_use_modules(${testName} Test) |
|
91 | 99 | |
|
92 | 100 | ADD_TEST( NAME ${testName} COMMAND ${testName} ) |
|
93 | 101 | |
|
94 | 102 | SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES}) |
|
95 | 103 | set(Coverage_NAME ${testName}) |
|
96 | 104 | SETUP_TARGET_FOR_COVERAGE(TARGET ${testName}_coverage OUTPUT ${testFile}-path NAME ${testFile} EXECUTABLE ${testName}) |
|
97 | 105 | LIST( APPEND TARGETS_COV ${testName}_coverage) |
|
98 | 106 | |
|
99 | 107 | ENDFOREACH( testFile ) |
|
100 | 108 | |
|
101 | 109 | add_custom_target(coverage) |
|
102 | 110 | |
|
103 | 111 | FOREACH( target_cov ${TARGETS_COV} ) |
|
104 | 112 | add_custom_command(TARGET coverage PRE_BUILD COMMAND make ${target_cov}) |
|
105 | 113 | ENDFOREACH( target_cov ) |
|
106 | 114 | |
|
107 | 115 | LIST(APPEND testFilesToFormat ${TESTS_SOURCES}) |
|
108 | 116 | LIST(APPEND testFilesToFormat ${TESTS_HEADERS}) |
|
109 | 117 | LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat}) |
|
110 | 118 | SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES) |
|
111 | 119 | ENDIF(BUILD_TESTS) |
|
112 | 120 | |
|
113 | 121 | # |
|
114 | 122 | # Set the files that must be formatted by clang-format. |
|
115 | 123 | # |
|
116 | 124 | LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES}) |
|
117 | 125 | SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES) |
|
118 | 126 | |
|
119 | 127 | # |
|
120 | 128 | # Set the directories that doxygen must browse to generate the |
|
121 | 129 | # documentation. |
|
122 | 130 | # |
|
123 | 131 | # Source directories: |
|
124 | 132 | LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs") |
|
125 | 133 | LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src") |
|
126 | 134 | SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS) |
|
127 | 135 | # Source directories to exclude from the documentation generation |
|
128 | 136 | #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*") |
|
129 | 137 | SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS) |
|
130 | 138 | |
|
131 | 139 | # |
|
132 | 140 | # Set the directories with the sources to analyze and propagate the |
|
133 | 141 | # modification to the parent scope |
|
134 | 142 | # |
|
135 | 143 | # Source directories to analyze: |
|
136 | 144 | LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src") |
|
137 | 145 | LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests") |
|
138 | 146 | SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS) |
|
139 | 147 | # Source directories to exclude from the analysis |
|
140 | 148 | #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir") |
|
141 | 149 | SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS) |
General Comments 0
You need to be logged in to leave comments.
Login now