# How to create a static library that use JUCE in official CMake?

**URL:** <https://forum.juce.com/t/how-to-create-a-static-library-that-use-juce-in-official-cmake/50080>\
**Category:** Development\
**Created:** [February 8, 2022, 7:33am UTC](https://forum.juce.com/t/how-to-create-a-static-library-that-use-juce-in-official-cmake/50080 "2022-02-08T07:33:31Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [February 8, 2022, 10:58am UTC](https://forum.juce.com/t/how-to-create-a-static-library-that-use-juce-in-official-cmake/50080/3 "2022-02-08T10:58:06Z")

</div>

> [@jiandingzhe](#):
>
> Recently I noticed JUCE have provided official CMake support. However it seems I can’t make JUCE-dependent static libraries with it?

The new CMake support was intended to make it easy for people to migrate from Projucer projects, while allowing users to write idiomatic modern(ish) CMake scripts. Before we added CMake support, the overwhelming majority of our users consume JUCE code through JUCE Modules, rather than using custom static/dynamic libraries, so this is the use-case for which we optimised.

Additionally, it can be dangerous to reuse the same JUCE object files across multiple projects if each project requires different module options. When sharing a JUCE static library between targets, you _must_ make sure that all dependent targets use exactly the same set of JUCE modules and module configuration flags.

All of that being said, if you’re aware of the dangers then you could use an approach such as the one described in the following post to create a JUCE staticlib:

> [@Using CMake flow to build libraries, Android apps](https://forum.juce.com/t/using-cmake-flow-to-build-libraries-android-apps/40492/20):
>
> FWIW I’ve got something like this working (staticlibs depending on JUCE) with the following sort of setup: # Set up JUCE library add\_library(juce\_plugin\_modules OBJECT) target\_link\_libraries(juce\_plugin\_modules PRIVATE juce::juce\_audio\_utils juce::juce\_dsp PUBLIC juce::juce\_recommended\_config\_flags juce::juce\_recommended\_warning\_flags) target\_compile\_definitions(juce\_plugin\_modules PUBLIC JucePlugin\_Build\_Standalone=1 JUCE\_STANDALONE…

From there, it’s straightforward to make your own staticlib targets that depend on the custom JUCE staticlib.

---

_[View the full topic](https://forum.juce.com/t/how-to-create-a-static-library-that-use-juce-in-official-cmake/50080)._
