### Defining GLFW Example Executables - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/examples/CMakeLists.txt Defines various example executables using the `add_executable` command. Each definition specifies the target name, platform properties (WIN32, MACOSX_BUNDLE), the main source file, the icon file, and required dependency source files (GLAD, TINYCTHREAD, GETOPT). ```CMake add_executable(boing WIN32 MACOSX_BUNDLE boing.c ${ICON} ${GLAD}) add_executable(gears WIN32 MACOSX_BUNDLE gears.c ${ICON} ${GLAD}) add_executable(heightmap WIN32 MACOSX_BUNDLE heightmap.c ${ICON} ${GLAD}) add_executable(offscreen offscreen.c ${ICON} ${GLAD}) add_executable(particles WIN32 MACOSX_BUNDLE particles.c ${ICON} ${TINYCTHREAD} ${GETOPT} ${GLAD}) add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c ${ICON} ${GLAD}) add_executable(simple WIN32 MACOSX_BUNDLE simple.c ${ICON} ${GLAD}) add_executable(splitview WIN32 MACOSX_BUNDLE splitview.c ${ICON} ${GLAD}) add_executable(wave WIN32 MACOSX_BUNDLE wave.c ${ICON} ${GLAD}) ``` -------------------------------- ### Configuring MSVC Entry Point - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/examples/CMakeLists.txt Sets the linker flags for Windows executables specifically for the MSVC compiler. The `/ENTRY:mainCRTStartup` flag forces MSVC to use the `main` function as the entry point instead of the default `WinMain` for GUI applications. ```CMake if (MSVC) # Tell MSVC to use main instead of WinMain for Windows subsystem executables set_target_properties(${WINDOWS_BINARIES} PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup") endif() ``` -------------------------------- ### Including GLFW and Dependency Headers - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/examples/CMakeLists.txt Adds include directories required for compiling GLFW examples. This includes the main GLFW headers and headers from its dependencies located in the 'deps' directory. ```CMake include_directories(${glfw_INCLUDE_DIRS} "${GLFW_SOURCE_DIR}/deps") ``` -------------------------------- ### Installing Headers, Config Files, and pkgconfig (CMake) Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/CMakeLists.txt This conditional block handles the installation of various files necessary for using the installed GLFW library, assuming the GLFW_INSTALL variable is true. It installs header files, the generated CMake configuration files, exports targets for linking, installs the generated pkgconfig file, and optionally creates an 'uninstall' custom target. The primary library artifact installation is handled by the src/CMakeLists.txt. ```CMake if (GLFW_INSTALL) install(DIRECTORY include/GLFW DESTINATION include FILES_MATCHING PATTERN glfw3.h PATTERN glfw3native.h) install(FILES "${GLFW_BINARY_DIR}/src/glfw3Config.cmake" "${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake" DESTINATION "${GLFW_CONFIG_PATH}") install(EXPORT glfwTargets FILE glfw3Targets.cmake EXPORT_LINK_INTERFACE_LIBRARIES DESTINATION "${GLFW_CONFIG_PATH}") install(FILES "${GLFW_BINARY_DIR}/src/glfw3.pc" DESTINATION "lib${LIB_SUFFIX}/pkgconfig") # Only generate this target if no higher-level project already has if (NOT TARGET uninstall) configure_file(cmake_uninstall.cmake.in cmake_uninstall.cmake IMMEDIATE @ONLY) add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${GLFW_BINARY_DIR}/cmake_uninstall.cmake") set_target_properties(uninstall PROPERTIES FOLDER "GLFW3") endif() endif() ``` -------------------------------- ### Defining Variables for Dependency Source Files - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/examples/CMakeLists.txt Defines CMake variables (`GLAD`, `GETOPT`, `TINYCTHREAD`) that group the source (.c) and header (.h) files for common dependencies used by multiple examples. This simplifies adding these files to target definitions. ```CMake set(GLAD "${GLFW_SOURCE_DIR}/deps/glad/glad.h" "${GLFW_SOURCE_DIR}/deps/glad.c") set(GETOPT "${GLFW_SOURCE_DIR}/deps/getopt.h" "${GLFW_SOURCE_DIR}/deps/getopt.c") set(TINYCTHREAD "${GLFW_SOURCE_DIR}/deps/tinycthread.h" "${GLFW_SOURCE_DIR}/deps/tinycthread.c") ``` -------------------------------- ### Linking Libraries for Particles Example - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/examples/CMakeLists.txt Links thread-related libraries to the 'particles' example executable. It links `CMAKE_THREAD_LIBS_INIT` (which resolves to pthreads or similar) and conditionally links an RT library if `RT_LIBRARY` is defined. ```CMake target_link_libraries(particles "${CMAKE_THREAD_LIBS_INIT}") if (RT_LIBRARY) target_link_libraries(particles "${RT_LIBRARY}") endif() ``` -------------------------------- ### Quoting Text Markdown Example Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/docs/CONTRIBUTING.md This snippet demonstrates the basic Markdown syntax using triple backticks to quote a block of text or code without specifying a programming language for syntax highlighting. This is useful for formatting generic text or console output within a GitHub issue. ```Markdown Some quoted text. ``` -------------------------------- ### Quoting C Code Markdown Example Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/docs/CONTRIBUTING.md This snippet shows how to use Markdown's triple backtick syntax followed by the language identifier 'c' to quote a block of C code with syntax highlighting. This is recommended for sharing code examples when reporting bugs or discussing implementation details. ```C int five(void) { return 5; } ``` -------------------------------- ### Define GLFW Installation Rules (CMake) Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/src/CMakeLists.txt Defines rules for installing the `glfw` target if `GLFW_INSTALL` is enabled, specifying destinations for runtime binaries, archive libraries, and shared libraries. ```CMake if (GLFW_INSTALL) install(TARGETS glfw EXPORT glfwTargets RUNTIME DESTINATION "bin" ARCHIVE DESTINATION "lib${LIB_SUFFIX}" LIBRARY DESTINATION "lib${LIB_SUFFIX}") endif() ``` -------------------------------- ### Bug Reporting Template: Window/Input/Event Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/docs/CONTRIBUTING.md Provides a quick template listing the essential information required when reporting bugs related to window handling, user input, or specific events. Includes fields for OS details, release/commit, error messages, and output from the 'events' tool. ```Text OS and version:\nRelease or commit:\nError messages:\nevents output: ``` -------------------------------- ### Configuring Global Properties and Build Options Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/CMakeLists.txt Sets the global property `USE_FOLDERS` for better organization in IDEs. Defines various boolean build options to control building shared libraries, examples, tests, documentation, installation target, and static Vulkan linking. ```CMake set_property(GLOBAL PROPERTY USE_FOLDERS ON) option(BUILD_SHARED_LIBS "Build shared libraries" OFF) option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ON) option(GLFW_BUILD_TESTS "Build the GLFW test programs" ON) option(GLFW_BUILD_DOCS "Build the GLFW documentation" ON) option(GLFW_INSTALL "Generate installation target" ON) option(GLFW_VULKAN_STATIC "Use the Vulkan loader statically linked into application" OFF) ``` -------------------------------- ### Grouping Executables by Platform Type - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/examples/CMakeLists.txt Defines CMake variables (`WINDOWS_BINARIES`, `CONSOLE_BINARIES`) that list the names of the example executables. This allows applying properties to groups of targets efficiently. ```CMake set(WINDOWS_BINARIES boing gears heightmap particles sharing simple splitview wave) set(CONSOLE_BINARIES offscreen) ``` -------------------------------- ### Linking GLFW Library - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/examples/CMakeLists.txt Links the GLFW library to all subsequent targets. This is a fundamental step required for building applications that depend on GLFW. ```CMake link_libraries(glfw) ``` -------------------------------- ### Adding OSMesa Definition - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/examples/CMakeLists.txt Adds the `USE_NATIVE_OSMESA` preprocessor definition if the `GLFW_USE_OSMESA` CMake variable is true. This enables support for building examples with OSMesa. ```CMake if (GLFW_USE_OSMESA) add_definitions(-DUSE_NATIVE_OSMESA) endif() ``` -------------------------------- ### Setting Target Folder Property - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/examples/CMakeLists.txt Sets the `FOLDER` property for all defined example executables. This organizes the targets into a specific folder ('GLFW3/Examples') within IDE project views (like Visual Studio or Xcode). ```CMake set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES FOLDER "GLFW3/Examples") ``` -------------------------------- ### Bug Reporting Template: Other Library Bugs Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/docs/CONTRIBUTING.md Provides a quick template listing the essential information required when reporting bugs in the library that are not related to window, input, or events. Includes fields for OS details, release/commit, and relevant error messages. ```Text OS and version:\nRelease or commit:\nError messages: ``` -------------------------------- ### Conditionally Linking Math Library - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/examples/CMakeLists.txt Links a math library if the `MATH_LIBRARY` variable is defined. This is often required for mathematical functions used in some examples. ```CMake if (MATH_LIBRARY) link_libraries("${MATH_LIBRARY}") endif() ``` -------------------------------- ### Disabling Optional GLFW Components CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/CMakeLists.txt Explicitly disables the building of optional components within the GLFW library sub-project, such as examples, tests, documentation, and the install target. This helps streamline the build process and reduces build time by only compiling the necessary parts of GLFW. ```CMake option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" OFF) option(GLFW_BUILD_TESTS "Build the GLFW test programs" OFF) option(GLFW_BUILD_DOCS "Build the GLFW documentation" OFF) option(GLFW_INSTALL "Generate installation target" OFF) ``` -------------------------------- ### Adding Component Subdirectories to Build (CMake) Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/CMakeLists.txt This snippet includes CMakeLists.txt files from various subdirectories (src, examples, tests, docs) into the main build process. The inclusion of examples, tests, and docs is conditional on CMake variables, allowing users to build only the desired components. The core library source directory (src) is always included. ```CMake add_subdirectory(src) if (GLFW_BUILD_EXAMPLES) add_subdirectory(examples) endif() if (GLFW_BUILD_TESTS) add_subdirectory(tests) endif() if (DOXYGEN_FOUND AND GLFW_BUILD_DOCS) add_subdirectory(docs) endif() ``` -------------------------------- ### Setting macOS Bundle Properties - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/examples/CMakeLists.txt Configures macOS-specific properties for each executable designated as a `MACOSX_BUNDLE`. This includes setting bundle display names, associating the icon file, and embedding version information and an Info.plist file. ```CMake if (APPLE) set_target_properties(boing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Boing") set_target_properties(gears PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gears") set_target_properties(heightmap PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Heightmap") set_target_properties(particles PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Particles") set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing") set_target_properties(simple PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Simple") set_target_properties(splitview PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "SplitView") set_target_properties(wave PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Wave") set_target_properties(${WINDOWS_BINARIES} PROPERTIES RESOURCE glfw.icns MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION} MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL} MACOSX_BUNDLE_ICON_FILE glfw.icns MACOSX_BUNDLE_INFO_PLIST "${GLFW_SOURCE_DIR}/CMake/MacOSXBundleInfo.plist.in") endif() ``` -------------------------------- ### Set Include Directories for GLFW (CMake) Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/src/CMakeLists.txt Specifies the include directories for the `glfw` target, including public interface directories for build and install paths, and private directories for source and binary locations. ```CMake target_include_directories(glfw PUBLIC "$" "$/include>") target_include_directories(glfw PRIVATE "${GLFW_SOURCE_DIR}/src" "${GLFW_BINARY_DIR}/src" ${glfw_INCLUDE_DIRS}) ``` -------------------------------- ### Adding MSVC Secure Warning Definition - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/examples/CMakeLists.txt Adds the `_CRT_SECURE_NO_WARNINGS` preprocessor definition specifically for the MSVC compiler. This disables warnings related to potentially unsafe C runtime functions. ```CMake if (MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) endif() ``` -------------------------------- ### Setting Platform-Specific Icon Files - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/examples/CMakeLists.txt Defines variables for the application icon file based on the target platform (Windows or Apple). For Apple, it also sets a source file property for the icon's location within the bundle. ```CMake if (WIN32) set(ICON glfw.rc) elseif (APPLE) set(ICON glfw.icns) set_source_files_properties(glfw.icns PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") endif() ``` -------------------------------- ### Defining GLFW Version Information Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/CMakeLists.txt Sets the major, minor, patch, and extra version components for GLFW, constructing full version strings. It also defines a cache variable `LIB_SUFFIX` to control the library installation directory. ```CMake set(GLFW_VERSION_MAJOR "3") set(GLFW_VERSION_MINOR "3") set(GLFW_VERSION_PATCH "0") set(GLFW_VERSION_EXTRA "") set(GLFW_VERSION "${GLFW_VERSION_MAJOR}.${GLFW_VERSION_MINOR}") set(GLFW_VERSION_FULL "${GLFW_VERSION}.${GLFW_VERSION_PATCH}${GLFW_VERSION_EXTRA}") set(LIB_SUFFIX "" CACHE STRING "Takes an empty string or 64. Directory where lib will be installed: lib or lib64") ``` -------------------------------- ### Generating Configuration and Package Files (CMake) Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/CMakeLists.txt This snippet generates various build and package configuration files required for consuming the GLFW library after installation. It uses CMakePackageConfigHelpers to create CMake config files (glfw3Config.cmake, glfw3ConfigVersion.cmake) from templates, a C header (glfw_config.h) containing build-time configuration, and a pkgconfig file (glfw3.pc). These files are populated with build-specific paths and variables using @ONLY substitution. ```CMake include(CMakePackageConfigHelpers) set(GLFW_CONFIG_PATH "lib${LIB_SUFFIX}/cmake/glfw3") configure_package_config_file(src/glfw3Config.cmake.in src/glfw3Config.cmake INSTALL_DESTINATION "${GLFW_CONFIG_PATH}" NO_CHECK_REQUIRED_COMPONENTS_MACRO) write_basic_package_version_file(src/glfw3ConfigVersion.cmake VERSION ${GLFW_VERSION_FULL} COMPATIBILITY SameMajorVersion) configure_file(src/glfw_config.h.in src/glfw_config.h @ONLY) configure_file(src/glfw3.pc.in src/glfw3.pc @ONLY) ``` -------------------------------- ### Configuring CMake Build for Ultralight Sample App Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 6 - Intro to C API/CMakeLists.txt This CMake script sets up the build for an Ultralight sample application. It defines the project name, includes necessary directories for the Ultralight SDK, links the required libraries, creates an executable from the source file, applies platform-specific properties for macOS bundles and MSVC entry points, and adds post-build commands to copy runtime binaries, assets, and resources. ```CMake set(APP_NAME Sample6) include_directories("${ULTRALIGHT_INCLUDE_DIR}") link_directories("${ULTRALIGHT_LIBRARY_DIR}") link_libraries(UltralightCore AppCore Ultralight WebCore) add_executable(${APP_NAME} WIN32 MACOSX_BUNDLE "main.c") if (APPLE) # Enable High-DPI on macOS through our custom Info.plist template set_target_properties(${APP_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in) endif() if (MSVC) # Tell MSVC to use main instead of WinMain for Windows subsystem executables set_target_properties(${APP_NAME} PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup") endif() # Copy all binaries to target directory add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${ULTRALIGHT_BINARY_DIR}" $) # Set the assets path to "/assets" or "/../Resources/assets" on macOS if (APPLE) set(ASSETS_PATH "$/../Resources/assets") else () set(ASSETS_PATH "$/assets") endif () # Copy assets to assets directory add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/assets/" "${ASSETS_PATH}") # Copy resources to assets directory add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${ULTRALIGHT_RESOURCES_DIR}" "${ASSETS_PATH}/resources") ``` -------------------------------- ### Configuring Ultralight Project Basics - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 9 - Multi Window/CMakeLists.txt Sets the application name, adds Ultralight include and library directories, and links the required Ultralight and AppCore libraries to the project. ```CMake set(APP_NAME Sample9) include_directories("${ULTRALIGHT_INCLUDE_DIR}") link_directories("${ULTRALIGHT_LIBRARY_DIR}") link_libraries(UltralightCore AppCore Ultralight WebCore) ``` -------------------------------- ### Configuring Ultralight Project and Linking Libraries - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 8 - Web Browser/CMakeLists.txt This snippet sets the target application name, specifies include directories for Ultralight headers, adds directories where Ultralight libraries can be found, and links the necessary Ultralight library components for the project. Requires ULTRALIGHT_INCLUDE_DIR and ULTRALIGHT_LIBRARY_DIR variables. ```CMake set(APP_NAME Sample8) include_directories("${ULTRALIGHT_INCLUDE_DIR}") link_directories("${ULTRALIGHT_LIBRARY_DIR}") link_libraries(UltralightCore AppCore Ultralight WebCore) ``` -------------------------------- ### Creating Executable Target CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/CMakeLists.txt Defines the main executable target using the specified source files and GLAD sources. The `MACOSX_BUNDLE` option is included, indicating that the target should be built as a macOS application bundle. ```CMake add_executable(${APP_NAME} MACOSX_BUNDLE ${SOURCES} ${GLAD_SOURCES}) ``` -------------------------------- ### Setting MSVC Entry Point - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 9 - Multi Window/CMakeLists.txt Configures Microsoft Visual C++ specific link flags for the executable. If building with MSVC, it sets the `/ENTRY:mainCRTStartup` flag to use the standard C main function instead of WinMain for Windows subsystem executables. ```CMake if (MSVC) # Tell MSVC to use main instead of WinMain for Windows subsystem executables set_target_properties(${APP_NAME} PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup") endif() ``` -------------------------------- ### Setting MSVC Entry Point for Windows (CMake) Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 4 - JavaScript/CMakeLists.txt Applies target properties specifically for MSVC builds (`if (MSVC)`). It sets the `LINK_FLAGS` property to `/ENTRY:mainCRTStartup`, instructing the MSVC linker to use the standard `main` function as the entry point for a Windows subsystem executable instead of the default `WinMain`. ```CMake if (MSVC) # Tell MSVC to use main instead of WinMain for Windows subsystem executables set_target_properties(${APP_NAME} PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup") endif() ``` -------------------------------- ### Configure Basic Project Settings and Dependencies CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 5 - File Loading/CMakeLists.txt Sets the application name, specifies include and library directories for Ultralight, and links the required Ultralight libraries to the project. Required variables like `ULTRALIGHT_INCLUDE_DIR`, `ULTRALIGHT_LIBRARY_DIR`, `UltralightCore`, `AppCore`, `Ultralight`, and `WebCore` must be defined externally (e.g., via CMake find_package or parent project). ```CMake set(APP_NAME Sample5) include_directories("${ULTRALIGHT_INCLUDE_DIR}") link_directories("${ULTRALIGHT_LIBRARY_DIR}") link_libraries(UltralightCore AppCore Ultralight WebCore) ``` -------------------------------- ### Linking Ultralight Libraries (CMake) Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 1 - Render to PNG/CMakeLists.txt This command specifies the specific Ultralight libraries that the application needs to link against. The list includes core components like `UltralightCore`, `Ultralight`, `WebCore`, and `AppCore`, which provide the necessary functionality for the sample application. ```CMake link_libraries(UltralightCore Ultralight WebCore AppCore) ``` -------------------------------- ### Copying Ultralight Binaries Post-Build (CMake) Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 1 - Render to PNG/CMakeLists.txt This adds a custom command that runs after the executable target is built. It uses the `cmake -E copy_directory` command to copy the Ultralight binary directory (`ULTRALIGHT_BINARY_DIR`) into the executable's output directory (`$`). This ensures necessary runtime dependencies are available. ```CMake add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${ULTRALIGHT_BINARY_DIR}" $) ``` -------------------------------- ### Setting MSVC Entry Point - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 3 - Resizable App/CMakeLists.txt Conditionally sets the /ENTRY:mainCRTStartup link flag for the executable target when building with the MSVC compiler (MSVC). This tells MSVC to use the standard C/C++ main function as the entry point instead of the default Windows-specific WinMain for subsystem executables. ```CMake if (MSVC) # Tell MSVC to use main instead of WinMain for Windows subsystem executables set_target_properties(${APP_NAME} PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup") endif() ``` -------------------------------- ### Copying Ultralight Binaries Post-Build (CMake) Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 4 - JavaScript/CMakeLists.txt Adds a custom command that executes after the target executable is built (`POST_BUILD`). It uses the `CMAKE_COMMAND -E copy_directory` command to copy the contents of the `ULTRALIGHT_BINARY_DIR` (containing Ultralight DLLs/shared libraries) to the target executable's output directory (`$`). ```CMake add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${ULTRALIGHT_BINARY_DIR}" $) ``` -------------------------------- ### Configuring Build Paths and Libraries - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 3 - Resizable App/CMakeLists.txt Sets the application name for the target, includes necessary header directories, specifies library search paths, and links the required Ultralight and AppCore libraries for the project build. Depends on predefined CMake variables like ULTRALIGHT_INCLUDE_DIR and ULTRALIGHT_LIBRARY_DIR. ```CMake set(APP_NAME Sample3) include_directories("${ULTRALIGHT_INCLUDE_DIR}") link_directories("${ULTRALIGHT_LIBRARY_DIR}") link_libraries(UltralightCore AppCore Ultralight WebCore) ``` -------------------------------- ### Defining Application and GLAD Source Files CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/CMakeLists.txt Specifies the source files (.h and .cpp) that constitute the main application logic and the GLAD OpenGL loader sources. These files are collected into variables that will be used later to define the executable target. ```CMake set(GLAD_SOURCES "${GLFW_DIR}/deps/glad/glad.h" "${GLFW_DIR}/deps/glad.c") set(SOURCES "src/Sample.h" "src/Sample.cpp" "src/WebTile.h" "src/WebTile.cpp" "src/Window.h" "src/Window.cpp" "src/GLTextureSurface.h" "src/GLTextureSurface.cpp" "src/main.cpp") ``` -------------------------------- ### Setting Ultralight Project Name and Linking Libraries (CMake) Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 4 - JavaScript/CMakeLists.txt Sets the application name, includes necessary directories for Ultralight headers, links directories containing Ultralight libraries, and specifies the required libraries (UltralightCore, AppCore, Ultralight, WebCore) for linking the executable. ```CMake set(APP_NAME Sample4) include_directories("${ULTRALIGHT_INCLUDE_DIR}") link_directories("${ULTRALIGHT_LIBRARY_DIR}") link_libraries(UltralightCore AppCore Ultralight WebCore) ``` -------------------------------- ### Configuring Ultralight Library Integration CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/CMakeLists.txt Configures the necessary include directories and library paths for the Ultralight framework and links the core Ultralight libraries required by the application. This step is essential for the compiler and linker to find the Ultralight headers and binaries. ```CMake include_directories("${ULTRALIGHT_INCLUDE_DIR}") link_directories("${ULTRALIGHT_LIBRARY_DIR}") link_libraries(UltralightCore Ultralight WebCore AppCore) ``` -------------------------------- ### Linking Ultralight Libraries Directory (CMake) Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 1 - Render to PNG/CMakeLists.txt This command adds the directory containing the Ultralight library files (e.g., `.lib`, `.dylib`, `.so`) to the linker's search path. The `ULTRALIGHT_LIBRARY_DIR` variable should point to where the compiled Ultralight libraries are located. This helps the linker find the required binaries during the final build stage. ```CMake link_directories("${ULTRALIGHT_LIBRARY_DIR}") ``` -------------------------------- ### Configuring for X11 Backend Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/CMakeLists.txt Finds the necessary X11 packages (including RandR, Xinerama, Xkb, and Xcursor) if the X11 backend is selected. It adds their include directories and libraries to the respective lists and adds required pkg-config dependencies. ```CMake if (_GLFW_X11) find_package(X11 REQUIRED) list(APPEND glfw_PKG_DEPS "x11") # Set up library and include paths list(APPEND glfw_INCLUDE_DIRS "${X11_X11_INCLUDE_PATH}") list(APPEND glfw_LIBRARIES "${X11_X11_LIB}" "${CMAKE_THREAD_LIBS_INIT}") # Check for XRandR (modern resolution switching and gamma control) if (NOT X11_Xrandr_FOUND) message(FATAL_ERROR "The RandR headers were not found") endif() # Check for Xinerama (legacy multi-monitor support) if (NOT X11_Xinerama_FOUND) message(FATAL_ERROR "The Xinerama headers were not found") endif() # Check for Xkb (X keyboard extension) if (NOT X11_Xkb_FOUND) message(FATAL_ERROR "The X keyboard extension headers were not found") endif() # Check for Xcursor (cursor creation from RGBA images) if (NOT X11_Xcursor_FOUND) message(FATAL_ERROR "The Xcursor headers were not found") endif() list(APPEND glfw_INCLUDE_DIRS "${X11_Xrandr_INCLUDE_PATH}" "${X11_Xinerama_INCLUDE_PATH}" "${X11_Xkb_INCLUDE_PATH}" "${X11_Xcursor_INCLUDE_PATH}") endif() ``` -------------------------------- ### Copying Ultralight Binaries Post-Build - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 8 - Web Browser/CMakeLists.txt This command adds a custom build step that executes after the main target is built. It uses cmake -E copy_directory to copy the contents of the ULTRALIGHT_BINARY_DIR (containing Ultralight runtime DLLs/SOs/dylibs) to the directory where the application executable is located. Requires ULTRALIGHT_BINARY_DIR variable. ```CMake add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${ULTRALIGHT_BINARY_DIR}" $) ``` -------------------------------- ### Adding Application Executable (CMake) Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 1 - Render to PNG/CMakeLists.txt This command defines the main executable target for the project. It names the target using the previously defined `APP_NAME` variable and specifies 'main.cpp' as the source file from which the executable will be built. This is the primary output of the build process. ```CMake add_executable(${APP_NAME} "main.cpp") ``` -------------------------------- ### Configuring for Wayland Backend Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/CMakeLists.txt Finds necessary Wayland packages (Client, Cursor, Egl), WaylandScanner, WaylandProtocols, and XKBCommon if the Wayland backend is selected. It adds their include directories and libraries and includes epoll-shim for non-Linux systems if available. ```CMake if (_GLFW_WAYLAND) find_package(ECM REQUIRED NO_MODULE) list(APPEND CMAKE_MODULE_PATH "${ECM_MODULE_PATH}") find_package(Wayland REQUIRED Client Cursor Egl) find_package(WaylandScanner REQUIRED) find_package(WaylandProtocols 1.12 REQUIRED) list(APPEND glfw_PKG_DEPS "wayland-egl") list(APPEND glfw_INCLUDE_DIRS "${Wayland_INCLUDE_DIRS}") list(APPEND glfw_LIBRARIES "${Wayland_LIBRARIES}" "${CMAKE_THREAD_LIBS_INIT}") find_package(XKBCommon REQUIRED) list(APPEND glfw_INCLUDE_DIRS "${XKBCOMMON_INCLUDE_DIRS}") include(CheckIncludeFiles) check_include_files(xkbcommon/xkbcommon-compose.h HAVE_XKBCOMMON_COMPOSE_H) if (NOT ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")) find_package(EpollShim) if (EPOLLSHIM_FOUND) list(APPEND glfw_INCLUDE_DIRS "${EPOLLSHIM_INCLUDE_DIRS}") list(APPEND glfw_LIBRARIES "${EPOLLSHIM_LIBRARIES}") endif() endif() endif() ``` -------------------------------- ### Copy Ultralight Binaries Post-Build CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 5 - File Loading/CMakeLists.txt Adds a custom command that runs after the executable is built. It copies all files from the `ULTRALIGHT_BINARY_DIR` (presumably containing DLLs, dylibs, etc.) to the executable's output directory. `ULTRALIGHT_BINARY_DIR` must be defined externally. ```CMake add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${ULTRALIGHT_BINARY_DIR}" $) ``` -------------------------------- ### Consolidating Package Dependencies and Libraries (CMake) Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/CMakeLists.txt This snippet iterates through the lists collected in glfw_PKG_DEPS and glfw_PKG_LIBS during dependency finding and concatenates the items into single space-separated strings, GLFW_PKG_DEPS and GLFW_PKG_LIBS. These consolidated strings are used when generating pkgconfig files or CMake package configuration files for the installed library, making dependency information easily accessible. ```CMake foreach(arg ${glfw_PKG_DEPS}) set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} ${arg}") endforeach() foreach(arg ${glfw_PKG_LIBS}) set(GLFW_PKG_LIBS "${GLFW_PKG_LIBS} ${arg}") endforeach() ``` -------------------------------- ### Add Executable Target CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 5 - File Loading/CMakeLists.txt Defines the main executable target for the application, specifying the target name (`APP_NAME`) and the source file (`main.cpp`). The `WIN32` and `MACOSX_BUNDLE` flags are used to indicate that this is a GUI application on Windows and a bundle on macOS. ```CMake add_executable(${APP_NAME} WIN32 MACOSX_BUNDLE "main.cpp") ``` -------------------------------- ### Configuring MSVC Entry Point for Windows - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 8 - Web Browser/CMakeLists.txt This conditional block applies only when building with the MSVC compiler. It sets a linker flag /ENTRY:mainCRTStartup to ensure that the main function is used as the entry point for the Windows subsystem executable, rather than the default WinMain. ```CMake if (MSVC) # Tell MSVC to use main instead of WinMain for Windows subsystem executables set_target_properties(${APP_NAME} PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup") endif() ``` -------------------------------- ### Adding Sample Executable in CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 4 - JavaScript/CMakeLists.txt Defines the executable target using the `add_executable` command. It names the executable using the `APP_NAME` variable and specifies the source file `main.cpp`. It also includes flags (`WIN32`, `MACOSX_BUNDLE`) for platform-specific executable types. ```CMake add_executable(${APP_NAME} WIN32 MACOSX_BUNDLE "main.cpp") ``` -------------------------------- ### Adding Sample Application Executable - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 9 - Multi Window/CMakeLists.txt Defines the executable target for the application. It is configured as a Win32 application on Windows and a MACOSX_BUNDLE on macOS, using 'main.cpp' as the source file. ```CMake add_executable(${APP_NAME} WIN32 MACOSX_BUNDLE "main.cpp") ``` -------------------------------- ### Copying Ultralight Resources Post-Build - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 3 - Resizable App/CMakeLists.txt Defines a custom build command executed after the target executable is built. It copies the contents of the ULTRALIGHT_RESOURCES_DIR (containing rendering resources like fonts) to a 'resources' subdirectory within the determined ASSETS_PATH. This ensures Ultralight has access to necessary resources for rendering web content. ```CMake add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${ULTRALIGHT_RESOURCES_DIR}" "${ASSETS_PATH}/resources") ``` -------------------------------- ### Configure MSVC Entry Point CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 5 - File Loading/CMakeLists.txt Conditionally sets the `LINK_FLAGS` property for the target executable when building with MSVC. This forces the linker to use `mainCRTStartup` as the entry point for Windows subsystem executables, allowing the use of a standard `main` function instead of `WinMain`. ```CMake if (MSVC) # Tell MSVC to use main instead of WinMain for Windows subsystem executables set_target_properties(${APP_NAME} PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup") endif() ``` -------------------------------- ### Copying Ultralight Binaries Post-Build in CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 2 - Basic App/CMakeLists.txt This snippet adds a custom command that executes after the build process is complete. It uses the CMake command-line tool to copy the Ultralight binaries from their source directory to the build output directory where the application executable is located. This ensures that the application can find the necessary shared libraries or DLLs at runtime. ```CMake add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${ULTRALIGHT_BINARY_DIR}" $) ``` -------------------------------- ### Copying Ultralight Binaries Post-Build - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 3 - Resizable App/CMakeLists.txt Defines a custom build command executed after the target executable is successfully built (POST_BUILD). It copies the contents of the ULTRALIGHT_BINARY_DIR to the target executable's output directory using the CMake -E copy_directory command. This ensures required runtime binaries (DLLs, dylibs, etc.) are located alongside the executable. ```CMake add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${ULTRALIGHT_BINARY_DIR}" $) ``` -------------------------------- ### Defining Application Source Files - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 8 - Web Browser/CMakeLists.txt This command defines a CMake variable SOURCES which holds a list of source and header files that comprise the application's codebase. These files will be used by the add_executable command. ```CMake set(SOURCES "src/Browser.h" "src/Browser.cpp" "src/Tab.h" "src/Tab.cpp" "src/UI.h" "src/UI.cpp" "src/main.cpp") ``` -------------------------------- ### Copying Ultralight Resources Post-Build (CMake) Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 4 - JavaScript/CMakeLists.txt Adds another custom command executed after the build (`POST_BUILD`). This command copies the contents of the `ULTRALIGHT_RESOURCES_DIR` (containing assets like fonts, etc.) to the determined `ASSETS_PATH` within an `resources` subdirectory. ```CMake add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${ULTRALIGHT_RESOURCES_DIR}" "${ASSETS_PATH}/resources") ``` -------------------------------- ### Copying Ultralight Binaries After Build CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/CMakeLists.txt Adds a custom command that runs after the application executable is built. This command copies the Ultralight binary directory content to the target directory where the application executable is located, ensuring necessary DLLs or dylibs are available at runtime. ```CMake add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${ULTRALIGHT_BINARY_DIR}" $) ``` -------------------------------- ### Configure Basic Dependencies and Build Flags (CMake) Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/tests/CMakeLists.txt Configures essential build settings for the test executables, including linking against the core GLFW library, adding necessary include directories for GLFW and its dependencies (like glad), conditionally linking a math library if defined, and adding a preprocessor definition (`_CRT_SECURE_NO_WARNINGS`) specifically for the MSVC compiler. ```CMake link_libraries(glfw) include_directories(${glfw_INCLUDE_DIRS} "${GLFW_SOURCE_DIR}/deps") if (MATH_LIBRARY) link_libraries("${MATH_LIBRARY}") endif() if (MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) endif() ``` -------------------------------- ### Defining Application Executable - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 3 - Resizable App/CMakeLists.txt Defines the executable target named by the ${APP_NAME} variable (Sample3) from the main.cpp source file. It is configured as a Windows GUI application (WIN32) and a macOS application bundle (MACOSX_BUNDLE). ```CMake add_executable(${APP_NAME} WIN32 MACOSX_BUNDLE "main.cpp") ``` -------------------------------- ### Copying Ultralight Resources Post-Build (CMake) Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 1 - Render to PNG/CMakeLists.txt This final post-build command copies Ultralight's internal resource files (`ULTRALIGHT_RESOURCES_DIR`) into a 'resources' subdirectory nested within the application's `ASSETS_PATH`. These resources are essential for the Ultralight framework itself, typically including default stylesheets, fonts, or other necessary data. ```CMake add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${ULTRALIGHT_RESOURCES_DIR}" "${ASSETS_PATH}/resources") ``` -------------------------------- ### Adding Executable Target in CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 2 - Basic App/CMakeLists.txt This snippet defines the main executable target for the project. It specifies the application name (defined previously) and the source file(s) required to build the executable. It also includes flags like WIN32 and MACOSX_BUNDLE to indicate target platform types. ```CMake add_executable(${APP_NAME} WIN32 MACOSX_BUNDLE "main.cpp") ``` -------------------------------- ### Add Windowed/Bundle Test Executables (CMake) Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/tests/CMakeLists.txt Adds test executables designed to run as windowed applications, specifying properties for Windows (`WIN32`) and macOS bundles (`MACOSX_BUNDLE`). Each executable includes its primary source file and required dependency files (glad, getopt, tinycthread) using predefined variables. ```CMake add_executable(empty WIN32 MACOSX_BUNDLE empty.c ${TINYCTHREAD} ${GLAD}) add_executable(gamma WIN32 MACOSX_BUNDLE gamma.c ${GLAD}) add_executable(icon WIN32 MACOSX_BUNDLE icon.c ${GLAD}) add_executable(inputlag WIN32 MACOSX_BUNDLE inputlag.c ${GETOPT} ${GLAD}) add_executable(joysticks WIN32 MACOSX_BUNDLE joysticks.c ${GLAD}) add_executable(opacity WIN32 MACOSX_BUNDLE opacity.c ${GLAD}) add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c ${GLAD}) add_executable(threads WIN32 MACOSX_BUNDLE threads.c ${TINYCTHREAD} ${GLAD}) add_executable(timeout WIN32 MACOSX_BUNDLE timeout.c ${GLAD}) add_executable(title WIN32 MACOSX_BUNDLE title.c ${GLAD}) add_executable(windows WIN32 MACOSX_BUNDLE windows.c ${GETOPT} ${GLAD}) ``` -------------------------------- ### Copy Ultralight Resources Post-Build CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 5 - File Loading/CMakeLists.txt Adds a final custom command to copy Ultralight-specific resources. It copies the contents of the `${ULTRALIGHT_RESOURCES_DIR}` directory into a 'resources' subdirectory within the calculated `ASSETS_PATH`. `ULTRALIGHT_RESOURCES_DIR` must be defined externally. ```CMake add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${ULTRALIGHT_RESOURCES_DIR}" "${ASSETS_PATH}/resources") ``` -------------------------------- ### Copying Ultralight Binaries After Build - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 9 - Multi Window/CMakeLists.txt Adds a post-build custom command to copy all necessary Ultralight binaries from the `ULTRALIGHT_BINARY_DIR` to the executable's target directory after the application is built. ```CMake add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${ULTRALIGHT_BINARY_DIR}" $) ``` -------------------------------- ### Copying Ultralight Resources Assets Post-Build - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 8 - Web Browser/CMakeLists.txt This post-build command copies the contents of the ULTRALIGHT_RESOURCES_DIR (containing standard Ultralight resources) to a resources subdirectory within the main ASSETS_PATH. This makes essential Ultralight resources available to the application. Requires ULTRALIGHT_RESOURCES_DIR and ASSETS_PATH variables. ```CMake add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${ULTRALIGHT_RESOURCES_DIR}" "${ASSETS_PATH}/resources") ``` -------------------------------- ### Adding and Configuring GLFW Subdirectory CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/CMakeLists.txt Adds the GLFW source directory as a sub-project to the build, includes its header paths, and links the compiled GLFW library to the current target. This integrates the GLFW windowing functionality into the application. ```CMake set(GLFW_DIR "glfw") add_subdirectory(${GLFW_DIR}) include_directories("${GLFW_DIR}/include") include_directories("${GLFW_DIR}/deps") link_libraries(glfw) ``` -------------------------------- ### Finding and Adding Unix Math and Time Libraries Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/CMakeLists.txt For Unix systems (excluding macOS), this block searches for and adds the required `rt` (realtime) and `m` (math) libraries to the `glfw_LIBRARIES` list, also adding their pkg-config equivalent flags. ```CMake if (UNIX AND NOT APPLE) find_library(RT_LIBRARY rt) mark_as_advanced(RT_LIBRARY) if (RT_LIBRARY) list(APPEND glfw_LIBRARIES "${RT_LIBRARY}") list(APPEND glfw_PKG_LIBS "-lrt") endif() find_library(MATH_LIBRARY m) mark_as_advanced(MATH_LIBRARY) if (MATH_LIBRARY) list(APPEND glfw_LIBRARIES "${MATH_LIBRARY}") list(APPEND glfw_PKG_LIBS "-lm") endif() if (CMAKE_DL_LIBS) list(APPEND glfw_LIBRARIES "${CMAKE_DL_LIBS}") list(APPEND glfw_PKG_LIBS "-l${CMAKE_DL_LIBS}") endif() endif() ``` -------------------------------- ### Copying Ultralight Resources After Build - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 9 - Multi Window/CMakeLists.txt Adds a post-build custom command to copy necessary Ultralight resource files from `ULTRALIGHT_RESOURCES_DIR` into the assets directory under a 'resources' subdirectory. ```CMake add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${ULTRALIGHT_RESOURCES_DIR}" "${ASSETS_PATH}/resources") ``` -------------------------------- ### Detecting and Selecting Backend API Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 7 - OpenGL Integration/glfw/CMakeLists.txt Selects the appropriate window creation backend based on build options and the detected platform. Supported backends include Wayland, Mir, OSMesa (headless), Win32, Cocoa (macOS), and X11. A fatal error occurs if no supported platform is found. ```CMake if (GLFW_USE_WAYLAND) set(_GLFW_WAYLAND 1) message(STATUS "Using Wayland for window creation") elseif (GLFW_USE_MIR) set(_GLFW_MIR 1) message(STATUS "Using Mir for window creation") elseif (GLFW_USE_OSMESA) set(_GLFW_OSMESA 1) message(STATUS "Using OSMesa for headless context creation") elseif (WIN32) set(_GLFW_WIN32 1) message(STATUS "Using Win32 for window creation") elseif (APPLE) set(_GLFW_COCOA 1) message(STATUS "Using Cocoa for window creation") elseif (UNIX) set(_GLFW_X11 1) message(STATUS "Using X11 for window creation") else() message(FATAL_ERROR "No supported platform was detected") endif() ``` -------------------------------- ### Copying Project Assets Post-Build - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 3 - Resizable App/CMakeLists.txt Defines a custom build command executed after the target executable is built. It copies the project's local 'assets/' directory content from the source directory to the ASSETS_PATH determined previously. This step makes application-specific assets like HTML, CSS, images, etc., available at runtime. ```CMake add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/assets/" "${ASSETS_PATH}") ``` -------------------------------- ### Configuring CMake Project and Including Subdirectory - CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/CMakeLists.txt This snippet defines the CMake project named 'Samples', specifying C and C++ as the primary languages. It sets the minimum required CMake version to 3.3.2 and mandates the use of the C++11 standard. Finally, it includes the `CMakeLists.txt` file from the 'samples' subdirectory, allowing CMake to process its build targets and configurations. ```CMake project(Samples C CXX) cmake_minimum_required(VERSION 3.3.2) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) add_subdirectory(samples) ``` -------------------------------- ### Copying Ultralight Resources Post-Build in CMake Source: https://github.com/ultralight-ux/ultralight/blob/master/samples/Sample 2 - Basic App/CMakeLists.txt This snippet adds a final custom command to copy the core Ultralight resource files from their source directory to a specific subdirectory ('resources') within the application's assets path. This ensures that the Ultralight library can load its internal resources, like fonts or cursors, at runtime. ```CMake add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${ULTRALIGHT_RESOURCES_DIR}" "${ASSETS_PATH}/resources") ```