facebook / zstd

Zstandard - Fast real-time compression algorithm
http://www.zstd.net
Other
22.77k stars 2.03k forks source link

The CMake build script breaks check_ipo_supported #4059

Open andyroiiid opened 1 month ago

andyroiiid commented 1 month ago

Describe the bug check_ipo_supported 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:

Repro environment 2:

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).