Install on matlab mex targets fails if archive/library output directory is set to the same location
I ran into an issue with mex targets with 3.22.1.
If you try to install mex targets to the location they already exist with no prefix set cmake will remove the file and then fail to find it and fail. The same behavior works fine with standard shared or static libraries.
example to reproduce:
IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
SET(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR} CACHE PATH "PREFIX DIR" FORCE)
ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
message(STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
find_package(Matlab REQUIRED)
matlab_add_mex(NAME my_mex SRC my_mex.c)
install(TARGETS my_mex DESTINATION lib)
Removing the OUTPUT directories or setting a install prefix resolves the issue, but trying to install to to where the file already exists causes a cmake error.