[CMake] Policy Stack within Macros/Functions

Sérgio Agostinho sergio.r.agostinho at gmail.com
Sun Oct 20 13:25:09 EDT 2019


Hey everyone,

I’m shipping a config file for my library and inside I set push/pop
specific policies so that me and the consumers of my library can target
different policies without us clashing against each other. However I’m
struggling with |cmake_policy(PUSH)|/|cmake_policy(POP)| once they are
invoked from macro/functions.

Here’s a minimal failure example illustrating my problem

|project(pcl-config-test) cmake_minimum_required(VERSION 3.5)
cmake_policy(PUSH) macro(return_early) # clean up code cmake_policy(POP)
return() endmacro() # 1. do a bunch of things. invoke a couple of
macros/functions # from within other macros/functions, etc... # 2. some
error occurs if(ERROR) return_early() endif() # 3. Everything went well
cmake_policy(POP) |

This produces the following output

|CMake Error at CMakeLists.txt:27 (my_macro): cmake_policy POP without
matching PUSH CMake Error in CMakeLists.txt: cmake_policy PUSH without
matching POP -- Configuring incomplete, errors occurred! |

I was counting on the policy stack being preserved for at least macros,
but that is not the case.

Is there a way for me to return early from my config file from within
macros?

Best regards,

Sérgio

​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20191020/680e6b8d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://cmake.org/pipermail/cmake/attachments/20191020/680e6b8d/attachment.sig>


More information about the CMake mailing list