[89] | 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 ${PLUGIN_NAME}.json 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 PacpusUtilities.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>\n"
|
---|
| 30 | "#include <qplugin.h>\n"
|
---|
| 31 | "\n"
|
---|
| 32 | "#include <Pacpus/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 | " //Qt5 Plugins Macro\n"
|
---|
| 41 | " Q_PLUGIN_METADATA(IID \"papus.pacpuscityvip." ${PLUGIN_NAME} "\" FILE \"" ${PLUGIN_NAME} ".json\")\n"
|
---|
| 42 | " Q_INTERFACES(PacpusPluginInterface)\n"
|
---|
| 43 | "\n"
|
---|
| 44 | "public:\n"
|
---|
| 45 | " ${PLUGIN_NAME}();\n"
|
---|
| 46 | " ~${PLUGIN_NAME}();\n"
|
---|
| 47 | "\n"
|
---|
| 48 | "protected:\n"
|
---|
| 49 | " QString name();\n"
|
---|
| 50 | "};\n"
|
---|
| 51 | "\n"
|
---|
| 52 | "#endif // __${PLUGIN_NAME_UPPER}_H__\n"
|
---|
| 53 | )
|
---|
| 54 |
|
---|
| 55 | # create the cpp file
|
---|
| 56 | file(WRITE ${PLUGIN_NAME}.cpp
|
---|
| 57 | "// Autogenerated file by PacpusUtilities.cmake\n"
|
---|
| 58 | "// DO NOT EDIT!!! ALL CHANGES WOULD BE REMOVED BY THE NEXT CALL OF CMAKE\n"
|
---|
| 59 | "\n"
|
---|
| 60 | "#include \"${PLUGIN_NAME}.h\"\n"
|
---|
| 61 | "\n"
|
---|
| 62 | "${PLUGIN_NAME}::${PLUGIN_NAME}()\n"
|
---|
| 63 | "{\n"
|
---|
| 64 | "}\n"
|
---|
| 65 | "\n"
|
---|
| 66 | "${PLUGIN_NAME}::~${PLUGIN_NAME}()\n"
|
---|
| 67 | "{\n"
|
---|
| 68 | "}\n"
|
---|
| 69 | "\n"
|
---|
| 70 | "QString ${PLUGIN_NAME}::name()\n"
|
---|
| 71 | "{\n"
|
---|
| 72 | " return \"${PLUGIN_NAME}\";\n"
|
---|
| 73 | "}\n"
|
---|
| 74 | "\n"
|
---|
| 75 | "//Qt4 Plugin Macro desactivated\n"
|
---|
| 76 | "//Q_EXPORT_PLUGIN2(${PLUGIN_NAME}, ${PLUGIN_NAME})\n"
|
---|
| 77 | )
|
---|
| 78 |
|
---|
| 79 | file(WRITE ${PLUGIN_NAME}.json
|
---|
| 80 | "{\n"
|
---|
| 81 | " \"Keys\": [\""${PLUGIN_NAME} "\"]\n"
|
---|
| 82 | "}\n"
|
---|
| 83 | )
|
---|
| 84 | endfunction(PACPUS_PLUGIN)
|
---|
| 85 |
|
---|
| 86 | # ========================================
|
---|
| 87 | # Replace backslashes by slashes
|
---|
| 88 | # ========================================
|
---|
| 89 | macro(pacpus_purge_backslash var)
|
---|
| 90 | string(REGEX REPLACE "\\\\" "/" ${var} "${${var}}")
|
---|
| 91 | endmacro()
|
---|
| 92 |
|
---|
| 93 | # ========================================
|
---|
| 94 | # Get the version of MSVC as a string
|
---|
| 95 | # ========================================
|
---|
| 96 | macro(pacpus_get_msvc output)
|
---|
| 97 | # By default, unknown
|
---|
| 98 | set(${output} "unknown")
|
---|
| 99 | if(MSVC9)
|
---|
| 100 | set(${output} "msvc2008")
|
---|
| 101 | elseif(MSVC10)
|
---|
| 102 | set(${output} "msvc2010")
|
---|
| 103 | else(MSVC11)
|
---|
| 104 | set(${output} "msvc2012")
|
---|
| 105 | endif()
|
---|
| 106 | endmacro()
|
---|
| 107 |
|
---|
| 108 | # ========================================
|
---|
| 109 | # Print a debug message
|
---|
| 110 | # ========================================
|
---|
| 111 | function(pacpus_output_status msg)
|
---|
| 112 | message(STATUS "${msg}")
|
---|
| 113 | string(REPLACE "\\" "\\\\" msg "${msg}")
|
---|
| 114 | string(REPLACE "\"" "\\\"" msg "${msg}")
|
---|
| 115 | endfunction()
|
---|
| 116 |
|
---|
| 117 | # ========================================
|
---|
| 118 | # Pacpus log message
|
---|
| 119 | # ========================================
|
---|
| 120 | function(pacpus_info text)
|
---|
| 121 | set(status_cond)
|
---|
| 122 | set(status_then)
|
---|
| 123 | set(status_else)
|
---|
| 124 |
|
---|
| 125 | set(status_current_name "cond")
|
---|
| 126 | foreach(arg ${ARGN})
|
---|
| 127 | if(arg STREQUAL "THEN")
|
---|
| 128 | set(status_current_name "then")
|
---|
| 129 | elseif(arg STREQUAL "ELSE")
|
---|
| 130 | set(status_current_name "else")
|
---|
| 131 | else()
|
---|
| 132 | list(APPEND status_${status_current_name} ${arg})
|
---|
| 133 | endif()
|
---|
| 134 | endforeach()
|
---|
| 135 |
|
---|
| 136 | if(DEFINED status_cond)
|
---|
| 137 | set(status_placeholder_length 32)
|
---|
| 138 | string(RANDOM LENGTH ${status_placeholder_length} ALPHABET " " status_placeholder)
|
---|
| 139 | string(LENGTH "${text}" status_text_length)
|
---|
| 140 | if(status_text_length LESS status_placeholder_length)
|
---|
| 141 | string(SUBSTRING "${text}${status_placeholder}" 0 ${status_placeholder_length} status_text)
|
---|
| 142 | elseif(DEFINED status_then OR DEFINED status_else)
|
---|
| 143 | pacpus_output_status("${text}")
|
---|
| 144 | set(status_text "${status_placeholder}")
|
---|
| 145 | else()
|
---|
| 146 | set(status_text "${text}")
|
---|
| 147 | endif()
|
---|
| 148 |
|
---|
| 149 | if(DEFINED status_then OR DEFINED status_else)
|
---|
| 150 | if(${status_cond})
|
---|
| 151 | string(REPLACE ";" " " status_then "${status_then}")
|
---|
| 152 | string(REGEX REPLACE "^[ \t]+" "" status_then "${status_then}")
|
---|
| 153 | pacpus_output_status("${status_text} ${status_then}")
|
---|
| 154 | else()
|
---|
| 155 | string(REPLACE ";" " " status_else "${status_else}")
|
---|
| 156 | string(REGEX REPLACE "^[ \t]+" "" status_else "${status_else}")
|
---|
| 157 | pacpus_output_status("${status_text} ${status_else}")
|
---|
| 158 | endif()
|
---|
| 159 | else()
|
---|
| 160 | string(REPLACE ";" " " status_cond "${status_cond}")
|
---|
| 161 | string(REGEX REPLACE "^[ \t]+" "" status_cond "${status_cond}")
|
---|
| 162 | pacpus_output_status("${status_text} ${status_cond}")
|
---|
| 163 | endif()
|
---|
| 164 | else()
|
---|
| 165 | pacpus_output_status("${text}")
|
---|
| 166 | endif()
|
---|
| 167 | endfunction()
|
---|
| 168 |
|
---|
| 169 | # ========================================
|
---|
| 170 | # Pacpus add library and set debug postfix
|
---|
| 171 | # ========================================
|
---|
| 172 | function(pacpus_add_library target)
|
---|
| 173 | add_library(
|
---|
| 174 | ${ARGV}
|
---|
| 175 | )
|
---|
| 176 | set_target_properties(
|
---|
| 177 | ${target}
|
---|
| 178 | PROPERTIES DEBUG_POSTFIX "_d"
|
---|
| 179 | )
|
---|
| 180 | endfunction()
|
---|
| 181 |
|
---|
| 182 | # ========================================
|
---|
| 183 | # Pacpus add executable and set debug postfix
|
---|
| 184 | # ========================================
|
---|
| 185 | function(pacpus_add_executable target)
|
---|
| 186 | add_executable(
|
---|
| 187 | ${ARGV}
|
---|
| 188 | )
|
---|
| 189 | set_target_properties(
|
---|
| 190 | ${target}
|
---|
| 191 | PROPERTIES DEBUG_POSTFIX "_d"
|
---|
| 192 | )
|
---|
| 193 | endfunction()
|
---|
| 194 |
|
---|
| 195 | # ========================================
|
---|
| 196 | # Pacpus install
|
---|
| 197 | # ========================================
|
---|
| 198 | function(pacpus_install)
|
---|
| 199 | install(
|
---|
| 200 | TARGETS ${ARGV}
|
---|
| 201 | RUNTIME DESTINATION ${PACPUS_INSTALL_DIR}/bin
|
---|
| 202 | LIBRARY DESTINATION ${PACPUS_INSTALL_DIR}/lib
|
---|
| 203 | ARCHIVE DESTINATION ${PACPUS_INSTALL_DIR}/lib
|
---|
| 204 | )
|
---|
| 205 | if(MSVC)
|
---|
| 206 | # install debug information files .pdb
|
---|
| 207 | foreach(target ${ARGV})
|
---|
| 208 | get_target_property(target_filepath ${target} LOCATION_DEBUG)
|
---|
| 209 | get_filename_component(target_directory ${target_filepath} PATH)
|
---|
| 210 | get_filename_component(target_basename ${target_filepath} NAME_WE)
|
---|
| 211 |
|
---|
| 212 | set(target_pdb "${target_directory}/${target_basename}.pdb")
|
---|
| 213 | install(FILES ${target_pdb}
|
---|
| 214 | CONFIGURATIONS Debug
|
---|
| 215 | DESTINATION ${PACPUS_INSTALL_DIR}/lib
|
---|
| 216 | )
|
---|
| 217 | endforeach()
|
---|
| 218 | endif(MSVC)
|
---|
| 219 | endfunction()
|
---|
| 220 |
|
---|
| 221 | # ========================================
|
---|
| 222 | # Pacpus folder
|
---|
| 223 | # ========================================
|
---|
| 224 | function(pacpus_folder target folder_name)
|
---|
| 225 | if(PACPUS_USE_SOLUTION_FOLDERS AND MSVC)
|
---|
| 226 | set_target_properties(${target}
|
---|
| 227 | PROPERTIES FOLDER ${folder_name}
|
---|
| 228 | )
|
---|
| 229 | endif()
|
---|
| 230 | endfunction()
|
---|
[99] | 231 |
|
---|
| 232 | # ========================================
|
---|
| 233 | # Get sub directories
|
---|
| 234 | # ========================================
|
---|
| 235 | MACRO(SUBDIRLIST result curdir)
|
---|
| 236 | FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
|
---|
| 237 | SET(dirlist "")
|
---|
| 238 | FOREACH(child ${children})
|
---|
| 239 | IF(IS_DIRECTORY ${curdir}/${child})
|
---|
| 240 | SET(dirlist ${dirlist} ${child})
|
---|
| 241 | ENDIF()
|
---|
| 242 | ENDFOREACH()
|
---|
| 243 | SET(${result} ${dirlist})
|
---|
| 244 | ENDMACRO()
|
---|