[cmake-developers] Making Config.cmake files safer

Brad King brad.king at kitware.com
Tue Nov 15 16:50:51 EST 2011


On 11/15/2011 3:54 PM, Alexander Neundorf wrote:
> Maybe you'll prefer a more map-like implementation ?

Yes.

I don't like the function because it pollutes the global namespace of
functions.  I took great care to design imported targets so they only
affect a directory namespace.  They are very lightweight and have no
effects outside the reporting directory.

Someday I'd like to scope macros and functions too but that will be
another policy/compatibility nightmare.

> list(APPEND _check_targets foo)
> set(_filesToCheck_foo libfoo.dll libfoo.lib)
> ...
> list(APPEND _check_targets bar)
> set(_filesToCheck_bar libbar.dll libbar.lib)
> ...
>
> foreach(target ${_check_targets} )
>    foreach(file ${_filesToCheck_${target}})
>      if (NOT EXISTS ${file})
>        message(FATAL_ERROR "...")
>      endif()
>    endforeach()
+    unset(_filesToCheck_${target})
> endforach()
+ unset(_check_targets)

That looks good.  Just add the lines I show above starting in '+' so that
the export() command's APPEND mode does not accumulate and repeat checks,
and so that the variables are left clean at the end of the import.  Also,
I think the variable names should be

   _IMPORT_CHECK_TARGETS
   _IMPORT_CHECK_FILES_IN_${target}

to match the _IMPORT_PREFIX convention already used.

Thanks,
-Brad



More information about the cmake-developers mailing list