Skip to content
Mark Gates edited this page Jul 13, 2023 · 1 revision

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" )

Clone this wiki locally