### Example: Custom libc++ Configuration (Shell) Source: https://github.com/boostorg/hana/wiki/Setting-up-a-custom-standard-library An example demonstrating how to set environment variables for a custom libc++ installation, including header and library paths, and linking flags. It also shows how to specify a custom compiler via CMake. ```shell export CXXFLAGS="-I ${HOME}/code/llvm36/build/include/c++/v1" export LDFLAGS="-L ${HOME}/code/llvm36/build/lib -l c++ -l c++abi" export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${HOME}/code/llvm36/build/lib" cmake .. -DCMAKE_CXX_COMPILER=clang++-3.6 ``` -------------------------------- ### Build and Configure Each Example (CMake) Source: https://github.com/boostorg/hana/blob/master/example/CMakeLists.txt Iterates through the list of example files. For each file, it creates an executable target, adds it as a test, sets test properties, links Boost if required, and applies specific compiler options for unused parameters or lambda captures. It also adds each example target as a dependency to the main 'examples' target. ```cmake foreach(_file IN LISTS EXAMPLES) boost_hana_target_name_for(_target "${_file}") add_executable(${_target} EXCLUDE_FROM_ALL "${_file}") add_test(${_target} "${CMAKE_CURRENT_BINARY_DIR}/${_target}") boost_hana_set_test_properties(${_target}) if (_file IN_LIST EXAMPLES_REQUIRING_BOOST) target_link_libraries(${_target} PRIVATE Boost::boost) endif() if (BOOST_HANA_HAS_WNO_UNUSED_PARAMETER) target_compile_options(${_target} PRIVATE -Wno-unused-parameter) endif() if (BOOST_HANA_HAS_WNO_UNUSED_LAMBDA_CAPTURE) target_compile_options(${_target} PRIVATE -Wno-unused-lambda-capture) endif() add_dependencies(examples ${_target}) endforeach() ``` -------------------------------- ### Setup 'check' Target for Running Tests and Examples (CMake) Source: https://github.com/boostorg/hana/blob/master/CMakeLists.txt This CMake code defines a custom target named `hana_check` that executes CTest with the `--output-on-failure` option in the build directory. It also ensures that the `check` target depends on `hana_check`, creating a unified way to run all tests and examples. ```cmake add_custom_target(hana_check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" COMMENT "Build and then run all the tests and examples." USES_TERMINAL) if (NOT TARGET check) add_custom_target(check DEPENDS hana_check) else() add_dependencies(check hana_check) endif() ``` -------------------------------- ### Checking Clang Version on Linux Source: https://github.com/boostorg/hana/wiki/General-notes-on-compiler-support This command verifies the installed Clang compiler version on a Linux system. It's a prerequisite for ensuring compatibility with Boost.Hana, which requires C++14 standards. ```bash clang++ -v ``` -------------------------------- ### Example Boost.Hana Commit Message Structure Source: https://github.com/boostorg/hana/blob/master/CONTRIBUTING.md This example illustrates the recommended format for commit messages in Boost.Hana contributions. It includes a concise subject line, followed by detailed explanations or bullet points, and optional tags like '[NFC]'. ```git [Searchable] Refactor the interface - Rename elem to contains - Rename subset to is_subset, and make is_subset applicable in infix notation - Add the at_key method - operator[] is now bound to at_key instead of find ``` -------------------------------- ### Boost.Hana Main Library Target Setup Source: https://github.com/boostorg/hana/blob/master/CMakeLists.txt Defines the main INTERFACE library target for Boost.Hana, sets include directories, and specifies C++14 as the required compile feature. It also includes installation rules for the library, CMake configuration files, and pkg-config files. ```cmake add_library(boost_hana INTERFACE) add_library(Boost::hana ALIAS boost_hana) target_include_directories(boost_hana INTERFACE include) target_link_libraries(boost_hana INTERFACE Boost::config Boost::core Boost::fusion Boost::mpl Boost::tuple ) target_compile_features(boost_hana INTERFACE cxx_std_14) ``` ```cmake add_library(hana INTERFACE) target_include_directories(hana INTERFACE "$") target_compile_features(hana INTERFACE cxx_std_14) # Export the `hana` library into a HanaConfig.cmake file install(TARGETS hana EXPORT HanaConfig INCLUDES DESTINATION include) install(EXPORT HanaConfig DESTINATION lib/cmake/hana) install(DIRECTORY include/boost DESTINATION include FILES_MATCHING PATTERN "*.hpp") # Also install an optional pkg-config file configure_file(cmake/hana.pc.in hana.pc @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/hana.pc" DESTINATION lib/pkgconfig) ``` -------------------------------- ### Compile Boost.Hana with Clang on Windows (Thread Support) Source: https://github.com/boostorg/hana/wiki/General-notes-on-compiler-support Enabling POSIX thread support might be necessary when encountering issues related to thread support in the GCC library when using Clang on Windows with Cygwin or MinGW. ```c++ -pthread ``` -------------------------------- ### Define Custom Target for Examples (CMake) Source: https://github.com/boostorg/hana/blob/master/example/CMakeLists.txt Defines a custom target named 'examples' in CMake, used to build all the project's examples. It also adds a dependency for 'hana_check' to this target, ensuring examples are built after 'hana_check'. ```cmake add_custom_target(examples COMMENT "Build all the examples.") add_dependencies(hana_check examples) ``` -------------------------------- ### Identify Examples Requiring Boost (CMake) Source: https://github.com/boostorg/hana/blob/master/example/CMakeLists.txt Uses CMake's `list(APPEND)` and `file(GLOB_RECURSE)` to collect a list of C++ source files that depend on Boost. This list is used later to link against the Boost library for these specific examples. ```cmake list(APPEND EXAMPLES_REQUIRING_BOOST "ext/boost/*.cpp" "tutorial/appendix_mpl.cpp" "tutorial/ext/fusion_to_hana.cpp" "tutorial/ext/mpl_vector.cpp" "tutorial/integral.cpp" "tutorial/introduction.cpp" "tutorial/mpl_cheatsheet.cpp" "tutorial/quadrants.cpp" "tutorial/quickstart.switchAny.cpp" "tutorial/rationale.container.cpp" "tutorial/type.cpp" "type/basic_type.cpp") file(GLOB_RECURSE EXAMPLES_REQUIRING_BOOST ${EXAMPLES_REQUIRING_BOOST}) ``` -------------------------------- ### Boost.Hana Overview Example Source: https://github.com/boostorg/hana/blob/master/README.md Demonstrates core Boost.Hana features including tuple manipulation, compile-time sequence operations, type metaprogramming, and expression validation using `hana::transform`, `hana::reverse`, `hana::length`, `hana::filter`, `hana::is_valid`, and compile-time literals. ```cpp #include #include #include namespace hana = boost::hana; using namespace hana::literals; struct Fish { std::string name; }; struct Cat { std::string name; }; struct Dog { std::string name; }; int main() { // Sequences capable of holding heterogeneous objects, and algorithms // to manipulate them. auto animals = hana::make_tuple(Fish{"Nemo"}, Cat{"Garfield"}, Dog{"Snoopy"}); auto names = hana::transform(animals, [](auto a) { return a.name; }); assert(hana::reverse(names) == hana::make_tuple("Snoopy", "Garfield", "Nemo")); // No compile-time information is lost: even if `animals` can't be a // constant expression because it contains strings, its length is constexpr. static_assert(hana::length(animals) == 3u, ""); // Computations on types can be performed with the same syntax as that of // normal C++. Believe it or not, everything is done at compile-time. auto animal_types = hana::make_tuple(hana::type_c, hana::type_c, hana::type_c); auto animal_ptrs = hana::filter(animal_types, [](auto a) { return hana::traits::is_pointer(a); }); static_assert(animal_ptrs == hana::make_tuple(hana::type_c, hana::type_c), ""); // And many other goodies to make your life easier, including: // 1. Access to elements in a tuple with a sane syntax. static_assert(animal_ptrs[0_c] == hana::type_c,""); static_assert(animal_ptrs[1_c] == hana::type_c,""); // 2. Unroll loops at compile-time without hassle. std::string s; hana::int_c<10>.times([&]{ s += "x"; }); // equivalent to s += "x"; s += "x"; ... s += "x"; // 3. Easily check whether an expression is valid. // This is usually achieved with complex SFINAE-based tricks. auto has_name = hana::is_valid([](auto&& x) -> decltype((void)x.name) { }); static_assert(has_name(animals[0_c]), ""); static_assert(!has_name(1), ""); } ``` -------------------------------- ### Glob and Filter Examples (CMake) Source: https://github.com/boostorg/hana/blob/master/example/CMakeLists.txt Finds all C++ files recursively using `file(GLOB_RECURSE)`, then finds all C++ files in the exclusion list. Finally, it removes any excluded files from the main list of examples to be built. ```cmake file(GLOB_RECURSE EXAMPLES "*.cpp") file(GLOB_RECURSE EXCLUDED_EXAMPLES ${EXCLUDED_EXAMPLES}) list(REMOVE_ITEM EXAMPLES "" ${EXCLUDED_EXAMPLES}) ``` -------------------------------- ### Check Ruby and Gems (CMake) Source: https://github.com/boostorg/hana/blob/master/benchmark/CMakeLists.txt This snippet checks if Ruby version 2.1 or higher is available and if the 'ruby-progressbar' and 'tilt' gems are installed. If not, it issues a warning and skips benchmarks. This ensures that the necessary tools for running benchmarks are present. ```cmake find_package(Ruby 2.1) if(NOT ${RUBY_FOUND}) message(WARNING "Ruby >= 2.1 was not found; the benchmarks will be unavailable.") return() endif() # Check for the 'ruby-progressbar' and 'tilt' gems execute_process(COMMAND ${RUBY_EXECUTABLE} -r ruby-progressbar -r tilt -e "" RESULT_VARIABLE __BOOST_HANA_MISSING_GEMS OUTPUT_QUIET ERROR_QUIET) if(${__BOOST_HANA_MISSING_GEMS}) message(WARNING "The 'ruby-progressbar' and/or 'tilt' gems were not found; " "the benchmarks will be unavailable." "Use `gem install ruby-progressbar tilt` to install the missing gems.") return() endif() ``` -------------------------------- ### Exclude Specific Examples (CMake) Source: https://github.com/boostorg/hana/blob/master/example/CMakeLists.txt Conditionally adds examples to an exclusion list if Boost is not found. Also, an explicit example ('cmake_integration/main.cpp') is added to the exclusion list. This prevents these examples from being built. ```cmake if (NOT Boost_FOUND) list(APPEND EXCLUDED_EXAMPLES ${EXAMPLES_REQUIRING_BOOST}) endif() list(APPEND EXCLUDED_EXAMPLES "cmake_integration/main.cpp") ``` -------------------------------- ### Compile Boost.Hana with Clang on Windows (No Exceptions) Source: https://github.com/boostorg/hana/wiki/General-notes-on-compiler-support When using Clang on Windows with Cygwin or MinGW, C++ exception handling can cause linker errors. This flag disables exceptions to resolve such issues. ```c++ #fno-exceptions ``` -------------------------------- ### Example CMake Configuration for C++ Compiler Source: https://github.com/boostorg/hana/wiki/Configuration-Options-for-CMake This snippet demonstrates how to set the C++ compiler for CMake builds. It's a common practice to specify the compiler path to ensure consistent build environments. ```shell cmake .. -DCMAKE_CXX_COMPILER=clang++ ``` -------------------------------- ### Linking Clang with libc++ on Linux Source: https://github.com/boostorg/hana/wiki/General-notes-on-compiler-support This compiler flag tells Clang to link against libc++, its own standard C++ library. This is an alternative to the default libstdc++ and is relevant for Boost.Hana's C++14 requirements. ```bash clang -stdlib=libc++ ``` -------------------------------- ### Linking Clang with libstdc++ on Linux Source: https://github.com/boostorg/hana/wiki/General-notes-on-compiler-support This compiler flag instructs Clang to link against libstdc++, the standard C++ library typically provided by GCC. This is the default behavior when the flag is not specified. ```bash clang -stdlib=libstdc++ ``` -------------------------------- ### CMake Project and Version Setup for Boost.Hana Source: https://github.com/boostorg/hana/blob/master/CMakeLists.txt Configures the CMake project for Boost.Hana, parsing the version number from `boost/hana/version.hpp`. It sets up necessary CMake modules and includes compiler support checks. ```cmake cmake_minimum_required(VERSION 3.8...3.20) project(boost_hana VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) ``` ```cmake cmake_minimum_required(VERSION 3.9) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") # Copyright Louis Dionne 2013-2022 # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) ############################################################################## # Setup CMake options ############################################################################## option(BOOST_HANA_ENABLE_CONCEPT_CHECKS "Enable concept checking in the interface methods." ON) option(BOOST_HANA_ENABLE_DEBUG_MODE "Enable Hana's debug mode." OFF) option(BOOST_HANA_ENABLE_STRING_UDL "Enable the GNU extension allowing the special string literal operator template, which enables the _s suffix for creating compile-time strings." ON) option(BOOST_HANA_ENABLE_EXCEPTIONS "Build with exceptions enabled. Note that Hana does not make use of exceptions, but this switch can be disabled when building the tests to assess that it is really the case." ON) ############################################################################## # Setup project # # We parse the canonical version number located in . # This is done to allow the library to be used without requiring a proper # installation during which the version would be written to this header. ############################################################################## foreach(level MAJOR MINOR PATCH) file(STRINGS include/boost/hana/version.hpp _define_${level} REGEX "#define BOOST_HANA_${level}_VERSION") string(REGEX MATCH "([0-9]+)" _version_${level} "${_define_${level}}") endforeach() set(Boost.Hana_VERSION_STRING "${_version_MAJOR}.${_version_MINOR}.${_version_PATCH}") project(Boost.Hana VERSION ${Boost.Hana_VERSION_STRING} LANGUAGES CXX) # Perform checks to make sure we support the current compiler include(CheckCxxCompilerSupport) ``` -------------------------------- ### Find Boost Optional Dependency (CMake) Source: https://github.com/boostorg/hana/blob/master/CMakeLists.txt This CMake code searches for the Boost library starting from version 1.64. If Boost is not found, it issues a warning message indicating that some tests and examples might be disabled due to the missing dependency. ```cmake find_package(Boost 1.64) if (NOT Boost_FOUND) message(WARNING "The rest of Boost was not found; some tests and examples will be disabled.") endif() ``` -------------------------------- ### Set Runtime Shared Library Path (Shell) Source: https://github.com/boostorg/hana/wiki/Setting-up-a-custom-standard-library Specifies the path for loading shared libraries at runtime. This ensures the program can find the custom standard library when it starts. ```shell export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/path/to/std-library" ``` -------------------------------- ### Build and Run Specific Boost.Hana Target Source: https://github.com/boostorg/hana/blob/master/README.md Builds a specific target within the Boost.Hana project, such as a test or an example associated with a source file. The target name is derived from the source file's path. ```shell cmake --build build --target path.to.file ``` -------------------------------- ### Add Subdirectories for Boost.Hana Modules (CMake) Source: https://github.com/boostorg/hana/blob/master/CMakeLists.txt This CMake code includes several subdirectories, indicating a modular structure for the Boost.Hana project. It adds `benchmark`, `doc`, `example`, and `test` directories, allowing CMake to process their respective `CMakeLists.txt` files. ```cmake add_subdirectory(benchmark) add_subdirectory(doc) add_subdirectory(example) add_subdirectory(test) ``` -------------------------------- ### Configure External Project with CMake Source: https://github.com/boostorg/hana/blob/master/test/CMakeLists.txt This CMake snippet uses `ExternalProject_Add` to configure and build an external project. It specifies source directories, build arguments like install prefix and compiler, and disables testing and update commands. It is used here to set up a fake root directory for deployment. ```cmake include(ExternalProject) set(HANA_FAKE_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/deploy/fakeroot") ExternalProject_Add(test.deploy.fakeroot SOURCE_DIR "${PROJECT_SOURCE_DIR}" EXCLUDE_FROM_ALL TRUE BUILD_ALWAYS TRUE CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${HANA_FAKE_INSTALL_DIR} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} TEST_COMMAND "" # Disable test step UPDATE_COMMAND "" # Disable source work-tree update ) ``` -------------------------------- ### Specify Custom Boost Root Directory with CMake Source: https://github.com/boostorg/hana/blob/master/README.md Configures the CMake build system to locate a custom installation of Boost headers and libraries. This ensures that Hana can find and utilize a specific Boost version. ```shell cmake -S . -B build -DCMAKE_CXX_COMPILER=/path/to/compiler -DBOOST_ROOT=/path/to/boost ``` -------------------------------- ### Configure Compiler Flags for Boost.Hana Tests and Examples (CMake) Source: https://github.com/boostorg/hana/blob/master/CMakeLists.txt This CMake function `boost_hana_set_test_properties` configures compiler flags for a given target, customizing build behavior based on the compiler (GCC/Clang vs. MSVC) and various build options like exception handling and concept checks. It uses `check_cxx_compiler_flag` to conditionally apply flags. ```cmake function(boost_hana_set_test_properties target) target_link_libraries(${target} PRIVATE hana) set_target_properties(${target} PROPERTIES CXX_EXTENSIONS NO) macro(setflag testname flag) check_cxx_compiler_flag(${flag} ${testname}) if (${testname}) target_compile_options(${target} PRIVATE ${flag}) endif() endmacro() if (NOT MSVC) setflag(BOOST_HANA_HAS_FDIAGNOSTICS_COLOR -fdiagnostics-color) setflag(BOOST_HANA_HAS_FTEMPLATE_BACKTRACE_LIMIT -ftemplate-backtrace-limit=0) setflag(BOOST_HANA_HAS_WALL -Wall) setflag(BOOST_HANA_HAS_WERROR -Werror) setflag(BOOST_HANA_HAS_WEXTRA -Wextra) setflag(BOOST_HANA_HAS_WNO_SELF_ASSIGN_OVERLOADED -Wno-self-assign-overloaded) setflag(BOOST_HANA_HAS_WNO_UNUSED_LOCAL_TYPEDEFS -Wno-unused-local-typedefs) setflag(BOOST_HANA_HAS_WWRITE_STRINGS -Wwrite-strings) else() setflag(BOOST_HANA_HAS_MSVC_EHSC -EHsc) setflag(BOOST_HANA_HAS_MSVC_BIGOBJ -bigobj) setflag(BOOST_HANA_HAS_MSVC_TERNARY -Zc:ternary) endif() if (NOT BOOST_HANA_ENABLE_EXCEPTIONS) setflag(BOOST_HANA_HAS_FNO_EXCEPTIONS -fno-exceptions) endif() if (NOT BOOST_HANA_ENABLE_CONCEPT_CHECKS) target_compile_definitions(${target} PRIVATE -DBOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS) endif() if (BOOST_HANA_ENABLE_DEBUG_MODE) target_compile_definitions(${target} PRIVATE -DBOOST_HANA_CONFIG_ENABLE_DEBUG_MODE) endif() if (BOOST_HANA_ENABLE_STRING_UDL) if (NOT MSVC) target_compile_definitions(${target} PRIVATE -DBOOST_HANA_CONFIG_ENABLE_STRING_UDL) # GCC pretends to have the flag, but produces a "unrecognized command line option" # warning when we use it. if (NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") setflag(BOOST_HANA_HAS_WNO_GNU_STRING_UDL -Wno-gnu-string-literal-operator-template) endif() endif() endif() endfunction() ``` -------------------------------- ### Cloning Boost.Hana Documentation Source: https://github.com/boostorg/hana/blob/master/README.md Instructions for cloning the Boost.Hana documentation from the `gh-pages` branch to a local directory, allowing offline access to the static website. ```shell git clone http://github.com/boostorg/hana --branch=gh-pages --depth=1 doc/html ``` -------------------------------- ### Build and Test Boost.Hana Project Source: https://github.com/boostorg/hana/blob/master/CONTRIBUTING.md This snippet demonstrates how to build and run tests for the Boost.Hana project using CMake. It involves creating a build directory, configuring the project, and executing the tests. ```shell mkdir build cmake -S . -B build cmake --build build --target check ``` -------------------------------- ### Set up Boost.Hana Build Directory with CMake Source: https://github.com/boostorg/hana/blob/master/README.md Initializes the build directory for the Boost.Hana project using CMake. This involves creating a 'build' directory and configuring the build system from the project root. ```shell mkdir build cmake -S . -B build ``` -------------------------------- ### Build 64-bit Release Hana with VS2015 and Clang-cl Source: https://github.com/boostorg/hana/wiki/Setting-up-Clang-on-Windows This snippet outlines the process for building Hana in a 64-bit release configuration using Visual Studio 2015 and the Clang-cl compiler on Windows. Similar to the 32-bit build, it requires setting up a build directory, configuring with CMake, and then employing MSBuild for compilation and testing. The commands differ in CMake generator and MSBuild platform/configuration arguments for a 64-bit release build. ```shell cd hana mkdir build_Win64 cd build_Win64 cmake .. -TLLVM-vs2014 -G"Visual Studio 14 2015 Win64" "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" Boost.Hana.sln /p:Configuration=Release /p:Platform=x64 /v:m /m "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" RUN_TESTS.vcxproj /p:Configuration=Release /p:Platform=x64 ``` -------------------------------- ### Build Boost.Hana with MinGW64 and Clang Source: https://github.com/boostorg/hana/wiki/Setting-up-Clang-on-Windows This snippet shows the process of configuring and building Boost.Hana using CMake with a native MinGW64 toolchain and Clang as the C++ compiler, employing the MSYS Makefiles generator. It navigates to the project directory, creates a build directory, configures the build with specific compiler flags, and then initiates the build and check process. ```shell cd hana mkdir build_MinGW64 cd build_MinGW64 cmake .. -DCMAKE_CXX_COMPILER=clang++ -G"MSYS Makefiles" make check ``` -------------------------------- ### Find Doxygen and Configure HTML Documentation Source: https://github.com/boostorg/hana/blob/master/doc/CMakeLists.txt This snippet finds the Doxygen executable and configures the CMake build to generate HTML documentation. It includes a warning if Doxygen is not found and sets variables for output directory, Docset generation, treeview, and search engine. ```cmake find_package(Doxygen) if (NOT DOXYGEN_FOUND) message(WARNING "Doxygen was not found; the 'doc' and 'docset' targets " "will be unavailable.") return() endif() set(HANA_HTML_OUTPUT html) set(HANA_GENERATE_DOCSET NO) set(HANA_GENERATE_TREEVIEW YES) set(HANA_SEARCHENGINE YES) configure_file(Doxyfile.in documentation.doxygen @ONLY) add_custom_target(doc COMMAND ${CMAKE_COMMAND} -E remove_directory html COMMAND ${DOXYGEN_EXECUTABLE} documentation.doxygen COMMENT "Generating API documentation with Doxygen" VERBATIM ) ``` -------------------------------- ### Set Custom Library Search Path and Link (Shell) Source: https://github.com/boostorg/hana/wiki/Setting-up-a-custom-standard-library Configures the linker to find libraries in a given directory and link against a specific library. This is necessary for custom standard libraries. ```shell export LDFLAGS="-L /path/to/std-library -l std-library" ``` -------------------------------- ### Build 32-bit Debug Hana with VS2015 and Clang-cl Source: https://github.com/boostorg/hana/wiki/Setting-up-Clang-on-Windows This snippet shows how to build Hana in a 32-bit debug configuration using Visual Studio 2015 with the Clang-cl compiler on Windows. It involves creating a build directory, configuring with CMake, and then using MSBuild to compile the solution and run tests. The commands use specific CMake generator and MSBuild arguments for a 32-bit debug build. ```shell cd hana mkdir build_Win32 cd build_Win32 cmake .. -TLLVM-vs2014 -G"Visual Studio 14 2015" "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" Boost.Hana.sln /p:Configuration=Debug /p:Platform=Win32 /v:m /m "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" RUN_TESTS.vcxproj /p:Configuration=Debug /p:Platform=Win32 ``` -------------------------------- ### Add Remaining Unit Tests (CMake) Source: https://github.com/boostorg/hana/blob/master/test/CMakeLists.txt Finds all remaining `.cpp` files, excludes specified ones, and creates an executable target for each. It links Boost if necessary and adds include directories. Each executable is added as a test and dependency to the main 'tests' target. ```cmake file(GLOB_RECURSE UNIT_TESTS "*.cpp") file(GLOB_RECURSE EXCLUDED_UNIT_TESTS ${EXCLUDED_UNIT_TESTS}) list(REMOVE_ITEM UNIT_TESTS ${EXCLUDED_UNIT_TESTS}) foreach(_file IN LISTS UNIT_TESTS) boost_hana_target_name_for(_target "${_file}") add_executable(${_target} EXCLUDE_FROM_ALL "${_file}") boost_hana_set_test_properties(${_target}) if (_file IN_LIST TESTS_REQUIRING_BOOST) target_link_libraries(${_target} PRIVATE Boost::boost) endif() target_include_directories(${_target} PRIVATE _include) add_test(${_target} "${CMAKE_CURRENT_BINARY_DIR}/${_target}") add_dependencies(tests ${_target}) endforeach() ``` -------------------------------- ### Configure Benchmark Script (CMake) Source: https://github.com/boostorg/hana/blob/master/benchmark/CMakeLists.txt This CMake command configures the 'measure.in.rb' script by replacing variables with appropriate values, creating the 'measure.rb' script in the build directory. This script is used later to generate benchmark data. ```cmake configure_file(${CMAKE_CURRENT_SOURCE_DIR}/measure.in.rb #input ${CMAKE_CURRENT_BINARY_DIR}/measure.rb #output @ONLY) ``` -------------------------------- ### Process Benchmark Files (CMake) Source: https://github.com/boostorg/hana/blob/master/benchmark/CMakeLists.txt This CMake loop iterates through all '.erb.json' files to set up custom targets for each benchmark. It generates a C++ source file, an executable, sets include directories and compile options (like template depth), and defines a rule to compile using the 'measure.rb' script. Finally, it creates a target to run the benchmark. ```cmake file(GLOB_RECURSE BOOST_HANA_BENCHMARKS *.erb.json) foreach(benchmark IN LISTS BOOST_HANA_BENCHMARKS) boost_hana_target_name_for(target ${benchmark} ".erb.json") get_filename_component(directory "${benchmark}" DIRECTORY) file(GLOB cpp_files "${directory}/*.erb.cpp") configure_file("${benchmark}" "${CMAKE_CURRENT_BINARY_DIR}/${target}.erb.json" @ONLY) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${target}.measure.cpp" "") add_executable(${target}.measure EXCLUDE_FROM_ALL "${CMAKE_CURRENT_BINARY_DIR}/${target}.measure.cpp") target_include_directories(${target}.measure PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") if (MPL11_FOUND) target_include_directories(${target}.measure PRIVATE "${MPL11_INCLUDE_DIR}") endif() if (Meta_FOUND) target_include_directories(${target}.measure PRIVATE "${Meta_INCLUDE_DIR}") endif() if (Boost_FOUND) target_link_libraries(${target}.measure PRIVATE Boost::boost) endif() boost_hana_set_test_properties(${target}.measure) if (BOOST_HANA_HAS_FTEMPLATE_DEPTH) target_compile_options(${target}.measure PRIVATE -ftemplate-depth=-1) endif() set_target_properties(${target}.measure PROPERTIES RULE_LAUNCH_COMPILE "${CMAKE_CURRENT_BINARY_DIR}/measure.rb") set_property(TARGET ${target}.measure APPEND PROPERTY INCLUDE_DIRECTORIES "${directory}") add_custom_target(${target}.measure.run COMMAND ${target}.measure) add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${target}.json" COMMAND ${RUBY_EXECUTABLE} -r tilt -r "${CMAKE_CURRENT_BINARY_DIR}/measure.rb" -e "MEASURE_FILE = '${CMAKE_CURRENT_BINARY_DIR}/${target}.measure.cpp'" -e "MEASURE_TARGET = '${target}.measure'" -e "json = Tilt::ERBTemplate.new('${CMAKE_CURRENT_BINARY_DIR}/${target}.erb.json').render" -e "File.open('${CMAKE_CURRENT_BINARY_DIR}/${target}.json', 'w') { |f| f.write(json) } " WORKING_DIRECTORY ${directory} DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${target}.erb.json" ${cpp_files} VERBATIM USES_TERMINAL COMMENT "Generating dataset for ${target}" ) add_custom_target(${target} DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${target}.json") add_dependencies(benchmarks ${target}) endforeach() ``` -------------------------------- ### Enable Testing and Configure Valgrind Memory Checking (CMake) Source: https://github.com/boostorg/hana/blob/master/CMakeLists.txt This CMake script enables the testing framework using `enable_testing()` and attempts to find the `valgrind` executable for memory checking. If found, it configures Valgrind options; otherwise, it prints a message indicating Valgrind was not found. It then includes the CTest module. ```cmake enable_testing() find_program(MEMORYCHECK_COMMAND valgrind) if (MEMORYCHECK_COMMAND) message(STATUS "Found Valgrind: ${MEMORYCHECK_COMMAND}") set(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --error-exitcode=1") else() message("Valgrind not found") endif() include(CTest) ``` -------------------------------- ### Generate Benchmark JSON (Ruby) Source: https://github.com/boostorg/hana/blob/master/benchmark/CMakeLists.txt This Ruby script, executed via CMake's add_custom_command, uses the Tilt ERB template engine to render a JSON dataset for a specific benchmark. It takes the ERB template, the output C++ measure file path, and the target executable name as inputs, producing a '.json' file. ```ruby MEASURE_FILE = '${CMAKE_CURRENT_BINARY_DIR}/${target}.measure.cpp'" MEASURE_TARGET = '${target}.measure'" json = Tilt::ERBTemplate.new('${CMAKE_CURRENT_BINARY_DIR}/${target}.erb.json').render" File.open('${CMAKE_CURRENT_BINARY_DIR}/${target}.json', 'w') { |f| f.write(json) } ``` -------------------------------- ### Build and Run Boost.Hana Unit Tests Source: https://github.com/boostorg/hana/blob/master/README.md Builds and executes the unit tests for the Boost.Hana library using CMake. The 'check' target is a standard way to run tests within a CMake-based project. ```shell cmake --build build --target check ``` -------------------------------- ### Configure Docset Documentation Generation Source: https://github.com/boostorg/hana/blob/master/doc/CMakeLists.txt This snippet configures the CMake build to generate a Docset package for Boost.Hana. It sets variables for output directory, Docset generation, treeview, and search engine, then defines a custom target to build the Docset. ```cmake set(HANA_HTML_OUTPUT _docset) set(HANA_GENERATE_DOCSET YES) set(HANA_GENERATE_TREEVIEW NO) set(HANA_SEARCHENGINE NO) configure_file(Doxyfile.in docset.doxygen @ONLY) add_custom_target(docset COMMAND ${DOXYGEN_EXECUTABLE} docset.doxygen COMMAND ${CMAKE_COMMAND} -E chdir _docset make COMMAND ${CMAKE_COMMAND} -E remove_directory boost.hana.docset COMMAND ${CMAKE_COMMAND} -E copy_directory _docset/boost.hana.docset boost.hana.docset COMMAND ${CMAKE_COMMAND} -E remove_directory _docset COMMENT "Generating documentation Docset" VERBATIM ) ``` -------------------------------- ### Set Custom Header Search Path (Shell) Source: https://github.com/boostorg/hana/wiki/Setting-up-a-custom-standard-library Instructs the compiler to look for headers in a specified directory. This is crucial when the default system headers are incompatible. ```shell export CXXFLAGS="-I /path/to/std-includes" ``` -------------------------------- ### Create Custom Deployment Target with CMake Source: https://github.com/boostorg/hana/blob/master/test/CMakeLists.txt This CMake snippet defines a custom target `test.deploy` which depends on an external project. It creates a build directory, changes into it, and then executes a CMake build process for the 'deploy' subdirectory. This is used to manage the deployment process for the project. ```cmake add_custom_target(test.deploy DEPENDS test.deploy.fakeroot COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/deploy/build" COMMAND ${CMAKE_COMMAND} -E chdir "${CMAKE_CURRENT_BINARY_DIR}/deploy/build" ${CMAKE_COMMAND} "${CMAKE_CURRENT_SOURCE_DIR}/deploy" -DCMAKE_CXX_COMPILER="${CMAKE_CXX_COMPILER}" -DCMAKE_PREFIX_PATH="${HANA_FAKE_INSTALL_DIR}" -DCMAKE_GENERATOR=${CMAKE_GENERATOR} -DCMAKE_TOOLCHAIN_FILE="${CMAKE_TOOLCHAIN_FILE}" COMMAND ${CMAKE_COMMAND} --build "${CMAKE_CURRENT_BINARY_DIR}/deploy/build" USES_TERMINAL ) add_dependencies(hana_check test.deploy) ``` -------------------------------- ### Shell script for adding new automatic unit tests Source: https://github.com/boostorg/hana/blob/master/test/_include/auto/README.md This script automates the creation of new C++ test files for Boost.Hana's automatic unit testing framework. It finds all 'auto' directories (excluding '_include/auto') and creates a new C++ file in each, pre-populated with necessary headers and a basic main function. ```shell DIRECTORIES=$(find test -type d -name auto | grep -v test/_include/auto) for d in ${DIRECTORIES}; do cat > ${d}/${FILE}.cpp < int main() { } EOF done ``` -------------------------------- ### Glob Recursively Find Boost-Dependent Files (CMake) Source: https://github.com/boostorg/hana/blob/master/test/CMakeLists.txt Uses the `file(GLOB_RECURSE ...)` command to find all `.cpp` files in the `ext/boost/` directory and all `.cpp` files in the `experimental/printable/` directory. These files are stored in the `TESTS_REQUIRING_BOOST` variable. ```cmake file(GLOB_RECURSE TESTS_REQUIRING_BOOST "ext/boost/*.cpp" "experimental/printable/*.cpp") ``` -------------------------------- ### Generate Travis CI Slugs (CMake) Source: https://github.com/boostorg/hana/blob/master/benchmark/CMakeLists.txt These CMake commands generate slugs for Travis CI, one based on the compiler ID and version, and another based on the build configuration. These slugs are useful for categorizing builds on CI platforms. ```cmake add_custom_target(travis_compiler_slug USES_TERMINAL COMMAND ${CMAKE_COMMAND} -E echo "travis_compiler_slug: $") add_custom_target(travis_config_slug USES_TERMINAL COMMAND ${CMAKE_COMMAND} -E echo "travis_config_slug: $>") ``` -------------------------------- ### Generate Header Inclusion Tests (CMake) Source: https://github.com/boostorg/hana/blob/master/test/CMakeLists.txt Defines a custom target `test.headers` for building header-inclusion tests. It then generates standalone header tests for non-Boost headers and, if Boost is found, generates tests for Boost-dependent headers. ```cmake add_custom_target(test.headers COMMENT "Build all the header-inclusion unit tests.") add_dependencies(tests test.headers) file(GLOB_RECURSE PUBLIC_HEADERS RELATIVE "${Boost.Hana_SOURCE_DIR}/include" "${Boost.Hana_SOURCE_DIR}/include/*.hpp" ) list(REMOVE_ITEM PUBLIC_HEADERS ${PUBLIC_HEADERS_REQUIRING_BOOST}) include(TestHeaders) add_header_test(test.headers.standalone EXCLUDE_FROM_ALL HEADERS ${PUBLIC_HEADERS} EXCLUDE ${EXCLUDED_PUBLIC_HEADERS}) target_link_libraries(test.headers.standalone PRIVATE hana) add_dependencies(test.headers test.headers.standalone) if (Boost_FOUND) add_header_test(test.headers.boost EXCLUDE_FROM_ALL HEADERS ${PUBLIC_HEADERS_REQUIRING_BOOST} EXCLUDE ${EXCLUDED_PUBLIC_HEADERS}) target_link_libraries(test.headers.boost PRIVATE hana Boost::boost) add_dependencies(test.headers test.headers.boost) endif() ``` -------------------------------- ### Define Custom Target for All Tests (CMake) Source: https://github.com/boostorg/hana/blob/master/test/CMakeLists.txt Creates a custom target named 'tests' which serves as a meta-target for building all unit tests. It also establishes a dependency between 'hana_check' and the 'tests' target. ```cmake add_custom_target(tests COMMENT "Build all the unit tests.") add_dependencies(hana_check tests) ``` -------------------------------- ### Run Specific Boost.Hana Test with CTest Source: https://github.com/boostorg/hana/blob/master/README.md Executes a specific unit test for the Boost.Hana library using the CTest testing tool. The '-R' flag filters tests by regular expression, allowing targeted execution. ```shell ctest --test-dir build -R path.to.file ``` -------------------------------- ### Link Executable with LTO and Strip Unused Symbols (Clang/GCC) Source: https://github.com/boostorg/hana/wiki/Troubleshooting This solution addresses the issue of huge executable sizes when using Hana's containers with Clang's Link Time Optimization (LTO). It involves enabling LTO during the linking process and then using the 'strip' command to remove unused symbol names. This helps reduce the executable size by optimizing symbol removal, especially when dealing with compile-time data encapsulated in Hana's type system. ```bash clang++ -o my_program my_program.o -flto strip my_program ``` ```bash g++ -o my_program my_program.o -flto strip my_program ``` -------------------------------- ### Glob Recursively Find Boost-Dependent Headers (CMake) Source: https://github.com/boostorg/hana/blob/master/test/CMakeLists.txt Finds all public header files (`.hpp`) in Boost-specific directories (`ext/boost/` and experimental/printable) relative to the Boost.Hana source directory. These are stored in `PUBLIC_HEADERS_REQUIRING_BOOST`. ```cmake file(GLOB_RECURSE PUBLIC_HEADERS_REQUIRING_BOOST RELATIVE "${Boost.Hana_SOURCE_DIR}/include" "${Boost.Hana_SOURCE_DIR}/include/boost/hana/ext/boost/*.hpp" "${Boost.Hana_SOURCE_DIR}/include/boost/hana/ext/boost.hpp" "${Boost.Hana_SOURCE_DIR}/include/boost/hana/experimental/printable.hpp") ``` -------------------------------- ### Check and Apply Compiler Flags (CMake) Source: https://github.com/boostorg/hana/blob/master/example/CMakeLists.txt Uses CMake's `check_cxx_compiler_flag` to determine if the compiler supports specific flags like `-Wno-unused-parameter` and `-Wno-unused-lambda-capture`. These findings are stored in boolean variables for later use. ```cmake include(CheckCXXCompilerFlag) check_cxx_compiler_flag(-Wno-unused-parameter BOOST_HANA_HAS_WNO_UNUSED_PARAMETER) check_cxx_compiler_flag(-Wno-unused-lambda-capture BOOST_HANA_HAS_WNO_UNUSED_LAMBDA_CAPTURE) ``` -------------------------------- ### Handle ODR Violations Test (GitHub Issue 75) (CMake) Source: https://github.com/boostorg/hana/blob/master/test/CMakeLists.txt Adds an executable target for testing ODR violations as described in GitHub issue 75. It links the necessary translation units and adds the executable to the 'tests' dependency list. ```cmake list(APPEND EXCLUDED_UNIT_TESTS "issues/github_75/*.cpp") boost_hana_target_name_for(github_75 "${CMAKE_CURRENT_LIST_DIR}/issues/github_75") add_executable(${github_75} EXCLUDE_FROM_ALL "issues/github_75/tu1.cpp" "issues/github_75/tu2.cpp") boost_hana_set_test_properties(${github_75}) add_test(${github_75} "${CMAKE_CURRENT_BINARY_DIR}/${github_75}") add_dependencies(tests ${github_75}) ``` -------------------------------- ### Switch to Regular Clang for Empty Base Optimization Issues (Clang-cl) Source: https://github.com/boostorg/hana/wiki/Troubleshooting This addresses a problem where Clang-cl (emulating MSVC) results in unexpectedly large sizes for empty structs and classes, particularly when inheriting multiple empty bases. This is due to Clang-cl's limited emulation of MSVC's Empty Base Optimization (EBO). The recommended solution is to switch to a regular Clang compiler, which handles EBO more effectively, thus avoiding the size increase. -------------------------------- ### Generate Target Name from Source File Path (CMake) Source: https://github.com/boostorg/hana/blob/master/CMakeLists.txt The `boost_hana_target_name_for` function generates a unique target name for a given source file. It calculates the relative path from the Boost.Hana source directory, removes the extension, and replaces slashes with dots to create a hierarchical target name. ```cmake function(boost_hana_target_name_for out file) if (NOT ARGV2) set(_extension ".cpp") else() set(_extension "${ARGV2}") endif() file(RELATIVE_PATH _relative "${Boost.Hana_SOURCE_DIR}" "${file}") string(REPLACE "${_extension}" "" _name "${_relative}") string(REGEX REPLACE "/" "." _name "${_name}") set(${out} "${_name}" PARENT_SCOPE) endfunction() ``` -------------------------------- ### Specify Custom C++ Compiler with CMake Source: https://github.com/boostorg/hana/blob/master/README.md Configures the CMake build system to use a specific C++ compiler. This is useful on systems where the default compiler is outdated or does not meet the project's C++ standard requirements. ```shell cmake -S . -B build -DCMAKE_CXX_COMPILER=/path/to/compiler ``` -------------------------------- ### Conditionally Exclude Boost-Dependent Files (CMake) Source: https://github.com/boostorg/hana/blob/master/test/CMakeLists.txt Checks if Boost is found (`Boost_FOUND`). If Boost is not found, it appends the Boost-dependent test files and public headers to `EXCLUDED_UNIT_TESTS` and `EXCLUDED_PUBLIC_HEADERS` respectively. ```cmake if (NOT Boost_FOUND) list(APPEND EXCLUDED_UNIT_TESTS ${TESTS_REQUIRING_BOOST}) list(APPEND EXCLUDED_PUBLIC_HEADERS ${PUBLIC_HEADERS_REQUIRING_BOOST}) endif() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.