[CMake] checking arguments
David Cole
david.cole at kitware.com
Wed Feb 22 10:48:04 EST 2012
On Wed, Feb 22, 2012 at 10:36 AM, Andrea Crotti
<andrea.crotti.0 at gmail.com> wrote:
> I find not so nice that CMake doesn't complain at all if some variables are
> not defined.
> Is there a way to make it complain if a variable used is actually blank?
>
> In the meanwhile I ended up with this:
>
> set(COMPULSORY_ARGUMENTS PSI)
> set(OPTIONAL_ARGUMENTS WORKSPACE CONTAINER_PATHS)
>
> macro (check_compulsory_variable var)
> if (NOT DEFINED ${var})
> message(FATAL_ERROR "variable ${var} is not defined")
> endif ()
> endmacro ()
>
> macro (check_optional_variable var)
> if (NOT DEFINED ${var})
> message(WARNING "variable ${var} is not defined")
> endif ()
> endmacro ()
>
> foreach (arg ${COMPULSORY_ARGUMENTS})
> check_compulsory_variable(${arg})
> endforeach ()
>
> foreach (arg ${OPTIONAL_ARGUMENTS})
> check_optional_variable(${arg})
> endforeach ()
>
>
> which is not great but it does the job.
> Any better solutions?
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
You could try using the command line flags "--warn-uninitialized"
and/or "--warn-unused-vars" to produce warnings about such
situations...
More information about the CMake
mailing list