The CMake build script breaks check_ipo_supported
- Dominant language
- C
- Stars
- 27.9k
- Forks
- 2.6k
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 8
Description
**Describe the bug**
[`check_ipo_supported`](https://cmake.org/cmake/help/latest/module/CheckIPOSupported.html) fails after adding `zstd` as a subdirectory.
**To Reproduce**
Steps to reproduce the behavior:
1. Here's a repro for the bug: https://github.com/andyroiiid/zstd-cmake-lto-bug.git
2. Clone the repo and run CMake
3. The configuring process will fail:
```
"C:\Users\username\AppData\Local\Programs\CLion 2\bin\cmake\win\x64\bin\cmake.exe" -DCMAKE_BUILD_TYPE=RelWithDebInfo "-DCMAKE_MAKE_PROGRAM=C:/Users/username/AppData/Local/Programs/CLion 2/bin/ninja/win/x64/ninja.exe" -G Ninja -S E:\Projects\zstd-cmake-lto-bug -B E:\Projects\zstd-cmake-lto-bug\cmake-build-relwithdebinfo
-- CMAKE_VERSION = 3.28.1
-- LANGUAGES = CXX;RC
-- ZSTD VERSION: 1.5.6
-- CMAKE_INSTALL_PREFIX: C:/Program Files (x86)/zstd_cmake_lto_bug
-- CMAKE_INSTALL_LIBDIR: lib
-- ZSTD_LEGACY_SUPPORT not defined!
-- ZSTD_MULTITHREAD_SUPPORT is enabled
-- LANGUAGES = ASM;C;CXX;RC
CMake Error at C:/Users/username/AppData/Local/Programs/CLion 2/bin/cmake/win/x64/share/cmake-3.28/Modules/CheckIPOSupported.cmake:68 (message):
IPO is not supported (CMake doesn't support IPO for current C compiler).
Call Stack (most recent call first):
C:/Users/username/AppData/Local/Programs/CLion 2/bin/cmake/win/x64/share/cmake-3.28/Modules/CheckIPOSupported.cmake:250 (_ipo_not_supported)
CMakeLists.txt:20 (check_ipo_supported)
-- Configuring incomplete, errors occurred!
[Finished]
```
Here's a copy of the CMakeLists.txt:
```cmake
cmake_minimum_required(VERSION 3.9)
project(zstd_cmake_lto_bug CXX)
set(CMAKE_CXX_STANDARD 20)
message(STATUS "CMAKE_VERSION = ${CMAKE_VERSION}")
include(CheckIPOSupported)
get_property(LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
message(STATUS "LANGUAGES = ${LANGUAGES}")
check_ipo_supported() # <----------------- This succeeds
add_subdirectory(zstd/build/cmake EXCLUDE_FROM_ALL)
get_property(LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
message(STATUS "LANGUAGES = ${LANGUAGES}")
check_ipo_supported() # <----------------- This fails
```
**Expected behavior**
`check_ipo_supported` should not fail after `zstd` is included.
**Screenshots and charts**
N/A
**Desktop:**
Repro environment 1:
- OS: Microsoft Windows 11 Home
- Version: 10.0.22631 Build 22631
- Compiler: Microsoft (R) C/C++ Optimizing Compiler Version 19.40.33811 for x64
- Flags: N/A - The bug happens before compilation.
- Other relevant hardware specs: i9-13950HX (Not exactly sure what to put here.)
- Build system: CMake
Repro environment 2:
- OS: Ubuntu 22.04 jammy
- Version: x86_64 Linux 5.15.0-107-generic
- Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
- Flags: N/A - The bug happens before compilation.
- Other relevant hardware specs: AMD Ryzen 5 PRO 2500U (Not exactly sure what to put here.)
- Build system: CMake
**Additional context**
I noticed that zstd adds `ASM` and `C` to the project language list. CMake will configure successfully if I change the project declaration from `project(zstd_cmake_lto_bug CXX)` to `project(zstd_cmake_lto_bug C CXX)`.
Contributor guide
Assessment
This issue has not been assessed yet.