See also

We note that, as of version 3.12 of CMake, OBJECT libraries are another viable approach to organizing large projects. The only modification to our example would be in the CMakeLists.txt for the libraries. The sources would be compiled into object files: neither archived into a static archive, nor linked into a shared library. For example:

add_library(io OBJECT "")target_sources(io  PRIVATE    io.cpp  PUBLIC    ${CMAKE_CURRENT_LIST_DIR}/io.hpp  )target_include_directories(io  PUBLIC    ${CMAKE_CURRENT_LIST_DIR}  )

The top-level CMakeLists.txt remains unchanged: the automata executable target links these object files into the final executable. Usage requirements, such as include directories, compile flags, and link libraries set on the OBJECT ...

Get CMake Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.