Project layout
To build any project, we should start with a clear understanding of what logical targets are going to be created in it. In this case, we'll follow the structure shown in Figure 12.2:
Let's explore the structure by following the build order. First, we'll compile calc_obj
, which is an object library. We did mention object libraries a few times in the book, but we didn't actually introduce them as a concept. Let's do this now.
Object libraries
Object libraries are used to group multiple source files under a single logical target and are compiled into the (.o
) object files during a build. To create an object library, we use the same method as with other libraries with the OBJECT
keyword:
add_library(<target> OBJECT <sources>)
Object files produced during the build can be added as compiled elements to other targets with the $<TARGET_OBJECTS:objlib...