zibbr

Random 3d and p2p stuff that was originally the beginnings of an overly ambitious p2p virtual world thingy
git clone https://code.literati.org/zibbr.git
Log | Files | Refs

PreprocessorUtils.cmake (1595B)


      1 #-------------------------------------------------------------------
      2 # This file is part of the CMake build system for OGRE
      3 #     (Object-oriented Graphics Rendering Engine)
      4 # For the latest info, see http://www.ogre3d.org/
      5 #
      6 # The contents of this file are placed in the public domain. Feel
      7 # free to make use of it in any way you like.
      8 #-------------------------------------------------------------------
      9 
     10 macro(get_preprocessor_entry CONTENTS KEYWORD VARIABLE)
     11   string(REGEX MATCH
     12     "# *define +${KEYWORD} +((\"([^\n]*)\")|([^ \n]*))"
     13     PREPROC_TEMP_VAR
     14     ${${CONTENTS}}
     15   )
     16   if (CMAKE_MATCH_3)
     17     set(${VARIABLE} ${CMAKE_MATCH_3})
     18   else ()
     19     set(${VARIABLE} ${CMAKE_MATCH_4})
     20   endif ()
     21 endmacro()
     22 
     23 macro(has_preprocessor_entry CONTENTS KEYWORD VARIABLE)
     24   string(REGEX MATCH
     25     "\n *# *define +(${KEYWORD})"
     26     PREPROC_TEMP_VAR
     27     ${${CONTENTS}}
     28   )
     29   if (CMAKE_MATCH_1)
     30     set(${VARIABLE} TRUE)
     31   else ()
     32     set(${VARIABLE} FALSE)
     33   endif ()
     34 endmacro()
     35 
     36 macro(replace_preprocessor_entry VARIABLE KEYWORD NEW_VALUE)
     37   string(REGEX REPLACE 
     38     "(// *)?# *define +${KEYWORD} +[^ \n]*"
     39 	"#define ${KEYWORD} ${NEW_VALUE}"
     40 	${VARIABLE}_TEMP
     41 	${${VARIABLE}}
     42   )
     43   set(${VARIABLE} ${${VARIABLE}_TEMP})  
     44 endmacro()
     45 
     46 macro(set_preprocessor_entry VARIABLE KEYWORD ENABLE)
     47   if (${ENABLE})
     48     set(TMP_REPLACE_STR "#define ${KEYWORD}")
     49   else ()
     50     set(TMP_REPLACE_STR "// #define ${KEYWORD}")
     51   endif ()
     52   string(REGEX REPLACE 
     53     "(// *)?# *define +${KEYWORD} *\n"
     54 	${TMP_REPLACE_STR}
     55 	${VARIABLE}_TEMP
     56 	${${VARIABLE}}
     57   )
     58   set(${VARIABLE} ${${VARIABLE}_TEMP})  
     59 endmacro()
     60