|
| 1 | +# =========================== Colorisation des messages =========================== |
| 2 | + |
| 3 | +string (ASCII 27 ESC) |
| 4 | +set (AnsiEscapeCodeReset "${ESC}[m") |
| 5 | +set (Bold "${ESC}[1m") |
| 6 | +set (BoldOff "${ESC}[22m") |
| 7 | +set (Em "${ESC}[35m") |
| 8 | +set (BoldEm "${ESC}[1;35m") |
| 9 | +set (Bold "${ESC}[1m") |
| 10 | +set (BoldOff "${ESC}[22m") |
| 11 | +set (CrossedOut "${ESC}[9m") |
| 12 | +set (CrossedOutOff "${ESC}[29m") |
| 13 | +set (ItalicOff "${ESC}[23m") |
| 14 | +set (Underline "${ESC}[4m") |
| 15 | +set (UnderlineOff "${ESC}[24m") |
| 16 | +set (BlackFg "${ESC}[30m") |
| 17 | +set (RedFg "${ESC}[31m") |
| 18 | +set (GreenFg "${ESC}[32m") |
| 19 | +set (YellowFg "${ESC}[33m") |
| 20 | +set (BlueFg "${ESC}[34m") |
| 21 | +set (MagentaFg "${ESC}[35m") |
| 22 | +set (CyanFg "${ESC}[36m") |
| 23 | +set (WhiteFg "${ESC}[37m") |
| 24 | +set (DefaultFg "${ESC}[39m") |
| 25 | +set (BlackBg "${ESC}[40m") |
| 26 | +set (RedBg "${ESC}[41m") |
| 27 | +set (GreenBg "${ESC}[42m") |
| 28 | +set (YellowBg "${ESC}[43m") |
| 29 | +set (BlueBg "${ESC}[44m") |
| 30 | +set (MagentaBg "${ESC}[45m") |
| 31 | +set (CyanBg "${ESC}[46m") |
| 32 | +set (WhiteBg "${ESC}[47m") |
| 33 | +set (DefaultBg "${ESC}[49m") |
| 34 | +set (SaveCursorPosition "${ESC}[s") # Does it work ? Even if ${ESC} 7 |
| 35 | +set (RestoreCursorPosition "${ESC}[u") # Does it work ? Even if ${ESC} 8 |
| 36 | +set (EraseAfterCursorPosition "${ESC}[0J") |
| 37 | +set (EraseFromBeginningToCursorPosition "${ESC}[1J") |
| 38 | +set (EraseScreen "${ESC}[2J") |
| 39 | + |
| 40 | +# ========================== ! Colorisation des messages ========================== |
| 41 | + |
| 42 | + |
| 43 | +# ================================ print_variables ================================ |
| 44 | + |
| 45 | +# Affiche toutes les variables cmake contenant pattern. |
| 46 | + |
| 47 | +function (print_variables pattern) |
| 48 | + |
| 49 | + message (STATUS "\n** dump #${pattern}# cmake variables ***") |
| 50 | + get_cmake_property (_all_var_names VARIABLES) |
| 51 | + foreach (_var_name ${_all_var_names}) |
| 52 | + string (FIND ${_var_name} "${pattern}" pos_found) |
| 53 | + if (NOT pos_found STREQUAL -1) |
| 54 | + message (STATUS "${_var_name}=${${_var_name}}") |
| 55 | + endif (NOT pos_found STREQUAL -1) |
| 56 | + endforeach ( ) |
| 57 | + message (STATUS "** dump end ***\n") |
| 58 | + |
| 59 | +endfunction (print_variables) |
| 60 | + |
| 61 | +# =============================== ! print_variables =============================== |
| 62 | + |
| 63 | + |
| 64 | +# ============================ print_target_properties ============================ |
| 65 | + |
| 66 | +# Affiche toutes les propriétés de la target transmises en argument. |
| 67 | +# https://stackoverflow.com/questions/32183975/how-to-print-all-the-properties-of-a-target-in-cmake/56738858#56738858 |
| 68 | + |
| 69 | +function (print_target_properties tgt) |
| 70 | + |
| 71 | + if (NOT TARGET ${tgt}) |
| 72 | + message (STATUS "There is no target named '${tgt}'") |
| 73 | + return ( ) |
| 74 | + endif (NOT TARGET ${tgt}) |
| 75 | + |
| 76 | + # On récupère toutes les propriétés supportées par cmake : |
| 77 | + execute_process (COMMAND cmake --help-property-list OUTPUT_VARIABLE CMAKE_PROPERTY_LIST) |
| 78 | + STRING (REGEX REPLACE ";" "\\\\;" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}") |
| 79 | + STRING (REGEX REPLACE "\n" ";" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}") |
| 80 | + list (REMOVE_DUPLICATES CMAKE_PROPERTY_LIST) |
| 81 | + |
| 82 | + # Dans le cas de libs réalisées au sein du projet, de la part de CMP0026, et comme elles |
| 83 | + # n'existent pas encore (on est en phase cmake), on va avoir un message du type : |
| 84 | + #The LOCATION property may not be read from target "abc". Use the target |
| 85 | + # name directly with add_custom_command, or use the generator expression |
| 86 | + # $<TARGET_FILE>, as appropriate. |
| 87 | + # Le contournement souvent proposé sur le net est d'enlever "LOCATION", "^LOCATION" |
| 88 | + # et "_LOCATION" de CMAKE_PROPERTY_LIST. Mais on l'enlève de toutes les cibles, ce qui nous |
| 89 | + # prive du coup de cette précieuse information de tout binaire généré :(. |
| 90 | + # Contournement proposé ici : on modifie cette politique juste le temps de la fonction. |
| 91 | + # Push the current (NEW) CMake policy onto the stack, and apply the OLD policy. |
| 92 | + # https://stackoverflow.com/questions/32197663/how-can-i-remove-the-the-location-property-may-not-be-read-from-target-error-i |
| 93 | + cmake_policy (PUSH) |
| 94 | +# On efface un message d'injures du fait de l'utilisation de cmake_policy (SET CMP0026 OLD) |
| 95 | +# message (STATUS "${SaveCursorPosition}") |
| 96 | + cmake_policy (SET CMP0026 OLD) |
| 97 | +# message (STATUS "${RestoreCursorPosition} ${EraseAfterCursorPosition}") |
| 98 | + message (STATUS "${ESC}[12F ${EraseAfterCursorPosition}") |
| 99 | + |
| 100 | + foreach (prop ${CMAKE_PROPERTY_LIST}) |
| 101 | + string (REPLACE "<CONFIG>" "${CMAKE_BUILD_TYPE}" prop ${prop}) |
| 102 | + # Ci-dessous : on ne récupère pas les propriétés définies mais vides : |
| 103 | + # get_target_property (propval ${tgt} ${prop}) |
| 104 | + # if (propval) |
| 105 | + # message (STATUS "${tgt} ${prop} = ${propval}") |
| 106 | + # endif (propval) |
| 107 | + # Ci-dessous : avec SET propval vaut 1 si la propriété existe. On récupère alors la valeur de |
| 108 | + # la propriété par un seconde appel : |
| 109 | + get_property (propval TARGET ${tgt} PROPERTY ${prop} SET) |
| 110 | + if (propval) |
| 111 | +# message (STATUS "${tgt} ${prop} = ${propval}") # 1 |
| 112 | + get_target_property (propval ${tgt} ${prop}) |
| 113 | + message (STATUS "${tgt} ${prop} = ${propval}") |
| 114 | + endif (propval) |
| 115 | + |
| 116 | + endforeach(prop) |
| 117 | + |
| 118 | + # Pop the previous policy from the stack to re-apply the NEW behavior. |
| 119 | + cmake_policy (POP) |
| 120 | + |
| 121 | +endfunction (print_target_properties) |
| 122 | + |
| 123 | +# =========================== ! print_target_properties =========================== |
0 commit comments