Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support finding modules not inside JUCE_ROOT_DIR #12

Open
yfede opened this issue Jul 16, 2018 · 5 comments
Open

Support finding modules not inside JUCE_ROOT_DIR #12

yfede opened this issue Jul 16, 2018 · 5 comments

Comments

@yfede
Copy link

yfede commented Jul 16, 2018

Having the possibility to explicitly specify several directories where to look for modules would be appreciated.

Some useful code is now being released by third parties in the form of a JUCE module, or companies are writing their own code to be reused in that form.

That code certainly does not belong inside the "modules" directory of the JUCE repo/submodule one has cloned.

I think that the a config variable MODULES_ROOT_DIRS could be added to contain a list of those rather than having just one JUCE_ROOT_DIR.

That variable could then contain "juce/modules", then "another-lib/modules", etc., and find_package should look in all of them to find a module.

@remymuller
Copy link
Owner

sounds reasonable, I won't have time to look at this right now, but will try when I get back from vacations.

@yfede
Copy link
Author

yfede commented Jul 17, 2018

cool, thanks!

@FlorianFranzen
Copy link

To change the path detection you will just have add additional path hints to the find_path call for JUCE_ROOT_DIR.

For example, I just added a JUCE_DIR variable as a path hint, which then only needs to be set before the call to find_package(JUCE ...):

find_path(JUCE_ROOT_DIR 
	"modules/juce_core/juce_core.h"
	HINTS
		${JUCE_DIR}
		${PROJECT_SOURCE_DIR}/../
		${PROJECT_SOURCE_DIR}/JUCE
		${CMAKE_CURRENT_LIST_DIR}/../../JUCE
		${CMAKE_CURRENT_LIST_DIR}/../JUCE
	DOC 
		"JUCE library directory"
)

You might also noticed I choose to look for modules/juce_core/juce_core.h instead of the default modules\JUCE Module Format.txt, as I often delete that file and the header is needed anyway to determine the JUCE version.

@remymuller: Any interested in a pull request for this?

@remymuller
Copy link
Owner

This only works if you want to change the global location of JUCE.

What is required is a more detailed handling of additional search paths in juce_add_module(), and taking care additional include path are properly added to targets.

I don't have time to test it right now though.

@christofmuc
Copy link

+1 for this feature.

I just had to makeup a small CMakeLists.txt just to include a trivial module. It's possible, but a bit of a pain:


find_package(JUCE REQUIRED 
	COMPONENTS 
		juce_core		
		juce_events
		juce_audio_basics
		juce_audio_devices
		juce_audio_formats
)

file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/JuceLibraryCode/JuceHeader.h "#include <ff_meters/ff_meters.h>")

include_directories(${CMAKE_CURRENT_LIST_DIR})

set(ff_meters_sources
	ff_meters/ff_meters.h
	ff_meters/ff_meters_LevelMeter.cpp
	ff_meters/ff_meters_LevelMeter.h
<snip more>
)

add_library(ff_meters ${ff_meters_sources})
target_include_directories(ff_meters INTERFACE ${CMAKE_CURRENT_LIST_DIR})
target_link_libraries(ff_meters PRIVATE ${JUCE_LIBRARIES})

The main trick is to

  1. Add the user JUCE module as a CMake library using the normal add_subdirectory()
  2. Have the CMakeLists.txt (above) for the JUCE module append the module's own include to the generated JuceHeader.h
  3. Add explicit includes to your own code versus relying on automatic import via JuceHeader. I prefer that anyway, however.

Thanks remymuller for the nice juce-cmake, BTW, I explored it a bit today and must say it all works fairly smoothly so far!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants