llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.13k stars 11.11k forks source link

[OpenMP] CMake fails to install .dll.lib on MSVC #88876

Open valgur opened 3 months ago

valgur commented 3 months ago

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 (the full one can be seen here https://gist.github.com/valgur/cc65918157c6e9835492cb19ab160e6a):

$ 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:

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
    --- 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
    --- 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
llvmbot commented 3 months ago

@llvm/issue-subscribers-openmp

Author: Martin Valgur (valgur)

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 (the full one can be seen here https://gist.github.com/valgur/cc65918157c6e9835492cb19ab160e6a): ``` $ 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 ```