Hi everyone,
I’m trying to convert an Open Source plugin, currently under development to the new CMake build system – mainly to learn a bit. My CMake knowledge is a very limited, I found my way around using it somehow in the past, but I’d really like to learn how to do it right
So, my current project, which can be found here has a folder structure like
root
Source
[all the source files here]
Ext
JUCE --> Juce included as sumodule
JBPluginBase --> My own repository containing a JUCE module named jb_plugin_base included as submodule
BinaryRessources
SVGs
[a bunch of svg files here]
So here is my initial approach:
- I placed the CMakeList.txt file in the root folder
- For the sources folder I created a variable like
set (Sources ${PROJECT_SOURCE_DIR}/Source)
and then undertarget_sources
I add them like${Sources}/Foo.cpp
,${Sources}/bar.cpp
- For the SVGs I did something similar, setting
set (SVGAssets ${PROJECT_SOURCE_DIR}/BinaryRessources/SVGs)
and then callingjuce_add_binary_data(EmbedddedSVGs SOURCES ${SVGAssets}/a.svg ${SVGAssets}/b.svg)
So far, is that a good or bad choice, how would CMake experts structure their files?
Now when it comes to including the modules, I don’t quite manage to get it working right now. I tried the following
juce_add_module (${PROJECT_SOURCE_DIR}/Ext/JBPluginBase/jb_plugin_base)
target_link_libraries(OJD PRIVATE
EmbedddedSVGs
juce::juce_audio_utils
juce::jb_plugin_base)
But it fails with
CMake Error at Ext/JUCE/extras/Build/CMake/JUCEUtils.cmake:1371 (add_library):
Target "OJD_VST3" links to target "juce::jb_plugin_base" but the target was
not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
Probably due to my wrong understanding of either what juce_add_module
does or what target_link_libraries
does.
I feel a bit like back when I started with C++ and tried to find hacky solutions just because I had not really understood how to read the language, how compilation works, how a well designed piece of code looks like etc…
So a best practice example of a CMake file for my project would be appreciated as well as some good resources to learn CMake done right from the start