-
Notifications
You must be signed in to change notification settings - Fork 23
cmake
From 1
-
Quote variables that are strings: they might be empty, which if not quoted would cause a syntax error.
set( var "foo" ) if ("${var}" STREQUAL "bar") # ok if (${var} STREQUAL "bar") # bug if var is empty!
-
Do not quote variables that are booleans:
set( var true ) if (var) # ok if (
${var}) # bug if var is empty! if ("$ {var}") # maybe ok? In old CMake, var would be interpreted twice, but that's fixed. -
Do not quote variables that are lists:
set( args "--foo" "--bar" ) execute_process( COMMAND foo
${args} ) # ok: foo "--foo" "--bar" (2 args) execute_process( COMMAND foo "$ {args}" ) # bug: foo "--foo --bar" (1 arg) -
Do not end paths with / which can lead to //, which is a bug on Windows.
set( path "/path/to/foo" ) # ok set( path "/path/to/foo/" ) # leads to // bug in next line set( file "${path}/bar.txt" )