remymuller / juce-cmake

CMake find module for the JUCE library
MIT License
30 stars 6 forks source link

Trouble getting juce-cmake working #16

Closed JanosGit closed 4 years ago

JanosGit commented 5 years ago

I started with CMake some weeks ago, so this might be a problem related to my lack of knowledge.

I want to integrate your solution in a cmake-based project I released here as I need JUCE for a project that should be able to build without the Projucer using some highly custom embedded toolchains.

My Project structure looks like that:

cmakeAndJUCE
   CMakeLists.txt
  JUCE <-- a fresh clone of the current JUCE repo
  juce-cmake <-- your project
  src <-- all project sources

I added the following lines to my CMakeLists.txt

set (CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/juce-cmake/cmake; ${CMAKE_MODULE_PATH};")
set (JUCE_ROOT_DIR "${PROJECT_SOURCE_DIR}/JUCE/")

find_package(JUCE REQUIRED
             COMPONENTS
             juce_core
             juce_cryptography
             juce_osc
             )

Now I get a bunch of errors, related to not finding the right paths to the modules if I get it right? I added a message after line 165 of FindJUCE.cmake to see where it looks for the headers (message("Header: ${header}")

CMake Error at juce-cmake/cmake/FindJUCE.cmake:76 (file):
  file failed to open for reading (No such file or directory):

    /Users/janosbuttgereit/Entwicklung/Projekte/Testprojekte/cmakeAndJUCE/JUCE_ROOT_DIR-NOTFOUND/modules/juce_core/juce_core.h
Call Stack (most recent call first):
  juce-cmake/cmake/FindJUCE.cmake:93 (juce_module_get_declaration)
  juce-cmake/cmake/FindJUCE.cmake:299 (juce_module_get_info)
  juce-cmake/cmake/FindJUCE.cmake:469 (juce_add_module)
  CMakeLists.txt:32 (find_package)

Header: JUCE_ROOT_DIR-NOTFOUND/modules/juce_core/juce_core.h
CMake Error at juce-cmake/cmake/FindJUCE.cmake:168 (file):
  file failed to open for reading (No such file or directory):

    /Users/janosbuttgereit/Entwicklung/Projekte/Testprojekte/cmakeAndJUCE/JUCE_ROOT_DIR-NOTFOUND/modules/juce_core/juce_core.h
Call Stack (most recent call first):
  juce-cmake/cmake/FindJUCE.cmake:302 (juce_module_get_config_flags)
  juce-cmake/cmake/FindJUCE.cmake:469 (juce_add_module)
  CMakeLists.txt:32 (find_package)

Header: /Users/janosbuttgereit/Entwicklung/SDKs/JUCE/modules/juce_cryptography/juce_cryptography.h
Header: /Users/janosbuttgereit/Entwicklung/Projekte/Testprojekte/cmakeAndJUCE/JUCE/modules/juce_osc/juce_osc.h
CMake Error at juce-cmake/cmake/FindJUCE.cmake:76 (file):
  file failed to open for reading (No such file or directory):

    /Users/janosbuttgereit/Entwicklung/Projekte/Testprojekte/cmakeAndJUCE/JUCE_ROOT_DIR-NOTFOUND/modules/juce_events/juce_events.h
Call Stack (most recent call first):
  juce-cmake/cmake/FindJUCE.cmake:93 (juce_module_get_declaration)
  juce-cmake/cmake/FindJUCE.cmake:299 (juce_module_get_info)
  juce-cmake/cmake/FindJUCE.cmake:348 (juce_add_module)
  juce-cmake/cmake/FindJUCE.cmake:469 (juce_add_module)
  CMakeLists.txt:32 (find_package)

Header: JUCE_ROOT_DIR-NOTFOUND/modules/juce_events/juce_events.h
CMake Error at juce-cmake/cmake/FindJUCE.cmake:168 (file):
  file failed to open for reading (No such file or directory):

    /Users/janosbuttgereit/Entwicklung/Projekte/Testprojekte/cmakeAndJUCE/JUCE_ROOT_DIR-NOTFOUND/modules/juce_events/juce_events.h
Call Stack (most recent call first):
  juce-cmake/cmake/FindJUCE.cmake:302 (juce_module_get_config_flags)
  juce-cmake/cmake/FindJUCE.cmake:348 (juce_add_module)
  juce-cmake/cmake/FindJUCE.cmake:469 (juce_add_module)
  CMakeLists.txt:32 (find_package)

What is confusing to me: In some case it fails with a path containing JUCE_ROOT_DIR-NOTFOUND (juce_core and juce_events), for juce_osc it finds the right path and for juce_cryptography it finds my copy of juce used for Projucer-Based projects with global juce paths on my machine.

I'd love to be able to use my global JUCE installation like its possible with Projucer-based projects, however having a copy of JUCE in the project folder is an option too, first of all I'd love to get this working. So what's wrong here?

Bonus question: How do I pass the path to my own modules that are not inside the JUCE modules folder?

remymuller commented 5 years ago

I would avoir shadowing CMAKE_MODULE_PATH, usually I do it the other way:

set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${PROJECT_SOURCE_DIR}/../juce-cmake/cmake")

Second JUCE_ROOT_DIR is an output, not an input for FindJuce, this is the current way of looking for JUCE

find_path(JUCE_ROOT_DIR 
    "modules/JUCE Module Format.txt"
    HINTS
        ${PROJECT_SOURCE_DIR}/../
        ${PROJECT_SOURCE_DIR}/JUCE
        ${CMAKE_CURRENT_LIST_DIR}/../../JUCE
        ${CMAKE_CURRENT_LIST_DIR}/../JUCE
    DOC 
        "JUCE library directory"
)

so given your layout, it should find your local JUCE version.

It it's not enough, according to cmake's documentation for find_path, https://cmake.org/cmake/help/v3.8/command/find_path.html?highlight=i

you could set CMAKE_INCLUDE_PATH to help cmake find JUCE.

Regarding 3rd party modules, they are not supported yet.