<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/88876>88876</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [OpenMP] CMake fails to install .dll.lib on MSVC
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          valgur
      </td>
    </tr>
</table>

<pre>
    When building OpenMP as a standalone with MSVC, `libomp.dll.lib` gets built as the import library, but CMake tries to install `libomp.lib` and fails.

OS: Windows 11
Compiler: Visual Studio 2022 / MSVC 19.38
CMake: both 3.21 and 3.29 fail
Configuration: x64 Release
Source version: openmp-18.1.3.src.tar.xz and cmake-18.1.3.src.tar.xz, but fails with v17 as well and older ones fail due to other reasons

Abbreviated build log:
```
$ cmake -B build src -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE="build/generators/conan_toolchain.cmake" -DCMAKE_POLICY_DEFAULT_CMP0091=NEW
$ cmake --build build --config Release
MSBuild version 17.8.3+195e7f5a3 for .NET Framework
 Generating libomp.def
     Creating library build/runtime/src/Release/libomp.dll.lib and object build/runtime/src/Release/libomp.dll.exp
  omp.vcxproj -> build\runtime\src\Release\libomp.dll
  Generating libomp.imp.def

$ cmake --install build --config Release --prefix package
-- Installing: package/bin/libomp.dll
CMake Error at runtime/src/cmake_install.cmake:51 (file):
  file INSTALL cannot find
 "build/runtime/src/Release/libomp.lib":
  File exists.
```
`cmake_toolchain.cmake`:
```cmake
set(BUILD_SHARED_LIBS ON)
set(OPENMP_STANDALONE_BUILD ON)
set(LIBOMP_ENABLE_SHARED ON)
set(LIBOMP_INSTALL_ALIASES OFF)
set(LIBOMP_OMPT_SUPPORT OFF)
set(OPENMP_ENABLE_LIBOMPTARGET OFF)
set(OPENMP_MSVC_NAME_SCHEME ON) # Fails with ON as well
```

Related to this PR on Conan Center Index: https://github.com/conan-io/conan-center-index/pull/22353

I wonder what I'm doing wrong since it seems unlikely for such a basic error to have persisted for so many versions? I did not find any similar issues or PRs either.

----

There are two potential fixes that I can suggest.
1. Keep the `.dll.lib` suffix and fix the installed file name:
https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/openmp/runtime/src/CMakeLists.txt#L306
```patch
--- openmp/runtime/src/CMakeLists.txt
+++ openmp/runtime/src/CMakeLists.txt
@@ -315,7 +315,7 @@
     # making it a .txt which CMAKE will filter out from the librarian (a .cpp will make lib.exe punt trying to resolve the .def symbols)
 add_library(${LIBOMP_IMP_LIB_TARGET} STATIC kmp_dummy.txt)
 set_target_properties(${LIBOMP_IMP_LIB_TARGET} PROPERTIES
-        PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_IMP_LIB_FILE}" LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE}
+        PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_GENERATED_IMP_LIB_FILENAME}" LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE}
         STATIC_LIBRARY_OPTIONS "${CMAKE_LINK_DEF_FILE_FLAG}${CMAKE_CURRENT_BINARY_DIR}/${LIBOMPIMP_GENERATED_DEF_FILE}")
 add_dependencies(${LIBOMP_IMP_LIB_TARGET} libompimp-needed-def-file)
 add_dependencies(omp ${LIBOMP_IMP_LIB_TARGET})
```
2. Change the suffix to `.lib` to match the installed file name:
https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/openmp/runtime/src/CMakeLists.txt#L267
```patch
--- openmp/runtime/src/CMakeLists.txt
+++ openmp/runtime/src/CMakeLists.txt
@@ -276,7 +276,7 @@
     endif()
 else()
     set(LIBOMP_IMP_LIB_FILE ${LIBOMP_LIB_NAME}${CMAKE_IMPORT_LIBRARY_SUFFIX})
- set(LIBOMP_GENERATED_IMP_LIB_FILENAME ${LIBOMP_LIB_FILE}${CMAKE_STATIC_LIBRARY_SUFFIX})
+ set(LIBOMP_GENERATED_IMP_LIB_FILENAME ${LIBOMP_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
   endif()
 set_target_properties(omp PROPERTIES
     VERSION ${LIBOMP_VERSION_MAJOR}.${LIBOMP_VERSION_MINOR} # uses /version flag
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWFtz4rgS_jXOS5ddWOb6kAcDdsZnuBWQmbNPLtkWoI0suSQ5l_PrT0m2CZDMzM7uy1IpAlL3162-fGqMlaJHTsi9M5g6g_kdrvVJyPtnzI61vMtE8Xb__UQ4ZDVlBeVHWFeELzeAFWBQGvMCM8EJvFB9guXu28xBM3CGPUYzUVZewZjHaOYMe3AkWlkYbZT1iQAtKyE1MJpJLN-MYlZrmC3xEwEtKVGgBVCuNGbsArPFw7yAA6ZMeU5v7vTC5n29c4IQvlNeiBcFvt-szkRZUUak2ftGVY0Z7HRdUAGohxA4KLa-gz_xgnGrYtww8pnQJwg85FuLgYcm1mwHzA_0WEusqeBG-nXYhy1hBCvSSOxELXMCz0SqVkRUhJeV64893ws8JXNPY-m9_s_i5yV-Ih_3uuDYAzfBfvZHJpAvhDGrKVhBJAhOlJWCoiYmfkKfiARJsBJcXUYqzDJJninWpGiyC0wcnaDddYa99q_5ivqNa-BOW2klc3AfwEHoOqL-yAbVQQjc-WwZfo3S_Xq9mH0Jk1UaJ4vICeYOQhbEQfGRcCKxFlI5KM4FxzzVQrD8hCn3rMlLpM16kcz-SOdRHD4u9ulsuen1Jr4TzFfR9w-euo2jzbvr5jZX19lZ7qZ2t00P-CNv7AUOmvqTARkdBjiAg5DgraI9xBKX5EXIp0YVHhrPTVN01U4O7Z55zSQ575oCh-7IsuaalsRBsZK5g-LOIxRfd02T1uxPkuvf0yWvVeeHWXrOXysp_gTXCaIWaDDrgAYzAzSYdUCD2TtQB_LxpPTytB8D3zXt56EH160kOdBXqHD-hI9tLlwXkkaPclOI510UZ5RfnfCiRSGSUkjAGm5DY51JW1faUgrCgQ8OGh8o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