### Project Setup Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/CMakeLists.txt Initializes the CMake project and sets minimum version, policies, and installation directories. ```cmake # Project setup. project(hayai) cmake_minimum_required(VERSION 2.4) cmake_policy(SET CMP0012 NEW) # Offer the user the choice of overriding the installation directories. set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries") set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables") set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files") if(WIN32 AND NOT CYGWIN) set(DEF_INSTALL_CMAKE_DIR CMake) else() set(DEF_INSTALL_CMAKE_DIR lib/CMake/hayai) endif() set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") # Make relative paths absolute (needed later on.) foreach(p LIB BIN INCLUDE CMAKE) set(var INSTALL_${p}_DIR) if(NOT IS_ABSOLUTE "${${var}}") set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") endif() endforeach() # Proxy external CXXFLAGS. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{CXXFLAGS}") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} $ENV{CXXFLAGS}") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} $ENV{CXXFLAGS}") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} $ENV{CXXFLAGS}") # Determine system-dependant library paths. include(CheckLibraryExists) CHECK_LIBRARY_EXISTS(rt clock_gettime "time.h" NEED_RT_LIB) if (${NEED_RT_LIB}) set(LIB_TIMING "rt") else (${NEED_RT_LIB}) set(LIB_TIMING "") endif (${NEED_RT_LIB}) ``` -------------------------------- ### Install hayai on Ubuntu using PPA Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/README.md Commands to add the hayai PPA and install the development package on Ubuntu. ```bash $ apt-add-repository ppa:bruun/hayai $ apt-get update $ apt-get install libhayai-dev ``` -------------------------------- ### Installation Rules Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/src/CMakeLists.txt Defines installation rules for the 'hayai_main' target, specifying destinations for runtime, archive, library, and public headers. ```cmake install( TARGETS hayai_main EXPORT hayai-targets RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" COMPONENT bin LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT shlib PUBLIC_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}/hayai" COMPONENT dev ) ``` -------------------------------- ### Install hayai on Mac OS X using Homebrew Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/README.md Command to install hayai using Homebrew on Mac OS X. ```bash $ brew install hayai ``` -------------------------------- ### Create a new branch Source: https://github.com/apress/pro-.net-memory/blob/master/Contributing.md Example of how to create a new branch for code contributions using Git. ```git git checkout -b my_code_contribution ``` -------------------------------- ### Include Subdirectories and Testing Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/CMakeLists.txt Includes source, sample, and optionally test subdirectories based on user input. ```cmake # Include the individual projects. add_subdirectory(src) add_subdirectory(sample) # Include tests if requested by the user passing -DTEST=true. if (${TEST}) enable_testing() add_subdirectory(vendor/gtest) add_subdirectory(tests) endif (${TEST}) ``` -------------------------------- ### CMakeLists.txt Configuration Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/sample/CMakeLists.txt This snippet shows the CMake configuration for the sample project, including setting policies, include directories, executable targets, and linked libraries. ```cmake if(COMMAND cmake_policy) cmake_policy(SET CMP0003 NEW) endif(COMMAND cmake_policy) include_directories( ${PROJECT_SOURCE_DIR}/src ) add_executable(sample delivery_man_benchmark.cpp delivery_man_benchmark_with_fixture.cpp delivery_man_benchmark_parameterized.cpp delivery_man_benchmark_parameterized_with_fixture.cpp delivery_man_sleep.cpp ) target_link_libraries(sample hayai_main ${LIB_TIMING} ) ``` -------------------------------- ### Build hayai from source Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/README.md Commands to build hayai from source using CMake and make. ```bash cd hayai cmake . make ``` -------------------------------- ### Build hayai with test suite enabled Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/README.md Commands to build hayai from source with the test suite enabled using CMake. ```bash cd hayai cmake -DTEST=true . make make test ``` -------------------------------- ### Export Targets and Package Configuration Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/CMakeLists.txt Configures CMake to export targets and create package configuration files for external use. ```cmake # Export targets and package # Add all targets to the build-tree export set export( TARGETS hayai_main FILE "${PROJECT_BINARY_DIR}/hayai-targets.cmake" ) # Export the package for use from the build-tree # (this registers the build-tree with a global CMake-registry.) export(PACKAGE hayai) # Create the hayai-config.cmake. file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}") # ... for the build tree set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}") configure_file(hayai-config.cmake.in "${PROJECT_BINARY_DIR}/hayai-config.cmake" @ONLY) # ... for the install tree set(CONF_INCLUDE_DIRS "\${HAYAI_CMAKE_DIR}/${REL_INCLUDE_DIR}") configure_file( hayai-config.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hayai-config.cmake" @ONLY ) # Install the hayai-config.cmake install( FILES "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hayai-config.cmake" DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev ) # Install the export set for use with the install-tree. install( EXPORT hayai-targets DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev ) ``` -------------------------------- ### Adding Library Target Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/src/CMakeLists.txt Adds a library target named 'hayai_main' with a source file 'hayai_posix_main.cpp'. ```cmake add_library(hayai_main hayai_posix_main.cpp ) ``` -------------------------------- ### CMakeLists.txt Configuration Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/tests/CMakeLists.txt This is the main CMake configuration file for the benchmark project. It sets up build policies, includes necessary directories, defines the executable, and links required libraries. ```cmake if(COMMAND cmake_policy) cmake_policy(SET CMP0003 NEW) endif(COMMAND cmake_policy) include_directories( ${PROJECT_SOURCE_DIR}/src ) include_directories( ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/vendor/gtest/include ) add_executable(tests hayai_test_parameter_descriptor.cpp ) target_link_libraries(tests gtest_main ${LIB_TIMING} ) add_test(HayaiTests tests) ``` -------------------------------- ### Project and Minimum Required Version Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/vendor/gtest/CMakeLists.txt Sets the project name to 'gtest' and specifies the minimum required CMake version. ```cmake project(gtest CXX C) cmake_minimum_required(VERSION 2.6.2) ``` -------------------------------- ### Link gtest_main to gtest Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/vendor/gtest/CMakeLists.txt Links the 'gtest_main' library to the 'gtest' library. ```cmake target_link_libraries(gtest_main gtest) ``` -------------------------------- ### CMake Options for Google Test Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/vendor/gtest/CMakeLists.txt Defines various build options for Google Test, such as building shared libraries, forcing shared runtime libraries, and enabling tests or sample programs. ```cmake option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) option( gtest_force_shared_crt "Use shared (DLL) run-time lib even when Google Test is built as static lib." OFF) option(gtest_build_tests "Build all of gtest's own tests." OFF) option(gtest_build_samples "Build gtest's sample programs." OFF) option(gtest_disable_pthreads "Disable uses of pthreads in gtest." OFF) ``` -------------------------------- ### Google Test Libraries Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/vendor/gtest/CMakeLists.txt Defines the 'gtest' and 'gtest_main' libraries, using strict compiler warnings for their source files. ```cmake cxx_library(gtest "${cxx_strict}" src/gtest-all.cc) cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc) ``` -------------------------------- ### Include Directories Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/vendor/gtest/CMakeLists.txt Specifies the directories where Google Test's header files can be found. ```cmake include_directories( ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) ``` -------------------------------- ### Setting Target Properties Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/src/CMakeLists.txt Sets the PUBLIC_HEADER property for the 'hayai_main' target to the list of globbed headers. ```cmake set_target_properties(hayai_main PROPERTIES PUBLIC_HEADER "${hayai_headers}" ) ``` -------------------------------- ### Link Directories Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/vendor/gtest/CMakeLists.txt Specifies the directories where Google Test's libraries can be found. ```cmake link_directories(${gtest_BINARY_DIR}/src) ``` -------------------------------- ### File Globbing for Headers Source: https://github.com/apress/pro-.net-memory/blob/master/Ch02/Cpp.Benchmarks/hayai-master/src/CMakeLists.txt Defines a CMake variable 'hayai_headers' by globbing all header files in the directory. ```cmake file(GLOB hayai_headers hayai.hpp hayai_benchmarker.hpp hayai_clock.hpp hayai_compatibility.hpp hayai_console.hpp hayai_console_outputter.hpp hayai_default_test_factory.hpp hayai_fixture.hpp hayai_json_outputter.hpp hayai_junit_xml_outputter.hpp hayai_outputter.hpp hayai_test.hpp hayai_test_descriptor.hpp hayai_test_factory.hpp hayai_test_result.hpp hayai_main.hpp ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.