xref: /aosp_15_r20/external/tink/cmake/TinkUtil.cmake (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1# Copyright 2019 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# Create an alias for SOURCE, called DESTINATION.
16#
17# On platforms that support them, this rule will effectively create a symlink.
18#
19# SOURCE may be relative to CMAKE_CURRENT_SOURCE_DIR, or absolute.
20# DESTINATION may relative to CMAKE_CURRENT_BINARY_DIR, or absolute.
21#
22# Adapted from https://github.com/google/binexport/blob/master/util.cmake
23function(add_directory_alias SOURCE DESTINATION)
24  get_filename_component(_destination_parent "${DESTINATION}" DIRECTORY)
25  file(MAKE_DIRECTORY "${_destination_parent}")
26
27  if (WIN32)
28    file(TO_NATIVE_PATH "${SOURCE}" _native_source)
29    file(TO_NATIVE_PATH "${DESTINATION}" _native_destination)
30    execute_process(COMMAND $ENV{ComSpec} /c mklink /J "${_native_destination}" "${_native_source}" ERROR_QUIET)
31  else()
32    execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${SOURCE}" "${DESTINATION}")
33  endif()
34endfunction(add_directory_alias)
35