ctkFunctionExtractOptionNameAndValue.cmake 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #
  2. #
  3. #
  4. #! \ingroup CMakeUtilities
  5. function(ctkFunctionExtractOptionNameAndValue my_opt var_opt_name var_opt_value)
  6. # Make sure option is correctly formated
  7. if(NOT "${my_opt}" MATCHES "^[- :/A-Za-z0-9._]+:(ON|OFF)$")
  8. message(FATAL_ERROR "Option ${my_opt} is incorrect. Options should be specified using the following format OPT1:[ON|OFF]. For example OPT1:OFF or OPT2:ON")
  9. endif()
  10. # Extract option name and option default value
  11. string(REGEX REPLACE ":(ON|OFF)$" "\\\\;\\1" my_opt_list ${my_opt})
  12. set(my_opt_list ${my_opt_list})
  13. list(GET my_opt_list 0 opt_name)
  14. list(GET my_opt_list 1 opt_value)
  15. set(${var_opt_name} ${opt_name} PARENT_SCOPE)
  16. set(${var_opt_value} ${opt_value} PARENT_SCOPE)
  17. endfunction()
  18. #
  19. # Test - Use cmake -DMACRO_TESTING:BOOL=ON -P ctkFunctionExtractOptionNameAndValue.cmake
  20. #
  21. if(MACRO_TESTING)
  22. message("Testing ctkFunctionExtractOptionNameAndValue ...")
  23. #
  24. # Test1
  25. #
  26. set(test1 "john:ON")
  27. ctkFunctionExtractOptionNameAndValue(${test1} test1_name test1_value)
  28. if(NOT test1_name STREQUAL "john")
  29. message(FATAL_ERROR "test1_name:${test1_name} - Expected:john")
  30. endif()
  31. if(NOT test1_value STREQUAL "ON")
  32. message(FATAL_ERROR "test1_value:${test1_value} - Expected:ON")
  33. endif()
  34. #
  35. # Test2
  36. #
  37. set(test2 "doe/john:OFF")
  38. ctkFunctionExtractOptionNameAndValue(${test2} test2_name test2_value)
  39. if(NOT test2_name STREQUAL "doe/john")
  40. message(FATAL_ERROR "test1_name:${test2_name} - Expected:doe/john")
  41. endif()
  42. if(NOT test2_value STREQUAL "OFF")
  43. message(FATAL_ERROR "test2_value:${test2_value} - Expected:OFF")
  44. endif()
  45. endif()