On Sun, 2019-10-20 at 19:25 +0200, Sérgio Agostinho wrote: > 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?
If you're trying to set policies within a function, set them at the module level rather than at the function level. The module-level policy settings will automatically be pushed when you call the function. That way, there will be no need to do cmake_policy(POP) within return_early(). Kyle -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake