PreprocessorUtils.cmake 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. macro(get_preprocessor_entry CONTENTS KEYWORD VARIABLE)
  10. string(REGEX MATCH
  11. "# *define +${KEYWORD} +((\"([^\n]*)\")|([^ \n]*))"
  12. PREPROC_TEMP_VAR
  13. ${${CONTENTS}}
  14. )
  15. if (CMAKE_MATCH_3)
  16. set(${VARIABLE} ${CMAKE_MATCH_3})
  17. else ()
  18. set(${VARIABLE} ${CMAKE_MATCH_4})
  19. endif ()
  20. endmacro()
  21. macro(has_preprocessor_entry CONTENTS KEYWORD VARIABLE)
  22. string(REGEX MATCH
  23. "\n *# *define +(${KEYWORD})"
  24. PREPROC_TEMP_VAR
  25. ${${CONTENTS}}
  26. )
  27. if (CMAKE_MATCH_1)
  28. set(${VARIABLE} TRUE)
  29. else ()
  30. set(${VARIABLE} FALSE)
  31. endif ()
  32. endmacro()
  33. macro(replace_preprocessor_entry VARIABLE KEYWORD NEW_VALUE)
  34. string(REGEX REPLACE
  35. "(// *)?# *define +${KEYWORD} +[^ \n]*"
  36. "#define ${KEYWORD} ${NEW_VALUE}"
  37. ${VARIABLE}_TEMP
  38. ${${VARIABLE}}
  39. )
  40. set(${VARIABLE} ${${VARIABLE}_TEMP})
  41. endmacro()
  42. macro(set_preprocessor_entry VARIABLE KEYWORD ENABLE)
  43. if (${ENABLE})
  44. set(TMP_REPLACE_STR "#define ${KEYWORD}")
  45. else ()
  46. set(TMP_REPLACE_STR "// #define ${KEYWORD}")
  47. endif ()
  48. string(REGEX REPLACE
  49. "(// *)?# *define +${KEYWORD} *\n"
  50. ${TMP_REPLACE_STR}
  51. ${VARIABLE}_TEMP
  52. ${${VARIABLE}}
  53. )
  54. set(${VARIABLE} ${${VARIABLE}_TEMP})
  55. endmacro()
粤ICP备19079148号