| 1 | # This module provides function for joining paths |
| 2 | # known from most languages |
| 3 | # |
| 4 | # Original license: |
| 5 | # SPDX-License-Identifier: (MIT OR CC0-1.0) |
| 6 | # Explicit permission given to distribute this module under |
| 7 | # the terms of the project as described in /LICENSE.rst. |
| 8 | # Copyright 2020 Jan Tojnar |
| 9 | # https://github.com/jtojnar/cmake-snips |
| 10 | # |
| 11 | # Modelled after Python’s os.path.join |
| 12 | # https://docs.python.org/3.7/library/os.path.html#os.path.join |
| 13 | # Windows not supported |
| 14 | function(join_paths joined_path first_path_segment) |
| 15 | set(temp_path "${first_path_segment}") |
| 16 | foreach(current_segment IN LISTS ARGN) |
| 17 | if(NOT ("${current_segment}" STREQUAL "")) |
| 18 | if(IS_ABSOLUTE "${current_segment}") |
| 19 | set(temp_path "${current_segment}") |
| 20 | else() |
| 21 | set(temp_path "${temp_path}/${current_segment}") |
| 22 | endif() |
| 23 | endif() |
| 24 | endforeach() |
| 25 | set(${joined_path} "${temp_path}" PARENT_SCOPE) |
| 26 | endfunction() |