CheckIPOSupported: Never detects LTO/IPO for Clang on Windows
Hello i'm trying the following code in my CMake:
if (CMAKE_BUILD_TYPE STREQUAL "Release")
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT output)
if (ipo_supported)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
message(STATUS "We are in release - Successfully enabled IPO")
else ()
message(WARNING "IPO NOT SUPPORTED - Skipping reason: ${output}")
endif ()
endif ()
And i always get:
CMake Warning at CMakeLists.txt:63 (message):
IPO NOT SUPPORTED - Skipping reason: Change Dir:
C:/Users/Public/Documents/atomicDEX-Desktop/cmake-build-release/CMakeFiles/_CMakeLTOTest-CXX/bin
Run Build Command(s):C:/ProgramData/scoop/shims/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
[4/4] Linking CXX executable boo.exe
FAILED: boo.exe
cmd.exe /C "cd . && C:\ProgramData\scoop\shims\clang++.exe
-fuse-ld=lld-link -nostartfiles -nostdlib -g -Xclang -gcodeview -O0
-D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -flto
CMakeFiles/boo.dir/main.cpp.obj -o boo.exe -Xlinker /implib:boo.lib
-Xlinker /pdb:boo.pdb -Xlinker /version:0.0 foo.lib -lkernel32 -luser32
-lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32
-ladvapi32 -loldnames && cmd.exe /C "cd /D
C:\Users\Public\Documents\atomicDEX-Desktop\cmake-build-release\CMakeFiles\_CMakeLTOTest-CXX\bin
&& C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile
-executionpolicy Bypass -file
C:/Users/Public/Documents/atomicDEX-Desktop/ci_tools_atomic_dex/vcpkg-repo/scripts/buildsystems/msbuild/applocal.ps1
-targetBinary
C:/Users/Public/Documents/atomicDEX-Desktop/cmake-build-release/CMakeFiles/_CMakeLTOTest-CXX/bin/boo.exe
-installedDir
C:/Users/Public/Documents/atomicDEX-Desktop/ci_tools_atomic_dex/vcpkg-repo/installed/x64-windows/debug/bin
-OutVariable out""
lld-link: error: undefined symbol: int __cdecl foo(void)
>>> referenced by
C:/Users/Public/Documents/atomicDEX-Desktop/cmake-build-release/CMakeFiles/_CMakeLTOTest-CXX/src/main.cpp
>>> CMakeFiles/boo.dir/main.cpp.obj
clang++: error: linker command failed with exit code 1 (use -v to see
invocation)
ninja: build stopped: subcommand failed.
Is there any reason ?
Compiler infos:
PS C:\Users\Public\Documents\atomicDEX-Desktop> clang --version
clang version 11.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\ProgramData\scoop\apps\llvm\current\bin
CMake version: 3.19.2
full CMake to reproduce:
cmake_minimum_required(VERSION 3.19.2)
project(cmake_lto)
set(CMAKE_CXX_STANDARD 20)
if (CMAKE_BUILD_TYPE STREQUAL "Release")
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT output)
if (ipo_supported)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
message(STATUS "We are in release - Successfully enabled IPO")
else ()
message(WARNING "IPO NOT SUPPORTED - Skipping reason: ${output}")
endif ()
endif ()
add_executable(cmake_lto main.cpp)
Note: -flto=thin is not used even if it's available: https://clang.llvm.org/docs/ThinLTO.html
Usage on windows:
clang-cl -flto=thin -O2 -c file1.c file2.c
% lld-link /out:a.exe file1.obj file2.obj