ctkFunctionExtractPluginTargets.cmake 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!
  2. #! Extracts target names from a string containing CMake option values.
  3. #!
  4. #! Example usage:
  5. #! \code
  6. #! set(build_options Plugins/org.mydomain.core:ON Plugins/org.mydomain.logic:ON)
  7. #! ctkFunctionExtractPluginTargets("${build_options}" ALL target_names)
  8. #! message("targets: ${target_names}")
  9. #! \endcode
  10. #! will print <code>targets: org_mydomain_core;org_mydomain_logic</code>.
  11. #!
  12. #! \param my_opts A string containing a list of options.
  13. #! \param my_filter One of ON, OFF or ALL. Checks the actual build option of the plugin.
  14. #! \param var_targets A variable name containing the output.
  15. #!
  16. function(ctkFunctionExtractPluginTargets my_opts my_filter var_targets)
  17. if("${my_filter}" STREQUAL "ON" OR "${my_filter}" STREQUAL "OFF"
  18. OR "${my_filter}" STREQUAL "ALL")
  19. set(valid_input 1)
  20. else()
  21. set(valid_input 0)
  22. set(error_msg "${my_filter} is not one of ON, OFF or ALL")
  23. endif()
  24. if(NOT valid_input)
  25. message(FATAL_ERROR "${error_msg}")
  26. endif()
  27. set(plugin_targets )
  28. foreach(opt ${my_opts})
  29. ctkFunctionExtractOptionNameAndValue(${opt} plugin_name_with_dirs plugin_value)
  30. string(REPLACE "/" ";" _tokens ${plugin_name_with_dirs})
  31. list(GET _tokens -1 plugin_name)
  32. string(REPLACE "." "_" plugin_target ${plugin_name})
  33. if("${my_filter}" STREQUAL "ALL")
  34. list(APPEND plugin_targets ${plugin_target})
  35. elseif("${my_filter}" STREQUAL "ON")
  36. if(${${plugin_name_with_dirs}_option_name})
  37. list(APPEND plugin_targets ${plugin_target})
  38. endif()
  39. else()
  40. if(NOT ${${plugin_name_with_dirs}_option_name})
  41. list(APPEND plugin_targets ${plugin_target})
  42. endif()
  43. endif()
  44. endforeach()
  45. set(${var_targets} ${plugin_targets} PARENT_SCOPE)
  46. endfunction()