1execute_process( 2 COMMAND ${CMAKE_COMMAND} -E environment 3 OUTPUT_VARIABLE out 4 ERROR_VARIABLE err 5 RESULT_VARIABLE res) 6 7if (res) 8 message(FATAL_ERROR "Failed with exit code ${res}: ${err}") 9endif () 10 11if (CMAKE_HOST_WIN32) 12 set(path_sep ";") 13else () 14 set(path_sep ":") 15endif () 16 17set(unexpect_SET_FROM_AMBIENT_unset "") 18set(unexpect_SET_FROM_ENVIRONMENT_PROPERTY_unset "") 19set(unexpect_UNSET_EXPLICIT "") 20set(unexpect_UNSET_VIA_RESET "") 21set(expect_DIRECT "new") 22set(expect_STRING_MANIP "prefix-pre-core-post-suffix") 23set(expect_PATH_MANIP "prefix${path_sep}pre${path_sep}core${path_sep}post${path_sep}suffix") 24set(expect_CMAKE_LIST_MANIP "prefix;pre;core;post;suffix") 25set(expect_STRING_DNE "prefix-prepost-suffix") 26set(expect_PATH_DNE "prefix${path_sep}pre${path_sep}post${path_sep}suffix") 27set(expect_CMAKE_LIST_DNE "prefix;pre;post;suffix") 28set(expect_SET_FROM_AMBIENT_replace "new") 29set(expect_SET_FROM_AMBIENT_string "basenew") 30set(expect_SET_FROM_AMBIENT_path "base${path_sep}new") 31set(expect_SET_FROM_AMBIENT_list "base;new") 32set(expect_SET_FROM_ENVIRONMENT_PROPERTY_replace "new") 33set(expect_SET_FROM_ENVIRONMENT_PROPERTY_string "basenew") 34set(expect_SET_FROM_ENVIRONMENT_PROPERTY_path "base${path_sep}new") 35set(expect_SET_FROM_ENVIRONMENT_PROPERTY_list "base;new") 36 37set(expected_vars 38 SET_FROM_AMBIENT_replace 39 SET_FROM_AMBIENT_string 40 SET_FROM_AMBIENT_path 41 SET_FROM_AMBIENT_list 42 SET_FROM_ENVIRONMENT_PROPERTY_replace 43 SET_FROM_ENVIRONMENT_PROPERTY_string 44 SET_FROM_ENVIRONMENT_PROPERTY_path 45 SET_FROM_ENVIRONMENT_PROPERTY_list 46 DIRECT 47 STRING_MANIP 48 PATH_MANIP 49 CMAKE_LIST_MANIP 50 STRING_DNE 51 PATH_DNE 52 CMAKE_LIST_DNE) 53 54while (out) 55 string(FIND "${out}" "\n" nl_pos) 56 string(SUBSTRING "${out}" 0 "${nl_pos}" line) 57 math(EXPR line_next "${nl_pos} + 1") 58 string(SUBSTRING "${out}" "${line_next}" -1 out) 59 60 string(FIND "${line}" "=" eq_pos) 61 string(SUBSTRING "${line}" 0 "${eq_pos}" name) 62 math(EXPR value_start "${eq_pos} + 1") 63 string(SUBSTRING "${line}" "${value_start}" -1 value) 64 65 if (DEFINED "unexpect_${name}") 66 message(SEND_ERROR "Found `${name}=${value}` when it should have been unset") 67 elseif (DEFINED "expect_${name}") 68 list(REMOVE_ITEM expected_vars "${name}") 69 if (expect_${name} STREQUAL value) 70 message(STATUS "Found `${name}=${value}` as expected") 71 else () 72 message(SEND_ERROR "Found `${name}=${value}` when it should have been ${expect_${name}}") 73 endif () 74 endif () 75endwhile () 76 77if (expected_vars) 78 message(SEND_ERROR "Did not test expected variables: ${expected_vars}") 79endif () 80