Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions xmake/modules/package/tools/cmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,10 @@ function _get_configs(package, configs, opt)
_get_configs_for_generic(package, configs, opt)
end

if not opt._configs_str:find("CMAKE_INTERPROCEDURAL_OPTIMIZATION", 1, true) then
table.insert(configs, "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=" .. (package:config("lto") and "ON" or "OFF"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

既然已经直接打 lto flags 进去了,为啥还要这个?跟现有打的 lto flags 冲突么?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有些库会探测是否有这个选项,如果没有就开启 lto。比如 clang ci 链接还是用的 gnu ld,就链接失败了

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前直接设置了 lto flags ,thin lto/full lto ,我不确定 CMAKE_INTERPROCEDURAL_OPTIMIZATION 用的是哪个,如果不一致,应该会有冲突问题。

不建议两个同时设置,如果设置了 CMAKE_INTERPROCEDURAL_OPTIMIZATION,那就不要再直接传递 lto flags

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那这个选项只传 off 就好了,lto flags 只让 xmake 传递。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有些库会探测是否有这个选项,如果没有就开启 lto。比如 clang ci 链接还是用的 gnu ld,就链接失败了

只传 off 不就又有这个问题了么。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 直接硬编码 set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) 的,只能手动 patch (msvc runtime 同理
  2. 有检测代码。只传 off 就是解决这种。
if(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
  set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
endif()

end

-- fix error for cmake 4.x
-- e.g. Compatibility with CMake < 3.5 has been removed from CMake.
if _get_cmake_version() and _get_cmake_version():ge("4.0") then
Expand Down
Loading