### Library Installation and Linking Source: https://github.com/babylonjs/babylonnative/blob/master/Install/Test/CMakeLists.txt Configures the library installation directory and links the executable against found libraries. It dynamically finds all .lib files in the install lib directory and adds them to the link list. ```cmake message(STATUS "Install lib directory: ${INSTALL_DIR}/lib") set(INSTALL_LIBS_DIR "${INSTALL_DIR}/lib") target_link_directories(TestInstall PRIVATE ${INSTALL_LIBS_DIR}) file(GLOB INSTALL_LIBS "${INSTALL_LIBS_DIR}/*.lib") set(INSTALL_LIB_NAMES) foreach(LIB_PATH ${INSTALL_LIBS}) get_filename_component(LIB_NAME ${LIB_PATH} NAME_WLE) list(APPEND INSTALL_LIB_NAMES ${LIB_NAME}) endforeach() message(STATUS "Found libs:") foreach(LIB_NAME ${INSTALL_LIB_NAMES}) message(STATUS " ${LIB_NAME}") endforeach() ``` -------------------------------- ### Install and Launch Android Validation Tests Source: https://github.com/babylonjs/babylonnative/blob/master/Documentation/ContinuousIntegration.md Installs the validation tests APK onto the Android emulator with all necessary permissions and then starts the main activity for the tests. ```shell adb install -t -g Apps/ValidationTests/Android/app/build/outputs/apk/debug/app-debug.apk adb shell am start -n com.android.babylonnative.validationtests/com.android.babylonnative.validationtests.ValidationTestsActivity ``` -------------------------------- ### Prepare JavaScript Assets Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/PrecompiledShaderTest/README.md Navigate to the JavaScript directory, install dependencies, and build the scene script and preprocessed shaders. ```bash cd JavaScript npm install npm run build ``` -------------------------------- ### Copy Rendering Content (D3D12 Example) Source: https://github.com/babylonjs/babylonnative/blob/master/Plugins/ExternalTexture/Readme.md Example demonstrating how to copy content from a D3D12 frame buffer to CPU-visible memory. This involves retrieving the D3D12 command queue from Babylon Native and creating a new command list for the copy operation. Assumes `externalTextureD3D12Resource` holds the native D3D12 frame buffer and `d3d12Device` is the ID3D12Device used for Babylon Native initialization. ```cpp // Retrieve the ID3D12CommandQueue used by Babylon Native ID3D12CommandQueue* commandQueue = nullptr; d3d12Device->GetPrivateData(Babylon::Graphics::Device::D3D12_COMMAND_QUEUE_PRIVATE_DATA_GUID, &commandQueue); // Create a new command list ID3D12CommandAllocator* commandAllocator; d3d12Device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&commandAllocator)); ID3D12GraphicsCommandList* commandList; d3d12Device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, commandAllocator, nullptr, IID_PPV_ARGS(&commandList)); // Copy the content of the frame buffer ID3D12Resource to CPU visible memory // Assuming externalTextureD3D12Resource is the ID3D12Resource of the frame buffer // and a staging buffer (cpuVisibleBuffer) has been created commandList->CopyResource(cpuVisibleBuffer.Get(), externalTextureD3D12Resource.Get()); // Close the command list and execute it commandList->Close(); commandQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&commandList); // Further operations to map and read from cpuVisibleBuffer would follow... ``` -------------------------------- ### Create and Start Android Emulator Source: https://github.com/babylonjs/babylonnative/blob/master/Documentation/ContinuousIntegration.md Creates a new Android Virtual Device (AVD) named 'test_android_emulator' using system-images for Android 27 and starts it in a detached process. It then waits for the device to boot and the key event to be sent. ```shell echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n test_android_emulator -k 'system-images;android-27;google_apis;x86' --force nohup $ANDROID_HOME/emulator/emulator -avd test_android_emulator -no-snapshot -skin 600x400 > /dev/null 2>&1 & $ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82' ``` -------------------------------- ### Install JavaScriptCore for Linux Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Installs the necessary package for using the JavaScriptCore engine on Ubuntu. ```bash sudo apt-get install libjavascriptcoregtk-4.1-dev ``` -------------------------------- ### NPM Package Installation Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/CMakeLists.txt This command installs Node.js packages using npm. Ensure Node.js and npm are installed and configured in your environment. ```bash npm(install) ``` -------------------------------- ### Install Linux Build Dependencies Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Installs essential packages for building on Ubuntu using a GCC toolchain. ```bash sudo apt-get install libgl1-mesa-dev x11proto-core-dev libx11-dev libcurl4-openssl-dev g++ cmake ninja-build ``` -------------------------------- ### Install PowerShell using winget Source: https://github.com/babylonjs/babylonnative/blob/master/Dependencies/WindowsAppSDK/README.md Installs the latest version of PowerShell using the Windows Package Manager. ```bash winget install Microsoft.PowerShell ``` -------------------------------- ### Install V8 for Linux Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Installs the necessary package for using the V8 JavaScript engine on Ubuntu. ```bash sudo apt-get install libv8-dev ``` -------------------------------- ### Executable Definition and Include Directories Source: https://github.com/babylonjs/babylonnative/blob/master/Install/Test/CMakeLists.txt Defines the main executable target 'TestInstall' and sets its include directories. It also prints the installation include directory status. ```cmake add_executable(TestInstall ${SOURCES}) message(STATUS "Install include directory: ${INSTALL_DIR}/include") target_include_directories(TestInstall PRIVATE "${INSTALL_DIR}/include") ``` -------------------------------- ### Install and Build JavaScript Dependencies Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/PrecompiledShaderTest/CMakeLists.txt Installs Node.js dependencies and builds the JavaScript project. Ensure Node.js and npm are installed. ```cmake set(JS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/JavaScript") npm(install WORKING_DIRECTORY "${JS_DIR}") npm(run build WORKING_DIRECTORY "${JS_DIR}") ``` -------------------------------- ### Linking Libraries to Executable Source: https://github.com/babylonjs/babylonnative/blob/master/Install/Test/CMakeLists.txt Links the 'TestInstall' executable against a list of libraries, including found installation libraries, googletest, and system libraries like d3d11. ```cmake target_link_libraries(TestInstall ${INSTALL_LIB_NAMES} gtest_main chakrart d3d11 d3dcompiler onecore) ``` -------------------------------- ### Compile Multiple Shader Pairs Source: https://github.com/babylonjs/babylonnative/blob/master/Plugins/ShaderTool/README.md Example of using ShaderTool to compile multiple pairs of shaders into a single cache file. ```bash ShaderTool -o cache.bin v1.glsl f1.glsl v2.glsl f2.glsl v3.glsl f3.glsl ``` -------------------------------- ### Compile Single Shader Pair Source: https://github.com/babylonjs/babylonnative/blob/master/Plugins/ShaderTool/README.md Example of using ShaderTool to compile a single pair of vertex and fragment shaders into a cache file. ```bash ShaderTool -o cache.bin vertex.glsl fragment.glsl ``` -------------------------------- ### Configure CMake for arm64 Windows Store Build Source: https://github.com/babylonjs/babylonnative/blob/master/Documentation/FAQ.md Use this CMake command to configure your project for building BabylonNative for arm64 on Windows, targeting the Windows Store. Ensure MSVC for arm64 is installed. ```bash C:>cmake -D CMAKE_SYSTEM_NAME=WindowsStore -D CMAKE_SYSTEM_VERSION=10.0 -A arm64 .. -- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0. CMake Error at CMakeLists.txt:5 (project): Failed to run MSBuild command: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe ``` -------------------------------- ### Open Visual Studio Solution (Windows Desktop) Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Open the generated Visual Studio solution file to begin development on Windows. ```bash start build\win32\BabylonNative.sln ``` -------------------------------- ### Initialize Babylon::Graphics::Device with a Provided Device Source: https://github.com/babylonjs/babylonnative/blob/master/Plugins/ExternalTexture/Readme.md Create a Babylon::Graphics::Device by providing an existing native graphics device. This is crucial for consuming native textures when both Babylon Native and the application share the same graphics device. ```cpp Babylon::Graphics::Configuration graphicsConfig {}; graphicsConfig.Device = d3dDevice; Babylon::Graphics::Device babylonDevice{config}; ``` -------------------------------- ### Setting Default Startup Project Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/Playground/CMakeLists.txt Configures the 'Playground' project as the default startup project when the solution is launched from the IDE. ```cmake set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Playground) ``` -------------------------------- ### Source Grouping Source: https://github.com/babylonjs/babylonnative/blob/master/Embedding/Android/CMakeLists.txt Defines a source group for the 'BabylonNativeEmbedding' target, organizing source files under a tree structure starting from the parent directory. ```cmake source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/.." FILES ${SOURCES}) ``` -------------------------------- ### Set Up Babylon Native Logging Output Source: https://github.com/babylonjs/babylonnative/blob/master/Documentation/DebugTrace.md Configure the logging output by setting a trace output function and enabling debug tracing. Logs will be printed to the console using printf. Ensure thread safety for the output function. ```cpp SetTraceOutput([](const char *trace) { printf("%s\n", trace); }); SetDebugTrace(true); ... DEBUG_TRACE("Error detected."); ``` -------------------------------- ### Configure UWP App Manifest and Assets in CMake Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/Playground/CMakeLists.txt Sets up application package files and assets for Universal Windows Platform (UWP) builds, marking them for deployment. ```cmake set(APPX_FILES "UWP/Package.appxmanifest" "UWP/TemporaryKey.pfx") set_property(SOURCE ${APPX_FILES} PROPERTY VS_DEPLOYMENT_CONTENT 1) set(APPX_ASSETS "UWP/Assets/LockScreenLogo.scale-200.png" "UWP/Assets/SplashScreen.scale-200.png" "UWP/Assets/Square44x44Logo.scale-200.png" "UWP/Assets/Square44x44Logo.targetsize-24_altform-unplated.png" "UWP/Assets/Square150x150Logo.scale-200.png" "UWP/Assets/StoreLogo.png" "UWP/Assets/Wide310x150Logo.scale-200.png") set_property(SOURCE ${APPX_ASSETS} PROPERTY VS_DEPLOYMENT_CONTENT 1) set_property(SOURCE ${APPX_ASSETS} PROPERTY VS_DEPLOYMENT_LOCATION "Assets") set(SOURCES ${SOURCES} ${APPX_FILES} ${APPX_ASSETS} "UWP/App.cpp" "UWP/App.h") ``` -------------------------------- ### Generate Xcode Project for visionOS Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Use this CMake command from the repository root to generate an Xcode project for visionOS. Ensure you have Xcode 15+ and Python 3.0+ installed. ```bash cmake -B build/visionOS -G Xcode -D VISIONOS=ON ``` -------------------------------- ### Configure Window Polyfill Library Source: https://github.com/babylonjs/babylonnative/blob/master/Polyfills/Window/CMakeLists.txt Defines the source files, adds the library, enforces warnings as errors, sets include directories, and links necessary libraries for the Window polyfill. This configuration is essential for building the Window module. ```cmake set(SOURCES "Include/Babylon/Polyfills/Window.h" "Source/Window.h" "Source/Window.cpp") add_library(Window ${SOURCES}) warnings_as_errors(Window) target_include_directories(Window PUBLIC "Include") target_link_libraries(Window PUBLIC napi PRIVATE base-n PRIVATE Scheduling PRIVATE JsRuntimeInternal PRIVATE GraphicsDeviceContext) set_property(TARGET Window PROPERTY FOLDER Polyfills) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) ``` -------------------------------- ### Find ANGLE Libraries on Windows Source: https://github.com/babylonjs/babylonnative/blob/master/CMakeLists.txt Locates ANGLE libraries (libEGL.dll, libGLESv2.dll) from Edge or Chrome installations when OpenGLWindowsDevOnly is enabled. It searches the registry for browser paths and then scans versioned directories for the DLLs. If not found, it raises a fatal error. ```cmake if(BABYLON_NATIVE_OPENGLES_FROM_BROWSER) foreach(_browser_exe "msedge.exe" "chrome.exe") if(ANGLE_LIBEGL) break() endif() foreach(_reg_root "HKLM" "HKCU") if(ANGLE_LIBEGL) break() endif() execute_process( COMMAND reg query "${_reg_root}\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\${_browser_exe}" /ve OUTPUT_VARIABLE _reg_output ERROR_QUIET RESULT_VARIABLE _reg_result OUTPUT_STRIP_TRAILING_WHITESPACE ) if(NOT _reg_result EQUAL 0) continue() endif() string(REGEX MATCH "REG_SZ[ ]+([^ ]+)" _ "${_reg_output}") string(STRIP "${CMAKE_MATCH_1}" _browser_path) if(NOT _browser_path) continue() endif() cmake_path(GET _browser_path PARENT_PATH _browser_dir) file(GLOB _version_dirs LIST_DIRECTORIES true "${_browser_dir}/[0-9]*") list(SORT _version_dirs ORDER DESCENDING) foreach(_version_dir ${_version_dirs}) if(IS_DIRECTORY "${_version_dir}" AND EXISTS "${_version_dir}/libEGL.dll") set(ANGLE_LIBEGL "${_version_dir}/libEGL.dll") set(ANGLE_LIBGLESV2 "${_version_dir}/libGLESv2.dll") message(STATUS "Found ANGLE libraries in: ${_version_dir}") break() endif() endforeach() endforeach() endforeach() if(NOT ANGLE_LIBEGL) message(FATAL_ERROR "OpenGLWindowsDevOnly requires ANGLE libraries (libEGL.dll, libGLESv2.dll) from Edge or Chrome, but none were found.") endif() endif() ``` -------------------------------- ### Build Babylon Native on Linux Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Executes the build process for Babylon Native on Linux using CMake and Ninja. ```bash cmake --build build/linux ``` -------------------------------- ### Open Visual Studio Solution Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Command to open the generated Visual Studio solution file for Babylon Native after CMake configuration. ```bash start build\uwp\BabylonNative.sln ``` -------------------------------- ### Platform Implementation Extension Source: https://github.com/babylonjs/babylonnative/blob/master/CMakeLists.txt Sets the file extension for platform-specific implementation files. Uses '.mm' for Apple platforms (Objective-C++) and '.cpp' for others. ```cmake if(APPLE) set(BABYLON_NATIVE_PLATFORM_IMPL_EXT "mm") else() set(BABYLON_NATIVE_PLATFORM_IMPL_EXT "cpp") endif() ``` -------------------------------- ### Run Linux CI Tests Source: https://github.com/babylonjs/babylonnative/blob/master/Documentation/ContinuousIntegration.md Configures the headless display using Xvfb and then runs the validation tests executable on Linux. The sleep command allows Xvfb to initialize. ```shell export DISPLAY=:99 Xvfb :99 -screen 0 1600x900x24 & sleep 3 cd build/Apps/ValidationTests ./ValidationTests ``` -------------------------------- ### Select Graphics API with Gradle for Android Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md For Android builds, use this Gradle parameter to switch to Vulkan instead of the default OpenGL. ```bash -PGRAPHICS_API=Vulkan ``` -------------------------------- ### Open Xcode Project for macOS Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Command to open the generated Xcode project for macOS development. ```bash open build/macOS/BabylonNative.xcodeproj ``` -------------------------------- ### Open Xcode Project for iOS Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Command to open the generated Xcode project for iOS development. ```bash open build/iOS/BabylonNative.xcodeproj ``` -------------------------------- ### Generate Visual Studio Solution (Windows Desktop x86) Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Use CMake to generate a Visual Studio solution for targeting Windows 32-bit desktop applications. ```bash cmake -B build\win32_x86 -A Win32 ``` -------------------------------- ### Open Xcode Project Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Open the generated Xcode project for Babylon Native. This command assumes you have already run the CMake command to generate the project in the 'build/visionOS' directory. ```bash open build/visionOS/BabylonNative.xcodeproj ``` -------------------------------- ### ShaderTool Command Line Usage Source: https://github.com/babylonjs/babylonnative/blob/master/Plugins/ShaderTool/README.md Basic command-line syntax for the ShaderTool. Specify the output file and pairs of vertex and fragment shader source files. ```bash ShaderTool -o [ ...] ``` -------------------------------- ### Configure DirectXTK for Windows Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/PrecompiledShaderTest/CMakeLists.txt Fetches and configures the DirectXTK library for Windows builds. Sets build options and defines the DirectX architecture. ```cmake FetchContent_Declare(DirectXTK GIT_REPOSITORY https://github.com/microsoft/DirectXTK.git GIT_TAG e7d9b64ca6bb8977d4e3006727deaf57a7c1de84) set(BUILD_TESTING OFF) set(BUILD_TOOLS OFF) set(BUILD_XAUDIO_WIN8 OFF) set(DIRECTX_ARCH ${CMAKE_VS_PLATFORM_NAME}) if(NOT TARGET DirectXTK) FetchContent_MakeAvailable_With_Message(DirectXTK) set_property(TARGET DirectXTK PROPERTY FOLDER Apps/Dependencies) endif() set(SOURCES ${SOURCES} "Source/App.Win32.cpp") set(PLATFORM_LIBRARIES PRIVATE DirectXTK) ``` -------------------------------- ### Create xr Library and Internal Interface Source: https://github.com/babylonjs/babylonnative/blob/master/Dependencies/xr/CMakeLists.txt Adds the main 'xr' library using the defined sources and creates an 'xrInternal' INTERFACE library for internal use. Includes a private compile definition for security. ```cmake add_library(xr ${SOURCES}) add_library(xrInternal INTERFACE) target_compile_definitions(xr PRIVATE _CRT_SECURE_NO_WARNINGS) ``` -------------------------------- ### Select Graphics API with CMake Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Use this CMake parameter to specify the graphics API for Win32, UWP, Android, and Linux builds. The default is D3D11 for Win32/UWP and OpenGL for Linux/Android. ```bash -D GRAPHICS_API= ``` -------------------------------- ### Generate Visual Studio Solution (Windows Desktop Default) Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Use CMake to generate a Visual Studio solution for Windows desktop applications. This command will default to the architecture of the build environment (e.g., x64 on a 64-bit system). ```bash cmake -B build\win32 ``` -------------------------------- ### Set C++ Standard and Project Name Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/Playground/Android/BabylonNative/CMakeLists.txt Configures the C++ standard to C++20 and sets the project name for BabylonNative. ```cmake cmake_minimum_required(VERSION 3.18) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) project(BabylonNative) ``` -------------------------------- ### Configure BabylonNativeEmbedding Target Include Directories Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/Playground/Android/BabylonNative/CMakeLists.txt Adds the playground directory to the include paths for the BabylonNativeEmbedding target. ```cmake target_include_directories(BabylonNativeEmbedding PRIVATE ${PLAYGROUND_DIR}) ``` -------------------------------- ### Configure CMake for Linux with Ninja (JavaScriptCore) Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Configures the build system using CMake to target a Ninja build for Linux, with JavaScriptCore as the engine. ```bash cmake -B build/linux -G Ninja ``` -------------------------------- ### Configure CMake for Windows UWP Build Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Use this command to configure CMake for a Windows UWP build, targeting the default processor architecture. ```bash cmake -B build/uwp -D CMAKE_SYSTEM_NAME=WindowsStore -D CMAKE_SYSTEM_VERSION=10.0 ``` -------------------------------- ### Add Executable for UWP Platform in CMake Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/Playground/CMakeLists.txt Creates a Windows executable for UWP, setting the subsystem to WINDOWS. ```cmake set(WIN32_EXECUTABLE TRUE) add_executable(Playground WIN32 ${REFERENCE_IMAGES} ${BABYLON_SCRIPTS} ${DEPENDENCIES} ${SCRIPTS} ${SOURCES} ${RESOURCE_FILES}) ``` -------------------------------- ### Conditional File Deployment for Windows Store Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/Playground/CMakeLists.txt Sets deployment properties for script and image files when building for the Windows Store. Files are marked as content and placed in specific subdirectories. ```cmake if(WINDOWS_STORE) set_property(SOURCE ${SCRIPTS} ${BABYLON_SCRIPTS} ${DEPENDENCIES} PROPERTY VS_DEPLOYMENT_CONTENT 1) set_property(SOURCE ${SCRIPTS} ${BABYLON_SCRIPTS} ${DEPENDENCIES} PROPERTY VS_DEPLOYMENT_LOCATION "Scripts") set_property(SOURCE ${REFERENCE_IMAGES} PROPERTY VS_DEPLOYMENT_LOCATION "ReferenceImages") else() foreach(SCRIPT ${SCRIPTS} ${BABYLON_SCRIPTS} ${DEPENDENCIES}) get_filename_component(SCRIPT_NAME "${SCRIPT}" NAME) add_custom_command( OUTPUT "${CMAKE_CFG_INTDIR}/Scripts/${SCRIPT_NAME}" COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${SCRIPT}" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Scripts/${SCRIPT_NAME}" COMMENT "Copying ${SCRIPT_NAME}" MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${SCRIPT}") endforeach() foreach(IMAGE ${REFERENCE_IMAGES}) get_filename_component(IMAGE_NAME "${IMAGE}" NAME) add_custom_command( OUTPUT "${CMAKE_CFG_INTDIR}/ReferenceImages/${IMAGE_NAME}" COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${IMAGE}" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/ReferenceImages/${IMAGE_NAME}" COMMENT "Copying ${IMAGE_NAME}" MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${IMAGE}") endforeach() endif() ``` -------------------------------- ### Cloning Babylon Native Repository Source: https://github.com/babylonjs/babylonnative/blob/master/Documentation/Extending.md Standard Git command to clone the Babylon Native repository from GitHub. ```bash git clone https://github.com/BabylonJS/BabylonNative ``` -------------------------------- ### Generate Xcode Project for iOS Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Use this command to generate an Xcode project for iOS development. Specify the IOS=ON flag. ```bash cmake -B build/iOS -G Xcode -D IOS=ON ``` -------------------------------- ### Add BabylonNativeEmbedding Static Library Source: https://github.com/babylonjs/babylonnative/blob/master/Embedding/Apple/CMakeLists.txt Creates a static library named 'BabylonNativeEmbedding' using the specified source files. ```cmake add_library(BabylonNativeEmbedding STATIC ${SOURCES}) ``` -------------------------------- ### Configure Babylon Native Tracing Plugin Source: https://github.com/babylonjs/babylonnative/blob/master/Plugins/NativeTracing/CMakeLists.txt This CMake script configures the NativeTracing library, setting source files, enabling warnings as errors, handling Objective-C ARC for Apple platforms, defining include directories, linking necessary libraries (napi, JsRuntimeInternal, Foundation, arcana), and organizing source files. ```cmake set(SOURCES "Include/Babylon/Plugins/NativeTracing.h" "Source/NativeTracing.cpp") add_library(NativeTracing ${SOURCES}) warnings_as_errors(NativeTracing) if (APPLE) enable_objc_arc(NativeTracing) endif() target_include_directories(NativeTracing PUBLIC "Include") target_link_libraries(NativeTracing PUBLIC napi PRIVATE JsRuntimeInternal PRIVATE Foundation PRIVATE arcana) set_property(TARGET NativeTracing PROPERTY FOLDER Plugins) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) ``` -------------------------------- ### Link Public and Internal Libraries Source: https://github.com/babylonjs/babylonnative/blob/master/Dependencies/xr/CMakeLists.txt Links the 'xr' library with the public 'arcana' library and sets up include directories. Also configures the 'xrInternal' interface library to link against 'xr'. ```cmake target_link_libraries(xr PUBLIC arcana) target_include_directories(xr PUBLIC "Include") target_include_directories(xr PRIVATE "Source/Shared") source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) target_include_directories(xrInternal INTERFACE "Source") target_link_libraries(xrInternal INTERFACE xr) ``` -------------------------------- ### Run Win32 CI Tests Source: https://github.com/babylonjs/babylonnative/blob/master/Documentation/ContinuousIntegration.md Executes the freshly built executable in the working directory for Win32 CI tests. Results and errors are stored in the Artifacts directory. ```shell cd buildWin32_x64\Apps\ValidationTests cd Release ValidationTests ``` -------------------------------- ### Copy Assets to Output Directory Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/PrecompiledShaderTest/CMakeLists.txt Configures post-build commands to copy essential assets (scripts, shaders, reference image) to the executable's output directory. This ensures runtime availability. ```cmake set(ASSETS) foreach(SCRIPT ${SCRIPTS}) list(APPEND ASSETS "${CMAKE_CURRENT_SOURCE_DIR}/${SCRIPT}") endforeach() list(APPEND ASSETS "${SHADERS_BIN}") list(APPEND ASSETS "${CMAKE_CURRENT_SOURCE_DIR}/${REFERENCE_IMAGE}") foreach(ASSET ${ASSETS}) get_filename_component(ASSET_NAME "${ASSET}" NAME) add_custom_command(TARGET PrecompiledShaderTest POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy "${ASSET}" "$/${ASSET_NAME}") endforeach() ``` -------------------------------- ### Define Application Source Files Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/HeadlessScreenshotApp/CMakeLists.txt Defines the lists of Babylon.js scripts, project scripts, and source files for the application. These lists are used to build the executable. ```cmake set(BABYLON_SCRIPTS "../node_modules/babylonjs/babylon.max.js" "../node_modules/babylonjs-loaders/babylonjs.loaders.js") set(SCRIPTS "Scripts/index.js") set(SOURCES "Win32/RenderDoc.h" "Win32/RenderDoc.cpp" "Win32/App.cpp") ``` -------------------------------- ### Configure Babylon Native Xr Plugin Build Source: https://github.com/babylonjs/babylonnative/blob/master/Plugins/NativeXr/CMakeLists.txt This CMake script configures the build for the Babylon Native Xr plugin. It defines the library target, includes necessary directories, and links against required dependencies. ```cmake set(HEADER "Include/Babylon/Plugins/NativeXr.h") FILE(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/Source/*") add_library(NativeXr ${SOURCES} ${HEADER}) warnings_as_errors(NativeXr) target_include_directories(NativeXr PUBLIC "Include") target_link_libraries(NativeXr PUBLIC napi PRIVATE arcana PRIVATE bgfx PRIVATE GraphicsDeviceContext PRIVATE JsRuntimeInternal PRIVATE xr) set_property(TARGET NativeXr PROPERTY FOLDER Plugins) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) if(WINDOWS_STORE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") endif() ``` -------------------------------- ### Add Executable for Win32 Desktop in CMake Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/Playground/CMakeLists.txt Creates a Windows executable for Win32 desktop, configuring it to use the CONSOLE subsystem and specifying the entry point for GUI applications. ```cmake add_executable(Playground ${REFERENCE_IMAGES} ${BABYLON_SCRIPTS} ${DEPENDENCIES} ${SCRIPTS} ${SOURCES} ${RESOURCE_FILES}) set_target_properties(Playground PROPERTIES LINK_FLAGS "/SUBSYSTEM:CONSOLE /ENTRY:wWinMainCRTStartup") ``` -------------------------------- ### Add Win32 Source Files in CMake Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/Playground/CMakeLists.txt Includes necessary source and resource files for Win32 desktop applications. ```cmake set(SOURCES ${SOURCES} "Win32/App.cpp" "Win32/App.h" "Win32/App.ico" "Win32/App.rc" "Win32/Resource.h" "Win32/small.ico" "Win32/targetver.h") ``` -------------------------------- ### Create Shared Library Source: https://github.com/babylonjs/babylonnative/blob/master/Embedding/Android/CMakeLists.txt Builds a shared library named 'BabylonNativeEmbedding' using the defined source files. ```cmake add_library(BabylonNativeEmbedding SHARED ${SOURCES}) ``` -------------------------------- ### Project and C++ Standard Configuration Source: https://github.com/babylonjs/babylonnative/blob/master/Install/Test/CMakeLists.txt Configures the project name and the C++ standard to be used. It also enables the 'USE_FOLDERS' property for better organization in IDEs. ```cmake project(TestInstall) set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) ``` -------------------------------- ### Configure Build Options Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/HeadlessScreenshotApp/CMakeLists.txt Sets build options to disable testing, tools, and specific Windows 8 audio support. These flags control which components are built. ```cmake set(BUILD_TESTING OFF) set(BUILD_TOOLS OFF) set(BUILD_XAUDIO_WIN8 OFF) ``` -------------------------------- ### Configure JavaScriptCore for Apple Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/PrecompiledShaderTest/CMakeLists.txt Finds and links the JavaScriptCore library for Apple platform builds. Includes the Apple-specific source file. ```cmake find_library(JAVASCRIPTCORE_LIBRARY JavaScriptCore) set(SOURCES ${SOURCES} "Source/App.Apple.mm") set(PLATFORM_LIBRARIES PRIVATE ${JAVASCRIPTCORE_LIBRARY}) ``` -------------------------------- ### Define Project and Sources Source: https://github.com/babylonjs/babylonnative/blob/master/Dependencies/xr/CMakeLists.txt Sets the project name and defines the source files for the main library. Platform-specific sources are added conditionally for Android and iOS. ```cmake project(xr) set(DYNAMIC_LOADER OFF CACHE BOOL "Build the loader as a .dll library") set(SOURCES "Include/XR.h" "Source/Shared/XRHelpers.h") if (ANDROID) set(SOURCES ${SOURCES} "Source/ARCore/Include/IXrContextARCore.h" "Source/ARCore/XR.cpp") elseif(IOS OR BABYLON_NATIVE_BUILD_SOURCETREE) set(SOURCES ${SOURCES} "Source/ARKit/Include/IXrContextARKit.h" "Source/ARKit/XR.mm") endif() ``` -------------------------------- ### Configure CMake for Linux with Ninja (V8) Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Configures the build system using CMake to target a Ninja build for Linux, explicitly setting V8 as the JavaScript engine. ```bash cmake -B build/linux -G Ninja -D NAPI_JAVASCRIPT_ENGINE=V8 ``` -------------------------------- ### Custom Build Command for DLL Copying Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/Playground/CMakeLists.txt Adds a post-build custom command to copy runtime DLLs for the Playground target to its output directory. This ensures necessary dynamic libraries are available at runtime. ```cmake add_custom_command(TARGET Playground POST_BUILD COMMAND ${CMAKE_COMMAND} -E $>,copy,true> $ $ COMMAND_EXPAND_LISTS) ``` -------------------------------- ### Create HeadlessScreenshotApp Executable Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/HeadlessScreenshotApp/CMakeLists.txt Adds an executable target named HeadlessScreenshotApp, linking together Babylon.js scripts, project scripts, and source files. It also sets compile definitions for Unicode support. ```cmake add_executable(HeadlessScreenshotApp ${BABYLON_SCRIPTS} ${SCRIPTS} ${SOURCES}) target_compile_definitions(HeadlessScreenshotApp PRIVATE UNICODE PRIVATE _UNICODE) ``` -------------------------------- ### Integrate Component Dependencies with CMake Source: https://github.com/babylonjs/babylonnative/blob/master/Documentation/Extending.md This CMake code demonstrates how to integrate a component's dependencies. Ensure all dependency CMake targets are defined before linking to them. ```cmake add_subdirectory(Core) add_subdirectory(Plugins/NativeEngine) ``` -------------------------------- ### Set Compiler to GCC on Linux Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Sets the C and C++ compilers to GCC for the build process on Linux. ```bash export CC=/usr/bin/gcc export CXX=/usr/bin/g++ ``` -------------------------------- ### Configure Babylon Native Capture Library Source: https://github.com/babylonjs/babylonnative/blob/master/Plugins/NativeCapture/CMakeLists.txt Defines the CMake build configuration for the NativeCapture library. It includes source files, sets include directories, links necessary libraries, and assigns the target to the Plugins folder. ```cmake set(SOURCES "Include/Babylon/Plugins/NativeCapture.h" "Source/NativeCapture.cpp") add_library(NativeCapture ${SOURCES}) warnings_as_errors(NativeCapture) target_include_directories(NativeCapture PUBLIC "Include") target_link_libraries(NativeCapture PUBLIC JsRuntimeInternal PRIVATE GraphicsDeviceContext) set_property(TARGET NativeCapture PROPERTY FOLDER Plugins) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) ``` -------------------------------- ### Set NativeCamera Include Directories Source: https://github.com/babylonjs/babylonnative/blob/master/Plugins/NativeCamera/CMakeLists.txt Configures the include directories for the NativeCamera target, making 'Include' directory publicly available. ```cmake target_include_directories(NativeCamera PUBLIC "Include") ``` -------------------------------- ### Locate Project Directories Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/Playground/Android/BabylonNative/CMakeLists.txt Determines the absolute paths for the Playground directory and the repository root directory. ```cmake get_filename_component(PLAYGROUND_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE) get_filename_component(REPO_ROOT_DIR "${PLAYGROUND_DIR}/../.." ABSOLUTE) ``` -------------------------------- ### Configure CMake for Windows UWP ARM64 Build Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Use this command to configure CMake for a Windows UWP build, specifically targeting the ARM64 architecture. ```bash cmake -B build/uwp_arm64 -D CMAKE_SYSTEM_NAME=WindowsStore -D CMAKE_SYSTEM_VERSION=10.0 -A arm64 ``` -------------------------------- ### Link WindowsApp Library for UWP in CMake Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/Playground/CMakeLists.txt Links the 'windowsapp' library to the 'Playground' target when building for UWP. ```cmake target_link_libraries(Playground PRIVATE windowsapp) ``` -------------------------------- ### Configure Include Directories for BabylonNativeEmbedding Source: https://github.com/babylonjs/babylonnative/blob/master/Embedding/Apple/CMakeLists.txt Sets public and private include directories for the BabylonNativeEmbedding library. Public includes are accessible to targets linking against this library, while private includes are only for its internal use. ```cmake target_include_directories(BabylonNativeEmbedding PUBLIC "${APPLE_EMBEDDING_INCLUDE_ROOT}" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/Source") ``` -------------------------------- ### Enable Bitcode for iOS Builds Source: https://github.com/babylonjs/babylonnative/blob/master/BUILDING.md Add this option to the CMake command line to enable bitcode support for iOS builds. ```bash cmake -B build/iOS -G Xcode -D IOS=ON -D ENABLE_BITCODE=ON ``` -------------------------------- ### Link Libraries to Executable Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/HeadlessScreenshotApp/CMakeLists.txt Links necessary libraries to the HeadlessScreenshotApp executable. Ensure these libraries are available and correctly configured in your build environment. ```cmake target_link_libraries(HeadlessScreenshotApp PRIVATE AppRuntime PRIVATE Console PRIVATE DirectXTK PRIVATE ExternalTexture PRIVATE NativeEngine PRIVATE ScriptLoader PRIVATE Window PRIVATE XMLHttpRequest) ``` -------------------------------- ### Set Compile Definitions Source: https://github.com/babylonjs/babylonnative/blob/master/Apps/StyleTransferApp/CMakeLists.txt Configures preprocessor definitions for the executable target, ensuring Unicode support. ```cmake target_compile_definitions(StyleTransferApp PRIVATE UNICODE PRIVATE _UNICODE) ``` -------------------------------- ### Configure Validation Tests Source: https://github.com/babylonjs/babylonnative/blob/master/Documentation/AddingNewValidationTests.md Add a new test scene by updating the config.json file with the playground ID and reference image name. ```json { "root": "https://cdn.babylonjs.com", "tests": [ { "title": "setParent", "playgroundId": "#JD49CT#2", "referenceImage": "setParent.png" }, ... } ```