You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OvtRunMultipleCommand.cmake 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #######################################################################
  2. # Software License Agreement (AGPL-3 License)
  3. #
  4. # OpenViBE SDK Test Software
  5. # Based on OpenViBE V1.1.0, Copyright (C) Inria, 2006-2015
  6. # Copyright (C) Inria, 2015-2017,V1.0
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License version 3,
  10. # as published by the Free Software Foundation.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program.
  19. # If not, see <http://www.gnu.org/licenses/>.
  20. #######################################################################
  21. # Cmake script used to wrap multiple commands into one.
  22. #
  23. # Mandatory Input parameters:
  24. # -UNQUOTE: set to 1 to unquote commands before processing, 0 otherwise
  25. # -CMD1 First commands to execute
  26. #
  27. # Optional Input parameters:
  28. # -CMD2 to CMD5: Other commands to execute
  29. #
  30. # Example usage:
  31. # ADD_TEST(NAME ${TEST_NAME}
  32. # COMMAND ${CMAKE_COMMAND}
  33. # -DUNQUOTE=1
  34. # -DCMD1="Command_1"
  35. # -DCMD2="Command_2"
  36. # -DCMD3="Command_3"
  37. # -P ${OpenViBE_TEST_CMAKE_DIR}/OvtRunMultipleCommand3.cmake)
  38. # Macro used to execute a command and check the result
  39. MACRO(EXEC_CHECK RAW_CMD UNQUOTE_CMD)
  40. SET(CMD_ARGS_RAW ${RAW_CMD})
  41. IF(${UNQUOTE_CMD})
  42. # First processing to remove enclosing quotes
  43. STRING(LENGTH "${RAW_CMD}" CMD_STRING_LENGTH)
  44. MATH(EXPR CMD_STRING_LENGTH "${CMD_STRING_LENGTH} - 2")
  45. STRING(SUBSTRING "${RAW_CMD}" 1 ${CMD_STRING_LENGTH} CMD_ARGS_RAW)
  46. ENDIF()
  47. # Process arguments to build an arg list
  48. SEPARATE_ARGUMENTS(CMD_ARGS WINDOWS_COMMAND ${CMD_ARGS_RAW})
  49. EXECUTE_PROCESS(COMMAND ${CMD_ARGS} RESULT_VARIABLE ret_var OUTPUT_VARIABLE output_var)
  50. MESSAGE(STATUS "----------------------------------------------\n")
  51. MESSAGE(STATUS "-----------NEW COMMAND EXECUTED-----------\n\n")
  52. MESSAGE(STATUS "----------------------------------------------\n\n")
  53. MESSAGE(STATUS "-----------Command Name & Arguments-----------\n${RAW_CMD}\n\n")
  54. MESSAGE(STATUS "-----------Command Output-----------\n${output_var}\n\n")
  55. IF(ret_var)
  56. MESSAGE(FATAL_ERROR "-----------Error-----------\n$Running command failed with code: ${ret_var}\n\n")
  57. ENDIF()
  58. ENDMACRO()
  59. IF(NOT DEFINED UNQUOTE)
  60. MESSAGE(FATAL_ERROR "Missing UNQUOTE parameter")
  61. ENDIF()
  62. IF(DEFINED CMD1)
  63. EXEC_CHECK(${CMD1} ${UNQUOTE})
  64. ELSE()
  65. MESSAGE(FATAL_ERROR "At least one command needed in OvtRunMultipleCommand script")
  66. ENDIF()
  67. IF(DEFINED CMD2)
  68. EXEC_CHECK(${CMD2} ${UNQUOTE})
  69. ENDIF()
  70. IF(DEFINED CMD3)
  71. EXEC_CHECK(${CMD3} ${UNQUOTE})
  72. ENDIF()
  73. IF(DEFINED CMD4)
  74. EXEC_CHECK(${CMD4} ${UNQUOTE})
  75. ENDIF()
  76. IF(DEFINED CMD5)
  77. EXEC_CHECK(${CMD5} ${UNQUOTE})
  78. ENDIF()