1*01826a49SYabin Cui# This module provides function for joining paths 2*01826a49SYabin Cui# known from most languages 3*01826a49SYabin Cui# 4*01826a49SYabin Cui# SPDX-License-Identifier: (MIT OR CC0-1.0) 5*01826a49SYabin Cui# Copyright 2020 Jan Tojnar 6*01826a49SYabin Cui# https://github.com/jtojnar/cmake-snips 7*01826a49SYabin Cui# 8*01826a49SYabin Cui# Modelled after Python’s os.path.join 9*01826a49SYabin Cui# https://docs.python.org/3.7/library/os.path.html#os.path.join 10*01826a49SYabin Cui# Windows not supported 11*01826a49SYabin Cuifunction(join_paths joined_path first_path_segment) 12*01826a49SYabin Cui set(temp_path "${first_path_segment}") 13*01826a49SYabin Cui foreach(current_segment IN LISTS ARGN) 14*01826a49SYabin Cui if(NOT ("${current_segment}" STREQUAL "")) 15*01826a49SYabin Cui if(IS_ABSOLUTE "${current_segment}") 16*01826a49SYabin Cui set(temp_path "${current_segment}") 17*01826a49SYabin Cui else() 18*01826a49SYabin Cui set(temp_path "${temp_path}/${current_segment}") 19*01826a49SYabin Cui endif() 20*01826a49SYabin Cui endif() 21*01826a49SYabin Cui endforeach() 22*01826a49SYabin Cui set(${joined_path} "${temp_path}" PARENT_SCOPE) 23*01826a49SYabin Cuiendfunction() 24