mybison.cmake 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # add the extra targets in the case we want on-the-fly grammar compiler
  2. find_package ( BISON QUIET )
  3. set ( BISON_DIR "${MANTICORE_BINARY_DIR}/config" )
  4. set ( BIS_FLAGS "" )
  5. if (BISON_VERSION VERSION_GREATER 3.0)
  6. set ( BIS_FLAGS "-Wno-deprecated" )
  7. endif ()
  8. function ( MY_BISON_ALLOWING_UNITY ParserName ParserSrc Dependency TargetBison )
  9. if (NOT BISON_FOUND)
  10. if (EXISTS "${BISON_DIR}/bis${ParserSrc}.c" AND EXISTS "${BISON_DIR}/bis${ParserSrc}.h")
  11. infomsg ( "Will use pre-built ${BISON_DIR}/bis${ParserSrc}.c and ${BISON_DIR}/bis${ParserSrc}.h for grammar parser ${ParserName}" )
  12. return ()
  13. else ()
  14. message ( FATAL_ERROR "No pre-compiled grammar files bis${ParserSrc}.c and bis${ParserSrc}.h for ${ParserSrc}.y exists, and Bison not found. Can't continue" )
  15. endif ()
  16. endif ()
  17. LIST ( APPEND ${TargetBison}_BISON "${ParserSrc}.y" )
  18. set ( ${TargetBison}_BISON ${${TargetBison}_BISON} PARENT_SCOPE )
  19. BISON_TARGET ( ${ParserName} "${CMAKE_CURRENT_SOURCE_DIR}/${ParserSrc}.y" "${BISON_DIR}/bis${ParserSrc}.c" COMPILE_FLAGS ${BIS_FLAGS} )
  20. set_source_files_properties ( ${Dependency} PROPERTIES OBJECT_DEPENDS ${BISON_${ParserName}_OUTPUT_SOURCE} )
  21. endfunction ()
  22. function ( MY_BISON ParserName ParserSrc Dependency TargetBison )
  23. if (NOT BISON_FOUND)
  24. if (EXISTS "${BISON_DIR}/bis${ParserSrc}.c" AND EXISTS "${BISON_DIR}/bis${ParserSrc}.h")
  25. infomsg ( "Will use pre-built ${BISON_DIR}/bis${ParserSrc}.c and ${BISON_DIR}/bis${ParserSrc}.h for grammar parser ${ParserName}" )
  26. return ()
  27. else ()
  28. message ( FATAL_ERROR "No pre-compiled grammar files bis${ParserSrc}.c and bis${ParserSrc}.h for ${ParserSrc}.y exists, and Bison not found. Can't continue" )
  29. endif ()
  30. endif ()
  31. LIST ( APPEND ${TargetBison}_BISON "${ParserSrc}.y" )
  32. set ( ${TargetBison}_BISON ${${TargetBison}_BISON} PARENT_SCOPE )
  33. BISON_TARGET ( ${ParserName} "${CMAKE_CURRENT_SOURCE_DIR}/${ParserSrc}.y" "${BISON_DIR}/bis${ParserSrc}.c" COMPILE_FLAGS ${BIS_FLAGS} )
  34. set_source_files_properties ( ${Dependency} PROPERTIES OBJECT_DEPENDS ${BISON_${ParserName}_OUTPUT_SOURCE} SKIP_UNITY_BUILD_INCLUSION ON )
  35. endfunction ()
  36. find_package ( FLEX QUIET )
  37. set ( FLEX_DIR "${MANTICORE_BINARY_DIR}/config" )
  38. function ( MY_FLEX LexerName LexerSrc Dependency TargetFlex )
  39. if (NOT FLEX_FOUND)
  40. if (EXISTS "${FLEX_DIR}/flex${LexerSrc}.c")
  41. infomsg ( "Will use pre-built ${FLEX_DIR}/flex${LexerSrc}.c for lexer ${LexerName}" )
  42. return ()
  43. else ()
  44. message ( FATAL_ERROR "No pre-compiled lexer file flex${LexerSrc}.c for ${LexerSrc}.l exists, and Flex not found. Can't continue" )
  45. endif ()
  46. endif ()
  47. LIST ( APPEND ${TargetFlex}_FLEX "${LexerSrc}.l" )
  48. set ( ${TargetFlex}_FLEX ${${TargetFlex}_FLEX} PARENT_SCOPE )
  49. FLEX_TARGET ( ${LexerName} "${CMAKE_CURRENT_SOURCE_DIR}/${LexerSrc}.l" "${FLEX_DIR}/flex${LexerSrc}.c" )
  50. set_property ( SOURCE ${Dependency} APPEND PROPERTY OBJECT_DEPENDS ${FLEX_${LexerName}_OUTPUTS} )
  51. endfunction ()