### Add Examples Subdirectory Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/rconfig/CMakeLists.txt Includes the examples directory in the build process. ```cmake add_subdirectory(examples) ``` -------------------------------- ### Installation Configuration Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/tl_expected/expected/CMakeLists.txt Configures package files and installation rules for the library. ```cmake configure_package_config_file( "${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" INSTALL_DESTINATION "share/cmake/${PROJECT_NAME}") write_basic_package_version_file( "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT) install(TARGETS expected EXPORT ${PROJECT_NAME}-targets INCLUDES DESTINATION "${CMAKE_INSTALL_DATADIR}") install(EXPORT ${PROJECT_NAME}-targets DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}" NAMESPACE tl:: FILE "${PROJECT_NAME}-targets.cmake") install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}") install(DIRECTORY "include/" TYPE INCLUDE) ``` -------------------------------- ### Compile example for Android Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/whereami/whereami/README.md Command to compile the example for Android using the generated toolchain. ```bash $ make -j -C _gnu-make/ platform=android architecture=arm64 CC=/tmp/android-toolchain/bin/aarch64-linux-android-gcc CXX=/tmp/android-toolchain/bin/aarch64-linux-android-g++ ``` -------------------------------- ### Example usage output Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/whereami/whereami/README.md The output of the example demonstrating path retrieval for an executable and a loaded library. ```text $ make -j -C _gnu-make $ cp ./bin/mac-x86_64/library.dylib /tmp/ $ ./bin/mac-x86_64/executable --load-library=/tmp/library.dylib executable path: /Users/gregory/Projects/whereami/bin/mac-x86_64/executable dirname: /Users/gregory/Projects/whereami/bin/mac-x86_64 basename: executable module path: /Users/gregory/Projects/whereami/bin/mac-x86_64/executable dirname: /Users/gregory/Projects/whereami/bin/mac-x86_64 basename: executable library loaded executable path: /Users/gregory/Projects/whereami/bin/mac-x86_64/executable dirname: /Users/gregory/Projects/whereami/bin/mac-x86_64 basename: executable module path: /private/tmp/library.dylib dirname: /private/tmp basename: library.dylib library unloaded ``` -------------------------------- ### Install Desktop and System Files Source: https://github.com/ashaduri/gsmartcontrol/blob/main/data/CMakeLists.txt Installs desktop files, appdata, PolKit policies, man pages, and helper scripts for non-Windows platforms. ```cmake if (NOT WIN32) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/gsmartcontrol.desktop" DESTINATION "${CMAKE_INSTALL_DATADIR}/applications/") # Appdata file install(FILES "${CMAKE_CURRENT_BINARY_DIR}/gsmartcontrol.appdata.xml" DESTINATION "${CMAKE_INSTALL_DATADIR}/metainfo/") # PolKit file install(FILES "${CMAKE_CURRENT_BINARY_DIR}/org.gsmartcontrol.policy" DESTINATION "${CMAKE_INSTALL_DATADIR}/polkit-1/actions/") # Man pages install(FILES "man1/gsmartcontrol.1" DESTINATION "${CMAKE_INSTALL_MANDIR}/man1") install(FILES "man1/gsmartcontrol.1" DESTINATION "${CMAKE_INSTALL_MANDIR}/man1" RENAME "gsmartcontrol-root.1") # Scripts (this goes to bin, not sbin, as it doesn't require root privileges before running) install(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/gsmartcontrol-root.sh" TYPE BIN RENAME "gsmartcontrol-root") endif() ``` -------------------------------- ### Install Windows Icon Source: https://github.com/ashaduri/gsmartcontrol/blob/main/data/CMakeLists.txt Installs the application icon file for Windows platforms. ```cmake if (WIN32) # .ico file install(FILES gsmartcontrol.ico DESTINATION .) endif() ``` -------------------------------- ### Install NSIS distribution files on Windows Source: https://github.com/ashaduri/gsmartcontrol/blob/main/packaging/CMakeLists.txt Installs the generated distribution.txt file to the documentation directory when building on Windows. ```cmake if (WIN32) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/nsis/distribution.txt" TYPE DOC) # nsis file, only for cross-compilation # if (NOT ${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows") # install(FILES "${CMAKE_CURRENT_BINARY_DIR}/nsis/gsmartcontrol.nsi" DESTINATION .) # endif() endif() ``` -------------------------------- ### Install GSmartControl on FreeBSD via Ports Source: https://github.com/ashaduri/gsmartcontrol/blob/main/docs/downloads.md Use the ports system to install GSmartControl on FreeBSD. ```bash cd /usr/ports/sysutils/gsmartcontrol/ && make install clean ``` -------------------------------- ### Run Windows installer in silent mode Source: https://github.com/ashaduri/gsmartcontrol/blob/main/docs/usage.md Use the /S flag with the installer executable to perform a silent installation. ```bash gsmartcontrol--win64.exe /S ``` -------------------------------- ### Install GSmartControl on FreeBSD via Package Source: https://github.com/ashaduri/gsmartcontrol/blob/main/docs/downloads.md Use the pkg_add command to install the GSmartControl package on FreeBSD. ```bash pkg_add -r gsmartcontrol ``` -------------------------------- ### C printf formatting example Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/fmt/fmt/README.md Demonstrates the concise syntax of printf for formatting floating-point numbers. ```c++ printf("%.2f\n", 1.23456); ``` -------------------------------- ### Install Internal Icons Source: https://github.com/ashaduri/gsmartcontrol/blob/main/data/CMakeLists.txt Installs internal application icons to platform-specific directories. ```cmake set (DATA_ICONS icons/drive-optical.png icons/drive-harddisk.png icons/drive-removable-media-usb.png ) # Install internal icons if (WIN32) install(FILES ${DATA_ICONS} DESTINATION icons) else() install(FILES ${DATA_ICONS} DESTINATION "${CMAKE_INSTALL_DATADIR}/gsmartcontrol/icons") endif() ``` -------------------------------- ### Install Application Icons Source: https://github.com/ashaduri/gsmartcontrol/blob/main/data/CMakeLists.txt Installs application icons into the hicolor icon theme directory for non-Windows platforms. ```cmake if (NOT WIN32) foreach(dir 16 22 24 32 48 64 128 256) install(FILES "${dir}/gsmartcontrol.png" DESTINATION "${CMAKE_INSTALL_DATADIR}/icons/hicolor/${dir}x${dir}/apps/") endforeach() # Don't run update-icon-cache, cpack is mostly for packaging. # install(CODE "execute_process (COMMAND gtk-update-icon-cache-3.0 -t -f \"@CMAKE_INSTALL_DATADIR@/icons/hicolor\")") endif() ``` -------------------------------- ### Print a container Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/fmt/fmt/README.md Printing standard containers using fmt::ranges. Includes example output. ```c++ #include #include int main() { std::vector v = {1, 2, 3}; fmt::print("{}\n", v); } ``` ```text [1, 2, 3] ``` -------------------------------- ### Run smartctl to get complete drive information Source: https://github.com/ashaduri/gsmartcontrol/blob/main/docs/support.md Use this command to see complete information about a drive, e.g., /dev/sda. Run as root, using sudo or su. On Windows, use /dev/pd1 for the second physical drive and run cmd as administrator. ```bash smartctl -x /dev/sda ``` -------------------------------- ### C++ iostreams formatting example Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/fmt/fmt/README.md Demonstrates the verbose syntax of iostreams for formatting floating-point numbers. ```c++ std::cout << std::setprecision(2) << std::fixed << 1.23456 << "\n"; ``` -------------------------------- ### Launch GSmartControl on macOS Source: https://github.com/ashaduri/gsmartcontrol/blob/main/docs/usage.md Run the application from the Terminal after installation via Homebrew. ```bash gsmartcontrol ``` ```bash brew doctor ``` -------------------------------- ### Install contrib directory on non-Windows platforms Source: https://github.com/ashaduri/gsmartcontrol/blob/main/contrib/CMakeLists.txt This CMake conditional block installs the contrib directory to the documentation directory on non-Windows systems, excluding the CMakeLists.txt file from the installation. ```cmake if (NOT WIN32) install(DIRECTORY "${CMAKE_SOURCE_DIR}/contrib" TYPE DOC PATTERN "CMakeLists.txt" EXCLUDE) endif() ``` -------------------------------- ### Print dates and times Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/fmt/fmt/README.md Formatting chrono objects with fmt::chrono. Includes example output. ```c++ #include int main() { auto now = std::chrono::system_clock::now(); fmt::print("Date and time: {}\n", now); fmt::print("Time: {:%H:%M}\n", now); } ``` ```text Date and time: 2023-12-26 19:10:31.557195597 Time: 19:10 ``` -------------------------------- ### Conditional Build Configuration Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/libdebug/examples/CMakeLists.txt Sets the directory properties to exclude the examples from the build process unless the APP_BUILD_EXAMPLES variable is set. ```cmake if (NOT APP_BUILD_EXAMPLES) set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL true) else() set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL false) endif() ``` -------------------------------- ### Functional utility: map Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/tl_expected/expected/README.md Example usage of the map member function to transform the stored object. ```cpp tl::expected s = exp_string.map(&std::string::size); ``` -------------------------------- ### Functional utility: or_else Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/tl_expected/expected/README.md Example usage of the or_else member function to handle cases where no value is stored. ```cpp exp.or_else([] { throw std::runtime_error{"oh no"}; }); ``` -------------------------------- ### Functional utility: and_then Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/tl_expected/expected/README.md Example usage of the and_then member function for operations that return a tl::expected. ```cpp tl::expected parse (const std::string& s); tl::expected exp_ast = exp_string.and_then(parse); ``` -------------------------------- ### Functional utility: map_error Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/tl_expected/expected/README.md Example usage of the map_error member function to transform the unexpected object. ```cpp my_error_code translate_error (std::error_code); tl::expected s = exp_int.map_error(translate_error); ``` -------------------------------- ### wai_getExecutablePath Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/whereami/whereami/README.md Returns the path of the enclosing executable. Use a two-call approach: first call with NULL to get the length, then allocate a buffer and call again to retrieve the path. ```APIDOC ## wai_getExecutablePath ### Description Returns the path of the enclosing executable. ### Usage 1. Call `int length = wai_getExecutablePath(NULL, 0, NULL);` to retrieve the length of the path. 2. Allocate the destination buffer with `path = (char*)malloc(length + 1);`. 3. Call `wai_getExecutablePath(path, length, &dirname_length);` again to retrieve the path. 4. Add a terminal NUL character with `path[length] = '\0';`. ### Parameters - `path` (char*) - Output buffer for the path. Pass NULL to get the required length. - `size` (int) - Size of the output buffer. Pass 0 when querying length. - `dirname_length` (int*) - Optional pointer to receive the length of the directory name. ### Returns - `int` - The length of the path (excluding the NUL terminator). ``` -------------------------------- ### Verbose error handling with std::expected Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/tl_expected/expected/README.md An example of manual error checking when chaining multiple operations that may fail. ```cpp std::expected get_cute_cat (const image& img) { auto cropped = crop_to_cat(img); if (!cropped) { return cropped; } auto with_tie = add_bow_tie(*cropped); if (!with_tie) { return with_tie; } auto with_sparkles = make_eyes_sparkle(*with_tie); if (!with_sparkles) { return with_sparkles; } return add_rainbow(make_smaller(*with_sparkles)); } ``` -------------------------------- ### Project Initialization Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/tl_expected/expected/CMakeLists.txt Sets up the project name, version, and required C++ standard. ```cmake cmake_minimum_required(VERSION 3.14) project(tl-expected HOMEPAGE_URL https://tl.tartanllama.xyz DESCRIPTION "C++11/14/17 std::expected with functional-style extensions" VERSION 1.0.0 LANGUAGES CXX) include(CMakePackageConfigHelpers) include(CMakeDependentOption) include(GNUInstallDirs) include(FetchContent) include(CTest) if (NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 14) endif() ``` -------------------------------- ### Packaging Configuration Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/tl_expected/expected/CMakeLists.txt Sets up CPack generators and package metadata. ```cmake if (NOT EXPECTED_BUILD_PACKAGE) return() endif() list(APPEND source-generators TBZ2 TGZ TXZ ZIP) if (CMAKE_HOST_WIN32) list(APPEND binary-generators "WIX") endif() if (EXPECTED_BUILD_PACKAGE_DEB) list(APPEND binary-generators "DEB") endif() if (EXPECTED_BUILD_RPM) list(APPEND binary-generators "RPM") endif() set(CPACK_SOURCE_GENERATOR ${source-generators}) set(CPACK_GENERATOR ${binary-generators}) set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}") set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}") set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Sy Brand") list(APPEND CPACK_SOURCE_IGNORE_FILES /.git/ /build/ .gitignore .DS_Store) include(CPack) ``` -------------------------------- ### Clone and configure format-benchmark repository Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/fmt/fmt/README.md Commands to clone the benchmark repository and generate Makefiles using CMake. ```bash $ git clone --recursive https://github.com/fmtlib/format-benchmark.git $ cd format-benchmark $ cmake . ``` -------------------------------- ### Build GSmartControl from source Source: https://github.com/ashaduri/gsmartcontrol/blob/main/docs/software_requirements.md Commands to configure and compile the project from the source directory. ```bash cd gsmartcontrol mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Release make ``` -------------------------------- ### Add devices via command line Source: https://github.com/ashaduri/gsmartcontrol/blob/main/docs/usage.md Use the --add-device option to specify drives manually, often in conjunction with --no-scan. ```bash --add-device /dev/sda --add-device /dev/twa0::3ware,2 --add-device '/dev/sdb::::-T permissive' ``` -------------------------------- ### Test loading library from APK Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/whereami/whereami/README.md Commands to package and test loading a library from an APK on Android. ```bash $ zip -Z store app bin/android/library.so $ zipalign -v -f -p 4 ./app.zip ./app.apk $ ./executable --load-library=$PWD/app.apk!/bin/android/library.so ``` -------------------------------- ### PkgConfig Initialization Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/CMakeLists.txt Initializes PkgConfig as a required package. ```cmake find_package(PkgConfig REQUIRED) # pkg_check_modules() ``` -------------------------------- ### Build Options Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/tl_expected/expected/CMakeLists.txt Defines build options for packaging and testing. ```cmake option(EXPECTED_BUILD_PACKAGE "Build package files as well" ON) cmake_dependent_option(EXPECTED_BUILD_TESTS "Enable tl::expected tests" ON "BUILD_TESTING" OFF) cmake_dependent_option(EXPECTED_BUILD_PACKAGE_DEB "Create a DEB" ON "EXPECTED_BUILD_PACKAGE" OFF) ``` -------------------------------- ### Format a string Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/fmt/fmt/README.md Using fmt::format to create a formatted string. ```c++ std::string s = fmt::format("The answer is {}.", 42); // s == "The answer is 42." ``` -------------------------------- ### Define example_rconfig Executable Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/rconfig/examples/CMakeLists.txt Defines the example_rconfig executable, specifies its source files, and links it against the rconfig library. ```cmake add_executable(example_rconfig) target_sources(example_rconfig PRIVATE example_rconfig.cpp ) target_link_libraries(example_rconfig PRIVATE rconfig ) ``` -------------------------------- ### Configure Gettext Interface Library Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/CMakeLists.txt Finds the Intl package and configures an interface library for Gettext support. ```cmake find_package(Intl REQUIRED) add_library(app_gettext_interface INTERFACE) if (Intl_INCLUDE_DIRS) target_include_directories(app_gettext_interface SYSTEM INTERFACE ${Intl_INCLUDE_DIRS} ) endif() if (Intl_LIBRARIES) target_link_libraries(app_gettext_interface INTERFACE ${Intl_LIBRARIES} ) endif() ``` -------------------------------- ### Launch GSmartControl on Linux and Unix Source: https://github.com/ashaduri/gsmartcontrol/blob/main/docs/usage.md Run the application using the desktop menu or the gsmartcontrol-root command to invoke it with root privileges. ```bash gsmartcontrol-root ``` -------------------------------- ### Configure NSIS distribution files Source: https://github.com/ashaduri/gsmartcontrol/blob/main/packaging/CMakeLists.txt Sets the WINDOWS_SUFFIX variable based on pointer size and configures the distribution.in.txt file for NSIS. ```cmake set(WINDOWS_SUFFIX "win32") if (CMAKE_SIZEOF_VOID_P EQUAL 8) set(WINDOWS_SUFFIX "win64") endif() configure_file("nsis/distribution.in.txt" "nsis/distribution.txt" ESCAPE_QUOTES @ONLY NEWLINE_STYLE DOS) # configure_file("nsis/gsmartcontrol.in.nsi" "nsis/gsmartcontrol.nsi" ESCAPE_QUOTES @ONLY NEWLINE_STYLE DOS) ``` -------------------------------- ### Test Suite Configuration Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/tl_expected/expected/CMakeLists.txt Fetches Catch2 and configures the test executable if tests are enabled. ```cmake if(EXPECTED_BUILD_TESTS) set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) set(CATCH_INSTALL_HELPERS OFF) set(CATCH_BUILD_TESTING OFF) set(CATCH_INSTALL_DOCS OFF) FetchContent_Declare(Catch2 URL https://github.com/catchorg/Catch2/archive/v2.13.10.zip) FetchContent_MakeAvailable(Catch2) file(GLOB test-sources CONFIGURE_DEPENDS tests/*.cpp) list(FILTER test-sources EXCLUDE REGEX "tests/test.cpp") add_executable(${PROJECT_NAME}-tests "${test-sources}") target_compile_options(${PROJECT_NAME}-tests PRIVATE $<$>:-Wall -Wextra>) target_link_libraries(${PROJECT_NAME}-tests PRIVATE Catch2::Catch2 expected) add_test(NAME tl::expected::tests COMMAND ${PROJECT_NAME}-tests) endif() ``` -------------------------------- ### Set include directories and compile definitions Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/hz/CMakeLists.txt Configures the include paths and compile-time definitions for the hz library. ```cmake target_include_directories(hz INTERFACE "${CMAKE_SOURCE_DIR}/src" ) target_compile_definitions(hz INTERFACE HZ_USE_LIBDEBUG=1 ) ``` -------------------------------- ### CMake configuration for test_all Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/test_all/CMakeLists.txt Configures the test_all executable, links necessary libraries, and sets up Catch2 test discovery. ```cmake if (NOT APP_BUILD_TESTS) set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL true) else() set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL false) endif() # Make sure include() works with our modules. set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/dependencies/catch2/Catch2/contrib") include(ParseAndAddCatchTests) add_executable(test_all) target_sources(test_all PRIVATE test_all.cpp ) target_link_libraries(test_all PRIVATE libdebug applib_tests hz_tests Catch2 ) if (NOT CMAKE_CROSSCOMPILING) catch_discover_tests(test_all) endif() ``` -------------------------------- ### Print with colors and text styles Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/fmt/fmt/README.md Applying colors and text emphasis using fmt::color and fmt::emphasis. ```c++ #include int main() { fmt::print(fg(fmt::color::crimson) | fmt::emphasis::bold, "Hello, {}!\n", "world"); fmt::print(fg(fmt::color::floral_white) | bg(fmt::color::slate_gray) | fmt::emphasis::underline, "Olá, {}!\n", "Mundo"); fmt::print(fg(fmt::color::steel_blue) | fmt::emphasis::italic, "你好{}!\n", "世界"); } ``` -------------------------------- ### Compile for Linux or Mac Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/whereami/whereami/README.md Command to compile the library using GNU Make. ```bash $ make -j -C _gnu-make/ ``` -------------------------------- ### Create standalone Android toolchain Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/whereami/whereami/README.md Command to generate a standalone Android toolchain using the NDK. ```bash $ $NDK_ROOT/build/tools/make_standalone_toolchain.py --arch=arm64 --api 21 --install-dir=/tmp/android-toolchain ``` -------------------------------- ### Compile for iOS via command line Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/whereami/whereami/README.md Command to compile for iOS and deploy to a jailbroken device through SSH. ```bash $ make -j -C _gnu-make/ binsubdir=ios CC="$(xcrun --sdk iphoneos --find clang) -isysroot $(xcrun --sdk iphoneos --show-sdk-path) -arch armv7 -arch armv7s -arch arm64" postbuild="codesign -s 'iPhone Developer'" ``` -------------------------------- ### Configure Application Files Source: https://github.com/ashaduri/gsmartcontrol/blob/main/data/CMakeLists.txt Uses configure_file to process input templates into final application files with escaped quotes. ```cmake configure_file("gsmartcontrol.appdata.in.xml" "gsmartcontrol.appdata.xml" ESCAPE_QUOTES @ONLY) configure_file("gsmartcontrol.in.desktop" "gsmartcontrol.desktop" ESCAPE_QUOTES @ONLY) configure_file("gsmartcontrol-root.in.sh" "gsmartcontrol-root.sh" ESCAPE_QUOTES @ONLY) configure_file("org.gsmartcontrol.in.policy" "org.gsmartcontrol.policy" ESCAPE_QUOTES @ONLY) ``` -------------------------------- ### Enable SMART and Automatic Offline Data Collection via smartctl Source: https://github.com/ashaduri/gsmartcontrol/blob/main/docs/troubleshooting.md Use this command in a system startup script to ensure SMART and Automatic Offline Data Collection are enabled on /dev/sda upon boot. ```bash smartctl -s on -o on /dev/sda ``` -------------------------------- ### Configure Interface Include Directories Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/tl_expected/CMakeLists.txt Sets the include directories for the tl_expected interface target as a system dependency. ```cmake target_include_directories(tl_expected SYSTEM INTERFACE "${CMAKE_SOURCE_DIR}/dependencies/tl_expected/expected/include" ) ``` -------------------------------- ### Run speed-test Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/fmt/fmt/README.md Command to execute the speed test after generating Makefiles. ```bash $ make speed-test ``` -------------------------------- ### Run GSmartControl with verbose logging Source: https://github.com/ashaduri/gsmartcontrol/blob/main/docs/support.md Run the program with the -v option to obtain an execution log. On Windows, the -v switch is on by default. ```bash gsmartcontrol-root -v ``` -------------------------------- ### Configure Interface Include Directories Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/nlohmann_json/CMakeLists.txt Sets the include directories for the nlohmann_json interface library as a system dependency. ```cmake target_include_directories(nlohmann_json SYSTEM INTERFACE "${CMAKE_SOURCE_DIR}/dependencies/nlohmann_json" ) ``` -------------------------------- ### Run bloat-test Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/fmt/fmt/README.md Command to execute the bloat test after generating Makefiles. ```bash $ make bloat-test ``` -------------------------------- ### Define hz interface library and sources Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/hz/CMakeLists.txt Initializes the hz library as an interface target and adds the header files as source files. ```cmake add_library(hz INTERFACE) # Relative sources are allowed only since cmake 3.13. target_sources(hz INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/bad_cast_exception.h ${CMAKE_CURRENT_SOURCE_DIR}/data_file.h ${CMAKE_CURRENT_SOURCE_DIR}/debug.h ${CMAKE_CURRENT_SOURCE_DIR}/enum_helper.h ${CMAKE_CURRENT_SOURCE_DIR}/env_tools.h ${CMAKE_CURRENT_SOURCE_DIR}/error_container.h ${CMAKE_CURRENT_SOURCE_DIR}/error_holder.h ${CMAKE_CURRENT_SOURCE_DIR}/format_unit.h ${CMAKE_CURRENT_SOURCE_DIR}/fs.h ${CMAKE_CURRENT_SOURCE_DIR}/fs_ns.h ${CMAKE_CURRENT_SOURCE_DIR}/launch_url.h ${CMAKE_CURRENT_SOURCE_DIR}/locale_tools.h ${CMAKE_CURRENT_SOURCE_DIR}/main_tools.h ${CMAKE_CURRENT_SOURCE_DIR}/process_signal.h ${CMAKE_CURRENT_SOURCE_DIR}/stream_cast.h ${CMAKE_CURRENT_SOURCE_DIR}/string_algo.h ${CMAKE_CURRENT_SOURCE_DIR}/string_num.h ${CMAKE_CURRENT_SOURCE_DIR}/string_sprintf.h ${CMAKE_CURRENT_SOURCE_DIR}/system_specific.h ${CMAKE_CURRENT_SOURCE_DIR}/win32_tools.h ) ``` -------------------------------- ### Configure Catch2 Include Directories Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/catch2/CMakeLists.txt Sets the include directory for the Catch2 interface library as a system interface. ```cmake target_include_directories(Catch2 SYSTEM INTERFACE "${CMAKE_SOURCE_DIR}/dependencies/catch2/Catch2/single_include" ) ``` -------------------------------- ### OBS Debian and RPM configuration Source: https://github.com/ashaduri/gsmartcontrol/blob/main/packaging/CMakeLists.txt Commented out configuration commands for OBS Debian changelog and RPM spec files. ```cmake # OBS Debian #configure_file("obs_debian/changelog.in" "obs_debian/changelog" ESCAPE_QUOTES @ONLY) # OBS RPM #configure_file(obs_rpm/gsmartcontrol.in.spec obs_rpm/gsmartcontrol.spec) ``` -------------------------------- ### Print to stdout Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/fmt/fmt/README.md Basic usage of fmt::print to output text to standard output. ```c++ #include int main() { fmt::print("Hello, world!\n"); } ``` -------------------------------- ### Define fmt static library Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/fmt/CMakeLists.txt Initializes the fmt library target as a static library. ```cmake add_library(fmt STATIC) ``` -------------------------------- ### Configure Gtkmm Interface Library Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/CMakeLists.txt Finds Gtkmm, creates an interface library, and sets necessary compile definitions. ```cmake pkg_check_modules(Gtkmm REQUIRED IMPORTED_TARGET GLOBAL "gtkmm-3.0>=3.0") add_library(app_gtkmm_interface INTERFACE) target_link_libraries(app_gtkmm_interface INTERFACE PkgConfig::Gtkmm ) target_compile_definitions(app_gtkmm_interface INTERFACE ENABLE_GLIB=1 ENABLE_GLIBMM=1 # For porting to GTK4 # GTK_DISABLE_DEPRECATED=1 # GDK_DISABLE_DEPRECATED=1 # GTKMM_DISABLE_DEPRECATED=1 # GDKMM_DISABLE_DEPRECATED=1 # GLIBMM_DISABLE_DEPRECATED=1 # GIOMM_DISABLE_DEPRECATED=1 ) ``` -------------------------------- ### Configure fmt include directories Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/fmt/CMakeLists.txt Sets the include directory for the fmt target as a system public dependency. ```cmake target_include_directories(fmt SYSTEM PUBLIC "fmt/include" ) ``` -------------------------------- ### Executable Target Definition Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/libdebug/examples/CMakeLists.txt Defines the example_libdebug executable, specifies its source file, and links it against the libdebug library. ```cmake add_executable(example_libdebug) target_sources(example_libdebug PRIVATE example_libdebug.cpp ) target_link_libraries(example_libdebug PRIVATE libdebug ) ``` -------------------------------- ### Write a file from a single thread Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/fmt/fmt/README.md Using fmt::output_file for high-performance file writing. ```c++ #include int main() { auto out = fmt::output_file("guide.txt"); out.print("Don't {}", "Panic"); } ``` -------------------------------- ### Define hz_tests Object Library Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/hz/tests/CMakeLists.txt Creates an object library named hz_tests, adds specific source files, and links the required hz and Catch2 dependencies. ```cmake # Use Object libraries to allow runtime test discovery add_library(hz_tests OBJECT) target_sources(hz_tests PRIVATE test_format_unit.cpp test_string_algo.cpp test_string_num.cpp ) target_link_libraries(hz_tests PRIVATE hz Catch2 ) ``` -------------------------------- ### Define build_config interface library Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/build_config/CMakeLists.txt Configures the build_config.h header file and defines an interface library to manage build-specific include directories and sources. ```cmake add_library(build_config INTERFACE) configure_file("build_config.in.h" "build_config.h" ESCAPE_QUOTES @ONLY) target_sources(build_config INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/build_config.h ) target_include_directories(build_config INTERFACE "${CMAKE_CURRENT_BINARY_DIR}") ``` -------------------------------- ### Configure whereami include directories Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/whereami/CMakeLists.txt Sets the include directory for the whereami library as a system public dependency. ```cmake target_include_directories(whereami SYSTEM PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/whereami/src" ) ``` -------------------------------- ### Define rconfig Interface Library Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/rconfig/CMakeLists.txt Initializes the rconfig library as an interface library. ```cmake add_library(rconfig INTERFACE) ``` -------------------------------- ### Define applib_tests Object Library Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/applib/tests/CMakeLists.txt Creates an object library for test source files and links the required applib and Catch2 dependencies. ```cmake add_library(applib_tests OBJECT) target_sources(applib_tests PRIVATE test_app_regex.cpp test_fractional_scaling.cpp test_selftest.cpp test_smartctl_parser.cpp test_smartctl_version_parser.cpp ) target_link_libraries(applib_tests PRIVATE applib Catch2 ) ``` -------------------------------- ### Library Definition Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/tl_expected/expected/CMakeLists.txt Defines the interface library and its include directories. ```cmake add_library(expected INTERFACE) target_include_directories(expected INTERFACE $ $) if (NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) add_library(tl::expected ALIAS expected) endif() ``` -------------------------------- ### Specify whereami source files Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/whereami/CMakeLists.txt Adds the source and header files to the whereami library target. ```cmake target_sources(whereami PRIVATE whereami/src/whereami.cpp whereami/src/whereami.h ) ``` -------------------------------- ### Set Interface Source Files Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/tl_expected/CMakeLists.txt Adds the tl_expected header file to the interface target sources. ```cmake target_sources(tl_expected INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/expected/include/tl/expected.hpp ) ``` -------------------------------- ### Define whereami static library Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/whereami/CMakeLists.txt Initializes the whereami library as a static target. ```cmake add_library(whereami STATIC) ``` -------------------------------- ### Add tests subdirectory Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/hz/CMakeLists.txt Includes the tests directory in the build process. ```cmake add_subdirectory(tests) ``` -------------------------------- ### Define Catch2 Interface Library Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/catch2/CMakeLists.txt Creates an interface library named Catch2 for the project. ```cmake add_library(Catch2 INTERFACE) ``` -------------------------------- ### Set Interface Target Sources Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/nlohmann_json/CMakeLists.txt Specifies the source file for the nlohmann_json interface library. ```cmake target_sources(nlohmann_json INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/nlohmann/json.hpp ) ``` -------------------------------- ### Check a format string at compile time Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/fmt/fmt/README.md Demonstrates how fmt can catch invalid format specifiers at compile time in C++20. ```c++ std::string s = fmt::format("{:d}", "I am not a number"); ``` -------------------------------- ### Add Third-Party Subdirectories Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/CMakeLists.txt Adds external project directories to the build process. ```cmake add_subdirectory(catch2) add_subdirectory(fmt) add_subdirectory(nlohmann_json) add_subdirectory(whereami) add_subdirectory(tl_expected) ``` -------------------------------- ### Define tl_expected Interface Library Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/tl_expected/CMakeLists.txt Initializes the tl_expected library as an INTERFACE target in CMake. ```cmake add_library(tl_expected INTERFACE) ``` -------------------------------- ### Detect Operating System and Set Kernel Flags Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/build_config/CMakeLists.txt Checks the CMAKE_SYSTEM_NAME variable to determine the host OS and sets specific configuration flags for build_config.in.h. For Windows, it further distinguishes between 32-bit and 64-bit architectures. ```cmake if ("${CMAKE_SYSTEM_NAME}" MATCHES "Windows" OR "${CMAKE_SYSTEM_NAME}" MATCHES "CYGWIN.*") if (CMAKE_SIZEOF_VOID_P EQUAL 4) set(CONFIG_KERNEL_WINDOWS32 TRUE) else() set(CONFIG_KERNEL_WINDOWS64 TRUE) endif() elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") set(CONFIG_KERNEL_LINUX TRUE) elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD" OR "${CMAKE_SYSTEM_NAME}" MATCHES "GNU/kFreeBSD") set(CONFIG_KERNEL_FREEBSD TRUE) elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "DragonFly") set(CONFIG_KERNEL_DRAGONFLY TRUE) elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "NetBSD") set(CONFIG_KERNEL_NETBSD TRUE) elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "OpenBSD") set(CONFIG_KERNEL_OPENBSD TRUE) elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "SunOS" OR "${CMAKE_SYSTEM_NAME}" MATCHES "Solaris") set(CONFIG_KERNEL_SOLARIS TRUE) elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") set(CONFIG_KERNEL_DARWIN TRUE) elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "QNX") set(CONFIG_KERNEL_QNX TRUE) endif() ``` -------------------------------- ### Link dependencies for hz Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/hz/CMakeLists.txt Configures the interface link libraries required by the hz library. ```cmake target_link_libraries(hz INTERFACE # libdebug app_gtkmm_interface # ENABLE_* macros app_gettext_interface # format_unit.h uses this libdebug # debug.h whereami # whereami.h tl_expected # error_container.h # std::filesystem # fs_ns.h, linking to stdc++fs / c++fs if needed ) ``` -------------------------------- ### Format a string using positional arguments Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/fmt/fmt/README.md Using positional indices to reorder arguments in a format string. ```c++ std::string s = fmt::format("I'd rather be {1} than {0}.", "right", "happy"); // s == "I'd rather be happy than right." ``` -------------------------------- ### Set rconfig Include Directories Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/rconfig/CMakeLists.txt Configures the include directory for the rconfig interface library. ```cmake target_include_directories(rconfig INTERFACE "${CMAKE_SOURCE_DIR}/src") ``` -------------------------------- ### Specify fmt target sources Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/fmt/CMakeLists.txt Adds the source and header files to the fmt target. Note that relative sources require CMake 3.13 or later. ```cmake target_sources(fmt PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/fmt/src/format.cc ${CMAKE_CURRENT_SOURCE_DIR}/fmt/include/fmt/args.h ${CMAKE_CURRENT_SOURCE_DIR}/fmt/include/fmt/base.h ${CMAKE_CURRENT_SOURCE_DIR}/fmt/include/fmt/chrono.h ${CMAKE_CURRENT_SOURCE_DIR}/fmt/include/fmt/color.h ${CMAKE_CURRENT_SOURCE_DIR}/fmt/include/fmt/compile.h ${CMAKE_CURRENT_SOURCE_DIR}/fmt/include/fmt/core.h ${CMAKE_CURRENT_SOURCE_DIR}/fmt/include/fmt/format.h ${CMAKE_CURRENT_SOURCE_DIR}/fmt/include/fmt/format-inl.h ${CMAKE_CURRENT_SOURCE_DIR}/fmt/include/fmt/os.h ${CMAKE_CURRENT_SOURCE_DIR}/fmt/include/fmt/ostream.h ${CMAKE_CURRENT_SOURCE_DIR}/fmt/include/fmt/printf.h ${CMAKE_CURRENT_SOURCE_DIR}/fmt/include/fmt/ranges.h ${CMAKE_CURRENT_SOURCE_DIR}/fmt/include/fmt/std.h ${CMAKE_CURRENT_SOURCE_DIR}/fmt/include/fmt/xchar.h ) ``` -------------------------------- ### Define nlohmann_json Interface Library Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/nlohmann_json/CMakeLists.txt Creates an interface library target named nlohmann_json. ```cmake add_library(nlohmann_json INTERFACE) ``` -------------------------------- ### Display C Compiler Status Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/build_config/CMakeLists.txt Logs the current C compiler path to the CMake status output. ```cmake message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}") ``` -------------------------------- ### Check for getrawpartition symbol Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/build_config/CMakeLists.txt Commented-out code used to check for the existence of the getrawpartition function in util.h for NetBSD and OpenBSD systems. ```cmake #check_symbol_exists(getrawpartition "util.h" HAVE_GETRAWPARTITION) #message(STATUS "getrawpartition() detected: ${HAVE_GETRAWPARTITION}") ``` -------------------------------- ### Functional chaining with tl::expected Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/tl_expected/expected/README.md A cleaner approach to chaining operations using functional extensions provided by tl::expected. ```cpp tl::expected get_cute_cat (const image& img) { return crop_to_cat(img) .and_then(add_bow_tie) .and_then(make_eyes_sparkle) .map(make_smaller) .map(add_rainbow); } ``` -------------------------------- ### Specify Catch2 Source Files Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/catch2/CMakeLists.txt Adds the catch.hpp header file to the Catch2 interface library. ```cmake target_sources(Catch2 INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/Catch2/single_include/catch2/catch.hpp ) ``` -------------------------------- ### wai_getModulePath Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/whereami/whereami/README.md Returns the path of the enclosing module. Use the same two-call pattern as wai_getExecutablePath. ```APIDOC ## wai_getModulePath ### Description Returns the path of the enclosing module. ### Usage 1. Call `int length = wai_getModulePath(NULL, 0, NULL);` to retrieve the length of the path. 2. Allocate the destination buffer with `path = (char*)malloc(length + 1);`. 3. Call `wai_getModulePath(path, length, &dirname_length);` again to retrieve the path. 4. Add a terminal NUL character with `path[length] = '\0';`. ### Parameters - `path` (char*) - Output buffer for the path. Pass NULL to get the required length. - `size` (int) - Size of the output buffer. Pass 0 when querying length. - `dirname_length` (int*) - Optional pointer to receive the length of the directory name. ### Returns - `int` - The length of the path (excluding the NUL terminator). ``` -------------------------------- ### Set rconfig Interface Sources Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/rconfig/CMakeLists.txt Specifies the header files associated with the rconfig interface library. ```cmake target_sources(rconfig INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/autosave.h ${CMAKE_CURRENT_SOURCE_DIR}/loadsave.h ${CMAKE_CURRENT_SOURCE_DIR}/rconfig.h ) ``` -------------------------------- ### Link rconfig Dependencies Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/rconfig/CMakeLists.txt Links the required interface dependencies to the rconfig library. ```cmake target_link_libraries(rconfig INTERFACE hz nlohmann_json app_gtkmm_interface ) ``` -------------------------------- ### Conditional Test Directory Configuration Source: https://github.com/ashaduri/gsmartcontrol/blob/main/src/applib/tests/CMakeLists.txt Configures whether the test directory is excluded from the build based on the APP_BUILD_TESTS variable. ```cmake if (NOT APP_BUILD_TESTS) set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL true) else() set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL false) endif() ``` -------------------------------- ### Glibmm Version Workaround Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/CMakeLists.txt Checks for older Glibmm versions and applies a compile definition workaround for throw specifications. ```cmake pkg_check_modules(Glibmm "glibmm-2.4") if ("${Glibmm_VERSION}" VERSION_LESS "2.50.1") target_compile_definitions(app_gtkmm_interface INTERFACE "APP_GLIBMM_USES_THROW") message(STATUS "Enabling old glibmm throw(...) workaround") endif() ``` -------------------------------- ### Suppress Compiler Warnings Source: https://github.com/ashaduri/gsmartcontrol/blob/main/dependencies/CMakeLists.txt Disables all compiler warnings based on the detected compiler ID for Clang, GNU, AppleClang, or MSVC. ```cmake if (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang OR ${CMAKE_CXX_COMPILER_ID} STREQUAL GNU OR ${CMAKE_CXX_COMPILER_ID} STREQUAL AppleClang) add_compile_options(-w) elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC) add_compile_options(/w) endif() ```