When installing same shared library to multiple components, generated cmake_install.cmake is incorrect
We have a project here that needs to install a certain shared library to multiple components, so that it is available to the components that use that library regardless of installer component selection. However, that does not seem to be working correctly for Windows builds. I've reduced to a small test case:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
project(foolib)
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME base)
add_library(foolib SHARED foolib.cpp)
install(TARGETS foolib
RUNTIME DESTINATION bin
LIBRARY DESTINATION bin
COMPONENT base)
install(TARGETS foolib
RUNTIME DESTINATION bin2
LIBRARY DESTINATION bin2
COMPONENT cmp2)
foolib.cpp:
#ifdef _WIN32
__declspec(dllexport)
#endif
int foo(int n) {
return n*n + 3;
}
On Linux, the generated cmake_install.cmake file is correct. However, on Windows with CMake version 3.12.2, the generated cmake_install.cmake file installs both copies to component "base" (example from the "NMake Makefiles" generator's cmake_install.cmake is below - but I've also reproduced it with "NMake Makefiles JOM" and "Visual Studio 15 2017 Win64" generators):
if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xbasex" OR NOT CMAKE_INSTALL_COMPONENT)
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" TYPE SHARED_LIBRARY FILES "B:/cmake-install-test/builddir/foolib.dll")
endif()
if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xbasex" OR NOT CMAKE_INSTALL_COMPONENT)
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/bin2" TYPE SHARED_LIBRARY FILES "B:/cmake-install-test/builddir/foolib.dll")
endif()
Edited by Daniel Schepler