IPO support check fails if CUDA is specified before CXX in enabled languages (on Windows, with Clang)
test_ipo_windows_clang_cuda_cxx.zip
- Platform: Windows
- Compiler: clang++ or clang-cl
- Generator: Ninja
In a project with CUDA enabled, specifying CUDA before CXX breaks the cache generation.
The attachment serves as an example project.
cmake_minimum_required(VERSION 3.18)
# Platform: Windows
# Command: cmake -G Ninja -D CMAKE_CXX_COMPILER="clang++" <src path>
# It fails also with clang-cl
# It does not fail with MSVC
# project(TestProgram LANGUAGES CXX CUDA) # this works
project(TestProgram LANGUAGES CUDA CXX) # this does not
include(CheckIPOSupported)
check_ipo_supported(RESULT result OUTPUT output LANGUAGES CXX)
if(result)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
message(STATUS "Interprocedural Optimization is ON for CXX")
else()
message(SEND_ERROR "IPO is not supported: ${output}")
endif()
add_library(lib STATIC lib.cpp)
add_executable(test_program main.cpp)
target_link_libraries(test_program PRIVATE lib)
_CMakeError.log_
CXX compiler IPO check failed with the following output:
Change Dir: D:/test_ipo_windows_clang_cuda_cxx/build/CMakeFiles/_CMakeLTOTest-CXX/bin
Run Build Command(s):D:/PROGRA~1/Ninja/ninja.exe && [1/4] Building CXX object CMakeFiles\foo.dir\foo.cpp.obj
[2/4] Building CXX object CMakeFiles\boo.dir\main.cpp.obj
[3/4] Linking CXX static library foo.lib
FAILED: foo.lib
cmd.exe /C "cd . && D:\PROGRA~1\MICROS~2\2019\BUILDT~1\VC\Tools\MSVC\1428~1.293\bin\Hostx64\x64\lib.exe /machine:x64 /out:foo.lib CMakeFiles\foo.dir\foo.cpp.obj && cd ."
Microsoft (R) Library Manager Version 14.28.29336.0
Copyright (C) Microsoft Corporation. All rights reserved.
CMakeFiles\foo.dir\foo.cpp.obj : fatal error LNK1107: invalid or corrupt file: cannot read at 0xBEC
ninja: build stopped: subcommand failed.