From 8e4e4af795dcae35f022652041a0e2e3e288cce3 Mon Sep 17 00:00:00 2001 From: tpoole Date: Tue, 31 Oct 2017 18:08:59 +0000 Subject: [PATCH] CLion: Fixed issues with setting the cpp standard, launching Windows GUI apps without the console, spaces in project names, and Windows style include paths --- .../ProjectSaving/jucer_ProjectExport_CLion.h | 115 +++++++++++++----- .../native/juce_win32_WASAPI.cpp | 3 +- .../utility/juce_IncludeSystemHeaders.h | 4 +- 3 files changed, 92 insertions(+), 30 deletions(-) diff --git a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_CLion.h b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_CLion.h index 16a144ac03..2ddb1eb731 100644 --- a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_CLion.h +++ b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_CLion.h @@ -264,6 +264,17 @@ private: return getSetting (enabledID); } + //============================================================================== + static bool isWindowsAbsolutePath (const String& path) + { + return path.length() > 1 && path[1] == ':'; + } + + static bool isUnixAbsolutePath (const String& path) + { + return path.isNotEmpty() && (path[0] == '/' || path[0] == '~' || path.startsWith ("$ENV{HOME}")); + } + //============================================================================== static String setCMakeVariable (const String& variableName, const String& value) { @@ -302,9 +313,8 @@ private: { for (auto* target : exporter.targets) { - if (target->getTargetFileType() == ProjectType::Target::TargetFileType::macOSAppex - || target->type == ProjectType::Target::Type::AggregateTarget - || target->type == ProjectType::Target::Type::AudioUnitv3PlugIn) + if (target->type == ProjectType::Target::Type::AggregateTarget + || target->type == ProjectType::Target::Type::AudioUnitv3PlugIn) continue; String functionName; @@ -314,6 +324,11 @@ private: { case ProjectType::Target::TargetFileType::executable: functionName = "add_executable"; + + if (exporter.isCodeBlocks() && exporter.isWindows() + && target->type != ProjectType::Target::Type::ConsoleApp) + properties.add ("WIN32"); + break; case ProjectType::Target::TargetFileType::staticLibrary: case ProjectType::Target::TargetFileType::sharedLibraryOrDLL: @@ -359,7 +374,7 @@ private: //============================================================================== void writeCMakeListsMakefileSection (OutputStream& out, MakefileProjectExporter& exporter) const { - out << "project (" << getProject().getTitle() << " C CXX)" << newLine + out << "project (" << getProject().getTitle().quoted() << " C CXX)" << newLine << newLine; out << "find_package (PkgConfig REQUIRED)" << newLine; @@ -426,7 +441,7 @@ private: out << " " << path.quoted() << newLine; out << ")" << newLine - << newLine; + << newLine; } for (auto* target : exporter.targets) @@ -437,8 +452,19 @@ private: const auto targetVarName = getTargetVarName (*target); out << "set_target_properties (" << targetVarName << " PROPERTIES" << newLine - << " OUTPUT_NAME " << config.getTargetBinaryNameString().quoted() << newLine - << ")" << newLine << newLine; + << " OUTPUT_NAME " << config.getTargetBinaryNameString().quoted() << newLine; + + auto cxxStandard = project.getCppStandardValue().toString(); + + if (cxxStandard == "latest") + cxxStandard = "1z"; + + out << " CXX_STANDARD " << cxxStandard << newLine; + + if (! shouldUseGNUExtensions()) + out << " CXX_EXTENSIONS OFF" << newLine; + + out << ")" << newLine << newLine; auto defines = exporter.getDefines (config); defines.addArray (target->getDefines (config)); @@ -493,9 +519,15 @@ private: cFlags.add (exporter.getArchFlags (config)); cFlags.addArray (exporter.getCPreprocessorFlags (config)); cFlags.addArray (exporter.getCFlags (config)); + out << addToCMakeVariable ("CMAKE_C_FLAGS", cFlags.joinIntoString (" ")) << newLine; - out << addToCMakeVariable ("CMAKE_C_FLAGS", cFlags.joinIntoString (" ")) << newLine - << addToCMakeVariable ("CMAKE_CXX_FLAGS", "${CMAKE_C_FLAGS} " + exporter.getCXXFlags().joinIntoString (" ")) << newLine + String cxxFlags; + + for (auto& flag : exporter.getCXXFlags()) + if (! flag.startsWith ("-std=")) + cxxFlags += " " + flag; + + out << addToCMakeVariable ("CMAKE_CXX_FLAGS", "${CMAKE_C_FLAGS} " + cxxFlags) << newLine << newLine; out << "endif (" << buildTypeCondition << ")" << newLine @@ -506,7 +538,7 @@ private: //============================================================================== void writeCMakeListsCodeBlocksSection (OutputStream& out, CodeBlocksProjectExporter& exporter) const { - out << "project (" << getProject().getTitle() << " C CXX)" << newLine + out << "project (" << getProject().getTitle().quoted() << " C CXX)" << newLine << newLine; writeCMakeTargets (out, exporter); @@ -537,7 +569,7 @@ private: out << "include_directories (" << newLine; for (auto& path : exporter.getIncludePaths (config)) - out << " " << path.quoted() << newLine; + out << " " << path.replace ("\\", "/").quoted() << newLine; out << ")" << newLine << newLine; @@ -549,8 +581,19 @@ private: const auto targetVarName = getTargetVarName (*target); out << "set_target_properties (" << targetVarName << " PROPERTIES" << newLine - << " OUTPUT_NAME " << config.getTargetBinaryNameString().quoted() << newLine - << ")" << newLine << newLine; + << " OUTPUT_NAME " << config.getTargetBinaryNameString().quoted() << newLine; + + auto cxxStandard = project.getCppStandardValue().toString(); + + if (cxxStandard == "latest") + cxxStandard = "1z"; + + out << " CXX_STANDARD " << cxxStandard << newLine; + + if (! shouldUseGNUExtensions()) + out << " CXX_EXTENSIONS OFF" << newLine; + + out << ")" << newLine << newLine; out << "target_compile_definitions (" << targetVarName << " PRIVATE" << newLine; @@ -562,7 +605,8 @@ private: out << "target_compile_options (" << targetVarName << " PRIVATE" << newLine; for (auto& option : exporter.getCompilerFlags (config, *target)) - out << " " << option.quoted() << newLine; + if (! option.startsWith ("-std=")) + out << " " << option.quoted() << newLine; out << ")" << newLine << newLine; @@ -575,12 +619,12 @@ private: for (auto& path : exporter.getLinkerSearchPaths (config, *target)) { - out << " \"-L"; + out << " \"-L\\\""; - if (! File::isAbsolutePath (path)) + if (! isWindowsAbsolutePath (path)) out << "${CMAKE_CURRENT_SOURCE_DIR}/"; - out << path << "\"" << newLine; + out << path.replace ("\\", "/") << "\\\"\"" << newLine; } for (auto& flag : exporter.getLinkerFlags (config, *target)) @@ -633,7 +677,7 @@ private: } } - out << "project (" << getProject().getTitle() << " C CXX)" << newLine << newLine; + out << "project (" << getProject().getTitle().quoted() << " C CXX)" << newLine << newLine; writeCMakeTargets (out, exporter); @@ -697,8 +741,9 @@ private: if (targetAttributeKeys.contains ("HEADER_SEARCH_PATHS")) { auto paths = targetAttributes["HEADER_SEARCH_PATHS"].trim().substring (1).dropLastCharacters (1); - paths = paths.replace ("\"$(inherited)\"", {}); - paths = paths.replace ("$(HOME)", "$ENV{HOME}"); + paths = paths.replace ("\"$(inherited)\"", {}) + .replace ("$(HOME)", "$ENV{HOME}") + .replace ("~", "$ENV{HOME}"); headerSearchPaths.addTokens (paths, ",\"\t\\", {}); headerSearchPaths.removeEmptyStrings(); targetAttributeKeys.removeString ("HEADER_SEARCH_PATHS"); @@ -785,11 +830,8 @@ private: targetAttributeKeys.removeString ("GCC_FAST_MATH"); } - if (targetAttributeKeys.contains ("CLANG_CXX_LANGUAGE_STANDARD")) - { - cppFlags.add ("-std=" + targetAttributes["CLANG_CXX_LANGUAGE_STANDARD"].unquoted()); - targetAttributeKeys.removeString ("CLANG_CXX_LANGUAGE_STANDARD"); - } + // We'll take this setting from the project + targetAttributeKeys.removeString ("CLANG_CXX_LANGUAGE_STANDARD"); if (targetAttributeKeys.contains ("CLANG_CXX_LIBRARY")) { @@ -818,7 +860,7 @@ private: { libPath = libPath.replace ("${CURRENT_ARCH}", archLabel); - if (! File::isAbsolutePath (libPath)) + if (! isUnixAbsolutePath (libPath)) libPath = "${CMAKE_CURRENT_SOURCE_DIR}/" + libPath; } @@ -872,7 +914,14 @@ private: << " " << rezFlags.unquoted().removeCharacters ("\\") << newLine; for (auto& path : headerSearchPaths) - out << " -I \"${PROJECT_SOURCE_DIR}/" << path.unquoted() << "\"" << newLine; + { + out << " -I \""; + + if (! isUnixAbsolutePath (path)) + out << "${PROJECT_SOURCE_DIR}/"; + + out << path << "\"" << newLine; + } out << " ${" << resSourcesVar << "}" << newLine << " -o ${" << resOutputVar << "}" << newLine @@ -930,6 +979,16 @@ private: out << "set_target_properties (" << targetVarName << " PROPERTIES" << newLine << " OUTPUT_NAME " << binaryName.quoted() << newLine; + auto cxxStandard = project.getCppStandardValue().toString(); + + if (cxxStandard == "latest") + cxxStandard = "1z"; + + out << " CXX_STANDARD " << cxxStandard << newLine; + + if (! shouldUseGNUExtensions()) + out << " CXX_EXTENSIONS OFF" << newLine; + for (auto& key : targetAttributeKeys) out << " XCODE_ATTRIBUTE_" << key << " " << targetAttributes[key] << newLine; @@ -960,7 +1019,7 @@ private: out << " SHARED_CODE" << newLine; for (auto& path : libSearchPaths) - out << " \"-L" << path << "\"" << newLine; + out << " \"-L\\\"" << path << "\\\"\"" << newLine; for (auto& flag : linkerFlags) out << " " << flag.quoted() << newLine; diff --git a/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp b/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp index 2dc3fa5365..a48c400164 100644 --- a/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp +++ b/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp @@ -1339,11 +1339,12 @@ private: bool isOpen_, isStarted; int currentBufferSizeSamples; double currentSampleRate; - bool sampleRateChangedByOutput, deviceBecameInactive; AudioIODeviceCallback* callback; CriticalSection startStopLock; + bool sampleRateChangedByOutput, deviceBecameInactive; + BigInteger lastKnownInputChannels, lastKnownOutputChannels; //============================================================================== diff --git a/modules/juce_audio_plugin_client/utility/juce_IncludeSystemHeaders.h b/modules/juce_audio_plugin_client/utility/juce_IncludeSystemHeaders.h index 48a5617baa..da0c178af6 100644 --- a/modules/juce_audio_plugin_client/utility/juce_IncludeSystemHeaders.h +++ b/modules/juce_audio_plugin_client/utility/juce_IncludeSystemHeaders.h @@ -31,7 +31,9 @@ #define STRICT 1 #include #include - #pragma warning (disable : 4312 4355) + #if ! JUCE_MINGW + #pragma warning (disable : 4312 4355) + #endif #ifdef __INTEL_COMPILER #pragma warning (disable : 1899) #endif