CMake netCDF Compatibility with WPS (#2121)
[WRF.git] / cmake / printOption.cmake
blobf00d893e9a2552709b05a4c43982588fd25eca0b
1 # https://stackoverflow.com/a/19578320
2 # Some color defintions
3 if ( NOT "${PRINT_OPTION_SUPPRESS_COLOR}" )
4   if ( NOT WIN32 )
5     string( ASCII 27 ESC )
6     set( COLOR_RESET  "${ESC}[m"     )
7     set( COLOR_BOLD   "${ESC}[1m"    )
8     set( RED          "${ESC}[31m"   )
9     set( GREEN        "${ESC}[32m"   )
10     set( YELLOW       "${ESC}[33m"   )
11     set( BLUE         "${ESC}[34m"   )
12     set( MAGENTA      "${ESC}[35m"   )
13     set( CYAN         "${ESC}[36m"   )
14     set( WHITE        "${ESC}[37m"   )
15     set( BOLD_RED      "${ESC}[1;31m" )
16     set( BOLD_GREEN    "${ESC}[1;32m" )
17     set( BOLD_YELLOW   "${ESC}[1;33m" )
18     set( BOLD_BLUE     "${ESC}[1;34m" )
19     set( BOLD_MAGENTA  "${ESC}[1;35m" )
20     set( BOLD_CYAN     "${ESC}[1;36m" )
21     set( BOLD_WHITE    "${ESC}[1;37m" )
22   endif()
23 endif()
25 function( print_option )
26   set( OPTION   ${ARGV0} )
27   set( JUSTIFY  ${ARGV1} )
29   if ( ${ARGC} GREATER_EQUAL 3 )
30     set( ALT_COLOR ${ARGV2} )
31   endif()
33   if ( DEFINED ALT_COLOR )
34     set( OPT_COLOR ${ALT_COLOR} )
35   else()
36     set( OPT_COLOR ${RED} )
37     if ( ${${OPTION}} )
38       set( OPT_COLOR ${GREEN} )
39     endif()
40   endif()
41   
42   set( OPTION_STR "${OPTION}" )
43   string( LENGTH ${OPTION_STR} OPTION_STR_LEN )
44   math( EXPR N_JUSTIFY "${JUSTIFY} - ${OPTION_STR_LEN}" )
46   if ( ${N_JUSTIFY} LESS 1 )
47     set( N_JUSTIFY 1 )
48   endif()
50   string( REPEAT " " ${N_JUSTIFY} JUSTIFY_WHITESPACE )
52   message( STATUS "${OPTION_STR}${JUSTIFY_WHITESPACE} : ${OPT_COLOR}${${OPTION}}${COLOR_RESET}" )
54 endfunction()