[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"
|
---|
[40] | 29 | "#include <QObject>\n"
|
---|
[3] | 30 | "#include <qplugin.h>\n"
|
---|
| 31 | "\n"
|
---|
[40] | 32 | "#include <Pacpus/kernel/PacpusPluginInterface.h>\n"
|
---|
[3] | 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)
|
---|
[50] | 81 | string(REGEX REPLACE "\\\\" "/" ${var} "${${var}}")
|
---|
[3] | 82 | endmacro()
|
---|
| 83 |
|
---|
| 84 | # ========================================
|
---|
| 85 | # Get the version of MSVC as a string
|
---|
| 86 | # ========================================
|
---|
| 87 | macro(pacpus_get_msvc output)
|
---|
[50] | 88 | # By default, unknown
|
---|
| 89 | set(${output} "unknown")
|
---|
| 90 | if(MSVC9)
|
---|
| 91 | set(${output} "msvc2008")
|
---|
| 92 | elseif(MSVC10)
|
---|
| 93 | set(${output} "msvc2010")
|
---|
| 94 | else(MSVC11)
|
---|
| 95 | set(${output} "msvc2012")
|
---|
| 96 | endif()
|
---|
[3] | 97 | endmacro()
|
---|
| 98 |
|
---|
| 99 | # ========================================
|
---|
| 100 | # Print a debug message
|
---|
| 101 | # ========================================
|
---|
| 102 | function(pacpus_output_status msg)
|
---|
[50] | 103 | message(STATUS "${msg}")
|
---|
| 104 | string(REPLACE "\\" "\\\\" msg "${msg}")
|
---|
| 105 | string(REPLACE "\"" "\\\"" msg "${msg}")
|
---|
[3] | 106 | endfunction()
|
---|
| 107 |
|
---|
| 108 | # ========================================
|
---|
| 109 | # Pacpus log message
|
---|
| 110 | # ========================================
|
---|
| 111 | function(pacpus_info text)
|
---|
[50] | 112 | set(status_cond)
|
---|
| 113 | set(status_then)
|
---|
| 114 | set(status_else)
|
---|
[3] | 115 |
|
---|
[50] | 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()
|
---|
[3] | 126 |
|
---|
[50] | 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()
|
---|
[3] | 139 |
|
---|
[50] | 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()
|
---|
[3] | 155 | else()
|
---|
[50] | 156 | pacpus_output_status("${text}")
|
---|
[3] | 157 | endif()
|
---|
| 158 | endfunction()
|
---|
[19] | 159 |
|
---|
| 160 | # ========================================
|
---|
[21] | 161 | # Pacpus add library and set debug postfix
|
---|
| 162 | # ========================================
|
---|
[22] | 163 | function(pacpus_add_library target)
|
---|
| 164 | add_library(
|
---|
[21] | 165 | ${ARGV}
|
---|
| 166 | )
|
---|
| 167 | set_target_properties(
|
---|
| 168 | ${target}
|
---|
| 169 | PROPERTIES DEBUG_POSTFIX "_d"
|
---|
| 170 | )
|
---|
| 171 | endfunction()
|
---|
| 172 |
|
---|
| 173 | # ========================================
|
---|
[19] | 174 | # Pacpus add executable and set debug postfix
|
---|
| 175 | # ========================================
|
---|
[22] | 176 | function(pacpus_add_executable target)
|
---|
| 177 | add_executable(
|
---|
[19] | 178 | ${ARGV}
|
---|
| 179 | )
|
---|
| 180 | set_target_properties(
|
---|
| 181 | ${target}
|
---|
| 182 | PROPERTIES DEBUG_POSTFIX "_d"
|
---|
| 183 | )
|
---|
| 184 | endfunction()
|
---|
| 185 |
|
---|
| 186 | # ========================================
|
---|
| 187 | # Pacpus install
|
---|
| 188 | # ========================================
|
---|
[21] | 189 | function(pacpus_install)
|
---|
[19] | 190 | install(
|
---|
[21] | 191 | TARGETS ${ARGV}
|
---|
[19] | 192 | RUNTIME DESTINATION ${PACPUS_INSTALL_DIR}/bin
|
---|
| 193 | LIBRARY DESTINATION ${PACPUS_INSTALL_DIR}/lib
|
---|
| 194 | ARCHIVE DESTINATION ${PACPUS_INSTALL_DIR}/lib
|
---|
| 195 | )
|
---|
| 196 | endfunction()
|
---|
| 197 |
|
---|
| 198 | # ========================================
|
---|
| 199 | # Pacpus folder
|
---|
| 200 | # ========================================
|
---|
| 201 | function(pacpus_folder target folder_name)
|
---|
[51] | 202 | if(PACPUS_USE_SOLUTION_FOLDERS AND MSVC)
|
---|
[19] | 203 | set_target_properties(${target}
|
---|
| 204 | PROPERTIES FOLDER ${folder_name}
|
---|
| 205 | )
|
---|
| 206 | endif()
|
---|
| 207 | endfunction()
|
---|