# Creating a library split into multiple sub-modules

**URL:** https://discourse.cmake.org/t/creating-a-library-split-into-multiple-sub-modules/13569
**Category:** Usage
**Created:** [February 13, 2025, 7:27am UTC](https://discourse.cmake.org/t/creating-a-library-split-into-multiple-sub-modules/13569 "2025-02-13T07:27:35Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Tapiwa\_Zimunhu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tapiwa_zimunhu/32/5315_2.png) [@Tapiwa\_Zimunhu](https://discourse.cmake.org/u/Tapiwa_Zimunhu)
#### Post date: [February 13, 2025, 7:27am UTC](https://discourse.cmake.org/t/creating-a-library-split-into-multiple-sub-modules/13569/1 "2025-02-13T07:27:35Z")

</div>

I’m trying to create a huge library and have decided to modularize that project by developing it component by component so that I can easily test and develop each component separately.  
But in the end all these components need to be compiled into one single library.  
So my root CMakeLists.txt has a couple of `add_subdirectory()` calls.  
Each sub-component is compiled as a STATIC lib.

My challenge now is how do I make the root CMakeLists.txt compile everything into one single lib.

How do I call `add_library()` in such a case?

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [February 17, 2025, 11:21am UTC](https://discourse.cmake.org/t/creating-a-library-split-into-multiple-sub-modules/13569/2 "2025-02-17T11:21:05Z")

</div>

One option would be to create two CMake targets for each of the submodules: an `OBJECT` library which will contain the actual source files, settings, etc.; and a `STATIC` library which will only link the object library and be used for tests etc.

Then, in the root file, you can link all the object libraries into your final huge library.
