1
0

CMake: Don't create symlinks if link == orig.

This commit is contained in:
Mattes D 2019-12-28 20:39:00 +01:00
parent 2d6f6a574d
commit 5df6d4f535

View File

@ -344,31 +344,41 @@ SET_TARGET_PROPERTIES(${CMAKE_PROJECT_NAME} PROPERTIES
# Create a symbolic link from ${orig} to ${link} # Create a symbolic link from ${orig} to ${link}
# If the orig and link point to the same thing, does nothing (-> in-source build)
# If ${link} already exists, does nothing. # If ${link} already exists, does nothing.
function(make_symlink orig link) function(make_symlink orig link)
# Get OS dependent path to use in `execute_process` # Get OS dependent path to use in `execute_process`
message("Creating symlink, orig = ${orig}; link = ${link}")
file(TO_NATIVE_PATH "${orig}" orig) file(TO_NATIVE_PATH "${orig}" orig)
file(TO_NATIVE_PATH "${link}" link) file(TO_NATIVE_PATH "${link}" link)
if (NOT EXISTS ${link}) # If both are the same, or link already exists, bail out:
if (CMAKE_HOST_UNIX) if ("${orig}" STREQUAL "${link}")
set(command ln -s ${orig} ${link}) return()
endif()
if (EXISTS ${link})
return()
endif()
# Create the symlink (platform-dependent):
message("Creating symlink, orig = ${orig}; link = ${link}")
if (CMAKE_HOST_UNIX)
set(command ln -s ${orig} ${link})
else()
if (IS_DIRECTORY ${orig})
set(command cmd.exe /c mklink /j ${link} ${orig})
else() else()
if (IS_DIRECTORY ${orig}) set(command cmd.exe /c mklink /h ${link} ${orig})
set(command cmd.exe /c mklink /j ${link} ${orig})
else()
set(command cmd.exe /c mklink /h ${link} ${orig})
endif()
endif() endif()
endif()
execute_process(COMMAND ${command} execute_process(
RESULT_VARIABLE result COMMAND ${command}
ERROR_VARIABLE output) RESULT_VARIABLE result
ERROR_VARIABLE output
)
if (NOT ${result} EQUAL 0) if (NOT ${result} EQUAL 0)
message(FATAL_ERROR "Could not create symbolic link for: ${link} --> ${orig}: ${output}") message(FATAL_ERROR "Could not create symbolic link for: ${link} --> ${orig}: ${output}")
endif()
endif() endif()
endfunction(make_symlink) endfunction(make_symlink)