install(IMPORTED_RUNTIME_ARTIFACTS ...) tries to install IMPORTED_SONAME on Windows
I want to install a target and it's imported dependencies on both linux and Windows. I tried something like this:
cmake_minimum_required(VERSION 3.24)
project(myproj)
add_library(my_imported_lib SHARED IMPORTED)
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(MY_DLL_PATH "${CMAKE_SOURCE_DIR}/add.dll")
else()
set(MY_DLL_PATH "${CMAKE_SOURCE_DIR}/libadd.so")
endif()
set_target_properties(my_imported_lib PROPERTIES
IMPORTED_LOCATION "${MY_DLL_PATH}"
IMPORTED_SONAME "libadd.so"
IMPORTED_IMPLIB "${CMAKE_SOURCE_DIR}/add.lib"
)
add_executable(main main.cpp)
target_link_libraries(main PRIVATE my_imported_lib)
install(TARGETS main
RUNTIME DESTINATION runtime
COMPONENT main
LIBRARY DESTINATION library
COMPONENT main
)
install(IMPORTED_RUNTIME_ARTIFACTS my_imported_lib
RUNTIME DESTINATION runtime
COMPONENT main
LIBRARY DESTINATION library
COMPONENT main
)
But cmake --install . --component main --config Release --prefix=./install
fails with this error:
-- Installing: C:/myproj/build/./install/runtime/main.exe
-- Up-to-date: C:/myproj/build/./install/runtime/add.dll
CMake Error at cmake_install.cmake:54 (file):
file INSTALL cannot find
"C:/myproj/libadd.so": No error.
libadd.so
is intentionally not present on the system when building/installing my project on Windows.
Depending on the specific CMakeLists.txt
the "No error" message can also be "No such file or directory".
I expected the IMPORTED_SONAME
to be ignored on Windows and not to try and find a file with that name at all - is this behaviour intended?
The documentation for IMPORTED_SONAME
says "This is meaningful only on platforms supporting the feature". I interpreted this to mean that the property would be ignored on platforms that don't support the feature. Is the SONAME actually meaningful for Windows dlls?
- cmake-3.25.1
- Windows 10
- Visual Studio 2019
https://cmake.org/cmake/help/latest/prop_tgt/IMPORTED_SONAME.html
https://github.com/travbid/cmake-imported-soname