cmake --build build doesn't work but make does for tutorial step 1

Win11 Home (x86-64)
cygwin 3.7.0
/usr/bin/cmake 4.2.1

I am totally confused. I am going through the tutorial and at the end of Step 1 Exercise 2 I have created a CMakeLists.txt file which generates a working Makefile but for which > cmake --build build generates an error saying there is no rule for making the MathFunctions target. In looking at the TODO expansions it looks like they are the same as in my CMakeLists.txt file. Any idea what I’ve done wrong?

Another issue is the statement that I have to include #include <MathFunctions.h>. I have tried all of the following followed by > make:

  1. Failure: #include <MathFunctions.h>
  2. Success: #include "MathFunctions/MathFunctions.h"
  3. Success: no include statement?

I guess I can understand 1 & 2. I did something wrong. But 3?

shell > clear;rm -rf build/*;cmake -B build;cmake --build build

Diagnostic message

gmake[2]: *** No rule to make target '/d/home/skidmarks/Projects/Test/cmake/src/MathFunctions/MathFunctions.cpp', needed by 'CMakeFiles/MathFunctions.dir/MathFunctions/MathFunctions.cpp.o'. Stop.
gmake[1]: *** [CMakeFiles/Makefile2:122: CMakeFiles/MathFunctions.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2

File CMakeLists.txt

# TODO1: Set the minimum required version of CMake to be 3.23
cmake_minimum_required(VERSION 3.23)

# TODO2: Create a project named Tutorial
project(Tutorial)

# TODO3: Add an executable target called Tutorial to the project
add_executable(Tutorial)

# TODO4: Add the Tutorial/Tutorial.cxx source file to the Tutorial target
target_sources(Tutorial PRIVATE Tutorial.cpp)

# TODO7: Add the MathFunctions library as a linked dependency
# to the Tutorial target
target_link_libraries(Tutorial PRIVATE MathFunctions)

# TODO11: Add the Tutorial subdirectory to the project

# TODO5: Add a library target called MathFunctions to the project
add_library(MathFunctions)

# TODO6: Add the source and header file located in Step1/MathFunctions to the
# MathFunctions target, note that the intended way to include the
# MathFunctions header is:
# 
#include <MathFunctions.h>
target_sources(MathFunctions
   PRIVATE  MathFunctions/MathFunctions.cpp

   PUBLIC
      FILE_SET mathheaders
         TYPE        HEADERS
         BASE_DIRS   MathFunctions
         FILES       MathFunctions/MathFunctions.h
)

# TODO13: Add the MathFunctions subdirectory to the project

It’s actually a very small error: Nothing to do with the headers at all.

The file in MathFunctions/ is named MathFunctions.cxx, not MathFunctions.cpp.

(And, actually, the file in Tutorial/ is named Tutorial.cxx, also. Not Tutorial.cpp.)

The CMake tutorial is from an older time, when the .cxx extension for C++ files was more common. (See also, the fact that you use project(... LANGUAGES CXX), not project(... LANGUAGES CPP), when configuring a C++ project.)

The CMake source code also uses the .cxx extension exclusively, so you can’t say they’re not at least consistent.

@FeRd

Using .cpp instead of .cxx is deliberate. Are you saying that CMake internals requires that C++ files be named .cxx and .hpp and that the error generated is because the naming convention is not followed?