install/strip broken when absolute DESTINATION is used in install() (on Windows)
While trying to figure out #16858 I realized an absolute DESTINATION
in install()
commands completely breaks the install/strip
target:
For a minimal CMakeLists
project (hello)
add_executable(hello helloworld.cpp)
install (TARGETS hello DESTINATION "E:\\bin")
the following output is created in cmake_install.cmake
file(INSTALL DESTINATION "E:/bin" TYPE EXECUTABLE FILES "E:/Temp/Project/build/hello.exe")
if(EXISTS "$ENV{DESTDIR}/E:/bin/hello.exe" AND
NOT IS_SYMLINK "$ENV{DESTDIR}/E:/bin/hello.exe")
if(CMAKE_INSTALL_DO_STRIP)
execute_process(COMMAND "C:/msys64/mingw64/bin/strip.exe" "$ENV{DESTDIR}/E:/bin/hello.exe")
endif()
endif()
Obviously already the call to if(EXISTS ...)
is bound to fail due to the illegal $ENV{DESTDIR}/
prefix.
Even for relative paths this is prone to failure:
For a minimal CMakeLists (now with relative path)
project (hello)
add_executable(hello helloworld.cpp)
install (TARGETS hello DESTINATION "bin")
the following output is created in cmake_install.cmake
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" TYPE EXECUTABLE FILES "E:/Temp/Project/build/hello.exe")
if(EXISTS "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/hello.exe" AND
NOT IS_SYMLINK "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/hello.exe")
if(CMAKE_INSTALL_DO_STRIP)
execute_process(COMMAND "C:/msys64/mingw64/bin/strip.exe" "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/hello.exe")
endif()
endif()
As soon as CMAKE_INSTALL_PREFIX
is set to an absolute path (for example the default C:\Program Files
, but also pretty much any path variable CMake has to offer) the code will fail if DESTDIR
is defined.
As a matter of fact I believe ${CMAKE_INSTALL_PREFIX}
even has to be absolute (unless I'm missing something) as relative paths would be relative to the root of the hard drive. (At least if I use DCMAKE_INSTALL_PREFIX=""
in the example the executable ends up in E:\bin\
)