zstd/build/cmake/README.md

105 lines
2.2 KiB
Markdown
Raw Normal View History

# 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
Spelling (#1582) * spelling: accidentally * spelling: across * spelling: additionally * spelling: addresses * spelling: appropriate * spelling: assumed * spelling: available * spelling: builder * spelling: capacity * spelling: compiler * spelling: compressibility * spelling: compressor * spelling: compression * spelling: contract * spelling: convenience * spelling: decompress * spelling: description * spelling: deflate * spelling: deterministically * spelling: dictionary * spelling: display * spelling: eliminate * spelling: preemptively * spelling: exclude * spelling: failure * spelling: independence * spelling: independent * spelling: intentionally * spelling: matching * spelling: maximum * spelling: meaning * spelling: mishandled * spelling: memory * spelling: occasionally * spelling: occurrence * spelling: official * spelling: offsets * spelling: original * spelling: output * spelling: overflow * spelling: overridden * spelling: parameter * spelling: performance * spelling: probability * spelling: receives * spelling: redundant * spelling: recompression * spelling: resources * spelling: sanity * spelling: segment * spelling: series * spelling: specified * spelling: specify * spelling: subtracted * spelling: successful * spelling: return * spelling: translation * spelling: update * spelling: unrelated * spelling: useless * spelling: variables * spelling: variety * spelling: verbatim * spelling: verification * spelling: visited * spelling: warming * spelling: workers * spelling: with
2019-04-12 11:18:11 -07:00
variables.
2019-09-14 10:15:35 -07:00
## How to build
2019-09-14 10:15:35 -07:00
As cmake doesn't support command like `cmake clean`, it's recommended to perform a "out of source build".
To do this, you can create a new directory and build in it:
```sh
cd build/cmake
mkdir builddir
cd builddir
cmake ..
make
```
2019-09-14 10:15:35 -07:00
Then you can clean all cmake caches by simply delete the new directory:
```sh
rm -rf build/cmake/builddir
```
And of course, you can directly build in build/cmake:
```sh
cd build/cmake
cmake
make
```
To show cmake build options, you can:
```sh
cd build/cmake/builddir
cmake -LH ..
```
2019-09-14 10:15:35 -07:00
Bool options can be set to `ON/OFF` with `-D[option]=[ON/OFF]`. You can configure cmake options like this:
```sh
cd build/cmake/builddir
cmake -DZSTD_BUILD_TESTS=ON -DZSTD_LEGACY_SUPPORT=ON ..
make
```
2019-09-14 10:15:35 -07:00
### referring
[Looking for a 'cmake clean' command to clear up CMake output](https://stackoverflow.com/questions/9680420/looking-for-a-cmake-clean-command-to-clear-up-cmake-output)
2019-09-14 10:15:35 -07:00
## CMake Style Recommendations
2019-09-14 10:15:35 -07:00
### 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.
2019-09-14 10:15:35 -07:00
### 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)
```
2019-09-14 10:15:35 -07:00
### 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)
```
2019-09-14 10:15:35 -07:00
### Other resources for best practices
2019-09-14 10:15:35 -07:00
https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#modules