1
0
mirror of synced 2024-12-22 20:50:00 +01:00

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 ```cmake
function(SIMPLE REQUIRED_ARG) 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) set(${REQUIRED_ARG} "From SIMPLE" PARENT_SCOPE)
endfunction() endfunction()
simple(This) simple(This Foo Bar)
message("Output: ${This}") 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. 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 ## Arguments

View File

@ -14,7 +14,7 @@ if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT) RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0") 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() 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: Here is a simple example of using Clang-Tidy:
```bash ```term
cmake -S . -B build-tidy -DCMAKE_CXX_CLANG_TIDY="$(which clang-tidy);-fix" ~/package # cmake -S . -B build-tidy -DCMAKE_CXX_CLANG_TIDY="$(which clang-tidy);-fix"
cmake --build build -j 1 ~/package # cmake --build build -j 1
``` ```
The `-fix` part is optional, and will modify your source files to try to fix 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: modifying the source:
```term ```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: Finally, you can collect the output and (optionally) apply the fixes:
```term ```term
build # cmake --build build-iwyu 2> iwyu.out ~/package # cmake --build build-iwyu 2> iwyu.out
build # fix_includes.py < iwyu.out ~/package # fix_includes.py < iwyu.out
``` ```
(You should check the fixes first, or touch them up after applying!) (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 ~/package/build $ cmake --install . # CMake 3.15+ only
# From the source directory (pick one) # From the source directory (pick one)
~/package $ make -C build install
~/package $ cmake --build build --target install ~/package $ cmake --build build --target install
~/package $ cmake --install build # CMake 3.15+ only ~/package $ cmake --install build # CMake 3.15+ only
{% endterm %} {% endterm %}

View File

@ -21,7 +21,7 @@ if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT) RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0") 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() endif()
endif() endif()