CMake install(TARGETS) does not check whether destination
Using CMake 3.12.2.
Consider the following project:
project(myproject)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "" FORCE)
add_executable(myprog hello.cpp)
install(TARGETS myprog
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
make install
builds myprog
, then it disappears, then CMake reports an error that it cannot find it (file INSTALL cannot find "path_to_build_directory/bin/myprog"
).
Apparently CMake removes the file at the destination for some reason before attempting the copy operation, which breaks everything if the source and destination happen to be the same.
install(FILES ...)
actually checks for an existing destination file and whether it matches the source file before attempting to copy anything, so I'm confused that install(TARGETS ...)
behaves fundamentally differently.
Someone else brought up the same issue on stackoverflow: https://stackoverflow.com/questions/52576869/why-make-install-is-deleting-library-files-so-generated-by-make
This is probably going to force me to create separate paths in my build system for development versus deployment.