YAMBi: Move dependency checking code into function
include (LibAddMacros)
-if (DEPENDENCY_PHASE)
+# ~~~
+# 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
+#
+# . 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)
+
include (CheckIncludeFileCXX)
set (CMAKE_REQUIRED_QUIET ON)
check_include_file_cxx (codecvt HAVE_CODECVT)
if (NOT HAVE_CODECVT)
- remove_plugin (yambi "because the current C++ library does not provide header file `codecvt`")
+ set (FAILURE_MESSAGE "because the current C++ library does not provide header file `codecvt`" PARENT_SCOPE)
return ()
endif (NOT HAVE_CODECVT)
@@ -17,22 +30,34 @@ if (DEPENDENCY_PHASE)
find_package (BISON 3 QUIET)
if (NOT BISON_FOUND)
- remove_plugin (yambi "Bison 3 (bison) not found")
+ set (FAILURE_MESSAGE "Bison 3 (bison) not found" PARENT_SCOPE)
return ()
endif (NOT BISON_FOUND)
if (BISON_VERSION VERSION_LESS 3)
- remove_plugin (yambi "Bison version 3 or later required (found version ${BISON_VERSION})")
+ set (FAILURE_MESSAGE "Bison version 3 or later required (found version ${BISON_VERSION})" PARENT_SCOPE)
return ()
endif (BISON_VERSION VERSION_LESS 3)
bison_target (YAMBI ${CMAKE_CURRENT_SOURCE_DIR}/parser.ypp ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp)
if (NOT BISON_YAMBI_DEFINED)
- remove_plugin (yambi "generating the parser code failed")
+ set (FAILURE_MESSAGE "generating the parser code failed" PARENT_SCOPE)
return ()
endif (NOT BISON_YAMBI_DEFINED)
+ 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)
+
+if (DEPENDENCY_PHASE)
+ check_dependencies ()
+ if (NOT FOUND_DEPENDENCIES)
+ remove_plugin (yambi ${FAILURE_MESSAGE})
+ endif (NOT FOUND_DEPENDENCIES)
+
set (SOURCE_FILES_INPUT input.hpp input.cpp)
if (ENABLE_ASAN AND CMAKE_COMPILER_IS_GNUCXX)
