YAMBi: Add function for code generation
-include (LibAddMacros)
-
-# ~~~
# This functions checks if the dependencies for the YAMBi plugin are available.
#
# If they are, the function sets the variable `FOUND_DEPENDENCIES` to `TRUE`. The function then also sets:
#
-# - BISON_YAMBI_OUTPUT_SOURCE to the path of the source files generated by Bison, and
-# - BISON_YAMBI_OUTPUT_HEADER to the path of the header files generated by Bison
+# - `BISON_VERSION` to the version number of the detected version of Bison
#
-# . If the function was unsuccessful it sets `FOUND_DEPENDENCIES` to `FALSE` and stores the reason for the failure in the variable
-# `FAILURE_MESSAGE`.
-# ~~~
+# and defines the macro `bison_target`. If the function was unsuccessful it sets `FOUND_DEPENDENCIES` to `FALSE` and stores the reason for
+# the failure in the variable `FAILURE_MESSAGE`.
function (check_dependencies)
set (FOUND_DEPENDENCIES FALSE PARENT_SCOPE)
@@ -40,6 +35,24 @@ function (check_dependencies)
return ()
endif (BISON_VERSION VERSION_LESS 3)
+ set (BISON_VERSION "${BISON_VERSION}" PARENT_SCOPE)
+ set (FOUND_DEPENDENCIES TRUE PARENT_SCOPE)
+
+endfunction (check_dependencies)
+
+# This functions generates the source files of the YAML parser using Bison. If generating the source files was successful, then it sets the
+# variables:
+#
+# - `GENERATED_CODE` to `TRUE`,
+# - `BISON_YAMBI_OUTPUT_SOURCE` to the filepath of the parser source, and
+# - `BISON_YAMBI_OUTPUT_HEADER` to the filepath of the parser header
+#
+# . If the function was unsuccessful it sets `GENERATED_CODE` to `FALSE` and stores the reason for the error in the variable
+# `FAILURE_MESSAGE`.
+function (generate_code)
+
+ set (GENERATED_CODE FALSE PARENT_SCOPE)
+
if (BISON_VERSION VERSION_LESS 3.3)
set (PARSER_NAME_DIRECTIVE "parser_class_name")
else (BISON_VERSION VERSION_LESS 3.3)
@@ -55,16 +68,21 @@ function (check_dependencies)
return ()
endif (NOT BISON_YAMBI_DEFINED)
+ set (GENERATED_CODE TRUE PARENT_SCOPE)
set (BISON_YAMBI_OUTPUT_SOURCE ${BISON_YAMBI_OUTPUT_SOURCE} PARENT_SCOPE)
set (BISON_YAMBI_OUTPUT_HEADER ${BISON_YAMBI_OUTPUT_HEADER} PARENT_SCOPE)
- set (FOUND_DEPENDENCIES TRUE PARENT_SCOPE)
-endfunction (check_dependencies)
+endfunction (generate_code)
if (DEPENDENCY_PHASE)
check_dependencies ()
if (NOT FOUND_DEPENDENCIES)
remove_plugin (yambi ${FAILURE_MESSAGE})
+ else (NOT FOUND_DEPENDENCIES)
+ generate_code ("${BISON_VERSION}")
+ if (NOT GENERATED_CODE)
+ remove_plugin (yambi ${FAILURE_MESSAGE})
+ endif (NOT GENERATED_CODE)
endif (NOT FOUND_DEPENDENCIES)
set (SOURCE_FILES_INPUT input.hpp input.cpp)
