@@ -37,10 +37,10 @@ understanding of its fundamentals.
3737
3838## 1. Command-line usage  
3939
40- [ CMake] ( https://cmake.org/ )  is an open-source cross-platform build system
41- generator created by Kitware and contributors. It is invoked on command line 
42- using ` cmake `  command. When working with CMake, there are two primary phases: 
43- the configuration and generation phase, followed by the build phase.
40+ [ CMake] ( https://cmake.org/ )  is an open-source,  cross-platform build system
41+ generator created by Kitware and contributors. It is invoked from the command 
42+ line  using the  ` cmake `  command. When working with CMake, there are two primary
43+ phases:  the configuration and generation phase, followed by the build phase.
4444
4545### 1.1. Configuration and generation phase  
4646
@@ -71,7 +71,7 @@ cmake --build build-directory --parallel
7171>  source directory (when source and build directories are the same):
7272> 
7373>  ``` sh 
74- >  cmake . 
74+ >  cmake .    #  Same as: cmake -S . -B . 
7575>  cmake --build .  --parallel
7676>  ` ` ` 
7777> 
@@ -81,10 +81,8 @@ cmake --build build-directory --parallel
8181>  within the source  directory:
8282> 
8383>  ` ` `  sh
84- >  mkdir build-directory
85- >  cd  build-directory
86- >  cmake ..
87- >  cmake --build .  --parallel
84+ >  cmake -B build-directory
85+ >  cmake --build build-directory --parallel
8886>  ` ` ` 
8987
9088# # 2. CMakeLists.txt
@@ -282,18 +280,32 @@ project. There are primarily two types: libraries and executables.
282280add_executable(php php.c php_2.c ...) 
283281
284282# Create a library target 
285- add_library(extension OBJECT|MODULE|SHARED|STATIC extension.c src.c ...) 
283+ add_library(extension extension.c src.c ...) 
284+ ``` 
285+ 
286+ Library can also have a type specified. For example, a shared library:
287+ 
288+ ``` cmake 
289+ add_library(extension SHARED extension.c src.c) 
286290``` 
287291
288- The keywords ` OBJECT ` , ` MODULE ` , ` SHARED ` , and ` STATIC `  specify how the library
289- is built. ` OBJECT `  libraries will compile source files to binary object files
290- without the linking step. These objects can be then referenced in other CMake
291- targets. ` SHARED `  libraries can be linked dynamically or dynamically loaded at
292- program runtime with ` dlopen() `  on * nix systems, or ` LoadLibrary() `  on Windows.
293- ` MODULE `  library is a special CMake concept that prevents such targets to be
294- linked dynamically with ` target_link_libraries() `  and are intended to be only
295- dynamically loaded during runtime. ` STATIC `  library is an archive of built
296- object files that can be linked to other targets.
292+ >  [ !IMPORTANT] 
293+ >  There are several library types:
294+ > 
295+ >  ``` cmake 
296+ > add_library(<name> [OBJECT|MODULE|SHARED|STATIC] <sources>...) 
297+ > ``` 
298+ > 
299+ > The keywords `OBJECT`, `MODULE`, `SHARED`, and `STATIC` specify how the 
300+ > library is built. `OBJECT` libraries will compile source files to binary 
301+ > object files without the linking step. These objects can be then referenced in 
302+ > other CMake targets. `SHARED` libraries can be linked dynamically or 
303+ > dynamically loaded at program runtime with `dlopen()` on *nix systems, or 
304+ > `LoadLibrary()` on Windows. `MODULE` library is a special CMake concept that 
305+ > prevents such targets to be linked dynamically with `target_link_libraries()` 
306+ > and are intended to be only dynamically loaded during runtime. `STATIC` 
307+ > library is an archive of built object files that can be linked to other 
308+ > targets. 
297309
298310The concepts of executable and library targets can be illustrated through 
299311examples of using a compiler like `gcc`. 
@@ -323,9 +335,9 @@ gcc -c -o src.o src.c
323335
324336### 4.3. SHARED library  
325337
326- CMake automatically adds sensible linker flags when building SHARED library. For 
327- example, ` -shared ` , ` -Wl,-soname,extension.so ` , position-independent code flag 
328- ` -fPIC ` , and similar.
338+ CMake automatically adds sensible linker flags when building ` SHARED `  library.
339+ For  example, ` -shared ` , ` -Wl,-soname,extension.so ` , position-independent code
340+ flag  ` -fPIC ` , and similar.
329341
330342``` sh 
331343#  Compile each source file to a binary object file with the -fPIC
@@ -337,10 +349,10 @@ gcc -fPIC -shared -Wl,-soname,extension.so -o extension.so extension.o src.o
337349
338350### 4.4. MODULE library  
339351
340- The MODULE library, on the other hand, is similar to the SHARED. However, CMake 
341- uses slightly different flags and treats it differently in CMake code. A MODULE 
342- library cannot be linked with ` target_link_libraries() `  in CMake, and certain 
343- handling inside CMake differs.
352+ The ` MODULE `  library, on the other hand, is similar to the ` SHARED ` . However,
353+ CMake  uses slightly different flags and treats it differently in CMake code. A
354+ ` MODULE `   library cannot be linked with ` target_link_libraries() `  in CMake, and
355+ certain  handling inside CMake differs.
344356
345357``` sh 
346358#  Compile each source file to a binary object file with the -fPIC
@@ -350,8 +362,8 @@ gcc -fPIC -c -o src.o src.c
350362gcc -fPIC -shared -o extension.so extension.o src.o
351363``` 
352364
353- Both MODULE and SHARED libraries can be loaded with ` dlopen ` -alike functionality 
354- during program runtime. For example:
365+ Both ` MODULE `  and ` SHARED `  libraries can be loaded with ` dlopen ` -alike
366+ functionality  during program runtime. For example:
355367
356368``` c 
357369/*  main.c */ 
@@ -370,7 +382,7 @@ int main(void)
370382
371383### 4.5. STATIC library 
372384
373- STATIC libraries are intended to be linked statically to other libraries or 
385+ ` STATIC`  libraries are intended to be linked statically to other libraries or
374386executables where they become part of the final binary. 
375387
376388```sh 
0 commit comments