### Installing pre-commit hooks Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/README.md This command installs pre-commit hooks to run clang-format on every commit. It requires the `pre-commit` tool to be installed, which can be done using `pip install pre-commit`. ```bash pre-commit install ``` -------------------------------- ### Installing WebView2 NuGet Package (Windows) Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/CMakeLists.txt Installs the Microsoft.Web.WebView2 NuGet package on Windows using a PowerShell script. This allows the use of WebViews in the JUCE application. ```cmake if (MSVC) message(STATUS "Setting up WebView dependencies") execute_process(COMMAND pwsh -NoProfile -File scripts/DownloadWebView2.ps1 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} RESULT_VARIABLE DOWNLOAD_WEBVIEW2_RESULT) if (NOT DOWNLOAD_WEBVIEW2_RESULT EQUAL 0) message(FATAL_ERROR "Failed to download Microsoft.Web.WebView2 NuGet package. Result: ${DOWNLOAD_WEBVIEW2_RESULT}") endif() endif() ``` -------------------------------- ### Zipping WebView files using CMake Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/plugin/CMakeLists.txt This snippet zips the WebView files using CMake commands. It defines the zip file name and target path, creates a custom target to execute the zip command, and sets the working directory. It uses cmake_path to get the absolute path and parent path of the WebView files source directory. ```cmake # Zip WebView files set(WEBVIEW_FILES_ZIP_NAME "webview_files.zip") set(TARGET_WEBVIEW_FILES_ZIP_PATH "${CMAKE_BINARY_DIR}/${WEBVIEW_FILES_ZIP_NAME}") cmake_path(ABSOLUTE_PATH WEBVIEW_FILES_SOURCE_DIR NORMALIZE OUTPUT_VARIABLE PUBLIC_PATH ) cmake_path(GET PUBLIC_PATH PARENT_PATH WORKING_DIRECTORY) add_custom_target(ZipWebViewFiles COMMAND ${CMAKE_COMMAND} -E tar cvf "${TARGET_WEBVIEW_FILES_ZIP_PATH}" --format=zip "${PUBLIC_PATH}" BYPRODUCTS "${TARGET_WEBVIEW_FILES_ZIP_PATH}" WORKING_DIRECTORY "${WORKING_DIRECTORY}" COMMENT "Zipping WebView files..." VERBATIM ) ``` -------------------------------- ### Building the project with CMake Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/README.md This command builds the project using CMake with a specified preset. The preset determines the build configuration. Common presets include 'default', 'release', 'vs', or 'Xcode'. ```bash cmake --build --preset default # or release, vs, or Xcode ``` -------------------------------- ### Generating project files with CMake Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/README.md This command generates project files using CMake with a specified preset. The preset determines the build system and configuration. Common presets include 'default' (Ninja), 'release', 'vs' (Visual Studio), and 'Xcode'. ```bash cmake --preset default # uses the Ninja build system ``` -------------------------------- ### Setting up project with JUCE plugin target Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/plugin/CMakeLists.txt This snippet sets up the basic project configuration, including the minimum CMake version, project name, and adding a JUCE plugin target with specified properties such as company name, plugin formats, and WebView requirements. It defines the plugin as a non-synth plugin that doesn't need MIDI input or output, and specifies AU, VST3, and Standalone formats. ```cmake cmake_minimum_required(VERSION 3.22 FATAL_ERROR) # Version is needed by JUCE. project(JuceWebViewPlugin VERSION 0.1.0) # Adds a plugin target (that's basically what the Projucer does). juce_add_plugin(${PROJECT_NAME} COMPANY_NAME WolfSound IS_SYNTH FALSE NEEDS_MIDI_INPUT FALSE NEEDS_MIDI_OUTPUT FALSE PLUGIN_MANUFACTURER_CODE WFSD PLUGIN_CODE JWVT FORMATS AU VST3 Standalone PRODUCT_NAME "JuceWebViewPlugin" # WebViews use web browser features: find necessary packages in the system to link against NEEDS_WEB_BROWSER TRUE # This will force JUCE to look for the WebView2 NuGet package on Windows NEEDS_WEBVIEW2 TRUE ) ``` -------------------------------- ### Packaging web UI sources as binary data Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/plugin/CMakeLists.txt This snippet packages the web UI sources as binary data using the `juce_add_binary_data` function. It specifies the header name, namespace, and source file for the binary data. It also adds a dependency on the `ZipWebViewFiles` target to ensure that the zip file is created before the binary data is packaged. ```cmake # Package web UI sources as binary data juce_add_binary_data(WebViewFiles HEADER_NAME WebViewFiles.h NAMESPACE webview_files SOURCES ${TARGET_WEBVIEW_FILES_ZIP_PATH} ) add_dependencies(WebViewFiles ZipWebViewFiles) ``` -------------------------------- ### Linking necessary dependencies for JUCE plugin Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/plugin/CMakeLists.txt This snippet links the necessary dependencies for the JUCE plugin, including JUCE modules and the WebViewFiles binary data. It specifies both private and public dependencies, including audio utilities, DSP, and recommended configuration and warning flags. ```cmake # Links to all necessary dependencies. The present ones are recommended by JUCE. # If you use one of the additional modules, like the DSP module, you need to specify it here. target_link_libraries(${PROJECT_NAME} PRIVATE juce::juce_audio_utils juce::juce_dsp WebViewFiles PUBLIC juce::juce_recommended_config_flags juce::juce_recommended_lto_flags juce::juce_recommended_warning_flags ) ``` -------------------------------- ### Adding JUCE Dependency with CPM Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/CMakeLists.txt Downloads and configures the JUCE framework using CPM. Specifies the JUCE version and source directory. ```cmake CPMAddPackage( NAME JUCE GIT_TAG 8.0.6 VERSION 8.0.6 GITHUB_REPOSITORY juce-framework/JUCE SOURCE_DIR ${LIB_DIR}/juce ) ``` -------------------------------- ### Setting source files and include directories Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/plugin/CMakeLists.txt This snippet sets the source files for the plugin project and defines the include directory. It then sets the target sources and include directories for the plugin, including the JUCE modules directory as a system include directory to suppress warnings. ```cmake # Sets the source files of the plugin project. set(SOURCES source/PluginEditor.cpp source/PluginProcessor.cpp) # Adding a directory with the library/application name as a subfolder of the # include folder is a good practice. It helps avoid name clashes later on. set(INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/JuceWebViewTutorial") target_sources(${PROJECT_NAME} PRIVATE ${SOURCES} ${INCLUDE_DIR}/PluginEditor.h ${INCLUDE_DIR}/PluginProcessor.h ) # Sets the include directories of the plugin project. target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ) # Mark JUCE headers as system headers to suppress warnings in them target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${JUCE_MODULES_DIR}) ``` -------------------------------- ### Setting Library Directory Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/CMakeLists.txt Defines the directory where dependencies will be downloaded. This is set to a 'libs' folder within the project's source directory. ```cmake set(LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libs) ``` -------------------------------- ### Adding Plugin Subdirectory Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/CMakeLists.txt Adds the 'plugin' subdirectory to the build, which contains the source code for the JUCE plugin. ```cmake add_subdirectory(plugin) ``` -------------------------------- ### Including CPM Package Manager Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/CMakeLists.txt Includes the CPM package manager, which simplifies dependency management within the CMake project. ```cmake include(cmake/cpm.cmake) ``` -------------------------------- ### Defining compile definitions for JUCE plugin Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/plugin/CMakeLists.txt This snippet retrieves the product and company names from the target properties and defines compile definitions for the JUCE plugin. These definitions include the product name, company name, and product version, which are used during the compilation process. ```cmake get_target_property(PRODUCT_NAME ${PROJECT_NAME} JUCE_PRODUCT_NAME) get_target_property(COMPANY_NAME ${PROJECT_NAME} JUCE_COMPANY_NAME) target_compile_definitions(${PROJECT_NAME} PRIVATE JUCE_PRODUCT_NAME="${PRODUCT_NAME}" JUCE_COMPANY_NAME="${COMPANY_NAME}" JUCE_PRODUCT_VERSION="${PROJECT_VERSION}") ``` -------------------------------- ### Defining Project Name and C++ Standard Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/CMakeLists.txt Sets the project name and the C++ standard to be used for compilation. The C++ standard is set to 20. ```cmake project(Juce8WebViewTutorial) set(CMAKE_CXX_STANDARD 20) ``` -------------------------------- ### Copying JUCE frontend library to plugin UI files Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/plugin/CMakeLists.txt This snippet copies the JUCE frontend library to the plugin's UI files directory. It defines the source directory for the web UI files and then copies the necessary JavaScript files from the JUCE modules directory to the destination directory within the web UI files. ```cmake # Folder where web UI data reside set(WEBVIEW_FILES_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ui/public") # Copy JUCE frontend library to plugin UI files file(COPY "${JUCE_MODULES_DIR}/juce_gui_extra/native/javascript/" DESTINATION "${WEBVIEW_FILES_SOURCE_DIR}/js/juce/") ``` -------------------------------- ### Setting Compiler Warnings Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/CMakeLists.txt Enables strict compiler warnings and treats them as errors. Different warning flags are used for MSVC and other compilers. ```cmake if (MSVC) set(CXX_PROJECT_WARNINGS "/W4;/WX;/wd4820;/wd4514") else() set(CXX_PROJECT_WARNINGS "-Wall;-Werror;-Wextra;-Wpedantic") endif() ``` -------------------------------- ### Setting compile definitions for WebView support Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/plugin/CMakeLists.txt This snippet sets compile definitions to enable WebView support in the JUCE plugin. It defines `JUCE_WEB_BROWSER` to enable the `WebBrowserComponent`, disables `JUCE_USE_CURL`, disables VST2 replacement, and enables WebView2 with static linking on Windows. ```cmake target_compile_definitions(${PROJECT_NAME} PUBLIC # JUCE_WEB_BROWSER=1 is important for using WebBrowserComponent JUCE_WEB_BROWSER=1 JUCE_USE_CURL=0 JUCE_VST3_CAN_REPLACE_VST2=0 # This will enable WebView2 as the WebView backend on Windows JUCE_USE_WIN_WEB_VIEW2_WITH_STATIC_LINKING=1 ) ``` -------------------------------- ### Setting Minimum CMake Version Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/CMakeLists.txt Specifies the minimum required CMake version for the project. JUCE requires CMake 3.22 or higher. ```cmake cmake_minimum_required(VERSION 3.22) ``` -------------------------------- ### Setting compile options for source files Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/plugin/CMakeLists.txt This snippet sets compile options for the source files, using the `CXX_PROJECT_WARNINGS` variable. This allows for custom warning levels to be applied during compilation. ```cmake set_source_files_properties(${SOURCES} PROPERTIES COMPILE_OPTIONS "${CXX_PROJECT_WARNINGS}") ``` -------------------------------- ### Passing zipped files prefix to C++ Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/plugin/CMakeLists.txt This snippet extracts the filename from the public path and passes it as a compile definition to the C++ code. This allows the C++ code to know the prefix of the zipped files. ```cmake # Pass the prefix of the zipped files (e.g., "public/") to C++ cmake_path(GET PUBLIC_PATH FILENAME ZIPPED_FILES_PREFIX) target_compile_definitions(${PROJECT_NAME} PRIVATE ZIPPED_FILES_PREFIX="${ZIPPED_FILES_PREFIX}/") ``` -------------------------------- ### Grouping source files in Visual Studio Source: https://github.com/janwilczek/juce-webview-tutorial/blob/main/plugin/CMakeLists.txt This snippet groups the source files in Visual Studio using source filters. It organizes the files in the solution explorer based on their directory structure. ```cmake # In Visual Studio this command provides a nice grouping of source files in "filters". source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/..) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.