cmake_policy(SET CMP0140 NEW) include ("${RunCMake_SOURCE_DIR}/check_errors.cmake") unset (errors) ############################################### ## First test with a path defining all elements ############################################### if (WIN32) set (path "C:/aa/bb/cc.ext1.ext2") else() set (path "/aa/bb/cc.ext1.ext2") endif() cmake_path(GET path ROOT_NAME reference) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "ROOT_NAME returns bad data: ${output}") endif() cmake_path(GET path ROOT_DIRECTORY reference) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "ROOT_DIRECTORY returns bad data: ${output}") endif() cmake_path(GET path ROOT_PATH reference) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "ROOT_PATH returns bad data: ${output}") endif() cmake_path(GET path FILENAME reference) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "FILENAME returns bad data: ${output}") endif() cmake_path(GET path EXTENSION reference) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "EXTENSION returns bad data: ${output}") endif() cmake_path(GET path EXTENSION LAST_ONLY reference) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "EXTENSION LAST_ONLY returns bad data: ${output}") endif() cmake_path(GET path STEM reference) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "STEM returns bad data: ${output}") endif() cmake_path(GET path STEM LAST_ONLY reference) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "STEM LAST_ONLY returns bad data: ${reference}") endif() cmake_path(GET path RELATIVE_PART reference) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "RELATIVE_PART returns bad data: ${output}") endif() cmake_path(GET path PARENT_PATH reference) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "PARENT_PATH returns bad data: ${output}") endif() ###################################### ## second, tests with missing elements ###################################### set (path "aa/bb/") cmake_path(GET path ROOT_NAME reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "ROOT_NAME returns bad data: ${output}") endif() cmake_path(GET path ROOT_DIRECTORY reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "ROOT_DIRECTORY returns bad data: >${output}<, >${reference}<") endif() cmake_path(GET path ROOT_PATH reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "ROOT_PATH returns bad data: ${output}") endif() cmake_path(GET path FILENAME reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "FILENAME returns bad data: ${output}") endif() cmake_path(GET path EXTENSION reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "EXTENSION returns bad data: ${output}") endif() cmake_path(GET path STEM reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "STEM returns bad data: ${output}") endif() cmake_path(GET path RELATIVE_PART reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "RELATIVE_PART returns bad data: ${output}") endif() cmake_path(GET path PARENT_PATH reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "PARENT_PATH returns bad data: ${output}") endif() ################################## set (path "/aa/bb/") cmake_path(GET path ROOT_NAME reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "ROOT_NAME returns bad data: ${output}") endif() cmake_path(GET path ROOT_DIRECTORY reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "ROOT_DIRECTORY returns bad data: ${output}") endif() cmake_path(GET path ROOT_PATH reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "ROOT_PATH returns bad data: ${output}") endif() ################################### set (path "/") cmake_path(GET path ROOT_NAME reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "ROOT_NAME returns bad data: ${output}") endif() cmake_path(GET path ROOT_DIRECTORY reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "ROOT_DIRECTORY returns bad data: ${output}") endif() cmake_path(GET path ROOT_PATH reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "ROOT_PATH returns bad data: ${output}") endif() cmake_path(GET path FILENAME reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "FILENAME returns bad data: ${output}") endif() cmake_path(GET path EXTENSION reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "EXTENSION returns bad data: ${output}") endif() cmake_path(GET path STEM reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "STEM returns bad data: ${output}") endif() cmake_path(GET path RELATIVE_PART reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "RELATIVE_PART returns bad data: ${output}") endif() cmake_path(GET path PARENT_PATH reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "PARENT_PATH returns bad data: ${output}") endif() ################################### set (path ".file") cmake_path(GET path FILENAME reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "FILENAME returns bad data: ${output}") endif() cmake_path(GET path EXTENSION reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "EXTENSION returns bad data: ${output}") endif() cmake_path(GET path STEM reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "STEM returns bad data: ${output}") endif() ################################### set (path ".file.ext") cmake_path(GET path FILENAME reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "FILENAME returns bad data: ${output}") endif() cmake_path(GET path EXTENSION reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "EXTENSION returns bad data: ${output}") endif() cmake_path(GET path EXTENSION LAST_ONLY reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "EXTENSION returns bad data: ${output}") endif() cmake_path(GET path STEM reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "STEM returns bad data: ${output}") endif() ################################### set (path ".file.ext1.ext2") cmake_path(GET path FILENAME reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "FILENAME returns bad data: ${output}") endif() cmake_path(GET path EXTENSION reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "EXTENSION returns bad data: ${output}") endif() cmake_path(GET path EXTENSION LAST_ONLY reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "EXTENSION returns bad data: ${output}") endif() cmake_path(GET path STEM reference) set(output "$") if (NOT output STREQUAL reference) list (APPEND errors "STEM returns bad data: ${output}") endif() ###################################### ## third, tests with list of paths ###################################### if (WIN32) set (paths "C:/aa/bb/cc.ext1.ext2" "D:/xx/yy/zz.ext3.ext4") else() set (paths "/aa/bb/cc.ext1.ext2" "/xx/yy/zz.ext3.ext4") endif() function (compute_reference action) unset(reference) foreach (path IN LISTS paths) cmake_path(GET path ${ARGV} result) list(APPEND reference "${result}") endforeach() if (reference STREQUAL "") # define the list as 2 empty elements set(reference ";") endif() return(PROPAGATE reference) endfunction() compute_reference(ROOT_NAME) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "ROOT_NAME returns bad data: ${output}") endif() compute_reference(ROOT_DIRECTORY) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "ROOT_DIRECTORY returns bad data: ${output}") endif() compute_reference(ROOT_PATH) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "ROOT_PATH returns bad data: ${output}") endif() compute_reference(FILENAME) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "FILENAME returns bad data: ${output}") endif() compute_reference(EXTENSION) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "EXTENSION returns bad data: ${output}") endif() compute_reference(EXTENSION LAST_ONLY) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "EXTENSION LAST_ONLY returns bad data: ${output}") endif() compute_reference(STEM) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "STEM returns bad data: ${output}") endif() compute_reference(STEM LAST_ONLY) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "STEM LAST_ONLY returns bad data: ${reference}") endif() compute_reference(RELATIVE_PART) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "RELATIVE_PART returns bad data: ${output}") endif() compute_reference(PARENT_PATH) if (WIN32) set(output "$") else() set (output "$") endif() if (NOT output STREQUAL reference) list (APPEND errors "PARENT_PATH returns bad data: ${output}") endif() check_errors("PATH:GET..." ${errors})