How to compile and run a hello world JUCE program?

2.6k Views Asked by At

I cloned https://github.com/juce-framework/JUCE

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

How am I supposed to put this path in CMAKE_PREFIX_PATHS?

1

There are 1 best solutions below

0
On BEST ANSWER

Clone this repository: https://github.com/juce-framework/JUCE

alsa and webkit2gtk are required dependencies which were absent on Ubuntu 18.04 in my computer. You too may have to install as follows:

sudo apt install libwebkit2gtk-4.0-dev libasound2-dev

In the examples/CMake folder in this repository there is a folder called GuiApp.

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

  1. Copy the GuiApp folder to a new location.

  2. In the GuiApp's CMakeLists.txt that you copied, replace the

    add_subdirectory(JUCE)

with

add_subdirectory("<path_to_JUCE_cloned_repository>" JUCE) 

replacing the path with the real location of the JUCE repository on your system.

  1. From the GuiApp folder that you copied, run

    cmake . -B cmake-build-dir

Above command will create a build tree folder named cmake-build-dir

  1. cmake --build cmake-build-dir

Above command will build all targets in the cmake-build-dir folder.

  1. After successful build, you can run the executable by going in directory:

    cmake-build-dir/GuiAppExample_artefacts/

and issuing ./Gui\ App\ Example. That's the name of the resultant default executable.

Credit: https://forum.juce.com/u/reuk/summary