Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vvvar/juce-conan

Unofficial Conan 2.0 recipe for JUCE Framework
https://github.com/vvvar/juce-conan

conan conan-recipe juce juce-framework

Last synced: 4 months ago
JSON representation

Unofficial Conan 2.0 recipe for JUCE Framework

Awesome Lists containing this project

README

        

# JUCE 7 Unofficial Conan 2.0 Recipe

This repository contains a recipe that makes [JUCE 7](https://juce.com) available as [Conan 2.0](https://docs.conan.io/2/) Package.

## Pre-requisites

Install:
- [Conan 2.0.2+](https://docs.conan.io/2/installation.html)

Read:
- [Conan 2.0 Getting Started](https://docs.conan.io/2/tutorial/consuming_packages.html)
- [JUCE Cmake Documentation](https://github.com/juce-framework/JUCE/blob/master/docs/CMake%20API.md)

## How to use

1. Create JUCE Conan Package with desired options(see all available options in [How to configure](#how-to-configure) chapter):
```sh
$ conan create . --options build_extras=True
```

2. Add it as a requirement in your Conan project:
```python
# conanfile.py
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout

class MyProject(ConanFile):
name = "MyPlugin"
version = "0.4.2"
user = "octocat"
channel = "testing"
settings = "os", "arch", "compiler", "build_type"

requires = "juce/7.0.5@juce/release" # Require JUCE
default_options = { # Configure it
"juce/*:build_extras": True
}

def layout(self):
cmake_layout(self)

def generate(self):
toolchain = CMakeToolchain(self)
toolchain.generate()
dependencies = CMakeDeps(self)
dependencies.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
```

3. Add it to your `CMakeList.txt`. Similar to the [find package approach](https://github.com/juce-framework/JUCE/blob/master/docs/CMake%20API.md#using-find_package):
```cmake
# CMakeList.txt
project(MyPlugin)

# Place it early, after `project()`
find_package(JUCE CONFIG REQUIRED)

# You can use standard JUCE CMake functions
juce_add_plugin(MyPlugin
PLUGIN_MANUFACTURER_CODE Ocat
PLUGIN_CODE Ocode
LV2URI "https://example.com"
FORMATS AU VST3 LV2 Standalone
VST3_CATEGORIES Fx Distortion Dynamics
AU_MAIN_TYPE kAudioUnitType_Effect
COMPANY_NAME "octocompany"
PRODUCT_NAME "MyPlugin"

# Just as normal JUCE CMake project
target_sources(MyPlugin
PRIVATE
Source/PluginEditor.cpp
Source/PluginProcessor.cpp)

# And link with JUCE libraries
target_link_libraries(MyPlugin
PRIVATE
juce::juce_dsp
juce::juce_audio_utils
juce::juce_audio_plugin_client
PUBLIC
juce::juce_recommended_config_flags
juce::juce_recommended_lto_flags
juce::juce_recommended_warning_flags)
```

4. Build as a normal Conan project:
```sh
$ conan install . && conan build .
```

## How to configure

All options of this recipe are just proxies for [already existing JUCE CMake Build Options](https://github.com/juce-framework/JUCE/blob/master/docs/CMake%20API.md#options):
- `build_extras` corresponds to [`JUCE_BUILD_EXTRAS`](https://github.com/juce-framework/JUCE/blob/master/docs/CMake%20API.md#juce_build_extras)
- `build_examples` corresponds to [`JUCE_BUILD_EXAMPLES`](https://github.com/juce-framework/JUCE/blob/master/docs/CMake%20API.md#juce_build_examples)
- `enable_module_source_groups` corresponds to [`JUCE_BUILD_EXAMPLES`](https://github.com/juce-framework/JUCE/blob/master/docs/CMake%20API.md#juce_build_examples)
- `copy_plugin_after_build` corresponds to [`JUCE_COPY_PLUGIN_AFTER_BUILD`](https://github.com/juce-framework/JUCE/blob/master/docs/CMake%20API.md#juce_copy_plugin_after_build)

All defaults follow the same rules as in JUCE. For example, if you haven't provided `build_extras` then Conan will set it to `False`, just as JUCE does.

## How does it work
1. Get the tagged version of JUCE that matches with version of this recipe
2. Translate Conan Options into [JUCE CMake Options](https://github.com/juce-framework/JUCE/blob/master/docs/CMake%20API.md#options)
3. Disable Conan's `XXXConfig.cmake` generation feature and force it to use the original `JUCEConfig.cmake` generated by JUCE
3. Build it and store it in the cache

## Versioning
This recipe follows the same versioning scheme as JUCE. This means that `7.0.5` version of this recipe corresponds to [`7.0.5 version of JUCE`](https://github.com/juce-framework/JUCE/releases/tag/7.0.5).

## Tips & Troubleshooting

### How can I change the CMake generator?

By default, Conan will ask CMake to use `Unix Makefiles` generator. You can change that by configuring `CMakeToolchain` in your `conanfile.py`. For example, if you want to use `Visual Studio 17 2022` for Windows and `Ninja` for everything else, then you need to modify your `def generate(self)`:` as follows:
```python
def generate(self):
toolchain = CMakeToolchain(self)
if self.settings.os == "Windows":
toolchain.generator = "Visual Studio 17 2022"
else:
toolchain.generator = "Ninja"
```

### I'm receiving `Missing prebuilt package` while building my project

If you're receiving this error:
```sh
ERROR: Missing prebuilt package for 'juce/7.0.5@juce/release'
```
then it means that you haven't built JUCE Conan Package with the correct options/settings.
For example, you've built it with `build_extras=False`:
```sh
$ conan create . --options build_extras=False
```
but in your project, it is required with `build_extras=True`:
```python
# conanfile.py
requires = "juce/7.0.5@juce/release"
default_options = {
"juce/*:build_extras": True # <-- Here, should match
}
```
Therefore, Conan would not be able to find a pre-build JUCE Conan Package in your cache because settings/options in your cache and your requirements should 1-1 match(see the [detailed explanation from Conan Docs](https://docs.conan.io/2/knowledge/faq.html?highlight=settings#error-missing-prebuilt-package)).
Thus, you should either create JUCE Conan Package with the correct options/settings:
```sh
$ conan create . --options build_extras=True
```
or, in your project, explicitly state that you'd like to build missing dependencies from the sources:
```sh
$ conan install . --build=missing && conan build .
```