### Installing Project Artifacts and Documentation (CMake) Source: https://github.com/rizsotto/bear/blob/master/CMakeLists.txt This snippet handles the final installation of the project. It installs files from the staged installation prefix to the destination, preserving source permissions. It also installs various documentation files (COPYING, README.md, etc.) to the CMAKE_INSTALL_DOCDIR. ```CMake include(GNUInstallDirs) install(DIRECTORY ${STAGED_INSTALL_PREFIX}/ DESTINATION . USE_SOURCE_PERMISSIONS ) install(FILES COPYING README.md INSTALL.md CONTRIBUTING.md CODE_OF_CONDUCT.md DESTINATION ${CMAKE_INSTALL_DOCDIR} ) ``` -------------------------------- ### Installing Executable 'bear' (CMake) Source: https://github.com/rizsotto/bear/blob/master/source/bear/CMakeLists.txt This snippet includes the `GNUInstallDirs` module to define standard installation directories and then configures the installation of the `bear` executable to the runtime binary directory specified by `${CMAKE_INSTALL_BINDIR}`. ```CMake include(GNUInstallDirs) install(TARGETS bear RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) ``` -------------------------------- ### Installing Wrapper Executable and Creating Symlinks in CMake Source: https://github.com/rizsotto/bear/blob/master/source/intercept/CMakeLists.txt This snippet handles the installation of the `wrapper` executable and creates a directory for its symlinks. It uses `install(CODE)` to execute a process that creates numerous symbolic links from common compiler and utility names (e.g., `cc`, `gcc`, `ar`) to the `wrapper` executable within a dedicated directory, enabling interception of build commands. ```CMake install(TARGETS wrapper RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/bear) install(DIRECTORY DESTINATION ${CMAKE_INSTALL_LIBDIR}/bear/wrapper.d) install(CODE " execute_process( COMMAND ln -sf ../wrapper ar COMMAND ln -sf ../wrapper as COMMAND ln -sf ../wrapper cc COMMAND ln -sf ../wrapper c++ COMMAND ln -sf ../wrapper cpp COMMAND ln -sf ../wrapper gcc COMMAND ln -sf ../wrapper g++ COMMAND ln -sf ../wrapper clang COMMAND ln -sf ../wrapper clang++ COMMAND ln -sf ../wrapper f77 COMMAND ln -sf ../wrapper flang COMMAND ln -sf ../wrapper flang-new COMMAND ln -sf ../wrapper ftnfe COMMAND ln -sf ../wrapper gfortran COMMAND ln -sf ../wrapper ifx COMMAND ln -sf ../wrapper ifort COMMAND ln -sf ../wrapper m2c COMMAND ln -sf ../wrapper pc COMMAND ln -sf ../wrapper lex COMMAND ln -sf ../wrapper flex COMMAND ln -sf ../wrapper yacc COMMAND ln -sf ../wrapper bison COMMAND ln -sf ../wrapper lint COMMAND ln -sf ../wrapper makeinfo COMMAND ln -sf ../wrapper tex COMMAND ln -sf ../wrapper tex2dvi COMMAND ln -sf ../wrapper weave COMMAND ln -sf ../wrapper cweave COMMAND ln -sf ../wrapper tangle COMMAND ln -sf ../wrapper ctangle COMMAND ln -sf ../wrapper nm COMMAND ln -sf ../wrapper ld COMMAND ln -sf ../wrapper strip COMMAND ln -sf ../wrapper objcopy COMMAND ln -sf ../wrapper objdump COMMAND ln -sf ../wrapper ranlib COMMAND ln -sf ../wrapper readelf WORKING_DIRECTORY ${DESTDIR}${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/bear/wrapper.d ) ") ``` -------------------------------- ### Installing Man Page in CMake Source: https://github.com/rizsotto/bear/blob/master/source/intercept/CMakeLists.txt This CMake command installs the generated man page file (`bear-intercept.1`) to the standard man page directory (`${CMAKE_INSTALL_MANDIR}/man1`). This ensures the documentation is available in the system's man pages after installation. ```CMake install(FILES man/bear-intercept.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) ``` -------------------------------- ### Installing Bear Dependencies on Ubuntu 20.04 (apt-get) Source: https://github.com/rizsotto/bear/blob/master/INSTALL.md Commands to install necessary build and runtime dependencies for Bear on Ubuntu 20.04 using `apt-get`. This includes core tools and development libraries required for compilation. ```shell apt-get install python cmake pkg-config apt-get install libfmt-dev libspdlog-dev nlohmann-json3-dev \ libgrpc++-dev protobuf-compiler-grpc libssl-dev ``` -------------------------------- ### Installing Man Page 'bear.1' (CMake) Source: https://github.com/rizsotto/bear/blob/master/source/bear/CMakeLists.txt This snippet installs the `bear.1` man page from the `man/` directory to the standard man page directory specified by `${CMAKE_INSTALL_MANDIR}/man1`. It assumes the man page has been pre-generated. ```CMake install(FILES man/bear.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) ``` -------------------------------- ### Installing Bear Dependencies on Arch Linux (pacman) Source: https://github.com/rizsotto/bear/blob/master/INSTALL.md Commands to install necessary build and runtime dependencies for Bear on Arch Linux using `pacman`. This covers core tools, libraries, and optional test frameworks. ```shell pacman -S python cmake pkg-config pacman -S grpc spdlog fmt nlohmann-json pacman -S gtest gmock # optional for running the tests ``` -------------------------------- ### Installing Man Page (CMake) Source: https://github.com/rizsotto/bear/blob/master/source/citnames/CMakeLists.txt This snippet uses the `install` command to place the `bear-citnames.1` man page into the standard system man page directory, determined by `CMAKE_INSTALL_MANDIR`. The surrounding comments indicate that the generation of this file from a Markdown source is a manual step, not automated by CMake, due to potential large dependencies of `pandoc`. ```CMake install(FILES man/bear-citnames.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) ``` -------------------------------- ### Setting Up and Running Tests for Bear Source: https://github.com/rizsotto/bear/blob/master/INSTALL.md This sequence of commands sets up the `lit` functional test framework within a Python virtual environment, then reconfigures CMake and builds the project, enabling test execution. It's important to re-run CMake after installing test dependencies. ```shell # install `lit` the functional test framework into a python virtualenv mkvirtualenv bear pip install lit # it's important to re-run the configure step again cmake $BEAR_SOURCE_DIR cmake --build $build_dir --parallel 4 ``` -------------------------------- ### Installing Bear Dependencies on macOS (Homebrew) Source: https://github.com/rizsotto/bear/blob/master/INSTALL.md Command to install core runtime dependencies for Bear on macOS using Homebrew. This includes libraries like `fmt`, `spdlog`, `nlohmann-json`, `grpc`, and `pkg-config`. ```shell brew install fmt spdlog nlohmann-json grpc pkg-config ``` -------------------------------- ### Installing Bear Dependencies on Alpine Linux (apk) Source: https://github.com/rizsotto/bear/blob/master/INSTALL.md Commands to install necessary build tools and development libraries for Bear on Alpine Linux edge using `apk`. This covers compilers, build systems, and various development headers. ```shell apk add git cmake pkgconf make g++ apk add fmt-dev spdlog-dev nlohmann-json protobuf-dev grpc-dev c-ares-dev ``` -------------------------------- ### Configuring CMake with Custom Library Install Directory Source: https://github.com/rizsotto/bear/blob/master/INSTALL.md This command configures CMake to specify a custom installation directory for libraries using `CMAKE_INSTALL_LIBDIR`. This is crucial for systems with varying library path conventions (e.g., `lib` vs. `lib64` or architecture-specific paths). ```shell cmake -DCMAKE_INSTALL_LIBDIR=lib/x86_64-linux-gnu ... $BEAR_SOURCE_DIR ``` -------------------------------- ### Installing Bear Dependencies on Fedora (dnf) Source: https://github.com/rizsotto/bear/blob/master/INSTALL.md Commands to install necessary build and runtime dependencies for Bear on Fedora 32/33 using `dnf`. This includes core tools, libraries, and optional test frameworks like `gtest` and `gmock`. ```shell dnf install python cmake pkg-config dnf install json-devel spdlog-devel fmt-devel grpc-devel grpc-plugins dnf install gtest-devel gmock-devel # optional for running the tests ``` -------------------------------- ### Configuring Superbuild and Dependencies (CMake) Source: https://github.com/rizsotto/bear/blob/master/CMakeLists.txt This section includes ExternalProject for superbuild capabilities, defines installation prefixes for staged and dependency installations, and includes GNUInstallDirs. It also adds a subdirectory for third-party dependency verification/installation. ```CMake include(ExternalProject) set_property(DIRECTORY PROPERTY EP_BASE ${CMAKE_BINARY_DIR}/subprojects) set(STAGED_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/stage) set(DEPENDENCIES_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/subprojects/Install) include(GNUInstallDirs) # Verify or install dependencies add_subdirectory(third_party) ``` -------------------------------- ### Appending spdlog Install Path to CMAKE_PREFIX_PATH Source: https://github.com/rizsotto/bear/blob/master/third_party/spdlog/CMakeLists.txt This snippet ensures that the externally installed 'spdlog' library is discoverable by subsequent CMake 'find_package' calls. It includes 'GNUInstallDirs' for standard directory variables, appends the 'spdlog' installation prefix to a list, and then updates 'CMAKE_PREFIX_PATH' to include this new location. ```CMake include(GNUInstallDirs) list(APPEND PREFIX_PATH "${DEPENDENCIES_INSTALL_PREFIX}/spdlog_dependency") set(CMAKE_PREFIX_PATH ${PREFIX_PATH};${CMAKE_PREFIX_PATH} CACHE PATH "append spdlog library into the search path" FORCE) endif () ``` -------------------------------- ### Example Bear Configuration File (JSON) Source: https://github.com/rizsotto/bear/blob/master/source/citnames/man/bear-citnames.1.md This JSON snippet illustrates a typical configuration file for the Bear tool, demonstrating how to customize compiler recognition and output format. It includes settings for adding or removing compiler flags, filtering output based on file paths, and controlling the format of the command field in the generated compilation database. ```json { "compilation": { "compilers_to_recognize": [ { "executable": "/usr/bin/mpicc", "flags_to_add": ["-I/opt/MPI/include"], "flags_to_remove": ["-Wall"] } ], "compilers_to_exclude": [] }, "output": { "content": { "include_only_existing_source": true, "paths_to_include": [], "paths_to_exclude": [], "duplicate_filter_fields": "file_output" }, "format": { "command_as_array": true, "drop_output_field": false } } } ``` -------------------------------- ### Building gRPC as an External Project in CMake Source: https://github.com/rizsotto/bear/blob/master/third_party/grpc/CMakeLists.txt This snippet defines an `ExternalProject` to download, configure, and build gRPC from its GitHub repository if it's not found on the system. It specifies the Git tag, enables submodules, and passes various CMake arguments to control the build process, including installation prefix and compiler flags. Finally, it updates `CMAKE_PREFIX_PATH` to include the newly installed gRPC. ```CMake else () message(STATUS "Looking for gRPC::grpc++ dependency -- not found") include(ExternalProject) ExternalProject_Add(grpc_dependency GIT_REPOSITORY https://github.com/grpc/grpc GIT_TAG v1.49.2 GIT_SUBMODULES GIT_SHALLOW 1 UPDATE_COMMAND "" LOG_CONFIGURE 1 LOG_BUILD 1 LOG_INSTALL 1 CMAKE_ARGS -DgRPC_INSTALL:BOOL=ON -DgRPC_BUILD_TESTS:BOOL=OFF -DgRPC_BUILD_CSHARP_EXT:BOOL=OFF -DCMAKE_INSTALL_PREFIX:PATH=${DEPENDENCIES_INSTALL_PREFIX}/grpc_dependency CMAKE_CACHE_ARGS -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} -DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_FIND_ROOT_PATH:PATH=${CMAKE_FIND_ROOT_PATH} -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER} -DCMAKE_C_COMPILER_TARGET:STRING=${CMAKE_C_COMPILER_TARGET} -DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS} -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_COMPILER_TARGET:STRING=${CMAKE_CXX_COMPILER_TARGET} -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} -DCMAKE_CXX_STANDARD_REQUIRED:BOOL=${CMAKE_CXX_STANDARD_REQUIRED} -DCMAKE_CXX_EXTENSIONS:BOOL=${CMAKE_CXX_EXTENSIONS} -DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS} -DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS} -DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS} -DCMAKE_MODULE_LINKER_FLAGS:STRING=${CMAKE_MODULE_LINKER_FLAGS} ) include(GNUInstallDirs) list(APPEND PREFIX_PATH "${DEPENDENCIES_INSTALL_PREFIX}/grpc_dependency") set(CMAKE_PREFIX_PATH ${PREFIX_PATH};${CMAKE_PREFIX_PATH} CACHE PATH "append gRPC libraries and binaries into the search path" FORCE) endif () ``` -------------------------------- ### Configuring CMake Search Path for nlohmann_json Source: https://github.com/rizsotto/bear/blob/master/third_party/nlohmann_json/CMakeLists.txt This snippet includes the `GNUInstallDirs` module to ensure standard installation directories are known. It then appends the installation path of the externally built `nlohmann_json` dependency to `CMAKE_PREFIX_PATH`. This modification ensures that subsequent `find_package` calls within the project can successfully locate the newly installed 'nlohmann_json' library. ```CMake include(GNUInstallDirs) list(APPEND PREFIX_PATH "${DEPENDENCIES_INSTALL_PREFIX}/nlohmann_json_dependency") set(CMAKE_PREFIX_PATH ${PREFIX_PATH};${CMAKE_PREFIX_PATH} CACHE PATH "append JSON library into the search path" FORCE) endif () ``` -------------------------------- ### Configuring Headers and Adding Subdirectories Source: https://github.com/rizsotto/bear/blob/master/source/CMakeLists.txt This snippet includes GNUInstallDirs for standard installation paths, configures config.h from a template, and adds the binary directory to the include paths. Finally, it includes several subdirectories, each likely containing its own CMakeLists.txt for building different components of the project. ```CMake include(GNUInstallDirs) # The directory names are used in the config file configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_subdirectory(libresult) add_subdirectory(libflags) add_subdirectory(libshell) add_subdirectory(libsys) add_subdirectory(libmain) add_subdirectory(intercept) add_subdirectory(citnames) add_subdirectory(bear) ``` -------------------------------- ### Building and Installing Execution Interceptor Shared Library (exec) in CMake Source: https://github.com/rizsotto/bear/blob/master/source/intercept/CMakeLists.txt This snippet defines the `exec` shared library, specifying its source files and linking it to the `exec_a` object library. It includes conditional logic to set platform-specific target properties for Linux (e.g., linker language, version script flags) and Darwin (e.g., architectures, RPATH). Finally, it installs the compiled shared library to the specified `CMAKE_INSTALL_LIBDIR`. ```CMake add_library(exec SHARED source/report/libexec/lib.cc source/report/libexec/std.cc ) target_link_libraries(exec exec_a) if (CMAKE_SYSTEM_NAME STREQUAL "Linux") set_target_properties(exec PROPERTIES LINKER_LANGUAGE "C" CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "" LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libexec.version" ) elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") set_target_properties(exec PROPERTIES LINKER_LANGUAGE "CXX" OSX_ARCHITECTURES:STRING "i386;x86_64" MACOSX_RPATH:BOOL ON ) endif () install(TARGETS exec LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/bear) ``` -------------------------------- ### Building Bear with Disabled Tests (CMake) Source: https://github.com/rizsotto/bear/blob/master/INSTALL.md This snippet shows the basic commands to configure, build, and install the Bear project using CMake, with unit and functional tests explicitly disabled. It assumes `$BEAR_SOURCE_DIR` is set to the project's source directory. ```shell cmake -DENABLE_UNIT_TESTS=OFF -DENABLE_FUNC_TESTS=OFF $BEAR_SOURCE_DIR make all make install ``` -------------------------------- ### Adding fmtlib as External Project (CMake) Source: https://github.com/rizsotto/bear/blob/master/third_party/fmt/CMakeLists.txt If fmtlib is not found, this section uses CMake's `ExternalProject` module to download, configure, build, and install fmtlib from its GitHub repository. It specifies the URL, MD5 hash for integrity, and various CMake arguments to control the build process and installation path. ```CMake else () message(STATUS "Looking for fmt dependency -- not found") include(ExternalProject) ExternalProject_Add(fmt_dependency URL https://github.com/fmtlib/fmt/archive/11.0.2.tar.gz URL_HASH MD5=3fe10c5184c8ecd0d2f9536c1b1ae95c DOWNLOAD_NO_PROGRESS 1 UPDATE_COMMAND "" LOG_CONFIGURE 1 LOG_BUILD 1 LOG_INSTALL 1 CMAKE_ARGS -DFMT_INSTALL:BOOL=ON -DFMT_TEST:BOOL=OFF -DFMT_FUZZ:BOOL=OFF -DFMT_DOC:BOOL=OFF -DCMAKE_INSTALL_PREFIX:PATH=${DEPENDENCIES_INSTALL_PREFIX}/fmt_dependency CMAKE_CACHE_ARGS -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} -DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_FIND_ROOT_PATH:PATH=${CMAKE_FIND_ROOT_PATH} -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER} -DCMAKE_C_COMPILER_TARGET:STRING=${CMAKE_C_COMPILER_TARGET} -DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS} -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_COMPILER_TARGET:STRING=${CMAKE_CXX_COMPILER_TARGET} -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} -DCMAKE_CXX_STANDARD_REQUIRED:BOOL=${CMAKE_CXX_STANDARD_REQUIRED} -DCMAKE_CXX_EXTENSIONS:BOOL=${CMAKE_CXX_EXTENSIONS} -DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS} -DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS} -DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS} -DCMAKE_MODULE_LINKER_FLAGS:STRING=${CMAKE_MODULE_LINKER_FLAGS} ) ``` -------------------------------- ### Finding gRPC and Tools with PkgConfig in CMake Source: https://github.com/rizsotto/bear/blob/master/third_party/grpc/CMakeLists.txt This snippet attempts to locate an existing gRPC C++ installation along with `protoc` and `grpc_cpp_plugin` using `PkgConfig` and `find_program`. It checks for specific versions of `protobuf` and `grpc++` and reports status messages. If all components are found, a custom target `grpc_dependency` is added. ```CMake message(STATUS "Looking for gRPC::grpc++ dependency") find_package(PkgConfig REQUIRED) pkg_check_modules(gRPC protobuf>=3.11 grpc++>=1.26) if (gRPC_FOUND) message(STATUS "Looking for gRPC::grpc++ dependency -- found") message(STATUS "Looking for protoc") find_program(PROTOC protoc) if (PROTOC) message(STATUS "Looking for protoc -- found") else() message(FATAL_ERROR "Looking for protoc -- not found") endif() message(STATUS "Looking for grpc_cpp_plugin") find_program(GRPC_CPP_PLUGIN grpc_cpp_plugin) if (GRPC_CPP_PLUGIN) message(STATUS "Looking for grpc_cpp_plugin -- found") else() message(FATAL_ERROR "Looking for grpc_cpp_plugin -- not found") endif() add_custom_target(grpc_dependency) ``` -------------------------------- ### Configuring CPack for Project Packaging in CMake Source: https://github.com/rizsotto/bear/blob/master/CMakeLists.txt This snippet configures CPack variables to define how the 'bear' project will be packaged. It sets essential metadata like package name, version, contact, vendor, and description. It also specifies paths for license and README files, installation prefixes, and format-specific options for RPM (release, license, group, URL, description, file exclusions) and Debian (shared library dependencies). ```CMake # Set up package from this project set(CPACK_PACKAGE_NAME "bear") set(CPACK_PACKAGE_CONTACT "László Nagy") set(CPACK_PACKAGE_VENDOR ${CPACK_PACKAGE_CONTACT}) set(CPACK_PACKAGE_VERSION ${CMAKE_PROJECT_VERSION}) set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "BuildEAR") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING") set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) set(CPACK_RPM_PACKAGE_RELEASE "1%{?dist}") set(CPACK_RPM_PACKAGE_LICENSE "GPLv3") set(CPACK_RPM_PACKAGE_GROUP "Development/Tools") set(CPACK_RPM_PACKAGE_URL "http://github.com/rizsotto/Bear") set(CPACK_RPM_PACKAGE_DESCRIPTION "Bear is a tool to generate compilation database for clang tooling.") set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CMAKE_INSTALL_MANDIR}" "${CMAKE_INSTALL_MANDIR}/man1") set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) include(CPack) ``` -------------------------------- ### Setting OpenSSL Path for pkg-config on macOS (Homebrew) Source: https://github.com/rizsotto/bear/blob/master/INSTALL.md This command sets the `PKG_CONFIG_PATH` environment variable to allow `pkg-config` to locate OpenSSL 1.1 installed via Homebrew, especially when it's keg-only. This is necessary for gRPC's dependency resolution. ```shell export PKG_CONFIG_PATH=$(brew --prefix)/opt/openssl@1.1/lib/pkgconfig ``` -------------------------------- ### Configuring main_a Object Library in CMake Source: https://github.com/rizsotto/bear/blob/master/source/libmain/CMakeLists.txt This snippet defines a CMake object library `main_a`, sets its public include directory, specifies private and interface source files, and links it against other libraries like `result_a`, `flags_a`, `fmt`, and `spdlog`. This setup is typical for creating reusable components within a larger CMake project. ```CMake add_library(main_a OBJECT) target_include_directories(main_a PUBLIC include/) target_sources(main_a PRIVATE source/ApplicationLogConfig.cc source/ApplicationFromArgs.cc source/SubcommandFromArgs.cc INTERFACE $ ) target_link_libraries(main_a PUBLIC result_a flags_a fmt::fmt spdlog::spdlog) ``` -------------------------------- ### Building Bear Source via ExternalProject (CMake) Source: https://github.com/rizsotto/bear/blob/master/CMakeLists.txt This ExternalProject_Add command configures the build process for the main Bear source. It specifies source directory, dependencies (e.g., nlohmann_json, fmt, spdlog, grpc, googletest), and passes numerous CMake arguments for configuration, build type, toolchain, and installation paths. It also enables unit tests and builds always. ```CMake unset(CMAKE_CACHE_ARGS_EXTRA) if (CMAKE_PROJECT_INCLUDE AND NOT CMAKE_PROJECT_INCLUDE STREQUAL "") set(CMAKE_CACHE_ARGS_EXTRA "-DCMAKE_PROJECT_INCLUDE:PATH=${CMAKE_PROJECT_INCLUDE}") endif() # Build the project itself ExternalProject_Add(BearSource SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/source" DEPENDS nlohmann_json_dependency fmt_dependency spdlog_dependency grpc_dependency googletest_dependency CMAKE_ARGS -DENABLE_UNIT_TESTS:BOOL=${ENABLE_UNIT_TESTS} -DENABLE_MULTILIB:BOOL=${ENABLE_MULTILIB} -DPKG_CONFIG_EXECUTABLE:PATH=${PKG_CONFIG_EXECUTABLE} CMAKE_CACHE_ARGS -DCMAKE_PROJECT_VERSION:STRING=${CMAKE_PROJECT_VERSION} -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} -DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_FIND_ROOT_PATH:PATH=${CMAKE_FIND_ROOT_PATH} -DCMAKE_IGNORE_PATH:PATH=${CMAKE_IGNORE_PATH} -DCMAKE_SYSROOT:PATH=${CMAKE_SYSROOT} -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER} -DCMAKE_C_COMPILER_TARGET:STRING=${CMAKE_C_COMPILER_TARGET} -DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS} -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_COMPILER_TARGET:STRING=${CMAKE_CXX_COMPILER_TARGET} -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} -DCMAKE_CXX_STANDARD_REQUIRED:BOOL=${CMAKE_CXX_STANDARD_REQUIRED} -DCMAKE_CXX_EXTENSIONS:BOOL=${CMAKE_CXX_EXTENSIONS} -DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS} -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH} -DCMAKE_INSTALL_PREFIX:PATH=${STAGED_INSTALL_PREFIX} -DCMAKE_INSTALL_LIBDIR:PATH=${CMAKE_INSTALL_LIBDIR} -DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS} -DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS} -DCMAKE_MODULE_LINKER_FLAGS:STRING=${CMAKE_MODULE_LINKER_FLAGS} -DROOT_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX} ${CMAKE_CACHE_ARGS_EXTRA} BUILD_ALWAYS 1 TEST_BEFORE_INSTALL 1 TEST_COMMAND ctest # or `ctest -T memcheck` ) ``` -------------------------------- ### Updating CMAKE_PREFIX_PATH for fmtlib (CMake) Source: https://github.com/rizsotto/bear/blob/master/third_party/fmt/CMakeLists.txt This snippet ensures that the installation directory of the `fmt_dependency` (whether found or built externally) is added to `CMAKE_PREFIX_PATH`. This allows subsequent `find_package` calls to locate `fmtlib` correctly, making it available for linking in the main project. ```CMake include(GNUInstallDirs) list(APPEND PREFIX_PATH "${DEPENDENCIES_INSTALL_PREFIX}/fmt_dependency") set(CMAKE_PREFIX_PATH ${PREFIX_PATH};${CMAKE_PREFIX_PATH} CACHE PATH "append fmt library into the search path" FORCE) endif () ``` -------------------------------- ### Checking for Existing fmtlib Dependency (CMake) Source: https://github.com/rizsotto/bear/blob/master/third_party/fmt/CMakeLists.txt This snippet attempts to find an existing installation of the fmtlib library using `find_package`. If found, it declares a custom target `fmt_dependency` to signify its availability, avoiding redundant external builds. ```CMake message(STATUS "Looking for fmt dependency") find_package(fmt 6.1 QUIET CONFIG) if (fmt_FOUND) message(STATUS "Looking for fmt dependency -- found") add_custom_target(fmt_dependency) ``` -------------------------------- ### Running Functional Tests via ExternalProject (CMake) Source: https://github.com/rizsotto/bear/blob/master/CMakeLists.txt This ExternalProject_Add command conditionally configures the functional tests if ENABLE_FUNC_TESTS is true. It depends on BearSource being built first and passes relevant installation path variables. It runs ctest --verbose for testing and explicitly sets INSTALL_COMMAND to empty as it only tests. ```CMake if (ENABLE_FUNC_TESTS) ExternalProject_Add(BearTest SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/test" DEPENDS BearSource CMAKE_CACHE_ARGS -DCMAKE_INSTALL_LIBDIR:PATH=${CMAKE_INSTALL_LIBDIR} -DCMAKE_INSTALL_BINDIR:PATH=${CMAKE_INSTALL_BINDIR} -DSTAGED_INSTALL_PREFIX:PATH=${STAGED_INSTALL_PREFIX} TEST_BEFORE_INSTALL 1 INSTALL_COMMAND "" TEST_COMMAND ctest --verbose ) endif () ``` -------------------------------- ### Adding spdlog as an External Project in CMake Source: https://github.com/rizsotto/bear/blob/master/third_party/spdlog/CMakeLists.txt This snippet defines 'spdlog' as an external project using CMake's 'ExternalProject_Add' module. It specifies the download URL, MD5 hash, and various build configuration arguments, including installation paths and compiler flags, ensuring 'spdlog' is built with specific options like disabling exceptions and tests. ```CMake include(ExternalProject) ExternalProject_Add(spdlog_dependency URL https://github.com/gabime/spdlog/archive/v1.14.1.tar.gz URL_HASH MD5=f2c3f15c20e67b261836ff7bfda302cf DOWNLOAD_NO_PROGRESS 1 UPDATE_COMMAND "" LOG_CONFIGURE 1 LOG_BUILD 1 LOG_INSTALL 1 DEPENDS fmt_dependency CMAKE_CACHE_ARGS -DSPDLOG_FMT_EXTERNAL:BOOL=ON -DSPDLOG_INSTALL:BOOL=ON -DSPDLOG_NO_EXCEPTIONS:BOOL=ON -DSPDLOG_BUILD_TESTS:BOOL=OFF -DSPDLOG_BUILD_EXAMPLE:BOOL=OFF -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH} -DCMAKE_INSTALL_PREFIX:PATH=${DEPENDENCIES_INSTALL_PREFIX}/spdlog_dependency CMAKE_CACHE_ARGS -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} -DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_FIND_ROOT_PATH:PATH=${CMAKE_FIND_ROOT_PATH} -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER} -DCMAKE_C_COMPILER_TARGET:STRING=${CMAKE_C_COMPILER_TARGET} -DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS} -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_COMPILER_TARGET:STRING=${CMAKE_CXX_COMPILER_TARGET} -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} -DCMAKE_CXX_STANDARD_REQUIRED:BOOL=${CMAKE_CXX_STANDARD_REQUIRED} -DCMAKE_CXX_EXTENSIONS:BOOL=${CMAKE_CXX_EXTENSIONS} -DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS} -DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS} -DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS} -DCMAKE_MODULE_LINKER_FLAGS:STRING=${CMAKE_MODULE_LINKER_FLAGS} ) ``` -------------------------------- ### Downloading and Building nlohmann_json using CMake ExternalProject Source: https://github.com/rizsotto/bear/blob/master/third_party/nlohmann_json/CMakeLists.txt This snippet utilizes CMake's `ExternalProject` module to download the 'nlohmann_json' library (v3.11.3) from GitHub, verify its MD5 hash, and then configure and build it. It sets various CMake arguments to control the build process, such as disabling tests and specifying the installation prefix, ensuring proper integration into the main project's build system. ```CMake include(ExternalProject) ExternalProject_Add(nlohmann_json_dependency URL https://github.com/nlohmann/json/archive/v3.11.3.tar.gz URL_HASH MD5=d603041cbc6051edbaa02ebb82cf0aa9 DOWNLOAD_NO_PROGRESS 1 UPDATE_COMMAND "" LOG_CONFIGURE 1 LOG_BUILD 1 LOG_INSTALL 1 CMAKE_ARGS -DJSON_Install:BOOL=ON -DJSON_BuildTests:BOOL=OFF -DCMAKE_INSTALL_PREFIX:PATH=${DEPENDENCIES_INSTALL_PREFIX}/nlohmann_json_dependency CMAKE_CACHE_ARGS -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} -DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_FIND_ROOT_PATH:PATH=${CMAKE_FIND_ROOT_PATH} -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER} -DCMAKE_C_COMPILER_TARGET:STRING=${CMAKE_C_COMPILER_TARGET} -DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS} -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_COMPILER_TARGET:STRING=${CMAKE_CXX_COMPILER_TARGET} -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} -DCMAKE_CXX_STANDARD_REQUIRED:BOOL=${CMAKE_CXX_STANDARD_REQUIRED} -DCMAKE_CXX_EXTENSIONS:BOOL=${CMAKE_CXX_EXTENSIONS} -DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS} -DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS} -DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS} -DCMAKE_MODULE_LINKER_FLAGS:STRING=${CMAKE_MODULE_LINKER_FLAGS} ) ``` -------------------------------- ### Downloading and Building GTest as External Project (CMake) Source: https://github.com/rizsotto/bear/blob/master/third_party/googletest/CMakeLists.txt This `else` block is executed when GTest is not found locally. It uses `ExternalProject_Add` to download Google Test from its official GitHub repository, specifying a version, MD5 hash for verification, and various CMake arguments to control its build and installation into a designated prefix, ensuring it's available for the main project. ```CMake else () message(STATUS "Looking for GTest dependency -- not found") include(ExternalProject) ExternalProject_Add(googletest_dependency URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz URL_HASH MD5=c8340a482851ef6a3fe618a082304cfc DOWNLOAD_NO_PROGRESS 1 UPDATE_COMMAND "" LOG_CONFIGURE 1 LOG_BUILD 1 LOG_INSTALL 1 CMAKE_ARGS -DINSTALL_GTEST:BOOL=ON -DCMAKE_INSTALL_PREFIX:PATH=${DEPENDENCIES_INSTALL_PREFIX}/googletest_dependency CMAKE_CACHE_ARGS -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} -DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_FIND_ROOT_PATH:PATH=${CMAKE_FIND_ROOT_PATH} -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER} -DCMAKE_C_COMPILER_TARGET:STRING=${CMAKE_C_COMPILER_TARGET} -DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS} -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_COMPILER_TARGET:STRING=${CMAKE_CXX_COMPILER_TARGET} -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} -DCMAKE_CXX_STANDARD_REQUIRED:BOOL=${CMAKE_CXX_STANDARD_REQUIRED} -DCMAKE_CXX_EXTENSIONS:BOOL=${CMAKE_CXX_EXTENSIONS} -DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS} -DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS} -DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS} -DCMAKE_MODULE_LINKER_FLAGS:STRING=${CMAKE_MODULE_LINKER_FLAGS} ) ``` -------------------------------- ### Enabling Multilib Support in CMake for Bear Source: https://github.com/rizsotto/bear/blob/master/INSTALL.md This command enables multilib support during the CMake configuration of the Bear project. It requires `CMAKE_INSTALL_LIBDIR` to be correctly set to ensure Bear looks for files in the appropriate multilib paths. ```shell cmake -DENABLE_MULTILIB=ON ... $BEAR_SOURCE_DIR ``` -------------------------------- ### Creating Executable 'bear' (CMake) Source: https://github.com/rizsotto/bear/blob/master/source/bear/CMakeLists.txt This snippet defines an executable named `bear` from `main.cc` and links it against the previously defined `bear_a` object library. This sets up the main application binary. ```CMake add_executable(bear main.cc ) target_link_libraries(bear bear_a) ``` -------------------------------- ### Generating Supervise gRPC/Protobuf Files (CMake) Source: https://github.com/rizsotto/bear/blob/master/source/intercept/proto/CMakeLists.txt This `add_custom_command` defines a build rule to compile the `supervise.proto` file. It uses the discovered `protoc` and `grpc_cpp_plugin` to generate C++ header and source files for both Protobuf messages (`.pb.h`, `.pb.cc`) and gRPC services (`.grpc.pb.h`, `.grpc.pb.cc`), placing them in the current binary directory. ```CMake get_filename_component(SUPERVISE_PROTO "supervise.proto" ABSOLUTE) get_filename_component(SUPERVISE_PROTO_PATH "${SUPERVISE_PROTO}" PATH) add_custom_command( COMMAND ${_PROTOBUF_PROTOC} ARGS -I "${SUPERVISE_PROTO_PATH}" --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" --cpp_out "${CMAKE_CURRENT_BINARY_DIR}" --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" "${SUPERVISE_PROTO}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/supervise.pb.h ${CMAKE_CURRENT_BINARY_DIR}/supervise.grpc.pb.h ${CMAKE_CURRENT_BINARY_DIR}/supervise.pb.cc ${CMAKE_CURRENT_BINARY_DIR}/supervise.grpc.pb.cc DEPENDS "${SUPERVISE_PROTO}" ) ``` -------------------------------- ### Updating CMake Search Paths for External GTest (CMake) Source: https://github.com/rizsotto/bear/blob/master/third_party/googletest/CMakeLists.txt Following the successful build of the external Google Test project, this snippet updates `CMAKE_PREFIX_PATH` to include the installation directory of the newly built GTest. This makes the installed GTest libraries and headers discoverable by subsequent `find_package` calls or target linking, and finally closes the conditional block. ```CMake include(GNUInstallDirs) list(APPEND PREFIX_PATH "${DEPENDENCIES_INSTALL_PREFIX}/googletest_dependency") set(CMAKE_PREFIX_PATH ${PREFIX_PATH};${CMAKE_PREFIX_PATH} CACHE PATH "append googletest library into the search path" FORCE) endif () ``` -------------------------------- ### Configuring Build Options and C++ Standard (CMake) Source: https://github.com/rizsotto/bear/blob/master/CMakeLists.txt This section defines various build options like ENABLE_UNIT_TESTS, ENABLE_FUNC_TESTS, and ENABLE_MULTILIB. It also enforces C++17 as the standard, requiring it and disabling extensions. ```CMake option(ENABLE_UNIT_TESTS "Build and run unit test for this project" ON) option(ENABLE_FUNC_TESTS "Build and run functional test for this project" ON) option(ENABLE_MULTILIB "Enable to build with multilib support" OFF) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) ``` -------------------------------- ### Defining and Configuring CMake Object Library 'flags_a' Source: https://github.com/rizsotto/bear/blob/master/source/libflags/CMakeLists.txt This snippet defines an object library named 'flags_a', specifies its public include directories, private and interface sources, and links it against 'result_a' and 'fmt::fmt'. It sets up the core library components for compilation and linking. ```CMake add_library(flags_a OBJECT) target_include_directories(flags_a PUBLIC include/) target_sources(flags_a PRIVATE source/Flags.cc INTERFACE $ ) target_link_libraries(flags_a PUBLIC result_a fmt::fmt) ``` -------------------------------- ### Locating Protobuf and gRPC Tools (CMake) Source: https://github.com/rizsotto/bear/blob/master/source/intercept/proto/CMakeLists.txt This snippet uses `find_program` to locate the `protoc` compiler and the `grpc_cpp_plugin` executable. These tools are essential prerequisites for generating C++ code from Protobuf and gRPC service definitions. Status messages are printed to indicate the success or failure of the discovery. ```CMake find_program(_PROTOBUF_PROTOC protoc HINTS ${gRPC_BINDIR}) message(STATUS "Looking for protoc ... ${_PROTOBUF_PROTOC}") find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin HINTS ${gRPC_BINDIR}) message(STATUS "Looking for grpc_cpp_plugin ... ${_GRPC_CPP_PLUGIN_EXECUTABLE}") ``` -------------------------------- ### Creating 'citnames_a' Static Library (CMake) Source: https://github.com/rizsotto/bear/blob/master/source/citnames/CMakeLists.txt This snippet defines a static object library named 'citnames_a', which serves as a core component. It specifies public include directories, a comprehensive list of private sources for semantic analysis tools (e.g., Build, Parsers, ToolClang, ToolGcc), and links against various public libraries such as 'main_a', 'citnames_json_a', 'events_db_a', 'domain_a', 'result_a', 'flags_a', 'sys_a', 'exec_a', 'fmt', and 'spdlog'. ```CMake add_library(citnames_a OBJECT) target_include_directories(citnames_a PUBLIC source/ include/) target_sources(citnames_a PRIVATE source/Citnames.cc source/semantic/Build.cc source/semantic/Common.cc source/semantic/Parsers.cc source/semantic/Semantic.cc source/semantic/ToolAny.cc source/semantic/ToolCrayFtnfe.cc source/semantic/ToolClang.cc source/semantic/ToolCuda.cc source/semantic/ToolGcc.cc source/semantic/ToolIntelFortran.cc source/semantic/ToolWrapper.cc source/semantic/ToolExtendingWrapper.cc INTERFACE $ ) target_link_libraries(citnames_a PUBLIC main_a citnames_json_a events_db_a domain_a result_a flags_a sys_a exec_a fmt::fmt spdlog::spdlog) ``` -------------------------------- ### Generating Compilation Database with Bear Source: https://github.com/rizsotto/bear/blob/master/README.md This command demonstrates the basic usage of Bear to generate a `compile_commands.json` file. The `--` separator indicates that all subsequent arguments are part of the build command that Bear should monitor, allowing it to capture compilation details. ```Shell bear -- ``` -------------------------------- ### Configuring Build and Test Files in CMake Source: https://github.com/rizsotto/bear/blob/master/test/CMakeLists.txt This snippet uses `configure_file` to generate `config.h` from `config.h.in` and `lit.site.cfg` from `lit.site.cfg.in`. The `@ONLY` option for `lit.site.cfg` ensures that only CMake variables are substituted, preventing unintended substitutions of other variables. ```CMake configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg @ONLY) ``` -------------------------------- ### Generating Man Page with Pandoc Source: https://github.com/rizsotto/bear/blob/master/source/intercept/CMakeLists.txt This shell command uses `pandoc` to convert a Markdown source file (`bear-intercept.1.md`) into a man page format (`-t man`) and outputs it to `bear-intercept.1`. It's a manual step for documentation generation, not automated due to potential dependency issues. ```Shell pandoc -s -t man bear-intercept.1.md -o bear-intercept.1 ``` -------------------------------- ### Creating gRPC RPC Stubs Object Library (CMake) Source: https://github.com/rizsotto/bear/blob/master/source/intercept/proto/CMakeLists.txt This snippet defines an object library named `rpc_a` to encapsulate the generated gRPC and Protobuf C++ source files. It includes the binary directory for generated headers, adds the compiled `.cc` files as private sources, and links against the `PkgConfig::gRPC` library, making the RPC stubs available for other targets. ```CMake # Create a static library, which contains the rpc stubs and clients. add_library(rpc_a OBJECT) target_include_directories(rpc_a PUBLIC "${CMAKE_CURRENT_BINARY_DIR}") target_sources(rpc_a PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/supervise.pb.cc ${CMAKE_CURRENT_BINARY_DIR}/supervise.grpc.pb.cc ${CMAKE_CURRENT_BINARY_DIR}/intercept.pb.cc ${CMAKE_CURRENT_BINARY_DIR}/intercept.grpc.pb.cc INTERFACE $ ) target_link_libraries(rpc_a PUBLIC PkgConfig::gRPC) ``` -------------------------------- ### Creating Static Object Library 'bear_a' (CMake) Source: https://github.com/rizsotto/bear/blob/master/source/bear/CMakeLists.txt This snippet defines an object library named `bear_a`, specifying its public include directories, private and interface sources, and linking it against several other libraries. This library is intended for use in unit tests and the final shared library. ```CMake add_library(bear_a OBJECT) target_include_directories(bear_a PUBLIC source/ ../citnames/include/ ../intercept/include/) target_sources(bear_a PRIVATE source/Application.cc INTERFACE $ ) target_link_libraries(bear_a PUBLIC main_a sys_a flags_a fmt::fmt citnames_a intercept_a spdlog::spdlog) ``` -------------------------------- ### Defining Domain Library (domain_a) in CMake Source: https://github.com/rizsotto/bear/blob/master/source/intercept/CMakeLists.txt This snippet defines an object library `domain_a` for domain-specific types and methods related to intercept artifacts. It specifies private include directories, source files (`Domain.cc`, `Convert.cc`), and links against the `rpc_a` library, indicating a dependency on RPC functionalities. ```CMake add_library(domain_a OBJECT) target_include_directories(domain_a PRIVATE source) target_sources(domain_a PRIVATE source/Domain.cc source/Convert.cc INTERFACE $) target_link_libraries(domain_a PUBLIC rpc_a) ``` -------------------------------- ### Locating Google Test with PkgConfig (CMake) Source: https://github.com/rizsotto/bear/blob/master/third_party/googletest/CMakeLists.txt This snippet initializes the dependency search for Google Test, Google Mock, and GTest Main using `pkg-config`. It ensures `PkgConfig` is available and checks for specific minimum versions of the GTest components, setting the `GTest_FOUND` variable and creating imported targets if successful. ```CMake message(STATUS "Looking for GTest dependency") find_package(PkgConfig REQUIRED) pkg_check_modules(GTest IMPORTED_TARGET gtest>=1.10 gtest_main>=1.10 gmock>=1.10) ``` -------------------------------- ### Initializing CMake Project and Setting CXX Flags Source: https://github.com/rizsotto/bear/blob/master/source/CMakeLists.txt This snippet sets the minimum required CMake version and policy, then defines the 'BearSource' project with C and C++ languages. It also appends several critical compiler flags to CMAKE_CXX_FLAGS, disabling exceptions, RTTI for Protobuf, and enabling strict warnings. ```CMake cmake_minimum_required(VERSION 3.12 FATAL_ERROR) cmake_policy(VERSION 3.12) project(BearSource VERSION ${CMAKE_PROJECT_VERSION} LANGUAGES C CXX ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSPDLOG_NO_EXCEPTIONS") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGOOGLE_PROTOBUF_NO_RTTI") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") ```