From: Hans Johnson Date: Mon, 24 Dec 2018 13:06:31 +0000 (-0600) Subject: DOC: Provide documentation for cmake best practices. X-Git-Tag: v1.3.8~5^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=443b5c40e4104099b75d36a2ba2a1d1a65aaf7aa;p=thirdparty%2Fzstd.git DOC: Provide documentation for cmake best practices. --- diff --git a/build/cmake/README.md b/build/cmake/README.md new file mode 100644 index 000000000..0c71a54ad --- /dev/null +++ b/build/cmake/README.md @@ -0,0 +1,65 @@ +# Cmake contributions + +Contributions to the cmake build configurations are welcome. Please +use case sensitivity that matches modern (ie. cmake version 2.6 and above) +conventions of using lower-case for commands, and upper-case for +varibles. + +# CMake Style Recommendations + +## Indent all code correctly, i.e. the body of + + * if/else/endif + * foreach/endforeach + * while/endwhile + * macro/endmacro + * function/endfunction + +Use spaces for indenting, 2, 3 or 4 spaces preferably. Use the same amount of +spaces for indenting as is used in the rest of the file. Do not use tabs. + +## Upper/lower casing + +Most important: use consistent upper- or lowercasing within one file ! + +In general, the all-lowercase style is preferred. + +So, this is recommended: + +``` +add_executable(foo foo.c) +``` + +These forms are discouraged + +``` +ADD_EXECUTABLE(bar bar.c) +Add_Executable(hello hello.c) +aDd_ExEcUtAbLe(blub blub.c) +``` + +## End commands +To make the code easier to read, use empty commands for endforeach(), endif(), +endfunction(), endmacro() and endwhile(). Also, use empty else() commands. + +For example, do this: + +``` +if(FOOVAR) + some_command(...) +else() + another_command(...) +endif() +``` + +and not this: + +``` +if(BARVAR) + some_other_command(...) +endif(BARVAR) +``` + +## Other resources for best practices + +`https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#modules`