Unknown CMake command "juce_add_gui_app"

Well, I have progressed now with the official CMake project of JUCE.
I cloned this whole directory: https://github.com/juce-framework/JUCE

I went inside:

.../temp/JUCE/examples/CMake/GuiApp$ ls
build  CMakeLists.txt  MainComponent.cpp  MainComponent.h  Main.cpp

I made that build directory for executing cmake.

Executing the cmake is resulting in following error:

.../temp/JUCE/examples/CMake/GuiApp/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:39 (juce_add_gui_app):
  Unknown CMake command "juce_add_gui_app".


-- Configuring incomplete, errors occurred!
See also "/home/xyz/Documents/abc/work/juce/temp/JUCE/examples/CMake/GuiApp/build/CMakeFiles/CMakeOutput.log".

Was I supposed to change something in the CMakeList.txt? Please guide about how to get rid of Unknown CMake command "juce_add_gui_app". .

There are instructions for building the GuiApp example in examples/CMake/GuiApp/CMakeLists.txt.

If you’re building the GuiApp example from inside JUCE (as you’ve attempted here), you’ll need to run cmake from the top level of the repo, like so:

cmake . -B cmake-build-dir -D JUCE_BUILD_EXAMPLES=ON
cmake --build cmake-build-dir --target GuiApp

However, if you’re starting a new JUCE project, it’s recommended to copy the whole GuiApp folder to a new location outside the repo, and then to use add_subdirectory(path/to/JUCE) to point the project to a copy of JUCE.

1 Like

Am thankful for your patience. I am not well versed with CMake yet.

I ran cmake . -B cmake-build-dir -D JUCE_BUILD_EXAMPLES=ON in the top level directory of the repository. It complained about missing ‘webkit2gtk-4.0’ , ‘gtk±x11-3.0’, and ‘alsa’.

Is it important to have these dependencies? Are they optional?

Secondly, where am I supposed to run the second command? cmake --build cmake-build-dir --target GuiApp?

I ran it in the top level repo’ build dir like this: cmake .. --build cmake-build-dir --target ../examples/CMake/GuiApp

It said:

CMake Error: The source "/home/xyz/Documents/abc/work/juce/temp/JUCE/examples/CMake/GuiApp/CMakeLists.txt" does not match the source "/home/xyz/Documents/abc/work/juce/temp/JUCE/CMakeLists.txt" used to generate cache. Re-run cmake with a different source directory.

Running it in the JUCE/examples/CMake/ repo complains about Unknown CMake command "juce_add_gui_app".

Where am I supposed to run the second command?

Besides what I wrote in the above post, I have also enabled find_package(JUCE CONFIG REQUIRED) in th GuiApp’s CMakeList.txt.

Now the innermost cmake says:

CMake Error at CMakeLists.txt:25 (find_package):
  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.

should I have done this?

I have added list(APPEND CMAKE_PREFIX_PATH "/home/xyz/Documents/abc/work/juce/temp/JUCE/")

That doesn’t seem to help though.

Again a change:

I cleaned the build folders and started again:

This time I first uncommented find_package(JUCE) in /GuiApp' CMakeList.txt.
Then I ran cmake .. . -B cmake-build-dir -D JUCE_BUILD_EXAMPLES=ON
on the top level directory.

It says:

-- Checking for modules 'webkit2gtk-4.0;gtk+-x11-3.0'
--   No package 'webkit2gtk-4.0' found
--   No package 'gtk+-x11-3.0' found
-- Checking for module 'alsa'
--   No package 'alsa' found
-- Configuring juceaide
-- Building juceaide
-- Exporting juceaide
CMake Error at examples/CMake/GuiApp/CMakeLists.txt:27 (find_package):
  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.


-- Configuring incomplete, errors occurred!

I tried to find where is JUCEConfig.cmake

 /work/juce/temp/JUCE/build$ find . -name JUCEConfig.cmake
./cmake-build-dir/tools/JUCEConfig.cmake

I am supposed to put this path in CMAKE_PREFIX_PATHS?

To resolve the missing packages, you should install libwebkit2gtk-4.0-dev and libasound2-dev:

sudo apt install libwebkit2gtk-4.0-dev libasound2-dev

To build a new GUI App project with JUCE/CMake, do this (starting from scratch):

  • Copy the GuiApp folder to a new location.
  • In the GuiApp CMakeLists that you copied, replace the add_subdirectory(JUCE) line with add_subdirectory("/home/xyz/Documents/abc/work/juce/temp/JUCE" JUCE), replacing the path with the real location of the JUCE repo on your system.
  • From the GuiApp folder that you copied, run
    • cmake . -B cmake-build-dir
      • This will create a build tree folder named cmake-build-dir
    • cmake --build cmake-build-dir
      • This will build all targets in the cmake-build-dir folder.
2 Likes

I am utterly thankful for the patience that you have shown here.
I followed all your steps and this time there were no errors.

I found the executable in the build directory and I ran it successfully.
Now I hope to speed up towards writing/learning coding.