Debian Codegraph @

cmake/kde_macro/KritaToNativePath.cmake

raw
1 # SPDX-FileCopyrightText: 2021 Dmitry Kazakov <[email protected]>
2 #
3 # SPDX-License-Identifier: BSD-3-Clause
4 #
5
6 # krita_to_native_path(<path_list> <output_var>)
7 #
8 # Converts path separators of the list <path_list> into the native format
9 # and stores the result in <output_var>
10 #
11 # Usage:
12 #
13 # krita_to_native_path("${KRITA_PYTHONPATH}" _krita_pythonpath)
14
15 function (krita_to_native_path path_list output_var)
16 if(WIN32)
17 if(${CMAKE_VERSION} VERSION_LESS "3.20.0")
18 foreach (_path ${path_list})
19 string(REPLACE "//" "/" _path "${_path}")
20 string(REPLACE "/" "\\" _path "${_path}")
21 list(APPEND _output_var "${_path}")
22 endforeach()
23
24 set (${output_var} ${_output_var} PARENT_SCOPE)
25 else()
26 cmake_path(CONVERT "${path_list}" TO_NATIVE_PATH_LIST _output_var NORMALIZE)
27 set (${output_var} ${_output_var} PARENT_SCOPE)
28 endif()
29 else()
30 set (${output_var} ${path_list} PARENT_SCOPE)
31 endif()
32 endfunction()
33
34
35 # krita_to_native_environment_path_list(<path_list> <output_var>)
36 #
37 # Converts the list of paths in <path_list> into the native format
38 # and then joins them into a string suitable to be assigned to
39 # PATH (or PATH-like) variable. On Windows the string is joined
40 # using ';' separator. On other platforms with ':' separator.
41 #
42 # To avoid conversion back to a list object, the function adds
43 # separators in a form of generators: $<SEMICOLON> or $<COLON>
44 #
45 # Usage:
46 #
47 # krita_to_native_environment_path_list("${KRITA_PYTHONPATH}" _krita_pythonpath)
48
49
50 function (krita_to_native_environment_path_list path_list output_var)
51 krita_to_native_path("${path_list}" _output_var)
52
53 if(WIN32)
54 list(JOIN _output_var $<SEMICOLON> _output_var)
55 else()
56 list(JOIN _output_var $<COLON> _output_var)
57 endif()
58
59 set (${output_var} ${_output_var} PARENT_SCOPE)
60 endfunction()