[cmake-developers] [PATCH] Wrap ARGV1 and ARGV2 in quotes to avoid errors when they are empty

Stephen Kelly steveire at gmail.com
Thu Mar 13 11:15:54 EDT 2014


Aurélien Gâteau wrote:

>> Here is an updated patch.

Hi,

Without your patch with this code:

 find_dependency(Foo "")

I get:

 CMake Error at .*/Modules/CMakeFindDependencyMacro.cmake:34 (if):
   if given arguments:

     "STREQUAL" "EXACT"

   Unknown arguments specified
 Call Stack (most recent call first):
   CMakeLists.txt:20 (find_dependency)


and I can use that information and backtrace to find the bug in my code. 

If I write this code:

 find_dependency(Foo problem)

I get

 CMake Error at .*/Modules/CMakeFindDependencyMacro.cmake:62 (find_package):
   find_package called with invalid argument "problem"
 Call Stack (most recent call first):
   CMakeLists.txt:20 (find_dependency)


Does that case need to be handled in the find_dependency macro too? Does it 
need to validate that the version is a number? 

How strongly do you feel about this? Macros are already very hard to write 
correctly, and I am concerned that making the implementation more 
complicated where not needed is likely to lead to more bugs.

For me, letting the existing APIs (like if() and find_package()) do the 
error checking is better than attempting to wrap and validate everything in 
a macro.

Thanks,

Steve.





More information about the cmake-developers mailing list