install(TARGETS) behaves differently in one versus multiple calls
If you specify, for example:
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION "somepath/bin/"
LIBRARY DESTINATION "somepath/bin/"
ARCHIVE DESTINATION "somepath/lib"
PUBLIC_HEADER DESTINATION "somepath/inc/mylib"
)
Then CMake does not attempt to create anything under C:\Program Files (x86).
However, if you instead do:
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION "somepath/bin/"
LIBRARY DESTINATION "somepath/bin/"
ARCHIVE DESTINATION "somepath/lib"
)
install(TARGETS ${PROJECT_NAME}
PUBLIC_HEADER DESTINATION "somepath/inc/mylib"
)
Then CMake will attempt, and fail, to create C:\Program Files (x86)\TopLevelProjectName\
[7/8] Performing install step for 'linux_x86_64_Debug'
FAILED: linux_x86_64_Debug-prefix/src/linux_x86_64_Debug-stamp/linux_x86_64_Debug-install
cmd.exe /C "cd /D D:\builds\cmake-build\linux_x86_64_Debug-prefix\src\linux_x86_64_Debug-build && D:\cmake\3.20.1\bin\cmake.exe --build . --target install && D:\cmake\3.20.1\bin\cmake.exe -E touch D:/builds/cmake-build/linux_x86_64_Debug-prefix/src/linux_x86_64_Debug-stamp/linux_x86_64_Debug-install"
[0/2] Re-checking globbed directories...
[0/1] Install the project...
-- Install configuration: "Debug"
-- Installing: D:/builds/3rdparty/pub/gen/bin/l64/openssl-l64d-21-3.so
CMake Error at 3rdparty/pub/dists/openssl/cmake_install.cmake:67 (file):
file cannot create directory: C:/Program Files (x86)/MyTopLevelProjectName/lib. Maybe need
administrative privileges.
Call Stack (most recent call first):
3rdparty/pub/dists/cmake_install.cmake:52 (include)
3rdpartye/cmake_install.cmake:57 (include)
cmake_install.cmake:47 (include)
Potentially influencing factor: For all of my build types, I provide a CMAKE_TOOLCHAIN_FILE
value, but some of my toolchain files do not set the CMAKE_SYSTEM_NAME
, and others do. This issue appears to affect all of my configurations, regardless.
This issue does not appear to be related to using ExternalProject
, even though several other issues I've reported have been related to ExternalProject
.
You might ask why I would have two different install function calls, and the answer is that I have a wrapper function add_3rdparty_library()
that sets up third party libraries that my build includes to have the correct installation paths by default. However, each library needs to have it's own installation path for header files (e.g. inc/openssl, inc/zlib, so on), and as such, I must specify a different directory name for each library to install the header files. The easiest way to do this is to just have 3rdparty libs call the install()
function just for their PUBLIC_HEADERS, and not try to specify the behavior of the other artifact types, leaving the add_3rdparty_library()
to do it's work for those artifact types.