CMake Bug JUCE6

Hey there,

I’m playing around with the CMake features of JUCE6. Great stuff. I’ve noticed a bug when trying to archive a GUI app within XCode. To reproduce:

I’m using as a Base: examples/CMake/GuiApp

I add two files Lib.hpp and Lib.cpp with a HelloWorld class.

At the bottom of CMakeLists.txt I add:

target_link_libraries(GuiAppExample PRIVATE
        juce::juce_gui_extra 
        Lib)

add_library(Lib STATIC "Lib.hpp" "Lib.cpp")

I generate with:
cmake -G Xcode ..

When I open the XCode Project, select the executable and hit Product->Archive I get:

clang: error: no such file or directory: 'xxx/build/xcode-macos/Release/libLib.a'

Normal build (not archiving) works fine.

It is not a bug, but the normal behavior of CMake.

When CMake executes target_link_libraries(... Lib), the Lib target is not yet defined. So CMake assumes that it is a pre-built library.

Move the add_library(Lib ...) call before the target_link_libraries one and it should work.

I hope this helps!

1 Like

Thanks @McMartin,

unfortunately that didn’t work. I just tried

add_library(Lib STATIC "Lib.hpp" "Lib.cpp")

target_link_libraries(GuiAppExample PRIVATE
        juce::juce_gui_extra
        Lib)

with the same result. I deleted the XCode project folder to make sure the Cache was not the problem. Any other idea?

Weird thing is that regular build in Debug and Release works fine. Also with Clion. Only archiving in XCode has issues.

Interesting, I can repro with cmake 3.17.1 and Xcode 11.4. It seems that, when archiving, the static library is built into a DerivedData location instead of into the build tree, but the linker looks for it in the build tree. Not sure why that should be (possibly a CMake bug?). I’ll let you know if I find any more details.

Haven’t tried it yet, but it looks like this solution might help as a work-around.

2 Likes

Ahh thanks @reuk, the workaround solves it for now. But yes, you’re right, it seems it’s not a JUCE issue, but a CMake issue. Even if I create a pure CMake target with add_executable I have the same problem.