CMake子项目的覆盖策略(CMake override policy for subproject)

编程入门 行业动态 更新时间:2024-10-24 00:26:50
CMake子项目的覆盖策略(CMake override policy for subproject)

我的CMake项目编译了一个与大型静态库链接的Python .so / .dylib扩展模块。 我想编译具有隐藏的符号可见性的子项目的静态库:它将允许链接器(或LTO优化器)丢弃我的python模块未使用的符号。

最好的方法是在子项目的静态库目标上使用CXX_VISIBILITY_PRESET和朋友。 但是,子项目通过声明:使用3.1.0中的策略:

cmake_minimum_required (VERSION 3.1.0)

策略CMP0063 NEW: Honor visibility properties for all target types. 仅从版本3.3引入,因此set_target_properties没有任何效果。

我的项目需要CMake 3.3,但我无法控制子项目。

我想避免修补子项目CMakeLists.txt,但目前我没有别的办法。

任何想法 ?

My CMake project compiles a Python .so/.dylib extension module linked with a big static library. I want to compile the subproject's static library with hidden visibility for symbols : it would allows the linker (or LTO optimizer) to discard symbols unused by my python module.

The best way to do this would be using CXX_VISIBILITY_PRESET and friends on the subproject's static library target. However, the subproject use policies from 3.1.0 by declaring :

cmake_minimum_required (VERSION 3.1.0)

The policy CMP0063 NEW: Honor visibility properties for all target types. is only introduced from version 3.3 and thus, the set_target_properties have no effects.

My project requires CMake 3.3, but I have no control on the subproject.

I would like to avoid patching the subproject CMakeLists.txt, but currently I see no other way.

Any idea ?

最满意答案

cmake_minimum_required()对CMake策略具有以下影响:

指定版本或更早版本中引入的所有策略都将设置为使用NEW行为。 将取消设置指定版本之后引入的所有策略。

但是你可以使用CMake的CMAKE_POLICY_DEFAULT_CMP<NNNN>全局变量来“默认为CMake Policy CMP,否则它将被取消设置”。

这是一个例子:

set(CMAKE_POLICY_DEFAULT_CMP0063 NEW) add_subdirectory(MySubProjDir)

参考

CMake:忽略外部模块的警告

The cmake_minimum_required() has the following effects on the CMake policies:

All policies introduced in the specified version or earlier will be set to use NEW behavior. All policies introduced after the specified version will be unset.

But you can use CMake's CMAKE_POLICY_DEFAULT_CMP<NNNN> global variables to "default for CMake Policy CMP when it is otherwise left unset."

Here is an example:

set(CMAKE_POLICY_DEFAULT_CMP0063 NEW) add_subdirectory(MySubProjDir)

Reference

CMake: ignore the warnings of external modules

更多推荐

本文发布于:2023-04-28 01:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1330269.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:策略   项目   CMake   subproject   policy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!