CTK 0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkFunctionExtractPluginTargets.cmake
Go to the documentation of this file.
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#!
16function(ctkFunctionExtractPluginTargets my_opts my_filter var_targets)
17
18 if("${my_filter}" STREQUAL "ON" OR "${my_filter}" STREQUAL "OFF"
19 OR "${my_filter}" STREQUAL "ALL")
20 set(valid_input 1)
21 else()
22 set(valid_input 0)
23 set(error_msg "${my_filter} is not one of ON, OFF or ALL")
24 endif()
25
26 if(NOT valid_input)
27 message(FATAL_ERROR "${error_msg}")
28 endif()
29
30 set(plugin_targets )
31 foreach(opt ${my_opts})
32 ctkFunctionExtractOptionNameAndValue(${opt} plugin_name_with_dirs plugin_value)
33 string(REPLACE "/" ";" _tokens ${plugin_name_with_dirs})
34 list(GET _tokens -1 plugin_name)
35 string(REPLACE "." "_" plugin_target ${plugin_name})
36 if("${my_filter}" STREQUAL "ALL")
37 list(APPEND plugin_targets ${plugin_target})
38 elseif("${my_filter}" STREQUAL "ON")
39 if(${${plugin_name_with_dirs}_option_name})
40 list(APPEND plugin_targets ${plugin_target})
41 endif()
42 else()
43 if(NOT ${${plugin_name_with_dirs}_option_name})
44 list(APPEND plugin_targets ${plugin_target})
45 endif()
46 endif()
47 endforeach()
48
49 set(${var_targets} ${plugin_targets} PARENT_SCOPE)
50
51endfunction()