CTK 0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
Loading...
Searching...
No Matches
ctkFunctionExtractOptionNameAndValue.cmake
Go to the documentation of this file.
1
2#
3#
4#
5
6#! \ingroup CMakeUtilities
7function(ctkFunctionExtractOptionNameAndValue my_opt var_opt_name var_opt_value)
8
9 # Make sure option is correctly formated
10 if(NOT "${my_opt}" MATCHES "^[- :/A-Za-z0-9._]+:(ON|OFF)$")
11 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")
12 endif()
13
14 # Extract option name and option default value
15 string(REGEX REPLACE ":(ON|OFF)$" "\\\\;\\1" my_opt_list ${my_opt})
16 set(my_opt_list ${my_opt_list})
17 list(GET my_opt_list 0 opt_name)
18 list(GET my_opt_list 1 opt_value)
19
20 set(${var_opt_name} ${opt_name} PARENT_SCOPE)
21 set(${var_opt_value} ${opt_value} PARENT_SCOPE)
22endfunction()
23
24#
25# Test - Use cmake -DMACRO_TESTING:BOOL=ON -P ctkFunctionExtractOptionNameAndValue.cmake
26#
27if(MACRO_TESTING)
28
29 message("Testing ctkFunctionExtractOptionNameAndValue ...")
30 #
31 # Test1
32 #
33 set(test1 "john:ON")
34 ctkFunctionExtractOptionNameAndValue(${test1} test1_name test1_value)
35
36 if(NOT test1_name STREQUAL "john")
37 message(FATAL_ERROR "test1_name:${test1_name} - Expected:john")
38 endif()
39
40 if(NOT test1_value STREQUAL "ON")
41 message(FATAL_ERROR "test1_value:${test1_value} - Expected:ON")
42 endif()
43
44 #
45 # Test2
46 #
47 set(test2 "doe/john:OFF")
48 ctkFunctionExtractOptionNameAndValue(${test2} test2_name test2_value)
49
50 if(NOT test2_name STREQUAL "doe/john")
51 message(FATAL_ERROR "test1_name:${test2_name} - Expected:doe/john")
52 endif()
53
54 if(NOT test2_value STREQUAL "OFF")
55 message(FATAL_ERROR "test2_value:${test2_value} - Expected:OFF")
56 endif()
57
58endif()