### Configure Windows Installer Source: https://github.com/mgba-emu/mgba/blob/master/CMakeLists.txt Configures the Inno Setup script (setup.iss) for creating a Windows installer. It determines installer details based on version, architecture, and release status. ```cmake if(DISTBUILD AND WIN32) set(BIN_DIR ".\\") string(REGEX REPLACE "[^-A-Za-z0-9_.]" "-" CLEAN_VERSION_STRING "${VERSION_STRING}") file(RELATIVE_PATH SETUP_DIR_SLASH "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/setup") file(RELATIVE_PATH RES_DIR_SLASH "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/res") string(REPLACE "/" "\\" SETUP_DIR "${SETUP_DIR_SLASH}") string(REPLACE "/" "\\" RES_DIR "${RES_DIR_SLASH}") if(CMAKE_SYSTEM_PROCESSOR MATCHES ".*64$") set(WIN_BITS 64) else() set(WIN_BITS 32) endif() if(GIT_TAG) set(IS_RELEASE 1) else() set(IS_RELEASE 0) endif() configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/setup/setup.iss.in" setup.iss) set_source_files_properties(setup.iss PROPERTIES GENERATED ON) if(INSTALLER_NAME) set(INSTALLER_TARGET "${INSTALLER_NAME}.exe") set(ISCC_FLAGS "/F${INSTALLER_NAME}") else() set(INSTALLER_TARGET "${PROJECT_NAME}-setup-${CLEAN_VERSION_STRING}-win${WIN_BITS}.exe") endif() if(CMAKE_CROSSCOMPILING) find_program(WINE NAMES wine wine-stable wine-development) find_file(ISCC ISCC.exe HINTS "$ENV{HOME}/.wine/drive_c/Program Files/" PATH_SUFFIXES "Inno Setup 5") add_custom_command(OUTPUT ${INSTALLER_TARGET} COMMAND "${WINE}" "${ISCC}" setup.iss /Q ${ISCC_FLAGS} DEPENDS ${BINARY_NAME}-qt ${BINARY_NAME}-sdl setup.iss CHANGES LICENSE) else() find_program(ISCC NAMES ISCC ISCC.exe PATH_SUFFIXES "Inno Setup 5") add_custom_command(OUTPUT ${INSTALLER_TARGET} COMMAND "${ISCC}" setup.iss /Q ${ISCC_FLAGS} DEPENDS ${BINARY_NAME}-qt ${BINARY_NAME}-sdl setup.iss CHANGES LICENSE) endif() if(ISCC) add_custom_target(installer ALL DEPENDS ${INSTALLER_TARGET}) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${INSTALLER_TARGET}" DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT installer) endif() endif() ``` -------------------------------- ### Install Programs Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/CMakeLists.txt Installs PNG binary targets, typically executables, to the runtime destination directory. ```cmake if(NOT SKIP_INSTALL_PROGRAMS AND NOT SKIP_INSTALL_ALL) install(TARGETS ${PNG_BIN_TARGETS} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") endif() ``` -------------------------------- ### Build Example Client-Server Source: https://github.com/mgba-emu/mgba/blob/master/CMakeLists.txt Sets up the example client-server application, including conditional compilation for SDL support and linking necessary libraries. ```cmake add_executable(${BINARY_NAME}-example-server ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/example/client-server/server.c) target_link_libraries(${BINARY_NAME}-example-server ${BINARY_NAME}) set_target_properties(${BINARY_NAME}-example-server PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}") ``` ```cmake add_executable(${BINARY_NAME}-example-client ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/example/client-server/client.c) target_link_libraries(${BINARY_NAME}-example-client ${BINARY_NAME} ${SDL_LIBRARY} ${SDLMAIN_LIBRARY} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY}) set_target_properties(${BINARY_NAME}-example-client PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}" INCLUDE_DIRECTORIES "${SDL_INCLUDE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/src;${CMAKE_CURRENT_SOURCE_DIR}/include") ``` -------------------------------- ### Install ZLIB Libraries and Headers Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/zlib/CMakeLists.txt Installs the zlib and zlibstatic libraries, public headers, man pages, and pkgconfig files. Installation is conditional on NOT SKIP_INSTALL_LIBRARIES, NOT SKIP_INSTALL_HEADERS, and NOT SKIP_INSTALL_FILES. ```cmake if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) install(TARGETS zlib zlibstatic RUNTIME DESTINATION "${INSTALL_BIN_DIR}" ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" LIBRARY DESTINATION "${INSTALL_LIB_DIR}" ) endif() if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL ) install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}") endif() if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) install(FILES zlib.3 DESTINATION "${INSTALL_MAN_DIR}/man3") endif() if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}") endif() ``` -------------------------------- ### Install README and CHANGELOG Files Source: https://github.com/mgba-emu/mgba/blob/master/CMakeLists.txt Installs README files and CHANGELOG/LICENSE. Conditionally uses unix2dos and markdown for conversion if available. ```cmake file(GLOB READMES ${CMAKE_CURRENT_SOURCE_DIR}/README*.md) ``` ```cmake if(UNIX OR NOT UNIX2DOS) if(UNIX OR NOT MARKDOWN) install(FILES ${READMES} DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT ${BINARY_NAME}) endif() install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/CHANGES" "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT ${BINARY_NAME}) else() add_custom_command(OUTPUT CHANGES.txt COMMAND ${UNIX2DOS} -n "${CMAKE_CURRENT_SOURCE_DIR}/CHANGES" "${CMAKE_CURRENT_BINARY_DIR}/CHANGES.txt" MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/CHANGES") add_custom_command(OUTPUT LICENSE.txt COMMAND ${UNIX2DOS} -n "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt" MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") add_custom_target(CHANGES ALL DEPENDS CHANGES.txt) add_custom_target(LICENSE ALL DEPENDS LICENSE.txt) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CHANGES.txt ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT ${BINARY_NAME}) endif() ``` -------------------------------- ### Install click library Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/discord-rpc/README.md Install the 'click' Python library, which is a dependency for the 'build.py' wrapper script. ```sh pip install click ``` -------------------------------- ### Create Example Executable Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/zlib/CMakeLists.txt Builds an executable named 'example' from test/example.c and links it against the zlib library. It also adds this as a test case. ```cmake add_executable(example test/example.c) target_link_libraries(example zlib) add_test(example example) ``` -------------------------------- ### Install Build Targets and Files Source: https://github.com/mgba-emu/mgba/blob/master/src/platform/wii/CMakeLists.txt Installs the debug executable, Wii-specific files (icon, meta.xml, boot.dol), and the performance build if enabled. ```cmake install(TARGETS ${BINARY_NAME}.elf DESTINATION . COMPONENT ${BINARY_NAME}-dbg) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/icon.png ${CMAKE_CURRENT_BINARY_DIR}/meta.xml DESTINATION . COMPONENT ${BINARY_NAME}-wii) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}.dol DESTINATION . RENAME boot.dol COMPONENT ${BINARY_NAME}-wii) ``` -------------------------------- ### Shader Installation Logic Source: https://github.com/mgba-emu/mgba/blob/master/src/platform/qt/CMakeLists.txt Installs shader files. It either installs them directly or, if using zip libraries, creates zip archives of shaders and installs those. This ensures shaders are available at runtime. ```cmake if(BUILD_GL OR BUILD_GLES2 OR BUILD_EPOXY) if(NOT USE_LIBZIP AND NOT USE_MINIZIP) install(DIRECTORY ${PROJECT_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt) else() file(GLOB SHADERS ${PROJECT_SOURCE_DIR}/res/shaders/*.shader) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/shaders) foreach(SHADER_DIR ${SHADERS}) get_filename_component(SHADER ${SHADER_DIR} NAME) add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/${SHADER}" COMMAND "${CMAKE_COMMAND}" -E tar cf "${CMAKE_CURRENT_BINARY_DIR}/shaders/${SHADER}" --format=zip . WORKING_DIRECTORY "${SHADER_DIR}") add_custom_target("${SHADER}" ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/shaders/${SHADER}") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/shaders/${SHADER}" DESTINATION ${DATADIR}/shaders COMPONENT ${BINARY_NAME}-qt) endforeach() endif() endif() ``` -------------------------------- ### Install Files and Package Configuration Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/CMakeLists.txt Installs man pages, pkg-config files, and configuration scripts for the PNG library, with platform-specific logic. ```cmake if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL) # Install the man pages. install(FILES libpng.3 libpngpf.3 DESTINATION "${CMAKE_INSTALL_MANDIR}/man3") install(FILES png.5 DESTINATION "${CMAKE_INSTALL_MANDIR}/man5") # Install the pkg-config files. if(NOT CMAKE_HOST_WIN32 OR CYGWIN OR MINGW) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libpng.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") install(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/libpng-config" DESTINATION "${CMAKE_INSTALL_BINDIR}") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libpng${PNGLIB_ABI_VERSION}.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") install(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/libpng${PNGLIB_ABI_VERSION}-config" DESTINATION "${CMAKE_INSTALL_BINDIR}") endif() endif() ``` -------------------------------- ### Install Executables Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/CMakeLists.txt Installs PNG configuration executables, such as libpng-config, with platform-specific handling. ```cmake if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL) if(NOT WIN32 OR CYGWIN OR MINGW) install(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/libpng-config" DESTINATION "${CMAKE_INSTALL_BINDIR}") install(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/libpng${PNGLIB_ABI_VERSION}-config" DESTINATION "${CMAKE_INSTALL_BINDIR}") endif() endif() ``` -------------------------------- ### Install Debug and Release Packages Source: https://github.com/mgba-emu/mgba/blob/master/src/platform/psp2/CMakeLists.txt Installs the main executable for debugging and the VPK package for PS Vita deployment. Components are used for selective installation. ```cmake install(TARGETS ${BINARY_NAME}.elf DESTINATION . COMPONENT ${BINARY_NAME}-dbg) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}.vpk DESTINATION . COMPONENT ${BINARY_NAME}-psp2) ``` -------------------------------- ### Create 64-bit Example Executable Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/zlib/CMakeLists.txt Builds a 64-bit version of the 'example' executable if HAVE_OFF64_T is defined. It links against zlib and sets a compile flag for 64-bit file offsets. ```cmake if(HAVE_OFF64_T) add_executable(example64 test/example.c) target_link_libraries(example64 zlib) set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") add_test(example64 example64) add_executable(minigzip64 test/minigzip.c) target_link_libraries(minigzip64 zlib) set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") endif() ``` -------------------------------- ### Install Mgba Qt Target Source: https://github.com/mgba-emu/mgba/blob/master/src/platform/qt/CMakeLists.txt This command installs the Mgba Qt target, specifying runtime destination, bundle destination, and component for installation. ```cmake install(TARGETS ${BINARY_NAME}-qt RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-qt BUNDLE DESTINATION ${APPDIR} COMPONENT ${BINARY_NAME}-qt) ``` -------------------------------- ### Configure Installation Directories for Unix-like Systems Source: https://github.com/mgba-emu/mgba/blob/master/CMakeLists.txt Includes GNUInstallDirs for standard installation paths on Unix-like systems. ```cmake if(UNIX OR WIN32_UNIX_PATHS) include(GNUInstallDirs) else() set(CMAKE_INSTALL_LIBDIR ".") set(CMAKE_INSTALL_BINDIR ".") set(CMAKE_INSTALL_DATADIR ".") set(CMAKE_INSTALL_DOCDIR ".") set(CMAKE_INSTALL_INCLUDEDIR "include") endif() ``` -------------------------------- ### Configure and Install Header Files Source: https://github.com/mgba-emu/mgba/blob/master/CMakeLists.txt Creates a directory for mGBA headers and configures the flags.h file, then installs header files to the system include directory. ```cmake file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/mgba) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/core/flags.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/mgba/flags.h) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/mgba DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT ${BINARY_NAME}-devFILES_MATCHING PATTERN "*.h") install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/mgba-util DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT ${BINARY_NAME}-devFILES_MATCHING PATTERN "*.h") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/mgba/flags.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mgba COMPONENT ${BINARY_NAME}-dev) ``` -------------------------------- ### Install License Files Source: https://github.com/mgba-emu/mgba/blob/master/CMakeLists.txt Installs license files to the documentation directory. Conditionally includes Discord RPC and rapidjson licenses if USE_DISCORD_RPC is enabled. Also includes mingw-std-threads license for Windows. ```cmake install(FILES DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME}) ``` ```cmake install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/inih.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME}) ``` ```cmake if(USE_DISCORD_RPC) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/discord-rpc.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME}) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/rapidjson.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME}) if(WIN32) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/mingw-std-threads.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME}) endif() endif() ``` ```cmake if(EXTRA_LICENSES) install(FILES ${EXTRA_LICENSES} DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME}) endif() ``` -------------------------------- ### Install Headers Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/CMakeLists.txt Installs public header files for the PNG library, including a versioned subdirectory for compatibility. ```cmake if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL) install(FILES ${libpng_public_hdrs} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") install(FILES ${libpng_public_hdrs} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/libpng${PNGLIB_ABI_VERSION}") endif() ``` -------------------------------- ### Configure Installation Directories Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/zlib/CMakeLists.txt Defines cache variables for installation directories for executables, libraries, headers, man pages, and pkgconfig files. ```cmake set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages") set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") ``` -------------------------------- ### Set Documentation Installation Directory for Apple Distbuild Source: https://github.com/mgba-emu/mgba/blob/master/CMakeLists.txt Sets the documentation installation directory specifically for Apple's DISTBUILD environment. ```cmake if(APPLE AND DISTBUILD) set(CMAKE_INSTALL_DOCDIR ".") endif() ``` -------------------------------- ### Install targets and files Source: https://github.com/mgba-emu/mgba/blob/master/src/platform/switch/CMakeLists.txt Installs the debug version of the executable and the final NRO package to their respective destinations. This makes the built artifacts available after the build process. ```cmake install(TARGETS ${BINARY_NAME}.elf DESTINATION . COMPONENT ${BINARY_NAME}-dbg) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}.nro DESTINATION . COMPONENT ${BINARY_NAME}-switch) ``` -------------------------------- ### Install mGBA Dependencies with vcpkg Source: https://github.com/mgba-emu/mgba/blob/master/README.md Installs essential libraries for mGBA development using vcpkg. Ensure vcpkg is installed first. This command may need adjustments for specific features like Nvidia hardware acceleration. ```bash vcpkg install ffmpeg[vpx,x264] libepoxy libpng libzip lua sdl2 sqlite3 ``` ```bash vcpkg install qt5-base qt5-multimedia ``` -------------------------------- ### Install Libraries Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/CMakeLists.txt Installs PNG library targets, including shared and static libraries, with specific handling for different operating systems and build configurations. ```cmake if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) install(TARGETS ${PNG_LIBRARY_TARGETS} EXPORT libpng RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" FRAMEWORK DESTINATION "${CMAKE_INSTALL_LIBDIR}") if(PNG_SHARED) # Create a symlink for libpng.dll.a => libpng16.dll.a on Cygwin if(NOT WIN32 OR CYGWIN OR MINGW) create_symlink(libpng${CMAKE_SHARED_LIBRARY_SUFFIX} TARGET png_shared) install(FILES "$/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}" DESTINATION "${CMAKE_INSTALL_LIBDIR}") endif() endif() if(PNG_STATIC) if(NOT WIN32 OR CYGWIN OR MINGW) create_symlink(libpng${CMAKE_STATIC_LIBRARY_SUFFIX} TARGET png_static) install(FILES "$/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}" DESTINATION "${CMAKE_INSTALL_LIBDIR}") endif() endif() endif() ``` -------------------------------- ### Set Output Name and Install Target Source: https://github.com/mgba-emu/mgba/blob/master/src/platform/sdl/CMakeLists.txt Configures the output name for non-Windows systems and installs the executable. ```cmake if(NOT WIN32) set_target_properties(${BINARY_NAME}-sdl PROPERTIES OUTPUT_NAME ${BINARY_NAME}) else() set_target_properties(${BINARY_NAME}-sdl PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") endif() install(TARGETS ${BINARY_NAME}-sdl DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-sdl) if(UNIX) install(FILES ${PROJECT_SOURCE_DIR}/doc/mgba.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-sdl) endif() ``` -------------------------------- ### Custom Target for Installing Python Components Source: https://github.com/mgba-emu/mgba/blob/master/src/platform/python/CMakeLists.txt Defines a custom target to install the Python components using 'setup.py install'. This target depends on the build target. ```cmake add_custom_target(${BINARY_NAME}-py-install COMMAND BINDIR=${PROJECT_BINARY_DIR} LIBDIR=${PROJECT_BINARY_DIR} CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON_EXECUTABLE} setup.py install -b ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${BINARY_NAME}-py) ``` -------------------------------- ### Install Dependencies and Build mGBA on macOS Source: https://github.com/mgba-emu/mgba/blob/master/README.md Commands for macOS users utilizing Homebrew to install necessary dependencies and build mGBA. Note that 'make install' is not recommended on macOS. ```bash brew install cmake ffmpeg libzip qt5 sdl2 libedit lua pkg-config mkdir build cd build cmake -DCMAKE_PREFIX_PATH=`brew --prefix qt5` .. make ``` -------------------------------- ### Install Desktop Entry on UNIX Source: https://github.com/mgba-emu/mgba/blob/master/src/platform/qt/CMakeLists.txt Installs the desktop entry file for mGBA on UNIX-like systems. This allows the application to be listed in desktop environments. ```cmake install(FILES ${PROJECT_SOURCE_DIR}/res/mgba-qt.desktop DESTINATION share/applications RENAME io.mgba.${PROJECT_NAME}.desktop COMPONENT ${BINARY_NAME}-qt) ``` -------------------------------- ### Build mGBA on Unix-like systems Source: https://github.com/mgba-emu/mgba/blob/master/README.md Standard CMake and make commands for building mGBA on Unix-based systems. This installs mGBA to /usr/bin and /usr/lib. Ensure dependencies are installed beforehand. ```bash mkdir build cd build cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .. make sudo make install ``` -------------------------------- ### Build discord-rpc with CMake Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/discord-rpc/README.md Use this command to generate build files and install the discord-rpc library. Ensure you have CMake installed and navigate to the discord-rpc directory. ```sh cd mkdir build cd build cmake .. -DCMAKE_INSTALL_PREFIX= cmake --build . --config Release --target install ``` -------------------------------- ### Set Runtime Path for Installation Source: https://github.com/mgba-emu/mgba/blob/master/CMakeLists.txt Configures the CMAKE_INSTALL_RPATH to include the library directory within the installation prefix. ```cmake set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIBDIR}") if(${CMAKE_INSTALL_PREFIX} STREQUAL "/usr") set(CMAKE_SKIP_RPATH ON) endif() ``` -------------------------------- ### Install Man Page on UNIX Source: https://github.com/mgba-emu/mgba/blob/master/src/platform/qt/CMakeLists.txt Installs the mGBA man page on UNIX-like systems. This provides users with command-line documentation. ```cmake install(FILES ${PROJECT_SOURCE_DIR}/doc/mgba-qt.6 DESTINATION ${MANDIR}/man6 COMPONENT ${BINARY_NAME}-qt) ``` -------------------------------- ### Configure PNG Library Include Directories Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/CMakeLists.txt Sets include directories for the png_framework target, distinguishing between build and installation interfaces. The SYSTEM keyword is used for the installation interface to indicate that the headers are not user-provided. ```cmake target_include_directories(png_framework PUBLIC "$") target_include_directories(png_framework SYSTEM INTERFACE "$") ``` -------------------------------- ### Toolchain File Examples for mGBA Build Source: https://github.com/mgba-emu/mgba/blob/master/README.md Specifies the CMake toolchain file to use for building mGBA on different platforms. Replace the example path with the correct one for your target platform. ```bash ../src/platform/3ds/CMakeToolchain.txt ``` ```bash ../src/platform/switch/CMakeToolchain.txt ``` ```bash ../src/platform/psp2/CMakeToolchain.vitasdk ``` ```bash ../src/platform/wii/CMakeToolchain.txt ``` -------------------------------- ### Custom Target for Development Mode Installation Source: https://github.com/mgba-emu/mgba/blob/master/src/platform/python/CMakeLists.txt Defines a custom target for installing Python components in development mode using 'setup.py develop'. This allows for easier development by linking to the source. ```cmake add_custom_target(${BINARY_NAME}-py-develop COMMAND BINDIR=${PROJECT_BINARY_DIR} LIBDIR=${PROJECT_BINARY_DIR} CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON_EXECUTABLE} setup.py develop -b ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${BINARY_NAME}-py) ``` -------------------------------- ### Enable CPACK_DEB_COMPONENT_INSTALL Source: https://github.com/mgba-emu/mgba/blob/master/CMakeLists.txt Enables component installation for Debian packages. ```cmake set(CPACK_DEB_COMPONENT_INSTALL ON) ``` -------------------------------- ### For Loop and Typecast Example Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt Demonstrates preferred spacing around control keywords, commas, semicolons, binary operators, and typecasts. Note the space after 'for' and before '?'. ```c for (i = 2; i > 0; --i) y[i] = a(x) + (int)b; ``` -------------------------------- ### Qt (C++) Header Guard Example Source: https://github.com/mgba-emu/mgba/blob/master/CONTRIBUTING.md For Qt headers, use a `QGBA_` prefix and omit `_H`. This is primarily for legacy reasons. ```cpp #ifndef QGBA_FILE_NAME #define QGBA_FILE_NAME // Header #endif ``` -------------------------------- ### Set Manual Directory Variable Source: https://github.com/mgba-emu/mgba/blob/master/CMakeLists.txt Defines the MANDIR variable, defaulting to the installation manual directory. ```cmake if (NOT DEFINED MANDIR) set(MANDIR ${CMAKE_INSTALL_MANDIR}) endif() ``` -------------------------------- ### Libpng Coding Style Example Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt Illustrates the libpng coding style, which is similar to the 'Allman' style, with curly braces placed on separate lines. ```c if (condition) { action; } else if (another condition) { ``` -------------------------------- ### Get Pixel Placement Information (libpng 1.5+) Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt These macros help in de-interlacing the image manually by providing the starting column and row, and the spacing between pixels for each pass. ```c png_uint_32 x = PNG_PASS_START_COL(pass); png_uint_32 y = PNG_PASS_START_ROW(pass); png_uint_32 xStep = 1U << PNG_PASS_COL_SHIFT(pass); ``` -------------------------------- ### Second Level Inflate Lookup Table Y Example Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/zlib/doc/algorithm.txt Represents the second level lookup table (Table Y) for inflate decompression, handling codes starting with '111'. It decodes symbols F, G, H, I, and J. ```text 000: F,2 001: F,2 010: G,2 011: G,2 100: H,2 101: H,2 110: I,3 111: J,3 ``` -------------------------------- ### Initialize PNG I/O Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt Sets up the input I/O for libpng to use the specified FILE pointer. The file must be opened in binary mode. ```c png_init_io(png_ptr, fp); ``` -------------------------------- ### Start Compression Loop Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/zlib/examples/zlib_how.html Begins the do-while loop for compressing data until the end of the file is reached. This loop contains the main deflate() call. ```c /* compress until end of file */ do { ``` -------------------------------- ### Second Level Inflate Lookup Table X Example Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/zlib/doc/algorithm.txt Represents the second level lookup table (Table X) for inflate decompression, handling codes starting with '110'. It decodes symbols C and D. ```text 00: C,1 01: C,1 10: D,2 11: E,2 ``` -------------------------------- ### Configure Distribution Build Options Source: https://github.com/mgba-emu/mgba/blob/master/CMakeLists.txt Sets various options for distribution builds, including archive component installation, DMG format, and volume name. ```cmake if(DISTBUILD) set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) set(CPACK_DMG_FILESYSTEM "HFS+") set(CPACK_DMG_FORMAT "UDBZ") set(CPACK_DMG_VOLUME_NAME "${PROJECT_NAME} ${VERSION_STRING}") endif() ``` -------------------------------- ### Build Libretro Core Source: https://github.com/mgba-emu/mgba/blob/master/CMakeLists.txt Configures and installs the libretro core library. Includes specific compile definitions for different build targets and platforms. ```cmake add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC} ${CORE_VFS_SRC}) add_dependencies(${BINARY_NAME}_libretro ${BINARY_NAME}-version-info) set_target_properties(${BINARY_NAME}_libretro PROPERTIES PREFIX "" COMPILE_DEFINITIONS "__LIBRETRO__;COLOR_16_BIT;COLOR_5_6_5;DISABLE_THREADING;MGBA_STANDALONE;${OS_DEFINES};${FUNCTION_DEFINES};ENABLE_VFS;MINIMAL_CORE=2") target_link_libraries(${BINARY_NAME}_libretro ${OS_LIB}) if(MSVC) install(TARGETS ${BINARY_NAME}_libretro RUNTIME DESTINATION ${LIBRETRO_LIBDIR} COMPONENT ${BINARY_NAME}_libretro) else() install(TARGETS ${BINARY_NAME}_libretro LIBRARY DESTINATION ${LIBRETRO_LIBDIR} COMPONENT ${BINARY_NAME}_libretro NAMELINK_SKIP) endif() ``` -------------------------------- ### C Header Guard Example Source: https://github.com/mgba-emu/mgba/blob/master/CONTRIBUTING.md Use all-caps filenames with underscores for C header guards. Ensure no comment follows the `#endif` directive. ```c #ifndef FILE_NAME_H #define FILE_NAME_H // Header #endif ``` -------------------------------- ### Build Unreal library files Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/discord-rpc/README.md Run this command to build the correct library files for Unreal projects and place them in their respective folders. ```sh python build.py unreal ``` -------------------------------- ### Build Unity library files Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/discord-rpc/README.md Run this command to build the correct library files for Unity projects and place them in their respective folders. ```sh python build.py unity ``` -------------------------------- ### Include Directories Source: https://github.com/mgba-emu/mgba/blob/master/CMakeLists.txt Sets up include directories for the build process, prioritizing before standard paths. ```cmake include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/include) ``` -------------------------------- ### Set up Switch Build Environment Source: https://github.com/mgba-emu/mgba/blob/master/src/platform/switch/CMakeToolchain.txt Configures build variables and flags for the Nintendo Switch target. Ensures libnx is correctly located and sets architecture-specific options. ```cmake include(${CMAKE_CURRENT_LIST_DIR}/../cmake/devkitPro.cmake) if(DEFINED ENV{LIBNX}) set(LIBNX $ENV{LIBNX}) else() set(LIBNX ${DEVKITPRO}/libnx) endif() set(cross_prefix aarch64-none-elf-) set(arch_flags "-mtune=cortex-a57 -ffunction-sections -march=armv8-a+crc+crypto -mtp=soft -fPIE") set(inc_flags "-I${LIBNX}/include ${arch_flags}") set(link_flags "-L${LIBNX}/lib -lnx -specs=${LIBNX}/switch.specs ${arch_flags}") set(CMAKE_SYSTEM_PROCESSOR aarch64 CACHE INTERNAL "processor") set(CMAKE_LIBRARY_ARCHITECTURE aarch64-none-elf CACHE INTERNAL "abi") set(SWITCH ON) add_definitions(-D__SWITCH__) create_devkit(A64) set(CMAKE_FIND_ROOT_PATH ${DEVKITA64}/${CMAKE_LIBRARY_ARCHITECTURE} ${DEVKITPRO}/portlibs/switch) ``` -------------------------------- ### Basic Discord RPC Initialization (C#) Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/discord-rpc/README.md This snippet demonstrates the minimal setup required to initialize the Discord RPC library. Ensure you have obtained your application's Client ID from the Discord developers site. ```csharp DiscordRpc.Initialize("YOUR_CLIENT_ID"); // ... your game logic ... DiscordRpc.Shutdown(); ``` -------------------------------- ### Include Standard Thread Header Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/discord-rpc/include/mingw-std-threads/README.md To use the library, include the corresponding mingw.xxx.h file instead of the standard header. This example shows replacing `` with `"mingw.thread.h"`. ```cpp #include "mingw.thread.h" ``` -------------------------------- ### Configure zlib.pc and zconf.h Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/zlib/CMakeLists.txt Configures the zlib.pc file and generates zconf.h in the build directory using CMake's configure_file command. ```cmake set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein ${ZLIB_PC} @ONLY) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY) include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) ``` -------------------------------- ### Unity Discord RPC Setup (C#) Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/discord-rpc/README.md This C# script is intended for use within a Unity project to manage Discord Rich Presence integration. It requires the DiscordRpc.cs file to be present in your Unity project's Assets folder. ```csharp using DiscordRpc; public class DiscordController : MonoBehaviour { private DiscordRpc.DiscordRpcClient client; void Start() { client = new DiscordRpc.DiscordRpcClient("YOUR_CLIENT_ID"); client.Initialize(); // Update presence, etc. client.SetPresence(new RichPresence() { Details = "Playing Game", State = "In Menus", Timestamps = Timestamps.Now }); } void OnDestroy() { client?.Dispose(); } } ``` -------------------------------- ### Configure Pkgconfig and Config Files Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/CMakeLists.txt Generates pkgconfig (.pc) and config files for libraries like libpng. This process is typically performed on non-Windows systems or for MinGW/Cygwin environments to ensure proper library integration. ```cmake if(NOT WIN32 OR CYGWIN OR MINGW) set(prefix "${CMAKE_INSTALL_PREFIX}") set(exec_prefix "${CMAKE_INSTALL_PREFIX}") set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}") set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") set(LIBS "-lz -lm") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libpng${PNGLIB_ABI_VERSION}.pc" @ONLY) create_symlink(libpng.pc FILE libpng${PNGLIB_ABI_VERSION}.pc) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in" "${CMAKE_CURRENT_BINARY_DIR}/libpng${PNGLIB_ABI_VERSION}-config" @ONLY) create_symlink(libpng-config FILE libpng${PNGLIB_ABI_VERSION}-config) endif() ``` -------------------------------- ### Symbol Definitions for Inflate Example Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/zlib/doc/algorithm.txt Defines symbols and their corresponding bit codes for a scaled-down inflate decompression example. Used to illustrate the construction of lookup tables. ```text A: 0 B: 10 C: 1100 D: 11010 E: 11011 F: 11100 G: 11101 H: 11110 I: 111110 J: 111111 ``` -------------------------------- ### Libpng Build and Compatibility Notes Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt Notes regarding build configurations and compatibility issues, particularly concerning compiler flags and header includes. ```APIDOC ## Build and Compatibility Notes ### Header Inclusion - **string.h**: The `string.h` header is no longer included in `png.h`. It has been moved to `pngpriv.h` and is not accessible by applications. Applications needing `string.h` functionality must explicitly include it (`#include `). This can be placed before or after `#include "png.h"`. ### Compiler Flags (Debug DLLs) - **Visual C++**: Libpng 1.5.x erroneously used `/MD` for Debug DLL builds. For libpng 1.6.x, if you used debug builds in your application and changed it to use `/MD`, you will need to change it back to `/MDd` for libpng 1.6.x. ### Type Definitions - **png_alloc_size_t**: The definition of `png_alloc_size_t` is now controlled by a flag, allowing systems with 'small size_t' to select it if necessary. This is related to the elimination of FAR/far types and support for 16-bit platforms. ``` -------------------------------- ### Install MSYS2 Dependencies for Windows Development Source: https://github.com/mgba-emu/mgba/blob/master/README.md Installs essential development dependencies for building mGBA on Windows using MSYS2. This command requires downloading a significant amount of data. ```bash pacman -Sy --needed base-devel git ${MINGW_PACKAGE_PREFIX}-{cmake,ffmpeg,gcc,gdb,libelf,libepoxy,libzip,lua,pkgconf,qt5,SDL2,ntldd-git} ``` -------------------------------- ### Initialize zlib Compression State Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/zlib/examples/zlib_how.html Initializes the zlib state for compression using deflateInit(). Must be called before the first use of deflate(). ```c strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; ret = deflateInit(&strm, level); if (ret != Z_OK) return ret; ``` -------------------------------- ### Prepare Distribution Package with cpack Source: https://github.com/mgba-emu/mgba/blob/master/README.md Generates a distributable zip file containing mGBA and its necessary DLLs for Windows, suitable for testing on machines without the MSYS2 environment. ```bash cpack -G ZIP ``` -------------------------------- ### Initialize PNG Info Structure Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt Allocates and initializes the PNG info structure. This must be done after the png_struct is successfully created. Check for NULL return. ```c png_infop info_ptr = png_create_info_struct(png_ptr); ``` -------------------------------- ### Get User Transform Pointer Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt Retrieve the pointer to the user-defined structure used for transformations. ```APIDOC ## Get User Transform Pointer ### Description Retrieves the pointer to the user-defined structure that was set using `png_set_user_transform_info()`. ### Function `read_user_transform_ptr = png_get_user_transform_ptr(png_ptr)` ### Parameters - **png_ptr** (png_structp) - Pointer to the libpng structure. ### Returns - **read_user_transform_ptr** (voidp) - Pointer to the user-defined structure. ``` -------------------------------- ### Configure Wii Build Environment Source: https://github.com/mgba-emu/mgba/blob/master/src/platform/wii/CMakeToolchain.txt Sets up cross-compilation prefix, architecture flags, include paths, and library paths for Wii builds. Ensures the correct compiler and libraries are used. ```cmake include(${CMAKE_CURRENT_LIST_DIR}/../cmake/devkitPro.cmake) set(cross_prefix powerpc-eabi-) set(arch_flags "-mrvl -mcpu=750 -meabi -mhard-float -g") set(inc_flags "-I${DEVKITPRO}/libogc/include ${arch_flags}") set(link_flags "-L${DEVKITPRO}/libogc/lib/wii ${arch_flags}") set(CMAKE_SYSTEM_PROCESSOR powerpc CACHE INTERNAL "processor") set(CMAKE_LIBRARY_ARCHITECTURE powerpc-none-eabi CACHE INTERNAL "abi") set(CMAKE_REQUIRED_LIBRARIES ogc) set(WII ON) add_definitions(-DGEKKO) create_devkit(PPC) set(CMAKE_FIND_ROOT_PATH ${DEVKITPPC}/powerpc-eabi ${DEVKITPRO}/portlibs/ppc) ``` -------------------------------- ### Show pngexifinfo Help Text Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/contrib/pngexif/README.md Display the help message for the pngexifinfo command to understand all available options and usage. ```bash pngexifinfo --help ``` -------------------------------- ### Set Library Directory Variable Source: https://github.com/mgba-emu/mgba/blob/master/CMakeLists.txt Defines the LIBDIR variable, defaulting to the installation library directory. ```cmake if(NOT DEFINED LIBDIR) set(LIBDIR "${CMAKE_INSTALL_LIBDIR}") endif() ``` -------------------------------- ### Retrieve I/O Pointer Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt Get the user-defined I/O pointer that was set during initialization or via set_read_fn/set_write_fn. ```c voidp read_io_ptr = png_get_io_ptr(read_ptr); voidp write_io_ptr = png_get_io_ptr(write_ptr); ``` -------------------------------- ### Get Chunk Malloc Max Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt Retrieves the current maximum memory limit for individual chunks. ```c chunk_malloc_max = png_get_chunk_malloc_max(png_ptr); ``` -------------------------------- ### Open File for Writing Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt Opens a file in binary write mode. Ensure the file pointer is checked for validity. ```c FILE *fp = fopen(file_name, "wb"); if (!fp) return ERROR; ``` -------------------------------- ### Get User Height Max Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt Retrieves the current maximum height limit applied by libpng. ```c height_max = png_get_user_height_max(png_ptr); ``` -------------------------------- ### Configure QtTest Package and Add Executables Source: https://github.com/mgba-emu/mgba/blob/master/src/platform/qt/CMakeLists.txt This snippet finds the QtTest package and, if found, iterates through all test sources to add them as executables. It links necessary libraries and sets compile definitions and options. ```cmake find_package(${QT}Test) if(${QT}Test_FOUND) get_property(ALL_TESTS DIRECTORY PROPERTY VARIABLES) list(FILTER ALL_TESTS INCLUDE REGEX "^TEST_QT_.*_SRC$") foreach(TEST_SRC ${ALL_TESTS}) string(REGEX REPLACE "^TEST_QT_(.*)_SRC$" "\1" TEST_NAME ${TEST_SRC}) add_executable(test-qt-${TEST_NAME} WIN32 ${${TEST_SRC}}) target_link_libraries(test-qt-${TEST_NAME} ${BINARY_NAME} ${QT_LIBRARIES} ${QT}::Test) set_target_properties(test-qt-${TEST_NAME} PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES};${FUNCTION_DEFINES};${OS_DEFINES};${QT_DEFINES}" COMPILE_OPTIONS "${FEATURE_FLAGS}") add_test(platform-qt-${TEST_NAME} test-qt-${TEST_NAME}) endforeach() else() message(WARNING "${QT}Test not found") endif() endif() ``` -------------------------------- ### Get User Width Max Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt Retrieves the current maximum width limit applied by libpng. ```c width_max = png_get_user_width_max(png_ptr); ``` -------------------------------- ### Configure Meta XML File Source: https://github.com/mgba-emu/mgba/blob/master/src/platform/wii/CMakeLists.txt Copies and configures the meta.xml file from a template to the build directory. ```cmake configure_file(${CMAKE_CURRENT_SOURCE_DIR}/meta.xml.in ${CMAKE_CURRENT_BINARY_DIR}/meta.xml) ``` -------------------------------- ### Find libraries Source: https://github.com/mgba-emu/mgba/blob/master/src/platform/switch/CMakeLists.txt Finds required libraries such as GLAPI and EGL. Ensure these libraries are installed and discoverable by CMake. ```cmake find_library(GLAPI_LIBRARY glapi REQUIRED) find_library(EGL_LIBRARY EGL REQUIRED) ``` -------------------------------- ### Get Current Row and Pass Number Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt Retrieve the current row and pass number during image processing. ```APIDOC ## Get Current Row and Pass Number ### Description Provides routines to determine the current position within an image during processing, specifically for interlaced images. ### Functions - `png_get_current_pass_number(png_ptr)` - `png_get_current_row_number(png_ptr)` ### Parameters - **png_ptr** (png_structp) - Pointer to the libpng structure. ### Returns - `png_get_current_pass_number()`: The current interlacing pass number. - `png_get_current_row_number()`: The current row number being processed. ### Notes - These functions are only supported if user transforms are enabled. - They should only be used within a transform callback function. - Results may be unexpected if called when a row is not actively being processed. ``` -------------------------------- ### Write PNG with Simplified API Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt Steps to write a PNG file using the simplified API. Initialize the 'png_image' structure and call the appropriate write function. ```c png_image_write... ``` -------------------------------- ### Get pHYs Resolution Data Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt Retrieves the physical resolution in the X and Y directions, and the unit type for this resolution. ```c png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y, &unit_type); ``` -------------------------------- ### Initialize PNG Image Read from File Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt Opens a PNG file and reads its header information into a `png_image` structure. Ensure the `png_image` structure is initialized with `opaque` set to NULL before calling. ```c int png_image_begin_read_from_file( png_imagep image, const char *file_name) ``` -------------------------------- ### Get Image Interlace Type (Libpng) Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt Retrieves the interlace type of the image. This will be either PNG_INTERLACE_NONE or PNG_INTERLACE_ADAM7. ```c interlace_type = png_get_interlace_type(png_ptr, info_ptr); ``` -------------------------------- ### Get Palette Data (Libpng) Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt Retrieves the palette for the file and the number of entries in it. The palette is an array of png_color structures. ```c png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette); ``` -------------------------------- ### Configure CPACK_COMPONENTS_ALL for Windows Source: https://github.com/mgba-emu/mgba/blob/master/CMakeLists.txt Defines the components to be included in the package for Windows builds. ```cmake elseif(WIN32) set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-qt ${BINARY_NAME}-sdl ${BINARY_NAME}-qt-dbg ${BINARY_NAME}-sdl-dbg ${BINARY_NAME}-perf installer) endif() ``` -------------------------------- ### Get Chunk Cache Max Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/libpng-manual.txt Retrieves the current maximum limit for the number of ancillary chunks that libpng will store. ```c chunk_cache_max = png_get_chunk_cache_max(png_ptr); ``` -------------------------------- ### PNG Dictionary for Fuzzer Source: https://github.com/mgba-emu/mgba/blob/master/src/third-party/libpng/contrib/oss-fuzz/README.txt A dictionary file containing common PNG keywords and structures used to guide the fuzzer. ```text # png.dict # # Copyright 2015 Chrome Devs # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # This file is used by the oss-fuzz project. # Common PNG keywords and structures. IHDR PLTE IDAT IEND IKEY # Color types 0 2 3 4 6 # Bit depths 1 2 4 8 16 # Compression methods 0 # Filter methods 0 1 2 3 4 # Interlace methods 0 1 ``` -------------------------------- ### Build Headless Executable Source: https://github.com/mgba-emu/mgba/blob/master/CMakeLists.txt Configures and installs the headless executable for mGBA, setting compile definitions and stripping debug symbols. ```cmake add_executable(${BINARY_NAME}-headless ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/headless-main.c) target_link_libraries(${BINARY_NAME}-headless ${PLATFORM_LIBRARY} ${BINARY_NAME}) debug_strip(${BINARY_NAME}-headless) target_compile_definitions(${BINARY_NAME}-headless PRIVATE "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}") install(TARGETS ${BINARY_NAME}-headless DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-headless) ```