[3] | 1 | #################################################
|
---|
| 2 | # ___________ ____ ______ __ __ _____ #
|
---|
| 3 | # \____ \__ \ _/ ___\\____ \| | \/ ___/ #
|
---|
| 4 | # | |_> > __ \\ \___| |_> > | /\___ \ #
|
---|
| 5 | # | __(____ /\___ > __/|____//____ > #
|
---|
| 6 | # |__| \/ \/|__| \/ #
|
---|
| 7 | # #
|
---|
| 8 | #################################################
|
---|
| 9 |
|
---|
| 10 | # ========================================
|
---|
| 11 | # Create a Pacpus plugin
|
---|
| 12 | # ========================================
|
---|
| 13 | function(PACPUS_PLUGIN OUT_CPP OUT_H PLUGIN_NAME)
|
---|
| 14 |
|
---|
| 15 | set(PLUGIN_NAME ${PLUGIN_NAME}Plugin)
|
---|
| 16 | set(${OUT_CPP} ${PLUGIN_NAME}.cpp PARENT_SCOPE)
|
---|
| 17 | set(${OUT_H} ${PLUGIN_NAME}.h PARENT_SCOPE)
|
---|
| 18 |
|
---|
| 19 | string(TOUPPER ${PLUGIN_NAME} PLUGIN_NAME_UPPER)
|
---|
| 20 |
|
---|
| 21 | # create the header file
|
---|
| 22 | file(WRITE ${PLUGIN_NAME}.h
|
---|
| 23 | "// Autogenerated file by PacpusPlugin.cmake\n"
|
---|
| 24 | "// DO NOT EDIT!!! ALL CHANGES WOULD BE REMOVED BY THE NEXT CALL OF CMAKE\n"
|
---|
| 25 | "\n"
|
---|
| 26 | "#ifndef __${PLUGIN_NAME_UPPER}_H__\n"
|
---|
| 27 | "#define __${PLUGIN_NAME_UPPER}_H__\n"
|
---|
| 28 | "\n"
|
---|
| 29 | "#include <qobject.h>\n"
|
---|
| 30 | "#include <qplugin.h>\n"
|
---|
| 31 | "\n"
|
---|
| 32 | "#include \"kernel/PacpusPluginInterface.h\"\n"
|
---|
| 33 | "\n"
|
---|
| 34 | "/// Auto-generated plugin class\n"
|
---|
| 35 | "class ${PLUGIN_NAME}\n"
|
---|
| 36 | " : public QObject\n"
|
---|
| 37 | " , public PacpusPluginInterface\n"
|
---|
| 38 | "{\n"
|
---|
| 39 | " Q_OBJECT\n"
|
---|
| 40 | " Q_INTERFACES(PacpusPluginInterface)\n"
|
---|
| 41 | "\n"
|
---|
| 42 | "public:\n"
|
---|
| 43 | " ${PLUGIN_NAME}();\n"
|
---|
| 44 | " ~${PLUGIN_NAME}();\n"
|
---|
| 45 | "\n"
|
---|
| 46 | "protected:\n"
|
---|
| 47 | " QString name();\n"
|
---|
| 48 | "};\n"
|
---|
| 49 | "\n"
|
---|
| 50 | "#endif // __${PLUGIN_NAME_UPPER}_H__\n"
|
---|
| 51 | )
|
---|
| 52 |
|
---|
| 53 | # create the cpp file
|
---|
| 54 | file(WRITE ${PLUGIN_NAME}.cpp
|
---|
| 55 | "// Autogenerated file by PacpusPlugin.cmake\n"
|
---|
| 56 | "// DO NOT EDIT!!! ALL CHANGES WOULD BE REMOVED BY THE NEXT CALL OF CMAKE\n"
|
---|
| 57 | "\n"
|
---|
| 58 | "#include \"${PLUGIN_NAME}.h\"\n"
|
---|
| 59 | "\n"
|
---|
| 60 | "${PLUGIN_NAME}::${PLUGIN_NAME}()\n"
|
---|
| 61 | "{\n"
|
---|
| 62 | "}\n"
|
---|
| 63 | "\n"
|
---|
| 64 | "${PLUGIN_NAME}::~${PLUGIN_NAME}()\n"
|
---|
| 65 | "{\n"
|
---|
| 66 | "}\n"
|
---|
| 67 | "\n"
|
---|
| 68 | "QString ${PLUGIN_NAME}::name()\n"
|
---|
| 69 | "{\n"
|
---|
| 70 | " return \"${PLUGIN_NAME}\";\n"
|
---|
| 71 | "}\n"
|
---|
| 72 | "\n"
|
---|
| 73 | "Q_EXPORT_PLUGIN2(${PLUGIN_NAME}, ${PLUGIN_NAME})\n"
|
---|
| 74 | )
|
---|
| 75 | endfunction(PACPUS_PLUGIN)
|
---|
| 76 |
|
---|
| 77 | # ========================================
|
---|
| 78 | # Replace backslashes by slashes
|
---|
| 79 | # ========================================
|
---|
| 80 | macro(pacpus_purge_backslash var)
|
---|
| 81 | string(REGEX REPLACE "\\\\" "/" ${var} ${${var}})
|
---|
| 82 | endmacro()
|
---|
| 83 |
|
---|
| 84 | # ========================================
|
---|
| 85 | # Get the version of MSVC as a string
|
---|
| 86 | # ========================================
|
---|
| 87 | macro(pacpus_get_msvc output)
|
---|
| 88 | # By default, unknown
|
---|
| 89 | set(${output} "unknown")
|
---|
| 90 | if (MSVC9)
|
---|
| 91 | set(${output} "msvc2008")
|
---|
[6] | 92 | elseif (MSVC10)
|
---|
[3] | 93 | set(${output} "msvc2010")
|
---|
[6] | 94 | else (MSVC11)
|
---|
[3] | 95 | set(${output} "msvc2012")
|
---|
| 96 | endif()
|
---|
| 97 | endmacro()
|
---|
| 98 |
|
---|
| 99 | # ========================================
|
---|
| 100 | # Print a debug message
|
---|
| 101 | # ========================================
|
---|
| 102 | function(pacpus_output_status msg)
|
---|
| 103 | message(STATUS "${msg}")
|
---|
| 104 | string(REPLACE "\\" "\\\\" msg "${msg}")
|
---|
| 105 | string(REPLACE "\"" "\\\"" msg "${msg}")
|
---|
| 106 | endfunction()
|
---|
| 107 |
|
---|
| 108 | # ========================================
|
---|
| 109 | # Pacpus log message
|
---|
| 110 | # ========================================
|
---|
| 111 | function(pacpus_info text)
|
---|
| 112 | set(status_cond)
|
---|
| 113 | set(status_then)
|
---|
| 114 | set(status_else)
|
---|
| 115 |
|
---|
| 116 | set(status_current_name "cond")
|
---|
| 117 | foreach(arg ${ARGN})
|
---|
| 118 | if(arg STREQUAL "THEN")
|
---|
| 119 | set(status_current_name "then")
|
---|
| 120 | elseif(arg STREQUAL "ELSE")
|
---|
| 121 | set(status_current_name "else")
|
---|
| 122 | else()
|
---|
| 123 | list(APPEND status_${status_current_name} ${arg})
|
---|
| 124 | endif()
|
---|
| 125 | endforeach()
|
---|
| 126 |
|
---|
| 127 | if(DEFINED status_cond)
|
---|
| 128 | set(status_placeholder_length 32)
|
---|
| 129 | string(RANDOM LENGTH ${status_placeholder_length} ALPHABET " " status_placeholder)
|
---|
| 130 | string(LENGTH "${text}" status_text_length)
|
---|
| 131 | if(status_text_length LESS status_placeholder_length)
|
---|
| 132 | string(SUBSTRING "${text}${status_placeholder}" 0 ${status_placeholder_length} status_text)
|
---|
| 133 | elseif(DEFINED status_then OR DEFINED status_else)
|
---|
| 134 | pacpus_output_status("${text}")
|
---|
| 135 | set(status_text "${status_placeholder}")
|
---|
| 136 | else()
|
---|
| 137 | set(status_text "${text}")
|
---|
| 138 | endif()
|
---|
| 139 |
|
---|
| 140 | if(DEFINED status_then OR DEFINED status_else)
|
---|
| 141 | if(${status_cond})
|
---|
| 142 | string(REPLACE ";" " " status_then "${status_then}")
|
---|
| 143 | string(REGEX REPLACE "^[ \t]+" "" status_then "${status_then}")
|
---|
| 144 | pacpus_output_status("${status_text} ${status_then}")
|
---|
| 145 | else()
|
---|
| 146 | string(REPLACE ";" " " status_else "${status_else}")
|
---|
| 147 | string(REGEX REPLACE "^[ \t]+" "" status_else "${status_else}")
|
---|
| 148 | pacpus_output_status("${status_text} ${status_else}")
|
---|
| 149 | endif()
|
---|
| 150 | else()
|
---|
| 151 | string(REPLACE ";" " " status_cond "${status_cond}")
|
---|
| 152 | string(REGEX REPLACE "^[ \t]+" "" status_cond "${status_cond}")
|
---|
| 153 | pacpus_output_status("${status_text} ${status_cond}")
|
---|
| 154 | endif()
|
---|
| 155 | else()
|
---|
| 156 | pacpus_output_status("${text}")
|
---|
| 157 | endif()
|
---|
| 158 | endfunction()
|
---|