1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

Modules: Update JUCE module format for improved consistency

This commit is contained in:
Anthony Nicholls 2023-03-24 17:13:18 +00:00 committed by reuk
parent 05d5c94990
commit c04354e1ee
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
4 changed files with 38 additions and 41 deletions

View file

@ -65,28 +65,28 @@ adding these files to their projects.
The names of these source files must begin with the name of the module, but they can have
a number or other suffix if there is more than one.
In order to specify that a source file should only be compiled on a specific platform,
then the filename can be suffixed with one of the following strings:
In order to specify that a source file should only be compiled for a specific platform,
then the filename can be suffixed with one of the following (case insensitive) strings:
_OSX
_Windows
_Linux
_Android
_iOS
_mac or _osx <- compiled for macOS and OSX platforms only
_windows <- compiled for Windows platforms only
_linux <- compiled for Linux and FreeBSD platforms only
_andoid <- compiled for Android platforms only
_ios <- compiled for iOS platforms only
e.g.
juce_mymodule/juce_mymodule_1.cpp <- compiled on all platforms
juce_mymodule/juce_mymodule_2.cpp <- compiled on all platforms
juce_mymodule/juce_mymodule_OSX.cpp <- compiled only on OSX
juce_mymodule/juce_mymodule_Windows.cpp <- compiled only on Windows
juce_mymodule/juce_mymodule_1.cpp <- compiled for all platforms
juce_mymodule/juce_mymodule_2.cpp <- compiled for all platforms
juce_mymodule/juce_mymodule_mac.cpp <- compiled for macOS and OSX platforms only
juce_mymodule/juce_mymodule_windows.cpp <- compiled for Windows platforms only
Often this isn't necessary, as in most cases you can easily add checks inside the files
to do different things depending on the platform, but this may be handy just to avoid
clutter in user projects where files aren't needed.
To simplify the use of obj-C++ there's also a special-case rule: If the folder contains
both a .mm and a .cpp file whose names are otherwise identical, then on OSX/iOS the .mm
both a .mm and a .cpp file whose names are otherwise identical, then on macOS/iOS the .mm
will be used and the cpp ignored. (And vice-versa for other platforms, of course).

View file

@ -155,24 +155,25 @@ function(_juce_get_metadata target key out_var)
endfunction()
# ==================================================================================================
function(_juce_should_build_module_source filename output_var)
get_filename_component(trimmed_name "${filename}" NAME_WE)
get_filename_component(trimmed_filename "${filename}" NAME_WE)
string(TOLOWER "${trimmed_filename}" trimmed_filename_lowercase)
set(system_name_regex_for_suffix
"android\;Android"
"ios\;iOS"
"linux\;Linux|.*BSD"
"mac\;Darwin"
"osx\;Darwin"
"windows\;Windows")
set(result TRUE)
set(pairs
"OSX\;Darwin"
"Windows\;Windows"
"Linux\;Linux"
"Android\;Android"
"iOS\;iOS")
foreach(pair IN LISTS pairs)
foreach(pair IN LISTS system_name_regex_for_suffix)
list(GET pair 0 suffix)
list(GET pair 1 system_name)
list(GET pair 1 regex)
if((trimmed_name MATCHES "_${suffix}$") AND NOT (CMAKE_SYSTEM_NAME STREQUAL "${system_name}"))
if((trimmed_filename_lowercase MATCHES "_${suffix}$") AND NOT (CMAKE_SYSTEM_NAME MATCHES "${regex}"))
set(result FALSE)
endif()
endforeach()

View file

@ -266,15 +266,20 @@ void LibraryModule::findBrowseableFiles (const File& folder, Array<File>& filesF
bool LibraryModule::CompileUnit::isNeededForExporter (ProjectExporter& exporter) const
{
if ((hasSuffix (file, "_osx") && ! exporter.isOSX())
|| (hasSuffix (file, "_mac") && ! exporter.isOSX())
|| (hasSuffix (file, "_ios") && ! exporter.isiOS())
|| (hasSuffix (file, "_windows") && ! exporter.isWindows())
|| (hasSuffix (file, "_linux") && ! exporter.isLinux())
|| (hasSuffix (file, "_android") && ! exporter.isAndroid()))
return false;
const auto trimmedFileNameLowercase = file.getFileNameWithoutExtension().toLowerCase();
auto targetType = Project::getTargetTypeFromFilePath (file, false);
const std::tuple<const char*, bool> shouldBuildForSuffix[] { { "_android", exporter.isAndroid() },
{ "_ios", exporter.isiOS() },
{ "_linux", exporter.isLinux() },
{ "_mac", exporter.isOSX() },
{ "_osx", exporter.isOSX() },
{ "_windows", exporter.isWindows() } };
for (const auto& [suffix, shouldBuild] : shouldBuildForSuffix)
if (trimmedFileNameLowercase.endsWith (suffix))
return shouldBuild;
const auto targetType = Project::getTargetTypeFromFilePath (file, false);
if (targetType != build_tools::ProjectType::Target::unspecified && ! exporter.shouldBuildTargetType (targetType))
return false;
@ -288,14 +293,6 @@ String LibraryModule::CompileUnit::getFilenameForProxyFile() const
return "include_" + file.getFileName();
}
bool LibraryModule::CompileUnit::hasSuffix (const File& f, const char* suffix)
{
auto fileWithoutSuffix = f.getFileNameWithoutExtension() + ".";
return fileWithoutSuffix.containsIgnoreCase (suffix + String ("."))
|| fileWithoutSuffix.containsIgnoreCase (suffix + String ("_"));
}
Array<LibraryModule::CompileUnit> LibraryModule::getAllCompileUnits (build_tools::ProjectType::Target::Type forTarget) const
{
auto files = getFolder().findChildFiles (File::findFiles, false);

View file

@ -59,7 +59,6 @@ public:
bool isNeededForExporter (ProjectExporter&) const;
String getFilenameForProxyFile() const;
static bool hasSuffix (const File&, const char*);
};
Array<CompileUnit> getAllCompileUnits (build_tools::ProjectType::Target::Type forTarget =