diff --git a/docs/JUCE Module Format.md b/docs/JUCE Module Format.md index c114b302aa..af59a76f22 100644 --- a/docs/JUCE Module Format.md +++ b/docs/JUCE Module Format.md @@ -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). diff --git a/extras/Build/CMake/JUCEModuleSupport.cmake b/extras/Build/CMake/JUCEModuleSupport.cmake index dea5d61e8f..1d64c9a34f 100644 --- a/extras/Build/CMake/JUCEModuleSupport.cmake +++ b/extras/Build/CMake/JUCEModuleSupport.cmake @@ -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() diff --git a/extras/Projucer/Source/Project/Modules/jucer_Modules.cpp b/extras/Projucer/Source/Project/Modules/jucer_Modules.cpp index bc5ee73ec7..eb74086897 100644 --- a/extras/Projucer/Source/Project/Modules/jucer_Modules.cpp +++ b/extras/Projucer/Source/Project/Modules/jucer_Modules.cpp @@ -266,15 +266,20 @@ void LibraryModule::findBrowseableFiles (const File& folder, Array& 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 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::getAllCompileUnits (build_tools::ProjectType::Target::Type forTarget) const { auto files = getFolder().findChildFiles (File::findFiles, false); diff --git a/extras/Projucer/Source/Project/Modules/jucer_Modules.h b/extras/Projucer/Source/Project/Modules/jucer_Modules.h index 554009b2f9..345f2dc24d 100644 --- a/extras/Projucer/Source/Project/Modules/jucer_Modules.h +++ b/extras/Projucer/Source/Project/Modules/jucer_Modules.h @@ -59,7 +59,6 @@ public: bool isNeededForExporter (ProjectExporter&) const; String getFilenameForProxyFile() const; - static bool hasSuffix (const File&, const char*); }; Array getAllCompileUnits (build_tools::ProjectType::Target::Type forTarget =