Screenplay: Public And Private Include Directories

Motivation

  • file-util.h and file-util.cpp

  • Used only in base/

  • ⟶ asymmetry: not all files installed (file-util.h isn’t)

  • file-util.h is visible

  • Modifications

    • sensor-w1.cpp

    • sysfs-switch.cpp

Move Code Around: toolcase/base/

$ mkdir -p include/{public,private} src
$ git mv file-util.h  include/private/
$ git mv *.h include/public/
$ git mv *.cpp src/
$ tree
.
├── CMakeLists.txt
├── include
│   ├── private
│   │   └── file-util.h
│   └── public
│       ├── hysteresis.h
│       ├── sensor-avg.h
│       ├── sensor-const.h
│       ├── sensor.h
│       ├── sensor-random.h
│       ├── sensor-w1.h
│       ├── switch.h
│       └── sysfs-switch.h
└── src
    ├── file-util.cpp
    ├── hysteresis.cpp
    ├── sensor-avg.cpp
    ├── sensor-const.cpp
    ├── sensor-random.cpp
    ├── sensor-w1.cpp
    └── sysfs-switch.cpp

Adjust CMakeLists.txt

  • Much typing

  • ⟶ variables for include/public/*.h, include/private/*.h, src/*.cpp

  • Note: variables are inherited into subdirectories (add_subdirectory())

Won’t compile! ⟶ Fix errors one by one …

Local Compilation In toolcase/base/

  • include/public not seen by local compilation

    .../src/sensor-const.cpp:1:10: fatal error: sensor-const.h: No such file or directory
        1 | #include "sensor-const.h"
          |          ^~~~~~~~~~~~~~~~
    

    Solution:

    target_include_directories(base PRIVATE ./include/public)
    
  • include/private not seen by local compilation

    .../src/sensor-w1.cpp:3:10: fatal error: file-util.h: No such file or directory
        3 | #include "file-util.h"
          |          ^~~~~~~~~~~~~
    

    Solution:

    target_include_directories(base PRIVATE ./include/private)
    

Dependent Nodes: toolcase/boiling-pot/ And toolcase/data-logger/

  • toolcase/base/include/public/ not seen from using nodes; e.g.

    .../toolcase/boiling-pot/boiling-pot.h:3:10: fatal error: sensor.h: No such file or directory
        3 | #include "sensor.h"
          |          ^~~~~~~~~~
    

    Solution: in toolcase/base/CMakeLists.txt,

    target_include_directories(base INTERFACE ./include/public)
    

Final Note: And PUBLIC?

In toolcase/base/CMakeLists.txt, we have

target_include_directories(base PRIVATE ./include/public)
target_include_directories(base INTERFACE ./include/public)

That is the same as

target_include_directories(base PUBLIC ./include/public)

Final Final Note: include_directories()

Why Noy Use include_directories() For That