Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake override policy for subproject

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 ?

like image 309
Piezoid Avatar asked Mar 21 '17 09:03

Piezoid


1 Answers

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
like image 86
Florian Avatar answered Oct 21 '22 02:10

Florian