3 Contributions to the cmake build configurations are welcome. Please
4 use case sensitivity that matches modern (i.e. cmake version 2.6 and above)
5 conventions of using lower-case for commands, and upper-case for
10 As cmake doesn't support command like `cmake clean`, it's recommended to perform an "out of source build".
11 To do this, you can create a new directory and build in it:
19 Then you can clean all cmake caches by simply delete the new directory:
21 rm -rf build/cmake/builddir
24 And of course, you can directly build in build/cmake:
31 To show cmake build options, you can:
33 cd build/cmake/builddir
37 Bool options can be set to `ON/OFF` with `-D[option]=[ON/OFF]`. You can configure cmake options like this:
39 cd build/cmake/builddir
40 cmake -DZSTD_BUILD_TESTS=ON -DZSTD_LEGACY_SUPPORT=OFF ..
44 ### how to use it with CMake FetchContent
46 For all options available, you can see it on <https://github.com/facebook/zstd/blob/dev/build/cmake/lib/CMakeLists.txt>
50 set(ZSTD_BUILD_STATIC ON)
51 set(ZSTD_BUILD_SHARED OFF)
55 URL "https://github.com/facebook/zstd/releases/download/v1.5.5/zstd-1.5.5.tar.gz"
56 DOWNLOAD_EXTRACT_TIMESTAMP TRUE
57 SOURCE_SUBDIR build/cmake
60 FetchContent_MakeAvailable(zstd)
62 target_link_libraries(
68 # On windows and macos this is needed
69 target_include_directories(
72 ${zstd_SOURCE_DIR}/lib
77 [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)
79 ## CMake Style Recommendations
81 ### Indent all code correctly, i.e. the body of
87 * function/endfunction
89 Use spaces for indenting, 2, 3 or 4 spaces preferably. Use the same amount of
90 spaces for indenting as is used in the rest of the file. Do not use tabs.
92 ### Upper/lower casing
94 Most important: use consistent upper- or lowercasing within one file !
96 In general, the all-lowercase style is preferred.
98 So, this is recommended:
101 add_executable(foo foo.c)
104 These forms are discouraged
107 ADD_EXECUTABLE(bar bar.c)
108 Add_Executable(hello hello.c)
109 aDd_ExEcUtAbLe(blub blub.c)
113 To make the code easier to read, use empty commands for endforeach(), endif(),
114 endfunction(), endmacro() and endwhile(). Also, use empty else() commands.
116 For example, do this:
130 some_other_command(...)
134 ### Other resources for best practices
136 https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#modules