@@ -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 |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
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 | # Sciqlop_modules.cmake |
|
2 | # Sciqlop_modules.cmake | |
3 | # |
|
3 | # | |
4 | # Set ouptut directories |
|
4 | # Set ouptut directories | |
5 | # |
|
5 | # | |
6 | SET (EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist) |
|
6 | SET (EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist) | |
7 | SET (LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist) |
|
7 | SET (LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist) | |
8 | IF (UNIX) |
|
8 | IF (UNIX) | |
9 | SET (CONFIG_OUTPUT_PATH $ENV{HOME}/.config/QtProject) |
|
9 | SET (CONFIG_OUTPUT_PATH $ENV{HOME}/.config/QtProject) | |
10 | ELSEIF(WIN32) |
|
10 | ELSEIF(WIN32) | |
11 | SET (CONFIG_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist/app/QtProject) |
|
11 | SET (CONFIG_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist/app/QtProject) | |
12 | ELSE() |
|
12 | ELSE() | |
13 | SET (CONFIG_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist) |
|
13 | SET (CONFIG_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist) | |
14 | ENDIF() |
|
14 | ENDIF() | |
15 |
|
15 | |||
16 | if(BUILD_TESTS) |
|
16 | if(BUILD_TESTS) | |
17 | INCLUDE ("cmake/sciqlop_code_coverage.cmake") |
|
17 | INCLUDE ("cmake/sciqlop_code_coverage.cmake") | |
18 | APPEND_COVERAGE_COMPILER_FLAGS() |
|
18 | APPEND_COVERAGE_COMPILER_FLAGS() | |
19 | endif(BUILD_TESTS) |
|
19 | endif(BUILD_TESTS) | |
20 |
|
20 | |||
21 | # |
|
21 | # | |
22 | # Compile the diffents modules |
|
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 | set(sciqlop-core_DIR "${CMAKE_SOURCE_DIR}/core/cmake") |
|
28 | set(sciqlop-core_DIR "${CMAKE_SOURCE_DIR}/core/cmake") | |
25 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-core_DIR}") |
|
29 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-core_DIR}") | |
26 | ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/core") |
|
30 | ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/core") | |
27 |
|
31 | |||
28 | set(sciqlop-gui_DIR "${CMAKE_SOURCE_DIR}/gui/cmake") |
|
32 | set(sciqlop-gui_DIR "${CMAKE_SOURCE_DIR}/gui/cmake") | |
29 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-gui_DIR}") |
|
33 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-gui_DIR}") | |
30 | ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/gui") |
|
34 | ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/gui") | |
31 |
|
35 | |||
32 | ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/app") |
|
36 | ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/app") | |
33 |
|
37 | |||
34 | # LOGGER |
|
38 | # LOGGER | |
35 | set(QTLOGGING_INI_FILE "${CMAKE_SOURCE_DIR}/config/QtProject/qtlogging.ini") |
|
39 | set(QTLOGGING_INI_FILE "${CMAKE_SOURCE_DIR}/config/QtProject/qtlogging.ini") | |
36 | FILE(COPY ${QTLOGGING_INI_FILE} DESTINATION ${CONFIG_OUTPUT_PATH}) |
|
40 | FILE(COPY ${QTLOGGING_INI_FILE} DESTINATION ${CONFIG_OUTPUT_PATH}) | |
37 |
|
41 | |||
38 |
|
42 | |||
39 | # |
|
43 | # | |
40 | # Code formatting |
|
44 | # Code formatting | |
41 | # |
|
45 | # | |
42 | # Vera++ exclusion files |
|
46 | # Vera++ exclusion files | |
43 | LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/formatting/vera-exclusions/exclusions.txt) |
|
47 | LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/formatting/vera-exclusions/exclusions.txt) | |
44 | #SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES) |
|
48 | #SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES) | |
45 | INCLUDE ("cmake/sciqlop_formatting.cmake") |
|
49 | INCLUDE ("cmake/sciqlop_formatting.cmake") | |
46 |
|
50 | |||
47 | # |
|
51 | # | |
48 | # Documentation generation |
|
52 | # Documentation generation | |
49 | # |
|
53 | # | |
50 | INCLUDE ("cmake/sciqlop_doxygen.cmake") |
|
54 | INCLUDE ("cmake/sciqlop_doxygen.cmake") | |
51 |
|
55 | |||
52 | # |
|
56 | # | |
53 | # Source code analysis |
|
57 | # Source code analysis | |
54 | # |
|
58 | # | |
55 | INCLUDE ("cmake/sciqlop_code_analysis.cmake") |
|
59 | INCLUDE ("cmake/sciqlop_code_analysis.cmake") | |
56 | INCLUDE ("cmake/sciqlop_code_cppcheck.cmake") |
|
60 | INCLUDE ("cmake/sciqlop_code_cppcheck.cmake") |
@@ -1,141 +1,149 | |||||
1 |
|
1 | |||
2 | ## core - CMakeLists.txt |
|
2 | ## core - CMakeLists.txt | |
3 | STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX) |
|
3 | STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX) | |
4 | SET(SQPCORE_LIBRARY_NAME "${LIBRARY_PREFFIX}_core${DEBUG_SUFFIX}") |
|
4 | SET(SQPCORE_LIBRARY_NAME "${LIBRARY_PREFFIX}_core${DEBUG_SUFFIX}") | |
5 | SET(SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/") |
|
5 | SET(SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/") | |
6 | SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/") |
|
6 | SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/") | |
7 |
|
7 | |||
8 | # Include core directory |
|
8 | # Include core directory | |
9 | include_directories("${INCLUDES_DIR}") |
|
9 | include_directories("${INCLUDES_DIR}") | |
10 |
|
10 | |||
11 | # Set a variable to display a warning in the version files. |
|
11 | # Set a variable to display a warning in the version files. | |
12 | SET(SCIQLOP_CMAKE_GENERATION_WARNING "DON'T CHANGE THIS FILE. AUTOGENERATED BY CMAKE.") |
|
12 | SET(SCIQLOP_CMAKE_GENERATION_WARNING "DON'T CHANGE THIS FILE. AUTOGENERATED BY CMAKE.") | |
13 | # Generate the version file from the cmake version variables. The version |
|
13 | # Generate the version file from the cmake version variables. The version | |
14 | # variables are defined in the cmake/sciqlop_version.cmake file. |
|
14 | # variables are defined in the cmake/sciqlop_version.cmake file. | |
15 | CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/resources/Version.h.in" |
|
15 | CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/resources/Version.h.in" | |
16 | "${INCLUDES_DIR}/Version.h") |
|
16 | "${INCLUDES_DIR}/Version.h") | |
17 | CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/resources/Version.cpp.in" |
|
17 | CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/resources/Version.cpp.in" | |
18 | "${SOURCES_DIR}/Version.cpp") |
|
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 | # Find Qt modules |
|
25 | # Find Qt modules | |
22 | # |
|
26 | # | |
23 | SCIQLOP_FIND_QT(Core) |
|
27 | SCIQLOP_FIND_QT(Core) | |
24 |
|
28 | |||
25 | # |
|
29 | # | |
26 | # Compile the library library |
|
30 | # Compile the library library | |
27 | # |
|
31 | # | |
28 | FILE (GLOB_RECURSE MODULE_SOURCES |
|
32 | FILE (GLOB_RECURSE MODULE_SOURCES | |
29 | ${INCLUDES_DIR}/*.h |
|
33 | ${INCLUDES_DIR}/*.h | |
30 | ${SOURCES_DIR}/*.c |
|
34 | ${SOURCES_DIR}/*.c | |
31 | ${SOURCES_DIR}/*.cpp |
|
35 | ${SOURCES_DIR}/*.cpp | |
32 | ${SOURCES_DIR}/*.h) |
|
36 | ${SOURCES_DIR}/*.h) | |
33 |
|
37 | |||
34 | ADD_LIBRARY(${SQPCORE_LIBRARY_NAME} ${MODULE_SOURCES}) |
|
38 | ADD_LIBRARY(${SQPCORE_LIBRARY_NAME} ${MODULE_SOURCES}) | |
35 | set_property(TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY CXX_STANDARD 14) |
|
39 | set_property(TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY CXX_STANDARD 14) | |
36 | set_property(TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) |
|
40 | set_property(TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) | |
37 | TARGET_LINK_LIBRARIES(${SQPCORE_LIBRARY_NAME}) |
|
41 | TARGET_LINK_LIBRARIES(${SQPCORE_LIBRARY_NAME}) | |
38 | qt5_use_modules(${SQPCORE_LIBRARY_NAME} Core) |
|
42 | qt5_use_modules(${SQPCORE_LIBRARY_NAME} Core) | |
39 |
|
43 | |||
40 | # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html |
|
44 | # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html | |
41 | # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order. |
|
45 | # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order. | |
42 | # The DEFINE_SYMBOL target property is also added as a compile definition as a special convenience case for SHARED and MODULE library targets |
|
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 | IF(BUILD_SHARED_LIBS) |
|
47 | IF(BUILD_SHARED_LIBS) | |
44 | SET_TARGET_PROPERTIES(${SQPCORE_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT") |
|
48 | SET_TARGET_PROPERTIES(${SQPCORE_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT") | |
45 | ELSE() |
|
49 | ELSE() | |
46 | TARGET_COMPILE_DEFINITIONS(${SQPCORE_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES") |
|
50 | TARGET_COMPILE_DEFINITIONS(${SQPCORE_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES") | |
47 | ENDIF() |
|
51 | ENDIF() | |
48 |
|
52 | |||
49 | # Set the variable to parent scope so that the other projects can copy the |
|
53 | # Set the variable to parent scope so that the other projects can copy the | |
50 | # dependent shared libraries |
|
54 | # dependent shared libraries | |
51 | SCIQLOP_SET_TO_PARENT_SCOPE(SQPCORE_LIBRARY_NAME) |
|
55 | SCIQLOP_SET_TO_PARENT_SCOPE(SQPCORE_LIBRARY_NAME) | |
52 |
|
56 | |||
53 | # Copy extern shared libraries to the lib folder |
|
57 | # Copy extern shared libraries to the lib folder | |
54 | SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPCORE_LIBRARY_NAME} ${EXTERN_SHARED_LIBRARIES}) |
|
58 | SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPCORE_LIBRARY_NAME} ${EXTERN_SHARED_LIBRARIES}) | |
55 |
|
59 | |||
56 | # Add the files to the list of files to be analyzed |
|
60 | # Add the files to the list of files to be analyzed | |
57 | LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES}) |
|
61 | LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES}) | |
58 | SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES) |
|
62 | SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES) | |
59 | # Vera++ exclusion files |
|
63 | # Vera++ exclusion files | |
60 | LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt) |
|
64 | LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt) | |
61 | SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES) |
|
65 | SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES) | |
62 |
|
66 | |||
63 | # |
|
67 | # | |
64 | # Compile the tests |
|
68 | # Compile the tests | |
65 | # |
|
69 | # | |
66 | IF(BUILD_TESTS) |
|
70 | IF(BUILD_TESTS) | |
67 | INCLUDE_DIRECTORIES(${SOURCES_DIR}) |
|
71 | INCLUDE_DIRECTORIES(${SOURCES_DIR}) | |
68 | FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp) |
|
72 | FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp) | |
69 | FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h) |
|
73 | FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h) | |
70 | SET( TEST_LIBRARIES ${SQPCORE_LIBRARY_NAME}) |
|
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 | SET(TARGETS_COV) |
|
80 | SET(TARGETS_COV) | |
73 | FOREACH( testFile ${TESTS_SOURCES} ) |
|
81 | FOREACH( testFile ${TESTS_SOURCES} ) | |
74 | GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY ) |
|
82 | GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY ) | |
75 | GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE ) |
|
83 | GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE ) | |
76 |
|
84 | |||
77 | # Add to the list of sources files all the sources in the same |
|
85 | # Add to the list of sources files all the sources in the same | |
78 | # directory that aren't another test |
|
86 | # directory that aren't another test | |
79 | FILE (GLOB currentTestSources |
|
87 | FILE (GLOB currentTestSources | |
80 | ${testDirectory}/*.c |
|
88 | ${testDirectory}/*.c | |
81 | ${testDirectory}/*.cpp |
|
89 | ${testDirectory}/*.cpp | |
82 | ${testDirectory}/*.h) |
|
90 | ${testDirectory}/*.h) | |
83 | LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES}) |
|
91 | LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES}) | |
84 | # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS}) |
|
92 | # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS}) | |
85 |
|
93 | |||
86 | ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources}) |
|
94 | ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources}) | |
87 | set_property(TARGET ${testName} PROPERTY CXX_STANDARD 14) |
|
95 | set_property(TARGET ${testName} PROPERTY CXX_STANDARD 14) | |
88 | set_property(TARGET ${testName} PROPERTY CXX_STANDARD_REQUIRED ON) |
|
96 | set_property(TARGET ${testName} PROPERTY CXX_STANDARD_REQUIRED ON) | |
89 | TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} ) |
|
97 | TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} ) | |
90 | qt5_use_modules(${testName} Test) |
|
98 | qt5_use_modules(${testName} Test) | |
91 |
|
99 | |||
92 | ADD_TEST( NAME ${testName} COMMAND ${testName} ) |
|
100 | ADD_TEST( NAME ${testName} COMMAND ${testName} ) | |
93 |
|
101 | |||
94 | SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES}) |
|
102 | SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES}) | |
95 | set(Coverage_NAME ${testName}) |
|
103 | set(Coverage_NAME ${testName}) | |
96 | SETUP_TARGET_FOR_COVERAGE(TARGET ${testName}_coverage OUTPUT ${testFile}-path NAME ${testFile} EXECUTABLE ${testName}) |
|
104 | SETUP_TARGET_FOR_COVERAGE(TARGET ${testName}_coverage OUTPUT ${testFile}-path NAME ${testFile} EXECUTABLE ${testName}) | |
97 | LIST( APPEND TARGETS_COV ${testName}_coverage) |
|
105 | LIST( APPEND TARGETS_COV ${testName}_coverage) | |
98 |
|
106 | |||
99 | ENDFOREACH( testFile ) |
|
107 | ENDFOREACH( testFile ) | |
100 |
|
108 | |||
101 | add_custom_target(coverage) |
|
109 | add_custom_target(coverage) | |
102 |
|
110 | |||
103 | FOREACH( target_cov ${TARGETS_COV} ) |
|
111 | FOREACH( target_cov ${TARGETS_COV} ) | |
104 | add_custom_command(TARGET coverage PRE_BUILD COMMAND make ${target_cov}) |
|
112 | add_custom_command(TARGET coverage PRE_BUILD COMMAND make ${target_cov}) | |
105 | ENDFOREACH( target_cov ) |
|
113 | ENDFOREACH( target_cov ) | |
106 |
|
114 | |||
107 | LIST(APPEND testFilesToFormat ${TESTS_SOURCES}) |
|
115 | LIST(APPEND testFilesToFormat ${TESTS_SOURCES}) | |
108 | LIST(APPEND testFilesToFormat ${TESTS_HEADERS}) |
|
116 | LIST(APPEND testFilesToFormat ${TESTS_HEADERS}) | |
109 | LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat}) |
|
117 | LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat}) | |
110 | SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES) |
|
118 | SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES) | |
111 | ENDIF(BUILD_TESTS) |
|
119 | ENDIF(BUILD_TESTS) | |
112 |
|
120 | |||
113 | # |
|
121 | # | |
114 | # Set the files that must be formatted by clang-format. |
|
122 | # Set the files that must be formatted by clang-format. | |
115 | # |
|
123 | # | |
116 | LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES}) |
|
124 | LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES}) | |
117 | SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES) |
|
125 | SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES) | |
118 |
|
126 | |||
119 | # |
|
127 | # | |
120 | # Set the directories that doxygen must browse to generate the |
|
128 | # Set the directories that doxygen must browse to generate the | |
121 | # documentation. |
|
129 | # documentation. | |
122 | # |
|
130 | # | |
123 | # Source directories: |
|
131 | # Source directories: | |
124 | LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs") |
|
132 | LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs") | |
125 | LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src") |
|
133 | LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src") | |
126 | SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS) |
|
134 | SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS) | |
127 | # Source directories to exclude from the documentation generation |
|
135 | # Source directories to exclude from the documentation generation | |
128 | #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*") |
|
136 | #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*") | |
129 | SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS) |
|
137 | SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS) | |
130 |
|
138 | |||
131 | # |
|
139 | # | |
132 | # Set the directories with the sources to analyze and propagate the |
|
140 | # Set the directories with the sources to analyze and propagate the | |
133 | # modification to the parent scope |
|
141 | # modification to the parent scope | |
134 | # |
|
142 | # | |
135 | # Source directories to analyze: |
|
143 | # Source directories to analyze: | |
136 | LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src") |
|
144 | LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src") | |
137 | LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests") |
|
145 | LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests") | |
138 | SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS) |
|
146 | SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS) | |
139 | # Source directories to exclude from the analysis |
|
147 | # Source directories to exclude from the analysis | |
140 | #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir") |
|
148 | #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir") | |
141 | SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS) |
|
149 | SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS) |
General Comments 0
You need to be logged in to leave comments.
Login now