From c1fc07244133ef9d11b6188ec27511ebad95fab9 Mon Sep 17 00:00:00 2001 From: Fabian Sandoval Saldias Date: Thu, 24 Jun 2021 15:43:44 +0000 Subject: [PATCH] Some fixes in the chapters --- chapters/basics/functions.md | 11 +++++++++-- chapters/basics/programs.md | 2 +- chapters/features/utilities.md | 12 ++++++------ chapters/intro/running.md | 1 + chapters/projects/submodule.md | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/chapters/basics/functions.md b/chapters/basics/functions.md index 1d7643c..921819d 100644 --- a/chapters/basics/functions.md +++ b/chapters/basics/functions.md @@ -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 diff --git a/chapters/basics/programs.md b/chapters/basics/programs.md index fa08628..8e4d998 100644 --- a/chapters/basics/programs.md +++ b/chapters/basics/programs.md @@ -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() ``` diff --git a/chapters/features/utilities.md b/chapters/features/utilities.md index f49aba4..18c0b32 100644 --- a/chapters/features/utilities.md +++ b/chapters/features/utilities.md @@ -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!) diff --git a/chapters/intro/running.md b/chapters/intro/running.md index 5b04cce..bfa0d8d 100644 --- a/chapters/intro/running.md +++ b/chapters/intro/running.md @@ -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 %} diff --git a/chapters/projects/submodule.md b/chapters/projects/submodule.md index 5940c9d..6e90bca 100644 --- a/chapters/projects/submodule.md +++ b/chapters/projects/submodule.md @@ -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()