CMake iOS find_package not working

I’m using find_package(JUCE CONFIG REQUIRED) to reference to JUCE. This works fine when i call it this way:

cmake -B cmake-build -DCMAKE_PREFIX_PATH=../juce/install

but it does not work when i want to genereate the Xcode file for iOS with DCMAKE_SYSTEM_NAME=iOS

cmake -Bbuild-ios -GXcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_PREFIX_PATH=../juce/install

I’m getting following error for the same CMake file:

CMake Error at CMakeLists.txt:8 (find_package):
  Could not find a package configuration file provided by "JUCE" with any of
  the following names:

    JUCEConfig.cmake
    juce-config.cmake

I’m a beginner with CMake. Any help is welcome.

try to use the add_subdirectory way, this was you won’t need to deal with prefix path

It does not fit my repository structure. I want to keep the JUCE library only once for all our products whenever possible. Is it possible to do this with add_subdirectory somehow?

you can do it as well just do

add_subdirectory({PROJECT_SOURCE_DIR}/../JUCE {CMAKE_CURRENT_BINARY_DIR}/JUCE)

The full error message i get:

  Could not find a package configuration file provided by "JUCE" with any of
  the following names:

    JUCEConfig.cmake
    juce-config.cmake

  Add the installation prefix of "JUCE" to CMAKE_PREFIX_PATH or set
  "JUCE_DIR" to a directory containing one of the above files.  If "JUCE"
  provides a separate development package or SDK, be sure it has been
  installed.

I also tried to set -JUCE_DIR=…/…/juce/install, but without any success so far. It looks like i need to point to a directory that contains a CMakeLists.txt in this case.

Some questions/suggestions:

  • Which version of CMake are you using?
  • What is the contents of ../juce/install?
  • What if you pass an absolute path to -DCMAKE_PREFIX_PATH= instead of a relative one?

I’m using the latest version. I build JUCE in a first step and install contains the installation:

sudo cmake -B cmake-build-install -DCMAKE_INSTALL_PREFIX=./install 
cmake --build cmake-build-install --target install

Unfortunately and absolute path didn’t work either. I read in forums that the same problem also exists for QT users.

What about the contents of juce/install? Does it contain bin, include and lib folders? Does juce/install/lib/cmake/JUCE-6.0.{0,1,2,3,4}/JUCEConfig.cmake exist?

Thanks for that one. It looks like this finishes successfully and generates a XCode project:

add_subdirectory(…/juce {CMAKE_CURRENT_BINARY_DIR}/juce)

I’ll report back as soon as i know if it really works.

Yes, the error only occurs if i add DCMAKE_SYSTEM_NAME=iOS

This solution seems to work. It generates the project file. I have one compiler error, but i don’t think it’s related.