mirror of
1
0
Fork 0

Some fixes in the chapters

This commit is contained in:
Fabian Sandoval Saldias 2021-06-24 15:43:44 +00:00 committed by Henry Schreiner
parent 58b3678d2a
commit c1fc072441
5 changed files with 18 additions and 10 deletions

View File

@ -72,14 +72,21 @@ An example of a simple function is as follows:
```cmake
function(SIMPLE REQUIRED_ARG)
message(STATUS "Simple arguments: ${REQUIRED_ARG}, followed by ${ARGV}")
message(STATUS "Simple arguments: ${REQUIRED_ARG}, followed by ${ARGN}")
set(${REQUIRED_ARG} "From SIMPLE" PARENT_SCOPE)
endfunction()
simple(This)
simple(This Foo Bar)
message("Output: ${This}")
```
The output would be:
```
-- Simple arguments: This, followed by Foo;Bar
Output: From SIMPLE
```
If you want positional arguments, they are listed explicitly, and all other arguments are collected in `ARGN` (`ARGV` holds all arguments, even the ones you list). You have to work around the fact that CMake does not have return values by setting variables. In the example above, you can explicitly give a variable name to set.
## Arguments

View File

@ -14,7 +14,7 @@ if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
```

View File

@ -33,9 +33,9 @@ This is the command line for running clang-tidy, as a list (remember, a semicolo
Here is a simple example of using Clang-Tidy:
```bash
cmake -S . -B build-tidy -DCMAKE_CXX_CLANG_TIDY="$(which clang-tidy);-fix"
cmake --build build -j 1
```term
~/package # cmake -S . -B build-tidy -DCMAKE_CXX_CLANG_TIDY="$(which clang-tidy);-fix"
~/package # cmake --build build -j 1
```
The `-fix` part is optional, and will modify your source files to try to fix
@ -66,14 +66,14 @@ include-what-you-use`. Then, you can pass this into your build without
modifying the source:
```term
build # cmake -S . -B build-iwyu -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=include-what-you-use
~/package # cmake -S . -B build-iwyu -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=include-what-you-use
```
Finally, you can collect the output and (optionally) apply the fixes:
```term
build # cmake --build build-iwyu 2> iwyu.out
build # fix_includes.py < iwyu.out
~/package # cmake --build build-iwyu 2> iwyu.out
~/package # fix_includes.py < iwyu.out
```
(You should check the fixes first, or touch them up after applying!)

View File

@ -30,6 +30,7 @@ Any *one* of these commands will install:
~/package/build $ cmake --install . # CMake 3.15+ only
# From the source directory (pick one)
~/package $ make -C build install
~/package $ cmake --build build --target install
~/package $ cmake --install build # CMake 3.15+ only
{% endterm %}

View File

@ -21,7 +21,7 @@ if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()