"cmake --install ." doesn't work on Windows
For the test, the source code of zlib was used.
MS VS 2022 comes with CMake 3.24.
I was hoping for a bug fix in 3.26, but it got worse.
d:\dev\zlib-1.2.13>cmake --version
cmake version 3.26.0-rc2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
set CMAKE_BUILD_TYPE=Release
set CMAKE_GENERATOR=Ninja
d:\dev\zlib-1.2.13>cmake --fresh . && cmake --build .
d:\dev\zlib-1.2.13>cmake --install .
-- Install configuration: "Release"
CMake Error at cmake_install.cmake:44 (file):
file cannot create directory: C:/Program Files (x86)/zlib/lib. Maybe need
administrative privileges.
OK. This is fine. But why "(x86)" for x64?
d:\dev\zlib-1.2.13>cmake --help
--install-prefix <directory> = Specify install directory [CMAKE_INSTALL_PREFIX].
--install <dir> = Install a CMake-generated project binary tree.
d:\dev\zlib-1.2.13>cmake --install-prefix d:\dev\zlib-1.2.13\_install --install .
CMake Error: Unknown argument --install
CMake Error: Run 'cmake --help' for all supported options.
d:\dev\zlib-1.2.13>cmake -DCMAKE_INSTALL_PREFIX=d:\dev\zlib-1.2.13\_install --install .
CMake Error: Unknown argument --install
CMake Error: Run 'cmake --help' for all supported options.
d:\dev\zlib-1.2.13>cmake --install . --prefix d:\dev\zlib-1.2.13\_install
-- Install configuration: "Release"
CMake Error at cmake_install.cmake:44 (file):
file cannot create directory: C:/Program Files (x86)/zlib/lib. Maybe need
administrative privileges.
d:\dev\zlib-1.2.13>set "CMAKE_INSTALL_PREFIX=d:\dev\zlib-1.2.13\_install"
d:\dev\zlib-1.2.13>cmake --install .
-- Install configuration: "Release"
CMake Error at cmake_install.cmake:44 (file):
file cannot create directory: C:/Program Files (x86)/zlib/lib. Maybe need
administrative privileges.
The cmake_install.cmake is written with "C:/Program Files (x86)/zlib" and --prefix will not replace the folder path. Other commands don't work too.
if(CMAKE_INSTALL_COMPONENT STREQUAL "Unspecified" OR NOT CMAKE_INSTALL_COMPONENT)
list(APPEND CMAKE_ABSOLUTE_DESTINATION_FILES
"C:/Program Files (x86)/zlib/lib/zlib.lib")
if(CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)
message(WARNING "ABSOLUTE path INSTALL DESTINATION : ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
endif()
if(CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)
message(FATAL_ERROR "ABSOLUTE path INSTALL DESTINATION forbidden (by caller): ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
endif()
# line 44:
file(INSTALL DESTINATION "C:/Program Files (x86)/zlib/lib" TYPE STATIC_LIBRARY OPTIONAL FILES "D:/dev/zlib-1.2.13/zlib.lib")
endif()
This hack is also broken:
set "DESTDIR=d:/dev/zlib-1.2.13/_install"
set "CMAKE_PREFIX_PATH=d:/dev/zlib-1.2.13/_install"
set "CMAKE_INSTALL_PREFIX=d:/dev/zlib-1.2.13/_install"
set CMAKE_INSTALL_MODE=COPY
set CMAKE_BUILD_TYPE=Release
set CMAKE_GENERATOR=Ninja
rem d:\dev\zlib-1.2.13
cmake --fresh . && cmake --build .
cmake_install.cmake from 3.26.0-rc2
# Set the install prefix
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "C:/Program Files (x86)/zlib")
endif()
cmake_install.cmake from 3.24
# Set the install prefix
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "d:/dev/zlib-1.2.13/_install/Program Files (x86)/zlib")
endif()