diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 000000000..efdc38131 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,50 @@ +############################################################################## +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and BLT +# project contributors. See the LICENSE file for details. +############################################################################## + +variables: + PROJECT_ALLOC_NAME: ${CI_PROJECT_NAME}_ci_${CI_PIPELINE_ID} + BUILD_ROOT: ${CI_PROJECT_DIR} + +stages: + - l_build + - q_allocate_resources + - q_build + - q_release_resources + +#### +# Template +.srun_build_script: + script: + #Use pre-existing allocation if any + - JOBID=$(squeue -h --name=${PROJECT_ALLOC_NAME} --format=%A) + - ASSIGN_ID=$(if [[ -n "${JOBID}" ]]; then echo "--jobid=${JOBID}"; fi) + - EXEC_PREFIX="srun -p pdebug ${ASSIGN_ID} -t 10 -N 1 --mpibind=off" + #BUILD + TEST + - echo -e "section_start:$(date +%s):build_and_test\r\e[0K + Build and test ${CI_PROJECT_NAME}" + - ${EXEC_PREFIX} .gitlab/build_and_test.sh + - echo -e "section_end:$(date +%s):build_and_test\r\e[0K" + artifacts: + reports: + junit: build/junit.xml + + +.build_blueos_3_ppc64le_ib_p9_script: + script: + - EXEC_PREFIX="lalloc 1 -W 10 -q pdebug" + #BUILD + TEST + - echo -e "section_start:$(date +%s):build_and_test\r\e[0K + Build and test ${CI_PROJECT_NAME}" + - ${EXEC_PREFIX} .gitlab/build_and_test.sh + - echo -e "section_end:$(date +%s):build_and_test\r\e[0K" + artifacts: + reports: + junit: build/junit.xml + + +# This is where jobs are included +include: + - local: .gitlab/build_quartz.yml + - local: .gitlab/build_lassen.yml diff --git a/.gitlab/build_and_test.sh b/.gitlab/build_and_test.sh new file mode 100755 index 000000000..cd6130187 --- /dev/null +++ b/.gitlab/build_and_test.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -e + +BUILD_DIR=`pwd`/build + +echo "~~~~~~~~~~ START:build_and_test.sh ~~~~~~~~~~~" +echo "CWD="`pwd` +echo "BUILD_DIR="$BUILD_DIR +echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" + +rm -rf $BUILD_DIR +mkdir $BUILD_DIR +cd $BUILD_DIR + +cmake -C ../host-configs/llnl/$SYS_TYPE/$HOST_CONFIG ../tests/internal +make -j8 +ctest -DCTEST_OUTPUT_ON_FAILURE=1 --no-compress-output -T Test -VV +xsltproc -o junit.xml ../tests/ctest-to-junit.xsl Testing/*/Test.xml + +echo "~~~~~~~~~~ END:build_and_test.sh ~~~~~~~~~~~~~" +echo "CWD="`pwd` +echo "BUILD_DIR="$BUILD_DIR +echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" diff --git a/.gitlab/build_lassen.yml b/.gitlab/build_lassen.yml new file mode 100644 index 000000000..0cd35459e --- /dev/null +++ b/.gitlab/build_lassen.yml @@ -0,0 +1,52 @@ +#### +# This is the share configuration of jobs for lassen +.on_lassen: + variables: + tags: + - shell + - lassen + rules: + - if: '$CI_COMMIT_BRANCH =~ /_lnone/ || $ON_LASSEN == "OFF"' #run except if ... + when: never + - when: on_success + +#### +# Load required modules +.with_cuda: + before_script: + - module load cmake/3.18.0 + - module load cuda/11.1.1 + +#### +# Template +.build_on_lassen: + stage: l_build + extends: [.build_blueos_3_ppc64le_ib_p9_script, .on_lassen] + needs: [] + +#### +# Build jobs +clang_upstream_link_with_nvcc (lassen): + variables: + HOST_CONFIG: "clang@upstream_link_with_nvcc.cmake" + extends: [.build_on_lassen, .with_cuda] + +clang_upstream_nvcc_c++17 (lassen): + variables: + HOST_CONFIG: "clang@upstream_nvcc_c++17.cmake" + extends: [.build_on_lassen, .with_cuda] + +clang_upstream_nvcc_c++17_no_separable (lassen): + variables: + HOST_CONFIG: "clang@upstream_nvcc_c++17_no_separable.cmake" + extends: [.build_on_lassen, .with_cuda] + +clang_upstream_nvcc_xlf (lassen): + variables: + HOST_CONFIG: "clang@upstream_nvcc_xlf.cmake" + extends: [.build_on_lassen, .with_cuda] + +pgi_20.4_nvcc (lassen): + variables: + HOST_CONFIG: "pgi@20.4_nvcc.cmake" + extends: [.build_on_lassen, .with_cuda] diff --git a/.gitlab/build_quartz.yml b/.gitlab/build_quartz.yml new file mode 100644 index 000000000..f9cc757d4 --- /dev/null +++ b/.gitlab/build_quartz.yml @@ -0,0 +1,63 @@ +#### +# This is the share configuration of jobs for quartz +.on_quartz: + tags: + - shell + - quartz + rules: + - if: '$CI_COMMIT_BRANCH =~ /_qnone/ || $ON_QUARTZ == "OFF"' #run except if ... + when: never + - if: '$CI_JOB_NAME =~ /release_resources/' + when: always + - when: on_success + +#### +# In pre-build phase, allocate a node for builds +allocate_resources_build_quartz: + variables: + GIT_STRATEGY: none + extends: [.on_quartz] + stage: q_allocate_resources + script: + - salloc -p pdebug -N 1 -c 36 -t 30 --no-shell --job-name=${PROJECT_ALLOC_NAME} --mpibind=off + needs: [] + +#### +# In post-build phase, deallocate resources +# Note : make sure this is run even on build phase failure +release_resources_build_quartz: + variables: + GIT_STRATEGY: none + extends: [.on_quartz] + stage: q_release_resources + script: + - export JOBID=$(squeue -h --name=${PROJECT_ALLOC_NAME} --format=%A) + - if [[ -n "${JOBID}" ]]; then scancel ${JOBID}; fi + +#### +# Template +.build_on_quartz: + stage: q_build + extends: [.srun_build_script, .on_quartz] + +#### +# Build jobs +clang_4_0_0_libcxx (quartz): + variables: + HOST_CONFIG: "clang@4.0.0-libcxx.cmake" + extends: [.build_on_quartz] + +clang_6_0_0_static_analysis (quartz): + variables: + HOST_CONFIG: "clang@6.0.0-static-analysis.cmake" + extends: [.build_on_quartz] + +gcc_8_3_1 (quartz): + variables: + HOST_CONFIG: "gcc@8.3.1.cmake" + extends: [.build_on_quartz] + +pgi_20_1 (quartz): + variables: + HOST_CONFIG: "pgi@20.1.cmake" + extends: [.build_on_quartz] diff --git a/.mailmap b/.mailmap index 5be06a215..781ba0da1 100644 --- a/.mailmap +++ b/.mailmap @@ -1,10 +1,24 @@ -George Zagaris George Zagaris -Kenneth Weiss Kenneth Weiss -Kenneth Weiss Kenny Weiss -Kenneth Weiss Kenny Weiss -Peter B. Robinson robinson96 -Peter B. Robinson robinspb -Randolph R. Settgast Randolph R. Settgast -Randolph R. Settgast Randolph Settgast -Randolph R. Settgast Randolph Settgast - +Alfredo Metere Alfredo Metere +Alfredo Metere metere1llnl <51676123+metere1llnl@users.noreply.github.com> +Benjamin Curtice Corbett Ben Corbett <32752943+corbett5@users.noreply.github.com> +Burl M. Hall BurlMHall <47543546+BurlMHall@users.noreply.github.com> +Daniel Taller Danny Taller <66029857+dtaller@users.noreply.github.com> +Geoffrey Oxberry Geoffrey M Oxberry +Geoffrey Oxberry Geoffrey M. Oxberry +George Zagaris George Zagaris +Jason Burmark Jason Burmark +Josh Essman Josh Essman <68349992+joshessman-llnl@users.noreply.github.com> +Keith Healy keithhealy <50376825+keithhealy@users.noreply.github.com> +Kenneth Weiss Kenny Weiss +Kenneth Weiss Kenny Weiss +Kenneth Weiss Kenneth Weiss +Kristi Belcher Kristi Belcher +Kristi Belcher Kristi Belcher +Kristi Belcher Kristi +Marty McFadden Marty McFadden +Peter B. Robinson robinson96 +Peter B. Robinson robinspb +Randolph R. Settgast Randolph Settgast +Randolph R. Settgast Randolph R. Settgast +Randolph R. Settgast Randolph Settgast +Johann Dahm Johann Dahm diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 158ca92e7..b88232e17 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,6 +3,8 @@ We welcome contributions to BLT. To do so please submit a pull request through our BLT github page at https://github.com/LLNL/blt. +Before submitting a pull request, update `RELEASE-NOTES.md` accordingly. + All contributions to BLT must be made under the BSD License. Any questions can be sent to blt-dev@llnl.gov. @@ -13,18 +15,6 @@ The BLT project uses git's commit history to track contributions from individual Since we want everyone to feel they are getting the proper attribution for their contributions, please add your name to the list below as part of your commit. -# Contributors (In Alphabetical Order) - -* Izaak Beekman -* Robert Blake, LLNL -* Jason Burmark, LLNL -* Ben Corbett, LLNL -* Johann Dahm -* Chip Freitag, AMD, Inc. -* Elsa Gonsiorowski, LLNL -* Burl Hall, LLNL -* Matt Larsen, LLNL -* Martin McFadden, LLNL -* Mark Miller, LLNL -* David Poliakoff, Sandia National Laboratories +# Contributors +Thanks to all of BLT's [contributors](https://github.com/LLNL/blt/graphs/contributors). diff --git a/LICENSE b/LICENSE index a7d513ff3..f08c6273a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC. +Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/README.md b/README.md index 459c02eab..b56eb0225 100644 --- a/README.md +++ b/README.md @@ -4,25 +4,25 @@ Status](https://dev.azure.com/llnl-blt/blt/_apis/build/status/LLNL.blt?branchName=develop)](https://dev.azure.com/llnl-blt/blt/_build/latest?definitionId=1&branchName=develop) [![Documentation Status](https://readthedocs.org/projects/llnl-blt/badge/?version=develop)](https://llnl-blt.readthedocs.io/en/develop/?badge=develop) -BLT is a streamlined [CMake](https://cmake.org)-based foundation for +BLT is a streamlined [CMake](https://cmake.org)-based foundation for Building, Linking and Testing large-scale high performance computing (HPC) applications. -BLT makes it easy to get up and running on a wide range of HPC compilers, +BLT makes it easy to get up and running on a wide range of HPC compilers, operating systems and technologies: * Compiler families: - [gcc](https://gcc.gnu.org), - [clang](https://clang.llvm.org), - [Intel](https://software.intel.com/en-us/compilers), - [XL](https://www.ibm.com/us-en/marketplace/ibm-c-and-c-plus-plus-compiler-family), + [gcc](https://gcc.gnu.org), + [clang](https://clang.llvm.org), + [Intel](https://software.intel.com/en-us/compilers), + [XL](https://www.ibm.com/us-en/marketplace/ibm-c-and-c-plus-plus-compiler-family), [Visual Studio](https://visualstudio.microsoft.com/vs/features/cplusplus) - * Operating systems: - Linux, - Mac OS, + * Operating systems: + Linux, + Mac OS, Windows * HPC programming models: - [MPI](https://www.mpi-forum.org/), - [OpenMP](https://www.openmp.org/), - [CUDA](https://developer.nvidia.com/cuda-zone), + [MPI](https://www.mpi-forum.org/), + [OpenMP](https://www.openmp.org/), + [CUDA](https://developer.nvidia.com/cuda-zone), [HIP](https://gpuopen.com/compute-product/hip-convert-cuda-to-portable-c-code) * Unit testing and benchmarking (built-in): [Google Test (gtest and gmock)](https://github.com/google/googletest), @@ -34,11 +34,14 @@ operating systems and technologies: * Code style: [AStyle](http://astyle.sourceforge.net), [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html), - [Uncrustify](http://uncrustify.sourceforge.net) + [cmake-format](https://github.com/cheshirekow/cmake_format), + [Uncrustify](http://uncrustify.sourceforge.net), + [YAPF (Yet Another Python Formatter)](https://github.com/google/yapf) * Code quality [clang-query](http://clang.llvm.org/docs/LibASTMatchers.html), + [clang-tidy](https://clang.llvm.org/extra/clang-tidy), [Cppcheck](http://cppcheck.sourceforge.net) - + Getting started --------------- @@ -54,39 +57,44 @@ For more information, please check our [user documentation and tutorial](https:/ Questions --------- -Any questions can be sent to blt-dev@llnl.gov. +Any questions can be sent to blt-dev@llnl.gov. If you are an LLNL employee or collaborator, we have an +internal Microsoft Teams group chat named "BLT" as well. -Authors -------- +Contributions +------------- + +We welcome all kinds of contributions: new features, bug fixes, documentation edits. -Developers include: +To contribute, make a [pull request](https://github.com/LLNL/blt/pulls), with `develop` +as the destination branch. We use CI testing and your branch must pass these tests before +being merged. - * Chris White, LLNL - * Kenneth Weiss, LLNL - * Cyrus Harrison, LLNL - * George Zagaris, LLNL - * Lee Taylor, LLNL - * Aaron Black, LLNL - * David A. Beckingsale, LLNL - * Richard Hornung, LLNL - * Randolph Settgast, LLNL +For more information, see the [contributing guide](https://github.com/LLNL/blt/blob/develop/CONTRIBUTING.md). -Please see our [contributing guide](https://github.com/LLNL/blt/blob/develop/CONTRIBUTING.md) -for details about how to contribute to the project. +Authors +------- -The full list of project contributors can be found on the -[BLT Contributors Page](https://github.com/LLNL/BLT/graphs/contributors). +Thanks to all of BLT's [contributors](https://github.com/LLNL/blt/graphs/contributors). Open-Source Projects using BLT ------------------------------ + * [Adiak](https://github.com/LLNL/Adiak): Library for collecting metadata from HPC application runs * [Ascent](https://github.com/Alpine-DAV/ascent): A flyweight in-situ visualization and analysis runtime for multi-physics HPC simulations * [Axom](https://github.com/LLNL/axom): Software infrastructure for the development of multi-physics applications and computational tools + * [CARE](https://github.com/LLNL/CARE): CHAI and RAJA extensions * [CHAI](https://github.com/LLNL/CHAI): Copy-hiding array abstraction to automatically migrate data between memory spaces * [Conduit](https://github.com/LLNL/conduit): Simplified data exchange for HPC simulations + * [Comb](https://github.com/LLNL/Comb): Communication performance benchmarking tool + * [ExaCMech](https://github.com/LLNL/ExaCMech): GPU-friendly library of constitutive models + * [Kripke](https://github.com/LLNL/Kripke): Simple, scalable, 3D Sn deterministic particle transport code * [RAJA](https://github.com/LLNL/raja): Performance portability layer for HPC + * [SAMRAI](https://github.com/LLNL/SAMRAI): Structured Adaptive Mesh Refinement Application Infrastructure + * [Serac](https://github.com/LLNL/serac): 3D implicit nonlinear thermal-structural simulation code + * [Spheral](https://github.com/LLNL/spheral): Steerable parallel environment for performing coupled hydrodynamical & gravitational numerical simulations * [Umpire](https://github.com/LLNL/Umpire): Application-focused API for memory management on NUMA and GPU architectures * [VTK-h](https://github.com/Alpine-DAV/vtk-h): Scientific visualization algorithms for emerging processor architectures + * [WCS](https://github.com/LLNL/wcs): Computational environment for simulating a whole cell model If you would like to add a library to this list, please let us know via [email](mailto:blt-dev@llnl.gov) or by submitting an [issue](https://github.com/LLNL/blt/issues) or [pull-request](https://github.com/LLNL/blt/pulls). @@ -101,7 +109,7 @@ Copyrights and patents in the BLT project are retained by contributors. No copyright assignment is required to contribute to BLT. See [LICENSE](./LICENSE) for details. - + Unlimited Open Source - BSD 3-clause Distribution `LLNL-CODE-725085` `OCEC-17-023` @@ -123,6 +131,8 @@ BLT bundles its external dependencies in thirdparty_builtin/. These packages are covered by various permissive licenses. A summary listing follows. See the license included with each package for full details. +[//]: # (Note: The spaces at the end of each line below add line breaks) + PackageName: fruit PackageHomePage: https://sourceforge.net/projects/fortranxunit/ PackageLicenseDeclared: BSD-3-Clause diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 04940d840..14045ab33 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -9,19 +9,85 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/ ## [Unreleased] - Release date yyyy-mm-dd +## [Version 0.4.0] - Release date 2021-04-09 + +## Added +- Added variable ``BLT_CMAKE_IMPLICIT_LINK_DIRECTORIES_EXCLUDE`` for filtering + link directories implicitly added by CMake. See the following example host-config: + ``host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_c++17.cmake`` +- Added support for clang-tidy static analysis check +- Added ability to change the output name of an executable via the OUTPUT_NAME + parameter of blt_add_executable +- Added user option for enforcing specific versions of autoformatters - the new options are + ``BLT_REQUIRED_ASTYLE_VERSION``, ``BLT_REQUIRED_CLANGFORMAT_VERSION``, and ``BLT_REQUIRED_UNCRUSTIFY_VERSION`` +- Added ``HEADERS`` to ``blt_add_executable``. This is important for build system dependency tracking + and IDE folder support. +- Added support for formatting Python code using YAPF. +- Added new ``blt_import_library`` macro that creates a real CMake target for imported libraries, + intended to be used instead of ``blt_register_library`` whenever possible +- Added new ``blt_patch_target`` macro to simplify modifying properties of an existing CMake target. + This macro accounts for known differences in compilers, target types, and CMake releases. +- Added support for formatting CMake code using cmake-format. +- Added an EXPORTABLE option to ``blt_import_library`` that allows imported libraries to be + added to an export set and installed. +- Added FRUIT's MPI parallel unit test reporting to BLT's internal copy of FRUIT +- CUDA device links for object libraries can be enabled with the existing ``CUDA_RESOLVE_DEVICE_SYMBOLS`` + target property. + +### Changed +- MPI Support when using CMake 3.13 and newer: MPI linker flags are now passed + as single string prefixed by ``SHELL:`` to prevent de-duplication of flags + passed to ``target_link_options``. +- For HIP-dependent builds, only add HCC include directory if it exists. +- HIP CMake utilities updated to AMD's latest version +- Updated ``add_code_coverage_target`` to ``blt_add_code_coverage_target``, which now supports + user-specified source directories +- Code coverage targets leave LCOV-generated files intact for later use; these files will + still be removed by ``make clean`` + +### Fixed +- ClangFormat checks now support multiple Python executable names +- Prefixed blt_register_library() internal variables with ``_`` to avoid collision + with input parameters. +- Turn off system includes for registered libraries when using the PGI compiler +- Removed unneeded SYSTEM includes added by googletest that was causing problems + in PGI builds (BLT was adding them already to the register library calls) +- Removed variable ``BLT_CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES_EXCLUDE``, functionality now + provided for all languages using ``BLT_CMAKE_IMPLICIT_LINK_DIRECTORIES_EXCLUDE`` variable +- ClangQuery was being auto-enabled in cases where no checker directories where defined. + This caused a crash. blt_add_clang_query_target learned parameter CHECKER_DIRECTORIES + and blt_add_code_checks learned parameter CLANGQUERY_CHECKER_DIRECTORIES. Both still + respect BLT_CLANGQUERY_CHECKER_DIRECTORIES. +- It is now a fatal error to supply CLANGFORMAT_CFG_FILE plus + ASTYLE_CFG_FILE or UNCRUSTIFY_CFG_FILE arguments to + blt_add_code_checks; previously, these combinations were implied to + be errors in BLT documentation, but BLT would not return an error in + those cases. +- ``blt_patch_target`` no longer attempts to set system include directories when a target + has no include directories +- Header-only libraries now can have dependencies via DEPENDS_ON in ``blt_add_library`` +- Added a workaround for include directories of imported targets on PGI. CMake was + erroneously marking them as SYSTEM but this is not supported by PGI. +- Check added to make sure that if HIP is enabled with fortran, the LINKER LANGUAGE + is not changed back to Fortran. +- Executables that link to libraries that depend on `hip`/`hip_runtime`/`cuda`/`cuda_runtime` + will automatically be linked with the HIP or CUDA (NVCC) linker +- Patched an issue with the FindHIP macros that added the inclusive scan of specified + DEFINEs to compile commands +- Re-added previous OpenMP flag patching logic to maintain compatibility with BLT-registered libraries + ## [Version 0.3.6] - Release date 2020-07-27 ### Changed - ``CUDA_TOOLKIT_ROOT_DIR`` is now optional. If it is not specified, FindCUDA.cmake will attempt to set it. - ## [Version 0.3.5] - Release date 2020-07-20 ### Added - Added blt_assert_exists() utility macro. -- Additional link flags for CUDA may now be specified by setting - ``CMAKE_CUDA_LINK_FLAGS`` when configuring CMake either in a host-config +- Additional link flags for CUDA may now be specified by setting + ``CMAKE_CUDA_LINK_FLAGS`` when configuring CMake either in a host-config or at the command-line. - Added support for ClangFormat. @@ -89,7 +155,7 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/ - Handle FindMPI variable MPIEXEC changed to MPIEXEC_EXECUTABLE in CMake 3.10+. This now works regardless of which the user defines or what CMake returns. - Handle CMake target property LINK_FLAGS changed to LINK_OPTIONS in CMake 3.13+. - blt_add_target_link_flags() handles this under the covers and converts the + blt_add_target_link_flags() handles this under the covers and converts the users strings to a list (3.13+) or list to a string (<3.13). New property supports generator expressions so thats a plus. - Improved how all BLT MPI information is being merged together and reported to users. @@ -136,7 +202,8 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/ -[Unreleased]: https://github.com/LLNL/blt/compare/v0.3.6...develop +[Unreleased]: https://github.com/LLNL/blt/compare/v0.4.0...develop +[Version 0.4.0]: https://github.com/LLNL/blt/compare/v0.3.6...v0.4.0 [Version 0.3.6]: https://github.com/LLNL/blt/compare/v0.3.5...v0.3.6 [Version 0.3.5]: https://github.com/LLNL/blt/compare/v0.3.0...v0.3.5 [Version 0.3.0]: https://github.com/LLNL/blt/compare/v0.2.5...v0.3.0 diff --git a/SetupBLT.cmake b/SetupBLT.cmake index 9f0559a73..322bde168 100644 --- a/SetupBLT.cmake +++ b/SetupBLT.cmake @@ -1,10 +1,10 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) if (NOT BLT_LOADED) - set(BLT_VERSION "0.3.6" CACHE STRING "") + set(BLT_VERSION "0.4.0" CACHE STRING "") mark_as_advanced(BLT_VERSION) message(STATUS "BLT Version: ${BLT_VERSION}") @@ -176,7 +176,10 @@ if (NOT BLT_LOADED) CACHE STRING "List of known file extensions used for C/CXX sources") set(BLT_Fortran_FILE_EXTS ".F" ".f" ".f90" ".F90" CACHE STRING "List of known file extensions used for Fortran sources") - + set(BLT_Python_FILE_EXTS ".py" + CACHE STRING "List of known file extensions used for Python sources") + set(BLT_CMAKE_FILE_EXTS ".cmake" # NOTE: CMakeLists.txt handled elsewhere + CACHE STRING "List of known file extensions used for CMake sources") ################################ # Setup compiler options diff --git a/azure-pipelines.yml b/azure-pipelines.yml index d6ff65ae4..5a7bd9a33 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) diff --git a/cmake/BLTGitMacros.cmake b/cmake/BLTGitMacros.cmake index d6024f6f6..e08a5d432 100644 --- a/cmake/BLTGitMacros.cmake +++ b/cmake/BLTGitMacros.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -144,7 +144,7 @@ macro(blt_git_tag) endif() ## set working directory - if ( NOT DEFINED arg_SOURCE_DIR} ) + if ( NOT DEFINED arg_SOURCE_DIR ) set(git_dir ${CMAKE_CURRENT_SOURCE_DIR}) else() set(git_dir ${arg_SOURCE_DIR}) diff --git a/cmake/BLTMacros.cmake b/cmake/BLTMacros.cmake index 5dc382b36..5fd6be7e3 100644 --- a/cmake/BLTMacros.cmake +++ b/cmake/BLTMacros.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -184,7 +184,13 @@ macro(blt_add_target_compile_flags) # Only add the flag if it is not empty string(STRIP "${arg_FLAGS}" _strippedFlags) if(NOT "${_strippedFlags}" STREQUAL "") - target_compile_options(${arg_TO} ${_scope} ${_strippedFlags}) + get_target_property(_target_type ${arg_TO} TYPE) + if (("${_target_type}" STREQUAL "INTERFACE_LIBRARY") AND (${CMAKE_VERSION} VERSION_LESS "3.11.0")) + set_property(TARGET ${arg_NAME} APPEND PROPERTY + INTERFACE_COMPILE_OPTIONS ${_strippedFlags}) + else() + target_compile_options(${arg_TO} ${_scope} ${_strippedFlags}) + endif() endif() unset(_strippedFlags) @@ -270,16 +276,30 @@ macro(blt_add_target_link_flags) endif() else() # In CMake <= 3.12, there is no target_link_flags or target_link_options command - get_target_property(_link_flags ${arg_TO} LINK_FLAGS) - if(NOT _link_flags) - set(_link_flags "") + get_target_property(_target_type ${arg_TO} TYPE) + if ("${_target_type}" STREQUAL "INTERFACE_LIBRARY") + # If it's an interface library, we add the flag via link_libraries + if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.11.0") + target_link_libraries(${arg_TO} INTERFACE ${_flags}) + else() + set_property(TARGET ${arg_NAME} APPEND PROPERTY + INTERFACE_LINK_LIBRARIES ${_flags}) + endif() + else() + get_target_property(_link_flags ${arg_TO} LINK_FLAGS) + # Append to existing flags + if(NOT _link_flags) + set(_link_flags "") + endif() + set(_link_flags "${_flags} ${_link_flags}") + + # Convert from a CMake ;-list to a string + string (REPLACE ";" " " _link_flags_str "${_link_flags}") + + set_target_properties(${arg_TO} + PROPERTIES LINK_FLAGS "${_link_flags_str}") endif() - set(_link_flags "${_flags} ${_link_flags}") - # Convert from a CMake ;-list to a string - string (REPLACE ";" " " _link_flags_str "${_link_flags}") - set_target_properties(${arg_TO} - PROPERTIES LINK_FLAGS "${_link_flags_str}") endif() endif() @@ -321,64 +341,242 @@ macro(blt_register_library) string(TOUPPER ${arg_NAME} uppercase_name) - set(BLT_${uppercase_name}_IS_REGISTERED_LIBRARY TRUE CACHE BOOL "" FORCE) + set(_BLT_${uppercase_name}_IS_REGISTERED_LIBRARY TRUE CACHE BOOL "" FORCE) if( arg_DEPENDS_ON ) - set(BLT_${uppercase_name}_DEPENDS_ON ${arg_DEPENDS_ON} CACHE STRING "" FORCE) - mark_as_advanced(BLT_${uppercase_name}_DEPENDS_ON) + set(_BLT_${uppercase_name}_DEPENDS_ON ${arg_DEPENDS_ON} CACHE STRING "" FORCE) + mark_as_advanced(_BLT_${uppercase_name}_DEPENDS_ON) endif() if( arg_INCLUDES ) - set(BLT_${uppercase_name}_INCLUDES ${arg_INCLUDES} CACHE STRING "" FORCE) - mark_as_advanced(BLT_${uppercase_name}_INCLUDES) + set(_BLT_${uppercase_name}_INCLUDES ${arg_INCLUDES} CACHE STRING "" FORCE) + mark_as_advanced(_BLT_${uppercase_name}_INCLUDES) endif() if( ${arg_OBJECT} ) - set(BLT_${uppercase_name}_IS_OBJECT_LIBRARY TRUE CACHE BOOL "" FORCE) + set(_BLT_${uppercase_name}_IS_OBJECT_LIBRARY TRUE CACHE BOOL "" FORCE) else() - set(BLT_${uppercase_name}_IS_OBJECT_LIBRARY FALSE CACHE BOOL "" FORCE) + set(_BLT_${uppercase_name}_IS_OBJECT_LIBRARY FALSE CACHE BOOL "" FORCE) endif() - mark_as_advanced(BLT_${uppercase_name}_IS_OBJECT_LIBRARY) + mark_as_advanced(_BLT_${uppercase_name}_IS_OBJECT_LIBRARY) - if( ${arg_TREAT_INCLUDES_AS_SYSTEM} ) - set(BLT_${uppercase_name}_TREAT_INCLUDES_AS_SYSTEM TRUE CACHE BOOL "" FORCE) + # PGI does not support -isystem + if( (${arg_TREAT_INCLUDES_AS_SYSTEM}) AND (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "PGI")) + set(_BLT_${uppercase_name}_TREAT_INCLUDES_AS_SYSTEM TRUE CACHE BOOL "" FORCE) else() - set(BLT_${uppercase_name}_TREAT_INCLUDES_AS_SYSTEM FALSE CACHE BOOL "" FORCE) + set(_BLT_${uppercase_name}_TREAT_INCLUDES_AS_SYSTEM FALSE CACHE BOOL "" FORCE) endif() - mark_as_advanced(BLT_${uppercase_name}_TREAT_INCLUDES_AS_SYSTEM) + mark_as_advanced(_BLT_${uppercase_name}_TREAT_INCLUDES_AS_SYSTEM) if( ENABLE_FORTRAN AND arg_FORTRAN_MODULES ) - set(BLT_${uppercase_name}_FORTRAN_MODULES ${arg_INCLUDES} CACHE STRING "" FORCE) - mark_as_advanced(BLT_${uppercase_name}_FORTRAN_MODULES) + set(_BLT_${uppercase_name}_FORTRAN_MODULES ${arg_INCLUDES} CACHE STRING "" FORCE) + mark_as_advanced(_BLT_${uppercase_name}_FORTRAN_MODULES) endif() if( arg_LIBRARIES ) - set(BLT_${uppercase_name}_LIBRARIES ${arg_LIBRARIES} CACHE STRING "" FORCE) + set(_BLT_${uppercase_name}_LIBRARIES ${arg_LIBRARIES} CACHE STRING "" FORCE) else() # This prevents cmake from falling back on adding -l # to the command line for BLT registered libraries which are not # actual CMake targets - set(BLT_${uppercase_name}_LIBRARIES "BLT_NO_LIBRARIES" CACHE STRING "" FORCE) + set(_BLT_${uppercase_name}_LIBRARIES "BLT_NO_LIBRARIES" CACHE STRING "" FORCE) endif() - mark_as_advanced(BLT_${uppercase_name}_LIBRARIES) + mark_as_advanced(_BLT_${uppercase_name}_LIBRARIES) if( arg_COMPILE_FLAGS ) - set(BLT_${uppercase_name}_COMPILE_FLAGS "${arg_COMPILE_FLAGS}" CACHE STRING "" FORCE) - mark_as_advanced(BLT_${uppercase_name}_COMPILE_FLAGS) + set(_BLT_${uppercase_name}_COMPILE_FLAGS "${arg_COMPILE_FLAGS}" CACHE STRING "" FORCE) + mark_as_advanced(_BLT_${uppercase_name}_COMPILE_FLAGS) endif() if( arg_LINK_FLAGS ) - set(BLT_${uppercase_name}_LINK_FLAGS "${arg_LINK_FLAGS}" CACHE STRING "" FORCE) - mark_as_advanced(BLT_${uppercase_name}_LINK_FLAGS) + set(_BLT_${uppercase_name}_LINK_FLAGS "${arg_LINK_FLAGS}" CACHE STRING "" FORCE) + mark_as_advanced(_BLT_${uppercase_name}_LINK_FLAGS) endif() if( arg_DEFINES ) - set(BLT_${uppercase_name}_DEFINES ${arg_DEFINES} CACHE STRING "" FORCE) - mark_as_advanced(BLT_${uppercase_name}_DEFINES) + set(_BLT_${uppercase_name}_DEFINES ${arg_DEFINES} CACHE STRING "" FORCE) + mark_as_advanced(_BLT_${uppercase_name}_DEFINES) endif() endmacro(blt_register_library) +##------------------------------------------------------------------------------ +## blt_patch_target( NAME +## DEPENDS_ON [dep1 [dep2 ...]] +## INCLUDES [include1 [include2 ...]] +## LIBRARIES [lib1 [lib2 ...]] +## TREAT_INCLUDES_AS_SYSTEM [ON|OFF] +## FORTRAN_MODULES [ path1 [ path2 ..]] +## COMPILE_FLAGS [ flag1 [ flag2 ..]] +## LINK_FLAGS [ flag1 [ flag2 ..]] +## DEFINES [def1 [def2 ...]] ) +## +## Modifies an existing CMake target - sets PUBLIC visibility except for INTERFACE +## libraries, which use INTERFACE visibility +##------------------------------------------------------------------------------ +macro(blt_patch_target) + set(singleValueArgs NAME TREAT_INCLUDES_AS_SYSTEM) + set(multiValueArgs INCLUDES + DEPENDS_ON + LIBRARIES + FORTRAN_MODULES + COMPILE_FLAGS + LINK_FLAGS + DEFINES ) + + ## parse the arguments + cmake_parse_arguments(arg + "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN} ) + + # Input checks + if( "${arg_NAME}" STREQUAL "" ) + message(FATAL_ERROR "blt_patch_target() must be called with argument NAME ") + endif() + + if (NOT TARGET ${arg_NAME}) + message(FATAL_ERROR "blt_patch_target() NAME argument must be a native CMake target") + endif() + + # Default to public scope, unless it's an interface library + set(_scope PUBLIC) + get_target_property(_target_type ${arg_NAME} TYPE) + if("${_target_type}" STREQUAL "INTERFACE_LIBRARY") + set(_scope INTERFACE) + endif() + + # Interface libraries were heavily restricted pre-3.11 + set(_standard_lib_interface FALSE) + if((${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.11.0") OR (NOT "${_target_type}" STREQUAL "INTERFACE_LIBRARY")) + set(_standard_lib_interface TRUE) + endif() + + # LIBRARIES and DEPENDS_ON are kept separate in case different logic is needed for + # the library itself versus its dependencies + set(_libs_to_link "") + if( arg_LIBRARIES ) + list(APPEND _libs_to_link ${arg_LIBRARIES}) + endif() + + # TODO: This won't expand BLT-registered libraries + if( arg_DEPENDS_ON ) + list(APPEND _libs_to_link ${arg_DEPENDS_ON}) + endif() + + if(_standard_lib_interface) + target_link_libraries(${arg_NAME} ${_scope} ${_libs_to_link}) + else() + set_property(TARGET ${arg_NAME} APPEND PROPERTY + INTERFACE_LINK_LIBRARIES ${_libs_to_link}) + endif() + + if( arg_INCLUDES ) + if(_standard_lib_interface) + target_include_directories(${arg_NAME} ${_scope} ${arg_INCLUDES}) + else() + # Interface include directories need to be set manually + set_property(TARGET ${arg_NAME} APPEND PROPERTY + INTERFACE_INCLUDE_DIRECTORIES ${arg_INCLUDES}) + endif() + endif() + + # PGI does not support -isystem + if( (${arg_TREAT_INCLUDES_AS_SYSTEM}) AND (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "PGI")) + get_target_property(_target_includes ${arg_NAME} INTERFACE_INCLUDE_DIRECTORIES) + # Don't copy if the target had no include directories + if(_target_includes) + if(_standard_lib_interface) + target_include_directories(${arg_NAME} SYSTEM ${_scope} ${_target_includes}) + else() + set_property(TARGET ${arg_NAME} PROPERTY + INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${_target_includes}) + endif() + endif() + endif() + + # FIXME: Is this all that's needed? + if( arg_FORTRAN_MODULES ) + target_include_directories(${arg_NAME} ${_scope} ${arg_FORTRAN_MODULES}) + endif() + + if( arg_COMPILE_FLAGS ) + blt_add_target_compile_flags(TO ${arg_NAME} + SCOPE ${_scope} + FLAGS ${arg_COMPILE_FLAGS}) + endif() + + if( arg_LINK_FLAGS ) + blt_add_target_link_flags(TO ${arg_NAME} + SCOPE ${_scope} + FLAGS ${arg_LINK_FLAGS}) + endif() + + if( arg_DEFINES ) + blt_add_target_definitions(TO ${arg_NAME} + SCOPE ${_scope} + TARGET_DEFINITIONS ${arg_DEFINES}) + endif() + +endmacro(blt_patch_target) + +##------------------------------------------------------------------------------ +## blt_import_library( NAME +## LIBRARIES [lib1 [lib2 ...]] +## DEPENDS_ON [dep1 [dep2 ...]] +## INCLUDES [include1 [include2 ...]] +## TREAT_INCLUDES_AS_SYSTEM [ON|OFF] +## FORTRAN_MODULES [ path1 [ path2 ..]] +## COMPILE_FLAGS [ flag1 [ flag2 ..]] +## LINK_FLAGS [ flag1 [ flag2 ..]] +## DEFINES [def1 [def2 ...]] +## GLOBAL [ON|OFF] +## EXPORTABLE [ON|OFF]) +## +## Imports a library as a CMake target +##------------------------------------------------------------------------------ +macro(blt_import_library) + set(singleValueArgs NAME TREAT_INCLUDES_AS_SYSTEM GLOBAL EXPORTABLE) + set(multiValueArgs LIBRARIES + INCLUDES + DEPENDS_ON + FORTRAN_MODULES + COMPILE_FLAGS + LINK_FLAGS + DEFINES ) + + ## parse the arguments + cmake_parse_arguments(arg + "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN} ) + + # Input checks + if( "${arg_NAME}" STREQUAL "" ) + message(FATAL_ERROR "blt_import_library() must be called with argument NAME ") + endif() + + if(${arg_EXPORTABLE}) + if(${arg_GLOBAL}) + message(FATAL_ERROR "blt_import_library: EXPORTABLE targets cannot be GLOBAL") + endif() + add_library(${arg_NAME} INTERFACE) + elseif(${arg_GLOBAL}) + add_library(${arg_NAME} INTERFACE IMPORTED GLOBAL) + else() + add_library(${arg_NAME} INTERFACE IMPORTED) + endif() + + blt_patch_target( + NAME ${arg_NAME} + LIBRARIES ${arg_LIBRARIES} + DEPENDS_ON ${arg_DEPENDS_ON} + INCLUDES ${arg_INCLUDES} + DEFINES ${arg_DEFINES} + TREAT_INCLUDES_AS_SYSTEM ${arg_TREAT_INCLUDES_AS_SYSTEM} + FORTRAN_MODULES ${arg_FORTRAN_MODULES} + COMPILE_FLAGS ${arg_COMPILE_FLAGS} + LINK_FLAGS ${arg_LINK_FLAGS} + DEFINES ${arg_DEFINES} + ) +endmacro(blt_import_library) + ##------------------------------------------------------------------------------ ## blt_add_library( NAME @@ -546,21 +744,23 @@ endmacro(blt_add_library) ##------------------------------------------------------------------------------ -## blt_add_executable( NAME -## SOURCES [source1 [source2 ...]] -## INCLUDES [dir1 [dir2 ...]] -## DEFINES [define1 [define2 ...]] -## DEPENDS_ON [dep1 [dep2 ...]] -## OUTPUT_DIR [dir] -## FOLDER [name]) +## blt_add_executable( NAME +## SOURCES [source1 [source2 ...]] +## HEADERS [header1 [header2 ...]] +## INCLUDES [dir1 [dir2 ...]] +## DEFINES [define1 [define2 ...]] +## DEPENDS_ON [dep1 [dep2 ...]] +## OUTPUT_DIR [dir] +## OUTPUT_NAME [name] +## FOLDER [name]) ## ## Adds an executable target, called , to be built from the given sources. ##------------------------------------------------------------------------------ macro(blt_add_executable) set(options ) - set(singleValueArgs NAME OUTPUT_DIR FOLDER) - set(multiValueArgs SOURCES INCLUDES DEFINES DEPENDS_ON) + set(singleValueArgs NAME OUTPUT_DIR OUTPUT_NAME FOLDER) + set(multiValueArgs HEADERS SOURCES INCLUDES DEFINES DEPENDS_ON) # Parse the arguments to the macro cmake_parse_arguments(arg @@ -578,9 +778,10 @@ macro(blt_add_executable) if (ENABLE_HIP) blt_add_hip_executable(NAME ${arg_NAME} SOURCES ${arg_SOURCES} + HEADERS ${arg_HEADERS} DEPENDS_ON ${arg_DEPENDS_ON}) else() - add_executable( ${arg_NAME} ${arg_SOURCES} ) + add_executable( ${arg_NAME} ${arg_SOURCES} ${arg_HEADERS}) if (ENABLE_CUDA AND NOT ENABLE_CLANG_CUDA) blt_setup_cuda_target( @@ -595,9 +796,7 @@ macro(blt_add_executable) list(GET arg_SOURCES 0 _first) get_source_file_property(_lang ${_first} LANGUAGE) if(_lang STREQUAL Fortran) - if (NOT CUDA_LINK_WITH_NVCC) - set_target_properties( ${arg_NAME} PROPERTIES LINKER_LANGUAGE Fortran ) - endif() + set_target_properties( ${arg_NAME} PROPERTIES LINKER_LANGUAGE Fortran ) target_include_directories(${arg_NAME} PRIVATE ${CMAKE_Fortran_MODULE_DIRECTORY}) endif() @@ -605,6 +804,15 @@ macro(blt_add_executable) DEPENDS_ON ${arg_DEPENDS_ON} OBJECT FALSE) + # Override the linker language with INTERFACE_BLT_LINKER_LANGUAGE_OVERRIDE, if applicable + # Will have just been populated by blt_setup_target + get_target_property(_blt_link_lang ${arg_NAME} INTERFACE_BLT_LINKER_LANGUAGE_OVERRIDE) + if(_blt_link_lang) + # This is the final link (b/c executable), so override the actual LINKER_LANGUAGE + # BLT currently uses this to override for HIP and CUDA linkers + set_target_properties(${arg_NAME} PROPERTIES LINKER_LANGUAGE ${_blt_link_lang}) + endif() + # fix the openmp flags for fortran if needed # NOTE: this needs to be called after blt_setup_target() if (_lang STREQUAL Fortran) @@ -619,6 +827,11 @@ macro(blt_add_executable) target_compile_definitions(${arg_NAME} PUBLIC ${arg_DEFINES}) endif() + if ( arg_OUTPUT_NAME ) + set_target_properties(${arg_NAME} PROPERTIES + OUTPUT_NAME ${arg_OUTPUT_NAME} ) + endif() + # when using shared libs on windows, all runtime targets # (dlls and exes) must live in the same dir # so we do not set runtime_output_dir in this case @@ -632,7 +845,7 @@ macro(blt_add_executable) blt_set_target_folder(TARGET ${arg_NAME} FOLDER "${arg_FOLDER}") endif() - blt_update_project_sources( TARGET_SOURCES ${arg_SOURCES} ) + blt_update_project_sources( TARGET_SOURCES ${arg_SOURCES} ${arg_HEADERS} ) blt_clean_target(TARGET ${arg_NAME}) @@ -1099,7 +1312,7 @@ macro(blt_print_target_properties) set(_is_blt_registered_target FALSE) string(TOUPPER ${arg_TARGET} _target_upper) - if(BLT_${_target_upper}_IS_REGISTERED_LIBRARY) + if(_BLT_${_target_upper}_IS_REGISTERED_LIBRARY) set(_is_blt_registered_target TRUE) message (STATUS "[${arg_TARGET} property] '${arg_TARGET}' is a blt_registered target") endif() @@ -1121,8 +1334,8 @@ macro(blt_print_target_properties) blt_list_remove_duplicates(TO _property_list) ## For interface targets, filter against whitelist of valid properties - get_property(_targetType TARGET ${arg_TARGET} PROPERTY TYPE) - if(${_targetType} STREQUAL "INTERFACE_LIBRARY") + get_property(_target_type TARGET ${arg_TARGET} PROPERTY TYPE) + if("${_target_type}" STREQUAL "INTERFACE_LIBRARY") blt_filter_list(TO _property_list REGEX "^(INTERFACE_|IMPORTED_LIBNAME_|COMPATIBLE_INTERFACE_|MAP_IMPORTED_CONFIG_)|^(NAME|TYPE|EXPORT_NAME)$" OPERATION "include") @@ -1141,11 +1354,11 @@ macro(blt_print_target_properties) unset(_propval) endif() - ## Additionally, output variables generated via blt_register_target of the form "BLT__*" + ## Additionally, output variables generated via blt_register_target of the form "_BLT__*" if(_is_blt_registered_target) - set(_target_prefix "BLT_${_target_upper}_") + set(_target_prefix "_BLT_${_target_upper}_") - ## Filter to get variables of the form BLT__ and print + ## Filter to get variables of the form _BLT__ and print get_cmake_property(_variable_names VARIABLES) foreach (prop ${_variable_names}) if(prop MATCHES "^${_target_prefix}") diff --git a/cmake/BLTOptions.cmake b/cmake/BLTOptions.cmake index 465059153..edd1e5168 100644 --- a/cmake/BLTOptions.cmake +++ b/cmake/BLTOptions.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) #------------------------------------------------------------------------------ @@ -28,6 +28,7 @@ option(ENABLE_SPHINX "Enables Sphinx support" ON) # Quality option(ENABLE_CLANGQUERY "Enables Clang-query support" ON) +option(ENABLE_CLANGTIDY "Enables clang-tidy support" ON) option(ENABLE_CPPCHECK "Enables Cppcheck support" ON) option(ENABLE_VALGRIND "Enables Valgrind support" ON) @@ -35,6 +36,8 @@ option(ENABLE_VALGRIND "Enables Valgrind support" ON) option(ENABLE_ASTYLE "Enables AStyle support" ON) option(ENABLE_CLANGFORMAT "Enables ClangFormat support" ON) option(ENABLE_UNCRUSTIFY "Enables Uncrustify support" ON) +option(ENABLE_YAPF "Enables Yapf support" ON) +option(ENABLE_CMAKEFORMAT "Enables CMakeFormat support" ON) #------------------------------------------------------------------------------ # Build Options @@ -78,6 +81,7 @@ endif() option(ENABLE_GTEST "Enable Google Test testing support (if ENABLE_TESTS=ON)" ${_CXX_enabled}) option(ENABLE_GMOCK "Enable Google Mock testing support (if ENABLE_TESTS=ON)" OFF) option(ENABLE_FRUIT "Enable Fruit testing support (if ENABLE_TESTS=ON and ENABLE_FORTRAN=ON)" ON) +option(ENABLE_FRUIT_MPI "Enable Fruit MPI testing support (if ENABLE_TESTS=ON and ENABLE_FORTRAN=ON and ENABLE_FRUIT=ON and ENABLE_MPI=ON" OFF) option(ENABLE_GBENCHMARK "Enable Google Benchmark support (if ENABLE_TESTS=ON)" ${ENABLE_BENCHMARKS}) @@ -103,6 +107,11 @@ mark_as_advanced(BLT_ENABLE_MSVC_STATIC_MD_TO_MT) #------------------------------------------------------------------------------ option(ENABLE_FOLDERS "Organize projects using folders (in generators that support this)" OFF) +#------------------------------------------------------------------------------ +# Export/Install Options +#------------------------------------------------------------------------------ +option(BLT_EXPORT_THIRDPARTY "Configure the third-party targets created by BLT to be exportable" OFF) + #------------------------------------------------------------------------------ # Advanced configuration options #------------------------------------------------------------------------------ @@ -142,4 +151,3 @@ mark_as_advanced( BLT_CODE_STYLE_TARGET_NAME BLT_DOCS_TARGET_NAME BLT_RUN_BENCHMARKS_TARGET_NAME ) - diff --git a/cmake/BLTPrivateMacros.cmake b/cmake/BLTPrivateMacros.cmake index 584872400..e7680c6d7 100644 --- a/cmake/BLTPrivateMacros.cmake +++ b/cmake/BLTPrivateMacros.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -93,24 +93,66 @@ function(blt_fix_fortran_openmp_flags target_name) if (ENABLE_FORTRAN AND ENABLE_OPENMP AND BLT_OPENMP_FLAGS_DIFFER) - set(_property_name LINK_FLAGS) - if( ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.13.0" ) - # In CMake 3.13+, LINK_FLAGS was converted to LINK_OPTIONS. - set(_property_name LINK_OPTIONS) - endif() - - get_target_property(target_link_flags ${target_name} ${_property_name}) - if ( target_link_flags ) + # The OpenMP interface library will have been added as a direct + # link dependency instead of via flags + get_target_property(target_link_libs ${target_name} LINK_LIBRARIES) + if ( target_link_libs ) + # Since this is only called on executable targets we can safely convert + # from a "real" target back to a "fake" one as this is a sink vertex in + # the DAG. Only the link flags need to be modified. + list(FIND target_link_libs "openmp" _omp_index) + if(${_omp_index} GREATER -1) + message(STATUS "Fixing OpenMP Flags for target[${target_name}]") + + # Remove openmp from libraries + list(REMOVE_ITEM target_link_libs "openmp") + set_target_properties( ${target_name} PROPERTIES + LINK_LIBRARIES "${target_link_libs}" ) + + # Add openmp compile flags verbatim w/ generator expression + get_target_property(omp_compile_flags openmp INTERFACE_COMPILE_OPTIONS) + target_compile_options(${target_name} PUBLIC ${omp_compile_flags}) + + # Change CXX flags to Fortran flags + + # These are set through blt_add_target_link_flags which needs to use + # the link_libraries for interface libraries in CMake < 3.13 + if( ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.13.0" ) + get_target_property(omp_link_flags openmp INTERFACE_LINK_OPTIONS) + else() + get_target_property(omp_link_flags openmp INTERFACE_LINK_LIBRARIES) + endif() - message(STATUS "Fixing OpenMP Flags for target[${target_name}]") + string( REPLACE "${OpenMP_CXX_FLAGS}" "${OpenMP_Fortran_FLAGS}" + correct_omp_link_flags + "${omp_link_flags}" + ) + if( ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.13.0" ) + target_link_options(${target_name} PRIVATE "${correct_omp_link_flags}") + else() + set_property(TARGET ${target_name} APPEND PROPERTY LINK_FLAGS "${correct_omp_link_flags}") + endif() + endif() - string( REPLACE "${OpenMP_CXX_FLAGS}" "${OpenMP_Fortran_FLAGS}" - correct_link_flags - "${target_link_flags}" - ) + # Handle registered library general case - set_target_properties( ${target_name} PROPERTIES ${_property_name} - "${correct_link_flags}" ) + # OpenMP is an interface library which doesn't have a LINK_FLAGS property + # in versions < 3.13 + set(_property_name LINK_FLAGS) + if( ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.13.0" ) + # In CMake 3.13+, LINK_FLAGS was converted to LINK_OPTIONS. + set(_property_name LINK_OPTIONS) + endif() + get_target_property(target_link_flags ${target_name} ${_property_name}) + if ( target_link_flags ) + + string( REPLACE "${OpenMP_CXX_FLAGS}" "${OpenMP_Fortran_FLAGS}" + correct_link_flags + "${target_link_flags}" + ) + set_target_properties( ${target_name} PROPERTIES ${_property_name} + "${correct_link_flags}" ) + endif() endif() endif() @@ -123,7 +165,8 @@ endfunction() ## ## This macro attempts to find the given executable via either a previously defined ## _EXECUTABLE or using find_program with the given EXECUTABLES. -## if EXECUTABLES is left empty, then NAME is used. +## if EXECUTABLES is left empty, then NAME is used. This macro will only attempt +## to locate the executable if _ENABLED is TRUE. ## ## If successful the following variables will be defined: ## _FOUND @@ -210,40 +253,96 @@ macro(blt_inherit_target_info) message( FATAL_ERROR "Must provide a FROM argument to the 'blt_inherit_target' macro" ) endif() + blt_determine_scope(TARGET ${arg_TO} OUT _scope) + get_target_property(_interface_system_includes ${arg_FROM} INTERFACE_SYSTEM_INCLUDE_DIRECTORIES) if ( _interface_system_includes ) - target_include_directories(${arg_TO} SYSTEM PUBLIC ${_interface_system_includes}) + target_include_directories(${arg_TO} SYSTEM ${_scope} ${_interface_system_includes}) endif() get_target_property(_interface_includes ${arg_FROM} INTERFACE_INCLUDE_DIRECTORIES) if ( _interface_includes ) - target_include_directories(${arg_TO} PUBLIC ${_interface_includes}) + target_include_directories(${arg_TO} ${_scope} ${_interface_includes}) endif() get_target_property(_interface_defines ${arg_FROM} INTERFACE_COMPILE_DEFINITIONS) if ( _interface_defines ) - target_compile_definitions( ${arg_TO} PUBLIC ${_interface_defines}) + target_compile_definitions( ${arg_TO} ${_scope} ${_interface_defines}) + endif() + + if( ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.13.0" ) + get_target_property(_interface_link_options + ${arg_FROM} INTERFACE_LINK_OPTIONS) + if ( _interface_link_options ) + target_link_options( ${arg_TO} ${_scope} ${_interface_link_options}) + endif() + endif() + + get_target_property(_interface_compile_options + ${arg_FROM} INTERFACE_COMPILE_OPTIONS) + if ( _interface_compile_options ) + target_compile_options( ${arg_TO} ${_scope} ${_interface_compile_options}) endif() if ( NOT arg_OBJECT ) get_target_property(_interface_link_directories ${arg_FROM} INTERFACE_LINK_DIRECTORIES) if ( _interface_link_directories ) - target_link_directories( ${arg_TO} PUBLIC ${_interface_link_directories}) + target_link_directories( ${arg_TO} ${_scope} ${_interface_link_directories}) endif() get_target_property(_interface_link_libraries ${arg_FROM} INTERFACE_LINK_LIBRARIES) if ( _interface_link_libraries ) - target_link_libraries( ${arg_TO} PUBLIC ${_interface_link_libraries}) + target_link_libraries( ${arg_TO} ${_scope} ${_interface_link_libraries}) endif() endif() endmacro(blt_inherit_target_info) +##------------------------------------------------------------------------------ +## blt_expand_depends( DEPENDS_ON [dep1 ...] +## RESULT [variable] ) +##------------------------------------------------------------------------------ +macro(blt_expand_depends) + set(options) + set(singleValueArgs RESULT) + set(multiValueArgs DEPENDS_ON) + + # Parse the arguments + cmake_parse_arguments(arg "${options}" "${singleValueArgs}" + "${multiValueArgs}" ${ARGN} ) + + # Expand dependency list + set(_deps_to_process ${arg_DEPENDS_ON}) + set(_expanded_DEPENDS_ON) + while(_deps_to_process) + # Copy the current set of dependencies to process + set(_current_deps_to_process ${_deps_to_process}) + # and add them to the full expanded list + list(APPEND _expanded_DEPENDS_ON ${_deps_to_process}) + # Then clear it so we can check if new ones were added + set(_deps_to_process) + foreach( dependency ${_current_deps_to_process} ) + string(TOUPPER ${dependency} uppercase_dependency ) + if ( DEFINED _BLT_${uppercase_dependency}_DEPENDS_ON ) + foreach(new_dependency ${_BLT_${uppercase_dependency}_DEPENDS_ON}) + # Don't add duplicates + if (NOT ${new_dependency} IN_LIST _expanded_DEPENDS_ON) + list(APPEND _deps_to_process ${new_dependency}) + endif() + endforeach() + endif() + endforeach() + endwhile() + + # Write the output to the requested variable + set(${arg_RESULT} ${_expanded_DEPENDS_ON}) +endmacro() + ##------------------------------------------------------------------------------ ## blt_setup_target( NAME [name] @@ -265,49 +364,51 @@ macro(blt_setup_target) message( FATAL_ERROR "Must provide a NAME argument to the 'blt_setup_target' macro" ) endif() - # Expand dependency list - set(_expanded_DEPENDS_ON ${arg_DEPENDS_ON}) - foreach( i RANGE 50 ) - foreach( dependency ${_expanded_DEPENDS_ON} ) - string(TOUPPER ${dependency} uppercase_dependency ) + # Default to "real" scope, unless it's an interface library + set(_private_scope PRIVATE) + set(_public_scope PUBLIC) + get_target_property(_target_type ${arg_NAME} TYPE) + if("${_target_type}" STREQUAL "INTERFACE_LIBRARY") + set(_private_scope INTERFACE) + set(_public_scope INTERFACE) + endif() - if ( DEFINED BLT_${uppercase_dependency}_DEPENDS_ON ) - foreach(new_dependency ${BLT_${uppercase_dependency}_DEPENDS_ON}) - if (NOT ${new_dependency} IN_LIST _expanded_DEPENDS_ON) - list(APPEND _expanded_DEPENDS_ON ${new_dependency}) - endif() - endforeach() - endif() - endforeach() - endforeach() + # Expand dependency list - avoid "recalculating" if the information already exists + set(_expanded_DEPENDS_ON) + if(NOT "${_target_type}" STREQUAL "INTERFACE_LIBRARY") + get_target_property(_expanded_DEPENDS_ON ${arg_NAME} BLT_EXPANDED_DEPENDENCIES) + endif() + if(NOT _expanded_DEPENDS_ON) + blt_expand_depends(DEPENDS_ON ${arg_DEPENDS_ON} RESULT _expanded_DEPENDS_ON) + endif() # Add dependency's information foreach( dependency ${_expanded_DEPENDS_ON} ) string(TOUPPER ${dependency} uppercase_dependency ) - if ( NOT arg_OBJECT AND BLT_${uppercase_dependency}_IS_OBJECT_LIBRARY ) - target_sources(${arg_NAME} PRIVATE $) + if ( NOT arg_OBJECT AND _BLT_${uppercase_dependency}_IS_OBJECT_LIBRARY ) + target_sources(${arg_NAME} ${_private_scope} $) endif() - if ( DEFINED BLT_${uppercase_dependency}_INCLUDES ) - if ( BLT_${uppercase_dependency}_TREAT_INCLUDES_AS_SYSTEM ) - target_include_directories( ${arg_NAME} SYSTEM PUBLIC - ${BLT_${uppercase_dependency}_INCLUDES} ) + if ( DEFINED _BLT_${uppercase_dependency}_INCLUDES ) + if ( _BLT_${uppercase_dependency}_TREAT_INCLUDES_AS_SYSTEM ) + target_include_directories( ${arg_NAME} SYSTEM ${_public_scope} + ${_BLT_${uppercase_dependency}_INCLUDES} ) else() - target_include_directories( ${arg_NAME} PUBLIC - ${BLT_${uppercase_dependency}_INCLUDES} ) + target_include_directories( ${arg_NAME} ${_public_scope} + ${_BLT_${uppercase_dependency}_INCLUDES} ) endif() endif() - if ( DEFINED BLT_${uppercase_dependency}_FORTRAN_MODULES ) - target_include_directories( ${arg_NAME} PUBLIC - ${BLT_${uppercase_dependency}_FORTRAN_MODULES} ) + if ( DEFINED _BLT_${uppercase_dependency}_FORTRAN_MODULES ) + target_include_directories( ${arg_NAME} ${_public_scope} + ${_BLT_${uppercase_dependency}_FORTRAN_MODULES} ) endif() if ( arg_OBJECT ) # Object libraries need to inherit info from their CMake targets listed # in their LIBRARIES - foreach( _library ${BLT_${uppercase_dependency}_LIBRARIES} ) + foreach( _library ${_BLT_${uppercase_dependency}_LIBRARIES} ) if(TARGET ${_library}) blt_inherit_target_info(TO ${arg_NAME} FROM ${_library} @@ -316,7 +417,7 @@ macro(blt_setup_target) endforeach() endif() - if ( arg_OBJECT OR BLT_${uppercase_dependency}_IS_OBJECT_LIBRARY ) + if ( arg_OBJECT OR _BLT_${uppercase_dependency}_IS_OBJECT_LIBRARY ) # We want object libraries to inherit the vital info but not call # target_link_libraries() otherwise you have to install the object # files associated with the object library which noone wants. @@ -325,34 +426,67 @@ macro(blt_setup_target) FROM ${dependency} OBJECT ${arg_OBJECT}) endif() - elseif (DEFINED BLT_${uppercase_dependency}_LIBRARIES) + elseif (DEFINED _BLT_${uppercase_dependency}_LIBRARIES) # This prevents cmake from adding -l to the # command line for BLT registered libraries which are not # actual CMake targets - if(NOT "${BLT_${uppercase_dependency}_LIBRARIES}" + if(NOT "${_BLT_${uppercase_dependency}_LIBRARIES}" STREQUAL "BLT_NO_LIBRARIES" ) - target_link_libraries( ${arg_NAME} PUBLIC - ${BLT_${uppercase_dependency}_LIBRARIES} ) + target_link_libraries( ${arg_NAME} ${_public_scope} + ${_BLT_${uppercase_dependency}_LIBRARIES} ) endif() else() - target_link_libraries( ${arg_NAME} PUBLIC ${dependency} ) + target_link_libraries( ${arg_NAME} ${_public_scope} ${dependency} ) endif() - if ( DEFINED BLT_${uppercase_dependency}_DEFINES ) - target_compile_definitions( ${arg_NAME} PUBLIC - ${BLT_${uppercase_dependency}_DEFINES} ) + if ( DEFINED _BLT_${uppercase_dependency}_DEFINES ) + target_compile_definitions( ${arg_NAME} ${_public_scope} + ${_BLT_${uppercase_dependency}_DEFINES} ) endif() - if ( DEFINED BLT_${uppercase_dependency}_COMPILE_FLAGS ) + if ( DEFINED _BLT_${uppercase_dependency}_COMPILE_FLAGS ) blt_add_target_compile_flags(TO ${arg_NAME} - FLAGS ${BLT_${uppercase_dependency}_COMPILE_FLAGS} ) + FLAGS ${_BLT_${uppercase_dependency}_COMPILE_FLAGS} ) endif() - if ( NOT arg_OBJECT AND DEFINED BLT_${uppercase_dependency}_LINK_FLAGS ) + if ( NOT arg_OBJECT AND DEFINED _BLT_${uppercase_dependency}_LINK_FLAGS ) blt_add_target_link_flags(TO ${arg_NAME} - FLAGS ${BLT_${uppercase_dependency}_LINK_FLAGS} ) + FLAGS ${_BLT_${uppercase_dependency}_LINK_FLAGS} ) endif() + if(TARGET ${dependency}) + # If it's an interface library CMake doesn't even allow us to query the property + get_target_property(_dep_type ${dependency} TYPE) + if(NOT "${_dep_type}" STREQUAL "INTERFACE_LIBRARY") + # Propagate the overridden linker language, if applicable + get_target_property(_blt_link_lang ${dependency} INTERFACE_BLT_LINKER_LANGUAGE_OVERRIDE) + # TODO: Do we need to worry about overwriting? Should only ever be HIP or CUDA + if(_blt_link_lang) + set_target_properties(${arg_NAME} PROPERTIES INTERFACE_BLT_LINKER_LANGUAGE_OVERRIDE ${_blt_link_lang}) + endif() + endif() + + # Check if a separate device link is needed + if(ENABLE_CUDA AND "${_dep_type}" STREQUAL "OBJECT_LIBRARY") + get_target_property(_device_link ${dependency} CUDA_RESOLVE_DEVICE_SYMBOLS) + if(_device_link AND CUDA_LINK_WITH_NVCC) + set(_dlink_obj "${dependency}_device_link${CMAKE_CUDA_OUTPUT_EXTENSION}") + # Make sure a target wasn't already added + get_source_file_property(_generated ${_dlink_obj} GENERATED) + if(NOT _generated) + # Convert string to list as it will be expanded + string(REPLACE " " ";" _cuda_flags ${CMAKE_CUDA_FLAGS}) + add_custom_command( + OUTPUT ${_dlink_obj} + COMMAND ${CMAKE_CUDA_COMPILER} --device-link ${_cuda_flags} $ -o ${_dlink_obj} + DEPENDS $ + COMMAND_EXPAND_LISTS + ) + endif() + target_sources(${arg_NAME} PRIVATE ${_dlink_obj}) + endif() + endif() + endif() endforeach() endmacro(blt_setup_target) @@ -398,6 +532,9 @@ macro(blt_setup_cuda_target) if (${_depends_on_cuda_runtime} OR ${_depends_on_cuda}) if (CUDA_LINK_WITH_NVCC) set_target_properties( ${arg_NAME} PROPERTIES LINKER_LANGUAGE CUDA) + # This will be propagated up to executable targets that depend on this + # library, which will need the HIP linker + set_target_properties( ${arg_NAME} PROPERTIES INTERFACE_BLT_LINKER_LANGUAGE_OVERRIDE CUDA) endif() endif() @@ -430,9 +567,47 @@ macro(blt_setup_cuda_target) CMAKE_CUDA_CREATE_STATIC_LIBRARY OFF) endif() endif() + + # Replicate the behavior of CMAKE_CUDA_RESOLVE_DEVICE_SYMBOLS + if(${CMAKE_VERSION} VERSION_LESS "3.16.0" AND CMAKE_CUDA_RESOLVE_DEVICE_SYMBOLS) + set_target_properties( ${arg_NAME} PROPERTIES + CUDA_RESOLVE_DEVICE_SYMBOLS ON) + endif() endif() endmacro(blt_setup_cuda_target) +##------------------------------------------------------------------------------ +## blt_cleanup_hip_globals(FROM_TARGET ) +## +## Needed as the SetupHIP macros (specifically, HIP_PREPARE_TARGET_COMMANDS) +## "pollutes" the global HIP_HIPCC_FLAGS with target-specific options. This +## macro removes the target-specific generator expressions from the global flags +## which have already been copied to source-file-specific instances of the +## run_hipcc script. Other global flags in HIP_HIPCC_FLAGS, e.g., those set by +## the user, are left untouched. +##------------------------------------------------------------------------------ +macro(blt_cleanup_hip_globals) + set(options) + set(singleValueArgs FROM_TARGET) + set(multiValueArgs) + + # Parse the arguments + cmake_parse_arguments(arg "${options}" "${singleValueArgs}" + "${multiValueArgs}" ${ARGN} ) + + # Check arguments + if ( NOT DEFINED arg_FROM_TARGET ) + message( FATAL_ERROR "Must provide a FROM_TARGET argument to the 'blt_cleanup_hip_globals' macro") + endif() + + # Remove the compile definitions generator expression + # This must be copied verbatim from HIP_PREPARE_TARGET_COMMANDS, + # which would have just added it to HIP_HIPCC_FLAGS + set(_defines_genexpr "$") + set(_defines_flags_genexpr "$<$:-D$>") + list(REMOVE_ITEM HIP_HIPCC_FLAGS ${_defines_flags_genexpr}) +endmacro(blt_cleanup_hip_globals) + ##------------------------------------------------------------------------------ ## blt_add_hip_library(NAME ## SOURCES [source1 [source2 ...]] @@ -486,22 +661,33 @@ macro(blt_add_hip_library) HIP_SOURCE_PROPERTY_FORMAT TRUE) hip_add_library( ${arg_NAME} ${arg_SOURCES} ${arg_LIBRARY_TYPE} ) + blt_cleanup_hip_globals(FROM_TARGET ${arg_NAME}) + # Link to the hip_runtime target so it gets pulled in by targets + # depending on this target + target_link_libraries(${arg_NAME} PUBLIC hip_runtime) else() add_library( ${arg_NAME} ${arg_LIBRARY_TYPE} ${arg_SOURCES} ${arg_HEADERS} ) endif() + if (${_depends_on_hip_runtime} OR ${_depends_on_hip}) + # This will be propagated up to executable targets that depend on this + # library, which will need the HIP linker + set_target_properties( ${arg_NAME} PROPERTIES INTERFACE_BLT_LINKER_LANGUAGE_OVERRIDE HIP) + endif() + endmacro(blt_add_hip_library) ##------------------------------------------------------------------------------ ## blt_add_hip_executable(NAME ## SOURCES [source1 [source2 ...]] +## HEADERS [header1 [header2 ...]] ## DEPENDS_ON [dep1 ...] ##------------------------------------------------------------------------------ macro(blt_add_hip_executable) set(options) set(singleValueArgs NAME) - set(multiValueArgs SOURCES DEPENDS_ON) + set(multiValueArgs HEADERS SOURCES DEPENDS_ON) # Parse the arguments cmake_parse_arguments(arg "${options}" "${singleValueArgs}" @@ -528,6 +714,20 @@ macro(blt_add_hip_executable) set(_depends_on_hip_runtime TRUE) endif() + blt_expand_depends(DEPENDS_ON ${arg_DEPENDS_ON} RESULT _expanded_DEPENDS_ON) + foreach( dependency ${_expanded_DEPENDS_ON} ) + if(TARGET ${dependency}) + get_target_property(_dep_type ${dependency} TYPE) + if(NOT "${_dep_type}" STREQUAL "INTERFACE_LIBRARY") + # Propagate the overridden linker language, if applicable + get_target_property(_blt_link_lang ${dependency} INTERFACE_BLT_LINKER_LANGUAGE_OVERRIDE) + if(_blt_link_lang STREQUAL "HIP") + set(_depends_on_hip_runtime TRUE) + endif() + endif() + endif() + endforeach() + if (${_depends_on_hip} OR ${_depends_on_hip_runtime}) # if hip is in depends_on, flag each file's language as HIP # instead of leaving it up to CMake to decide @@ -543,26 +743,35 @@ macro(blt_add_hip_executable) HIP_SOURCE_PROPERTY_FORMAT TRUE) hip_add_executable( ${arg_NAME} ${arg_SOURCES} ) + blt_cleanup_hip_globals(FROM_TARGET ${arg_NAME}) else() - add_executable( ${arg_NAME} ${arg_SOURCES} ) + add_executable( ${arg_NAME} ${arg_SOURCES} ${arg_HEADERS}) endif() + # Save the expanded dependencies to avoid recalculating later + set_target_properties(${arg_NAME} PROPERTIES + BLT_EXPANDED_DEPENDENCIES "${_expanded_DEPENDS_ON}") + endmacro(blt_add_hip_executable) ##------------------------------------------------------------------------------ ## blt_split_source_list_by_language( SOURCES ## C_LIST -## Fortran_LIST ) +## Fortran_LIST +## Python_LIST ) +## CMAKE_LIST ) ## -## Filters source list by file extension into C/C++ and Fortran source lists -## based on BLT_C_FILE_EXTS and BLT_Fortran_FILE_EXTS (global BLT variables). -## Files with no extension or generator expressions that are not object libraries -## (of the form "$") will throw fatal errors. -##------------------------------------------------------------------------------ +## Filters source list by file extension into C/C++, Fortran, Python, and +## CMake source lists based on BLT_C_FILE_EXTS, BLT_Fortran_FILE_EXTS, +## and BLT_CMAKE_FILE_EXTS (global BLT variables). Files named +## "CMakeLists.txt" are also filtered here. Files with no extension +## or generator expressions that are not object libraries (of the form +## "$") will throw fatal errors. +## ------------------------------------------------------------------------------ macro(blt_split_source_list_by_language) set(options) - set(singleValueArgs C_LIST Fortran_LIST) + set(singleValueArgs C_LIST Fortran_LIST Python_LIST CMAKE_LIST) set(multiValueArgs SOURCES) # Parse the arguments @@ -584,23 +793,33 @@ macro(blt_split_source_list_by_language) message(FATAL_ERROR "blt_split_source_list_by_language macro does not support generator expressions because CMake does not provide a way to evaluate them. Given generator expression: ${_file}") endif() - get_filename_component(_ext ${_file} EXT) + get_filename_component(_ext "${_file}" EXT) if("${_ext}" STREQUAL "") message(FATAL_ERROR "blt_split_source_list_by_language given source file with no extension: ${_file}") endif() - string(TOLOWER ${_ext} _ext_lower) + get_filename_component(_name "${_file}" NAME) + + string(TOLOWER "${_ext}" _ext_lower) - if(${_ext_lower} IN_LIST BLT_C_FILE_EXTS) + if("${_ext_lower}" IN_LIST BLT_C_FILE_EXTS) if (DEFINED arg_C_LIST) - list(APPEND ${arg_C_LIST} ${_file}) + list(APPEND ${arg_C_LIST} "${_file}") endif() - elseif(${_ext_lower} IN_LIST BLT_Fortran_FILE_EXTS) + elseif("${_ext_lower}" IN_LIST BLT_Fortran_FILE_EXTS) if (DEFINED arg_Fortran_LIST) - list(APPEND ${arg_Fortran_LIST} ${_file}) + list(APPEND ${arg_Fortran_LIST} "${_file}") + endif() + elseif("${_ext_lower}" IN_LIST BLT_Python_FILE_EXTS) + if (DEFINED arg_Python_LIST) + list(APPEND ${arg_Python_LIST} "${_file}") + endif() + elseif("${_ext_lower}" IN_LIST BLT_CMAKE_FILE_EXTS OR "${_name}" STREQUAL "CMakeLists.txt") + if (DEFINED arg_CMAKE_LIST) + list(APPEND ${arg_CMAKE_LIST} "${_file}") endif() else() - message(FATAL_ERROR "blt_split_source_list_by_language given source file with unknown file extension. Add the missing extension to the corresponding list (BLT_C_FILE_EXTS or BLT_Fortran_FILE_EXTS).\n Unknown file: ${_file}") + message(FATAL_ERROR "blt_split_source_list_by_language given source file with unknown file extension. Add the missing extension to the corresponding list (BLT_C_FILE_EXTS, BLT_Fortran_FILE_EXTS, BLT_Python_FILE_EXTS, or BLT_CMAKE_FILE_EXTS).\n Unknown file: ${_file}") endif() endforeach() diff --git a/cmake/SetupCodeChecks.cmake b/cmake/SetupCodeChecks.cmake index 4e47c4dc7..8e3facda9 100644 --- a/cmake/SetupCodeChecks.cmake +++ b/cmake/SetupCodeChecks.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) #------------------------------------------------------------------------------ @@ -9,7 +9,10 @@ add_custom_target(${BLT_CODE_CHECK_TARGET_NAME}) add_custom_target(${BLT_CODE_STYLE_TARGET_NAME}) +set(_BLT_STYLE_VERSION_WARNING_ISSUED FALSE CACHE BOOL "Limits BLT issuing more than one warning for style version") + if(ASTYLE_FOUND) + set(BLT_REQUIRED_ASTYLE_VERSION "" CACHE STRING "Required version of astyle") # targets for verifying formatting add_custom_target(astyle_check) add_dependencies(${BLT_CODE_CHECK_TARGET_NAME} astyle_check) @@ -20,6 +23,7 @@ if(ASTYLE_FOUND) endif() if(CLANGFORMAT_FOUND) + set(BLT_REQUIRED_CLANGFORMAT_VERSION "" CACHE STRING "Required version of clang-format") # targets for verifying formatting add_custom_target(clangformat_check) add_dependencies(${BLT_CODE_CHECK_TARGET_NAME} clangformat_check) @@ -30,6 +34,7 @@ if(CLANGFORMAT_FOUND) endif() if(UNCRUSTIFY_FOUND) + set(BLT_REQUIRED_UNCRUSTIFY_VERSION "" CACHE STRING "Required version of uncrustify") # targets for verifying formatting add_custom_target(uncrustify_check) add_dependencies(${BLT_CODE_CHECK_TARGET_NAME} uncrustify_check) @@ -39,6 +44,28 @@ if(UNCRUSTIFY_FOUND) add_dependencies(${BLT_CODE_STYLE_TARGET_NAME} uncrustify_style) endif() +if(YAPF_FOUND) + set(BLT_REQUIRED_YAPF_VERSION "" CACHE STRING "Required version of yapf") + # targets for verifying formatting + add_custom_target(yapf_check) + add_dependencies(${BLT_CODE_CHECK_TARGET_NAME} yapf_check) + + # targets for modifying formatting + add_custom_target(yapf_style) + add_dependencies(${BLT_CODE_STYLE_TARGET_NAME} yapf_style) +endif() + +if(CMAKEFORMAT_FOUND) + set(BLT_REQUIRED_CMAKEFORMAT_VERSION "" CACHE STRING "Required version of cmake-format") + # targets for verifying formatting + add_custom_target(cmakeformat_check) + add_dependencies(${BLT_CODE_CHECK_TARGET_NAME} cmakeformat_check) + + # targets for modifying formatting + add_custom_target(cmakeformat_style) + add_dependencies(${BLT_CODE_STYLE_TARGET_NAME} cmakeformat_style) +endif() + if(CPPCHECK_FOUND) add_custom_target(cppcheck_check) add_dependencies(${BLT_CODE_CHECK_TARGET_NAME} cppcheck_check) @@ -55,11 +82,16 @@ if(CLANGQUERY_FOUND) add_dependencies(${BLT_CODE_CHECK_TARGET_NAME} clang_query_check) endif() +if(CLANGTIDY_FOUND) + add_custom_target(clang_tidy_check) + add_dependencies(${BLT_CODE_CHECK_TARGET_NAME} clang_tidy_check) +endif() + # Code check targets should only be run on demand foreach(target - check uncrustify_check astyle_check clangformat_check cppcheck_check - style uncrustify_style astyle_style clangformat_style - clang_query_check interactive_clang_query_check) + check cmakeformat_check yapf_check uncrustify_check astyle_check clangformat_check cppcheck_check + style cmakeformat_style yapf_style uncrustify_style astyle_style clangformat_style + clang_query_check interactive_clang_query_check clang_tidy_check) if(TARGET ${target}) set_property(TARGET ${target} PROPERTY EXCLUDE_FROM_ALL TRUE) set_property(TARGET ${target} PROPERTY EXCLUDE_FROM_DEFAULT_BUILD TRUE) @@ -73,7 +105,10 @@ endforeach() ## ASTYLE_CFG_FILE ## CLANGFORMAT_CFG_FILE ## UNCRUSTIFY_CFG_FILE -## CPPCHECK_FLAGS ) +## YAPF_CFG_FILE +## CMAKEFORMAT_CFG_FILE +## CPPCHECK_FLAGS +## CLANGQUERY_CHECKER_DIRECTORIES [dir1 [dir2]]) ## ## This macro adds all enabled code check targets for the given SOURCES. It ## filters checks based on file extensions. @@ -82,8 +117,8 @@ endforeach() macro(blt_add_code_checks) set(options ) - set(singleValueArgs PREFIX ASTYLE_CFG_FILE CLANGFORMAT_CFG_FILE UNCRUSTIFY_CFG_FILE) - set(multiValueArgs SOURCES CPPCHECK_FLAGS) + set(singleValueArgs PREFIX ASTYLE_CFG_FILE CLANGFORMAT_CFG_FILE UNCRUSTIFY_CFG_FILE YAPF_CFG_FILE CMAKEFORMAT_CFG_FILE) + set(multiValueArgs SOURCES CPPCHECK_FLAGS CLANGQUERY_CHECKER_DIRECTORIES) cmake_parse_arguments(arg "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN}) @@ -113,16 +148,31 @@ macro(blt_add_code_checks) # Generate source lists based on language set(_c_sources) set(_f_sources) + set(_py_sources) + set(_cmake_sources) blt_split_source_list_by_language(SOURCES ${_rel_sources} C_LIST _c_sources - Fortran_LIST _f_sources) - - # Check that at most one formatting config file was supplied - if (DEFINED arg_UNCRUSTIFY_CFG_FILE AND DEFINED arg_ASTYLE_CFG_FILE) - message(FATAL_ERROR - "blt_add_code_checks macro does not support multiple " - "style config parameters within the same invocation. " - "Both UNCRUSTIFY_CFG_FILE and ASTYLE_CFG_FILE were supplied.") + Fortran_LIST _f_sources + Python_LIST _py_sources + CMAKE_LIST _cmake_sources) + + # Check that no more than one formatting config file was supplied + # for C-style languages. + set(_c_formatter_cfgs_supplied) + foreach (_c_formatter ASTYLE UNCRUSTIFY CLANGFORMAT) + if (DEFINED arg_${_c_formatter}_CFG_FILE) + list(APPEND _c_formatter_cfgs_supplied ${_c_formatter}_CFG_FILE) + endif() + endforeach() + list(LENGTH _c_formatter_cfgs_supplied _num_c_formatter_cfgs_supplied) + if (_num_c_formatter_cfgs_supplied GREATER 1) + message(FATAL_ERROR + "blt_add_code_checks macro does not support multiple " + "style config parameters within the same invocation. " + "At most one of ASTYLE_CFG_FILE, CLANGFORMAT_CFG_FILE, " + "and UNCRUSTIFY_CFG_FILE may be supplied. " + "The following style config parameters were supplied: " + ${_c_formatter_cfgs_supplied}) endif() # Add code checks @@ -185,6 +235,44 @@ macro(blt_add_code_checks) SRC_FILES ${_c_sources} ) endif() + if (YAPF_FOUND AND DEFINED arg_YAPF_CFG_FILE) + set(_check_target_name ${arg_PREFIX}_yapf_check) + blt_error_if_target_exists(${_check_target_name} ${_error_msg}) + set(_style_target_name ${arg_PREFIX}_yapf_style) + blt_error_if_target_exists(${_style_target_name} ${_error_msg}) + + blt_add_yapf_target( NAME ${_check_target_name} + MODIFY_FILES FALSE + CFG_FILE ${arg_YAPF_CFG_FILE} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + SRC_FILES ${_py_sources} ) + + blt_add_yapf_target( NAME ${_style_target_name} + MODIFY_FILES TRUE + CFG_FILE ${arg_YAPF_CFG_FILE} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + SRC_FILES ${_py_sources} ) + endif() + + if (CMAKEFORMAT_FOUND AND DEFINED arg_CMAKEFORMAT_CFG_FILE) + set(_check_target_name ${arg_PREFIX}_cmakeformat_check) + blt_error_if_target_exists(${_check_target_name} ${_error_msg}) + set(_style_target_name ${arg_PREFIX}_cmakeformat_style) + blt_error_if_target_exists(${_style_target_name} ${_error_msg}) + + blt_add_cmakeformat_target( NAME ${_check_target_name} + MODIFY_FILES FALSE + CFG_FILE ${arg_CMAKEFORMAT_CFG_FILE} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + SRC_FILES ${_cmake_sources} ) + + blt_add_cmakeformat_target( NAME ${_style_target_name} + MODIFY_FILES TRUE + CFG_FILE ${arg_CMAKEFORMAT_CFG_FILE} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + SRC_FILES ${_cmake_sources} ) + endif() + if (CPPCHECK_FOUND) set(_cppcheck_target_name ${arg_PREFIX}_cppcheck_check) blt_error_if_target_exists(${_cppcheck_target_name} ${_error_msg}) @@ -195,23 +283,44 @@ macro(blt_add_code_checks) PREPEND_FLAGS ${arg_CPPCHECK_FLAGS}) endif() - if (CLANGQUERY_FOUND) + # Append possible checker directories and only enable clang-query if at least one is provided + set(_clangquery_checker_directories) + if (DEFINED arg_CLANGQUERY_CHECKER_DIRECTORIES) + list(APPEND _clangquery_checker_directories ${arg_CLANGQUERY_CHECKER_DIRECTORIES}) + endif() + if (DEFINED BLT_CLANG_QUERY_CHECKER_DIRECTORIES) + list(APPEND _clangquery_checker_directories ${BLT_CLANG_QUERY_CHECKER_DIRECTORIES}) + endif() + blt_list_remove_duplicates(TO _clangquery_checker_directories) + list(LENGTH _clangquery_checker_directories _len) + + if (CLANGQUERY_FOUND AND (_len GREATER 0)) set(_clang_query_target_name ${arg_PREFIX}_clang_query_check) blt_error_if_target_exists(${_clang_query_target_name} ${_error_msg}) - blt_add_clang_query_target( NAME ${_clang_query_target_name} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - SRC_FILES ${_c_sources}) + blt_add_clang_query_target( NAME ${_clang_query_target_name} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + SRC_FILES ${_c_sources} + CHECKER_DIRECTORIES ${_clangquery_checker_directories}) + endif() + + if (CLANGTIDY_FOUND) + set(_clang_tidy_target_name ${arg_PREFIX}_clang_tidy_check) + blt_error_if_target_exists(${_clang_tidy_target_name} ${_error_msg}) + blt_add_clang_tidy_target( NAME ${_clang_tidy_target_name} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + SRC_FILES ${_c_sources}) endif() endmacro(blt_add_code_checks) ##----------------------------------------------------------------------------- -## blt_add_clang_query_target( NAME -## WORKING_DIRECTORY -## COMMENT -## CHECKERS -## DIE_ON_MATCH -## SRC_FILES [FILE1 [FILE2 ...]] ) +## blt_add_clang_query_target( NAME +## WORKING_DIRECTORY +## COMMENT +## CHECKERS +## DIE_ON_MATCH +## SRC_FILES [FILE1 [FILE2 ...]] +## CHECKER_DIRECTORIES [dir1 [dir2]]) ## ## Creates a new target with the given NAME for running clang_query over the given SRC_FILES ##----------------------------------------------------------------------------- @@ -221,7 +330,7 @@ macro(blt_add_clang_query_target) ## parse the arguments to the macro set(options) set(singleValueArgs NAME COMMENT WORKING_DIRECTORY DIE_ON_MATCH) - set(multiValueArgs SRC_FILES CHECKERS) + set(multiValueArgs SRC_FILES CHECKERS CHECKER_DIRECTORIES) cmake_parse_arguments(arg "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN} ) @@ -240,10 +349,26 @@ macro(blt_add_clang_query_target) else() set(_wd ${CMAKE_CURRENT_SOURCE_DIR}) endif() - + + # Append possible checker directories and only enable clang-query if at least one is provided + set(_checker_directories) + if (DEFINED arg_CHECKER_DIRECTORIES) + list(APPEND _checker_directories ${arg_CHECKER_DIRECTORIES}) + endif() + if (DEFINED BLT_CLANG_QUERY_CHECKER_DIRECTORIES) + list(APPEND _checker_directories ${BLT_CLANG_QUERY_CHECKER_DIRECTORIES}) + endif() + blt_list_remove_duplicates(TO _checker_directories) + list(LENGTH _checker_directories _len) + + if (_len EQUAL 0) + message(FATAL_ERROR "blt_add_clang_query_target requires either CLANGQUERY_CHECKER_DIRECTORIES parameter" + "or variable BLT_CLANG_QUERY_CHECKER_DIRECTORIES defined.") + endif() + set(interactive_target_name interactive_${arg_NAME}) set(CLANG_QUERY_HELPER_SCRIPT ${BLT_ROOT_DIR}/cmake/clang-query-wrapper.py) - set(CLANG_QUERY_HELPER_COMMAND python ${CLANG_QUERY_HELPER_SCRIPT} --clang-query ${CLANGQUERY_EXECUTABLE} --checker-directories ${BLT_CLANG_QUERY_CHECKER_DIRECTORIES} --compilation-database-path ${CMAKE_BINARY_DIR}) + set(CLANG_QUERY_HELPER_COMMAND python ${CLANG_QUERY_HELPER_SCRIPT} --clang-query ${CLANGQUERY_EXECUTABLE} --checker-directories ${_checker_directories} --compilation-database-path ${CMAKE_BINARY_DIR}) if(arg_DIE_ON_MATCH) set(CLANG_QUERY_HELPER_COMMAND ${CLANG_QUERY_HELPER_COMMAND} --die-on-match) @@ -279,6 +404,71 @@ macro(blt_add_clang_query_target) endif() endmacro(blt_add_clang_query_target) +##----------------------------------------------------------------------------- +## blt_add_clang_tidy_target( NAME +## WORKING_DIRECTORY +## COMMENT +## CHECKS +## FIX +## SRC_FILES [FILE1 [FILE2 ...]] ) +## +## Creates a new target with the given NAME for running clang-tidy over the given SRC_FILES +##----------------------------------------------------------------------------- +macro(blt_add_clang_tidy_target) + if(CLANGTIDY_FOUND) + + ## parse the arguments to the macro + set(options) + set(singleValueArgs NAME COMMENT WORKING_DIRECTORY FIX) + set(multiValueArgs SRC_FILES CHECKS) + + cmake_parse_arguments(arg + "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN} ) + + # Check required parameters + if(NOT DEFINED arg_NAME) + message(FATAL_ERROR "blt_add_clang_tidy_target requires a NAME parameter") + endif() + + if(NOT DEFINED arg_SRC_FILES) + message(FATAL_ERROR "blt_add_clang_tidy_target requires a SRC_FILES parameter") + endif() + + if(DEFINED arg_WORKING_DIRECTORY) + set(_wd ${arg_WORKING_DIRECTORY}) + else() + set(_wd ${CMAKE_CURRENT_SOURCE_DIR}) + endif() + + set(CLANG_TIDY_HELPER_SCRIPT ${BLT_ROOT_DIR}/cmake/run-clang-tidy.py) + set(CLANG_TIDY_HELPER_COMMAND ${CLANG_TIDY_HELPER_SCRIPT} -clang-tidy-binary=${CLANGTIDY_EXECUTABLE} -p ${CMAKE_BINARY_DIR}) + + if(arg_FIX) + set(CLANG_TIDY_HELPER_COMMAND ${CLANG_TIDY_HELPER_COMMAND} -fix) + endif() + + if(DEFINED arg_CHECKS) + STRING(REGEX REPLACE " " "," CHECK_ARG_STRING ${arg_CHECKS}) + add_custom_target(${arg_NAME} + COMMAND ${CLANG_TIDY_HELPER_COMMAND} -checks=${CHECK_ARG_STRING} ${arg_SRC_FILES} + WORKING_DIRECTORY ${_wd} + COMMENT "${arg_COMMENT}Running specified clang-tidy source code static analysis checks.") + else() #DEFINED CHECKERS + add_custom_target(${arg_NAME} + COMMAND ${CLANG_TIDY_HELPER_COMMAND} ${arg_SRC_FILES} + WORKING_DIRECTORY ${_wd} + COMMENT "${arg_COMMENT}Running default clang-tidy source code static analysis checks.") + endif() + + # hook our new target into the proper dependency chain + add_dependencies(clang_tidy_check ${arg_NAME}) + + # Code check targets should only be run on demand + set_property(TARGET ${arg_NAME} PROPERTY EXCLUDE_FROM_ALL TRUE) + set_property(TARGET ${arg_NAME} PROPERTY EXCLUDE_FROM_DEFAULT_BUILD TRUE) + endif() +endmacro(blt_add_clang_tidy_target) + ##----------------------------------------------------------------------------- ## blt_add_cppcheck_target( NAME @@ -376,19 +566,31 @@ macro(blt_add_astyle_target) set(_generate_target TRUE) + # Check the version -- output is of the form "Artistic Style Version X.Y.Z" + execute_process( + COMMAND ${ASTYLE_EXECUTABLE} --version + OUTPUT_VARIABLE _version_str + ERROR_VARIABLE _version_str + OUTPUT_STRIP_TRAILING_WHITESPACE ) + string(REGEX MATCH "([0-9]+(\\.)?)+$" _astyle_version ${_version_str}) + + if(BLT_REQUIRED_ASTYLE_VERSION) + # The user may only specify a part of the version (e.g. just the maj ver) + # so check for substring + string(FIND "${_astyle_version}" ${BLT_REQUIRED_ASTYLE_VERSION} VERSION_POS) + if (NOT VERSION_POS EQUAL 0) + set(_generate_target FALSE) + if(NOT _BLT_STYLE_VERSION_WARNING_ISSUED) + message(WARNING "blt_add_astyle_target: astyle '${BLT_REQUIRED_ASTYLE_VERSION}' is required, found '${_astyle_version}'. Disabling 'style' build target.") + set(_BLT_STYLE_VERSION_WARNING_ISSUED TRUE CACHE BOOL "Limits BLT issuing more than one warning for style version" FORCE) + endif() + endif() + endif() + if(${arg_MODIFY_FILES}) set(MODIFY_FILES_FLAG --suffix=none) else() set(MODIFY_FILES_FLAG --dry-run) - - # Check the version -- output is of the form "Artistic Style Version X.Y.Z" - execute_process( - COMMAND ${ASTYLE_EXECUTABLE} --version - OUTPUT_VARIABLE _version_str - ERROR_VARIABLE _version_str - OUTPUT_STRIP_TRAILING_WHITESPACE ) - string(REGEX MATCH "([0-9]+(\\.)?)+$" _astyle_version ${_version_str}) - # Skip 'check' target if version is not high enough if(_astyle_version VERSION_LESS 2.05) set(_generate_target FALSE) @@ -476,10 +678,29 @@ macro(blt_add_clangformat_target) set(_generate_target TRUE) - # Copy config file to given working directory since ClangFormat doesn't support pointing to one - configure_file(${arg_CFG_FILE} ${arg_WORKING_DIRECTORY}/.clang-format COPYONLY) + # If a required version was set, check it + if(BLT_REQUIRED_CLANGFORMAT_VERSION) + execute_process(COMMAND ${CLANGFORMAT_EXECUTABLE} --version + OUTPUT_VARIABLE _version_str + OUTPUT_STRIP_TRAILING_WHITESPACE) + # The version number is the last token - can contain non-numeric + string(REGEX MATCH "([0-9a-zA-Z\\-]+(\\.)?)+$" _clangformat_version ${_version_str}) + # The user may only specify a part of the version (e.g. just the maj ver) + # so check for substring + string(FIND "${_clangformat_version}" ${BLT_REQUIRED_CLANGFORMAT_VERSION} VERSION_POS) + if (NOT VERSION_POS EQUAL 0) + set(_generate_target FALSE) + if (NOT _BLT_STYLE_VERSION_WARNING_ISSUED) + message(WARNING "blt_add_clangformat_target: clang-format '${BLT_REQUIRED_CLANGFORMAT_VERSION}'' is required, found '${_clangformat_version}'. Disabling 'style' build target.") + set(_BLT_STYLE_VERSION_WARNING_ISSUED TRUE CACHE BOOL "Limits BLT issuing more than one warning for style version" FORCE) + endif() + endif() + endif() if(_generate_target) + # Copy config file to given working directory since ClangFormat doesn't support pointing to one + configure_file(${arg_CFG_FILE} ${arg_WORKING_DIRECTORY}/.clang-format COPYONLY) + # ClangFormat does not support --dry-run until version 10 which isn't on many machines. # For now, use run-clang-format for dry running purposes. if(${arg_MODIFY_FILES}) @@ -557,18 +778,31 @@ macro(blt_add_uncrustify_target) set(_generate_target TRUE) + # Check the version -- output is of the form "uncrustify X.Y.Z" + execute_process( + COMMAND ${UNCRUSTIFY_EXECUTABLE} --version + OUTPUT_VARIABLE _version_str + OUTPUT_STRIP_TRAILING_WHITESPACE ) + string(REGEX MATCH "([0-9]+(\\.)?)+(_[a-zA-Z])?" _uncrustify_version ${_version_str}) + + if(BLT_REQUIRED_UNCRUSTIFY_VERSION) + # The user may only specify a part of the version (e.g. just the maj ver) + # so check for substring + string(FIND "${_uncrustify_version}" ${BLT_REQUIRED_UNCRUSTIFY_VERSION} VERSION_POS) + if (NOT VERSION_POS EQUAL 0) + set(_generate_target FALSE) + if (NOT _BLT_STYLE_VERSION_WARNING_ISSUED) + message(WARNING "blt_add_uncrustify_target: uncrustify '${BLT_REQUIRED_UNCRUSTIFY_VERSION}' is required, found '${_uncrustify_version}'. Disabling 'style' build target.") + set(_BLT_STYLE_VERSION_WARNING_ISSUED TRUE CACHE BOOL "Limits BLT issuing more than one warning for style version" FORCE) + endif() + endif() + endif() + if(${arg_MODIFY_FILES}) set(MODIFY_FILES_FLAG --replace;--no-backup) else() set(MODIFY_FILES_FLAG "--check") - # Check the version -- output is of the form "uncrustify X.Y.Z" - execute_process( - COMMAND ${UNCRUSTIFY_EXECUTABLE} --version - OUTPUT_VARIABLE _version_str - OUTPUT_STRIP_TRAILING_WHITESPACE ) - string(REGEX MATCH "([0-9]+(\\.)?)+(_[a-zA-Z])?" _uncrustify_version ${_version_str}) - # Skip 'check' target if version is not high enough if(_uncrustify_version VERSION_LESS 0.61) set(_generate_target FALSE) @@ -576,7 +810,7 @@ macro(blt_add_uncrustify_target) " for style check targets. " " Current uncrustify executable: '${UNCRUSTIFY_EXECUTABLE}' " " Current uncrustify version is: ${_uncrustify_version}." ) - endif() + endif() endif() if(_generate_target) @@ -599,3 +833,195 @@ macro(blt_add_uncrustify_target) endif() endmacro(blt_add_uncrustify_target) + + +##------------------------------------------------------------------------------ +## blt_add_yapf_target( NAME +## MODIFY_FILES [TRUE | FALSE (default)] +## CFG_FILE +## PREPEND_FLAGS +## APPEND_FLAGS +## COMMENT +## WORKING_DIRECTORY +## SRC_FILES [FILE1 [FILE2 ...]] ) +## +## Creates a new target with the given NAME for running yapf over the given SRC_FILES. +##------------------------------------------------------------------------------ +macro(blt_add_yapf_target) + + ## parse the arguments to the macro + set(options) + set(singleValueArgs NAME MODIFY_FILES CFG_FILE COMMENT WORKING_DIRECTORY) + set(multiValueArgs SRC_FILES PREPEND_FLAGS APPEND_FLAGS) + + cmake_parse_arguments(arg + "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN} ) + + # Check/Set required parameters + if(NOT DEFINED arg_NAME) + message(FATAL_ERROR "blt_add_yapf_target requires a NAME parameter") + endif() + + if(NOT DEFINED arg_CFG_FILE) + message(FATAL_ERROR "blt_add_yapf_target requires a CFG_FILE parameter") + endif() + + if(NOT DEFINED arg_SRC_FILES) + message(FATAL_ERROR "blt_add_yapf_target requires a SRC_FILES parameter") + endif() + + if(NOT DEFINED arg_MODIFY_FILES) + set(arg_MODIFY_FILES FALSE) + endif() + + if(DEFINED arg_WORKING_DIRECTORY) + set(_wd ${arg_WORKING_DIRECTORY}) + else() + set(_wd ${CMAKE_CURRENT_SOURCE_DIR}) + endif() + + set(_generate_target TRUE) + + # Check the version -- output is of the form "yapf X.Y.Z" + execute_process( + COMMAND ${YAPF_EXECUTABLE} --version + OUTPUT_VARIABLE _version_str + ERROR_VARIABLE _version_str + OUTPUT_STRIP_TRAILING_WHITESPACE ) + string(REGEX MATCH "([0-9]+(\\.)?)+$" _yapf_version ${_version_str}) + + if(BLT_REQUIRED_YAPF_VERSION) + # The user may only specify a part of the version (e.g. just the maj ver) + # so check for substring + string(FIND "${_yapf_version}" ${BLT_REQUIRED_YAPF_VERSION} VERSION_POS) + if (NOT VERSION_POS EQUAL 0) + set(_generate_target FALSE) + if (NOT _BLT_STYLE_VERSION_WARNING_ISSUED) + message(WARNING "blt_add_yapf_target: yapf ${BLT_REQUIRED_YAPF_VERSION} is required, found ${_yapf_version}. Disabling 'style' build target.") + set(_BLT_STYLE_VERSION_WARNING_ISSUED TRUE CACHE BOOL "Limits BLT issuing more than one warning for style version" FORCE) + endif() + endif() + endif() + + if(${arg_MODIFY_FILES}) + set(MODIFY_FILES_FLAG --in-place) + else() + set(MODIFY_FILES_FLAG --diff) + endif() + + if(_generate_target) + add_custom_target( + ${arg_NAME} + COMMAND ${YAPF_EXECUTABLE} ${arg_PREPEND_FLAGS} + --style ${arg_CFG_FILE} ${MODIFY_FILES_FLAG} ${arg_SRC_FILES} ${arg_APPEND_FLAGS} + WORKING_DIRECTORY ${_wd} + COMMENT "${arg_COMMENT}Running Yapf source code formatting checks.") + + # Hook our new target into the proper dependency chain + if(${arg_MODIFY_FILES}) + add_dependencies(yapf_style ${arg_NAME}) + else() + add_dependencies(yapf_check ${arg_NAME}) + endif() + + # Code formatting targets should only be run on demand + set_property(TARGET ${arg_NAME} PROPERTY EXCLUDE_FROM_ALL TRUE) + set_property(TARGET ${arg_NAME} PROPERTY EXCLUDE_FROM_DEFAULT_BUILD TRUE) + endif() +endmacro(blt_add_yapf_target) + + +##------------------------------------------------------------------------------ +## blt_add_cmakeformat_target( NAME +## MODIFY_FILES [TRUE | FALSE (default)] +## CFG_FILE +## PREPEND_FLAGS +## APPEND_FLAGS +## COMMENT +## WORKING_DIRECTORY +## SRC_FILES [FILE1 [FILE2 ...]] ) +## +## Creates a new target with the given NAME for running cmake-format over the given SRC_FILES. +##------------------------------------------------------------------------------ +macro(blt_add_cmakeformat_target) + + ## parse the arguments to the macro + set(options) + set(singleValueArgs NAME MODIFY_FILES CFG_FILE COMMENT WORKING_DIRECTORY) + set(multiValueArgs SRC_FILES PREPEND_FLAGS APPEND_FLAGS) + + cmake_parse_arguments(arg + "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN} ) + + # Check/Set required parameters + if(NOT DEFINED arg_NAME) + message(FATAL_ERROR "blt_add_cmakeformat_target requires a NAME parameter") + endif() + + if(NOT DEFINED arg_CFG_FILE) + message(FATAL_ERROR "blt_add_cmakeformat_target requires a CFG_FILE parameter") + endif() + + if(NOT DEFINED arg_SRC_FILES) + message(FATAL_ERROR "blt_add_cmakeformat_target requires a SRC_FILES parameter") + endif() + + if(NOT DEFINED arg_MODIFY_FILES) + set(arg_MODIFY_FILES FALSE) + endif() + + if(DEFINED arg_WORKING_DIRECTORY) + set(_wd ${arg_WORKING_DIRECTORY}) + else() + set(_wd ${CMAKE_CURRENT_SOURCE_DIR}) + endif() + + set(_generate_target TRUE) + + # Check the version -- output is of the form "X.Y.Z" + execute_process( + COMMAND ${CMAKEFORMAT_EXECUTABLE} --version + OUTPUT_VARIABLE _version_str + ERROR_VARIABLE _version_str + OUTPUT_STRIP_TRAILING_WHITESPACE ) + string(REGEX MATCH "([0-9]+(\\.)?)+$" _cmakeformat_version ${_version_str}) + + if(BLT_REQUIRED_CMAKEFORMAT_VERSION) + # The user may only specify a part of the version (e.g. just the maj ver) + # so check for substring + string(FIND "${_cmakeformat_version}" ${BLT_REQUIRED_CMAKEFORMAT_VERSION} VERSION_POS) + if (NOT VERSION_POS EQUAL 0) + set(_generate_target FALSE) + if(NOT _BLT_STYLE_VERSION_WARNING_ISSUED) + message(WARNING "blt_add_cmakeformat_target: cmake-format '${BLT_REQUIRED_CMAKEFORMAT_VERSION}' is required, found '${_cmakeformat_version}'. Disabling 'style' build target.") + set(_BLT_STYLE_VERSION_WARNING_ISSUED TRUE CACHE BOOL "Limits BLT issuing more than one warning for style version" FORCE) + endif() + endif() + endif() + + if(${arg_MODIFY_FILES}) + set(MODIFY_FILES_FLAG --in-place) + else() + set(MODIFY_FILES_FLAG --check) + endif() + + if(_generate_target) + add_custom_target( + ${arg_NAME} + COMMAND ${CMAKEFORMAT_EXECUTABLE} ${arg_PREPEND_FLAGS} + --config-files ${arg_CFG_FILE} ${MODIFY_FILES_FLAG} ${arg_SRC_FILES} ${arg_APPEND_FLAGS} + WORKING_DIRECTORY ${_wd} + COMMENT "${arg_COMMENT}Running CMakeFormat source code formatting checks.") + + # Hook our new target into the proper dependency chain + if(${arg_MODIFY_FILES}) + add_dependencies(cmakeformat_style ${arg_NAME}) + else() + add_dependencies(cmakeformat_check ${arg_NAME}) + endif() + + # Code formatting targets should only be run on demand + set_property(TARGET ${arg_NAME} PROPERTY EXCLUDE_FROM_ALL TRUE) + set_property(TARGET ${arg_NAME} PROPERTY EXCLUDE_FROM_DEFAULT_BUILD TRUE) + endif() +endmacro(blt_add_cmakeformat_target) diff --git a/cmake/SetupCodeCoverageReports.cmake b/cmake/SetupCodeCoverageReports.cmake index 996037222..28717a9a7 100644 --- a/cmake/SetupCodeCoverageReports.cmake +++ b/cmake/SetupCodeCoverageReports.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2012 - 2015, Lars Bilke. See the top-level COPYRIGHT file for details +# Copyright (c) 2012 - 2015, Lars Bilke. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -21,6 +21,8 @@ # 2017-07-25, Cyrus Harrison # - Refactored to only include report gen logic, not coverage flags # +# 2020-11-18, Josh Essman +# - Continue generation after failing tests, allow user to specify src dir set(BLT_CODE_COVERAGE_REPORTS ON) @@ -45,47 +47,70 @@ endif() mark_as_advanced(BLT_CODE_COVERAGE_REPORTS) -###################################################################### -# Function that adds target that generates code coverage reports -##################################################################### -# Param _targetname The name of new the custom make target and output file name. -# Param _testrunner The name of the target which runs the tests. -# MUST return ZERO always, even on errors. -# If not, no coverage report will be created! -# Optional fourth parameter is passed as arguments to _testrunner -# Pass them in list form, e.g.: "-j;2" for -j 2 -function(add_code_coverage_target _targetname _testrunner) +##------------------------------------------------------------------------------ +## blt_add_code_coverage_target( NAME +## RUNNER +## SOURCE_DIRECTORIES [dir1 [dir2 ...]]) +## +## Creates a new target with the given NAME that generates a code coverage report. +##------------------------------------------------------------------------------ +function(blt_add_code_coverage_target) + + set(options) + set(singleValueArgs NAME) + set(multiValueArgs RUNNER SOURCE_DIRECTORIES) + + # parse the arguments + cmake_parse_arguments(arg + "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN} ) + + # Check/Set required parameters + if(NOT DEFINED arg_NAME) + message(FATAL_ERROR "blt_add_code_coverage_target requires a NAME parameter") + endif() + + if(NOT DEFINED arg_RUNNER) + message(FATAL_ERROR "blt_add_code_coverage_target requires a RUNNER parameter") + endif() + + set(_coverage_directories "--directory=${CMAKE_BINARY_DIR}") + if(DEFINED arg_SOURCE_DIRECTORIES) + foreach(_src_dir ${arg_SOURCE_DIRECTORIES}) + list(APPEND _coverage_directories "--directory=${_src_dir}") + endforeach() + else() + # Default to everything + list(APPEND _coverage_directories "--directory=${CMAKE_CURRENT_SOURCE_DIR}") + endif() # Setup target - add_custom_target(${_targetname} + add_custom_target(${arg_NAME} # Cleanup lcov - ${LCOV_EXECUTABLE} --no-external --gcov-tool ${GCOV_EXECUTABLE} --directory ${CMAKE_BINARY_DIR} --directory ${CMAKE_SOURCE_DIR}/components --zerocounters + ${LCOV_EXECUTABLE} --no-external --gcov-tool ${GCOV_EXECUTABLE} ${_coverage_directories} --zerocounters - # Run tests - COMMAND ${_testrunner} ${ARGV2} + # Run tests - allow for failing tests + COMMAND ${arg_RUNNER} || (exit 0) # Capture lcov counters and generating report - COMMAND ${LCOV_EXECUTABLE} --no-external --gcov-tool ${GCOV_EXECUTABLE} --directory ${CMAKE_BINARY_DIR} --directory ${CMAKE_SOURCE_DIR}/components --capture --output-file ${_targetname}.info - COMMAND ${LCOV_EXECUTABLE} --no-external --gcov-tool ${GCOV_EXECUTABLE} --directory ${CMAKE_BINARY_DIR} --directory ${CMAKE_SOURCE_DIR}/components --remove ${_targetname}.info '/usr/include/*' --output-file ${_targetname}.info.cleaned - COMMAND ${GENHTML_EXECUTABLE} -o ${_targetname} ${_targetname}.info.cleaned - COMMAND ${CMAKE_COMMAND} -E remove ${_targetname}.info ${_targetname}.info.cleaned - + COMMAND ${LCOV_EXECUTABLE} --no-external --gcov-tool ${GCOV_EXECUTABLE} ${_coverage_directories} --capture --output-file ${arg_NAME}.info + COMMAND ${LCOV_EXECUTABLE} --no-external --gcov-tool ${GCOV_EXECUTABLE} ${_coverage_directories} --remove ${arg_NAME}.info '/usr/include/*' --output-file ${arg_NAME}.info.cleaned + COMMAND ${GENHTML_EXECUTABLE} -o ${arg_NAME} ${arg_NAME}.info.cleaned + BYPRODUCTS ${arg_NAME}.info ${arg_NAME}.info.cleaned WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." ) # Show info where to find the report - add_custom_command(TARGET ${_targetname} POST_BUILD + add_custom_command(TARGET ${arg_NAME} POST_BUILD COMMAND ; - COMMENT "Open ./${_targetname}/index.html in your browser to view the coverage report." + COMMENT "Open ./${arg_NAME}/index.html in your browser to view the coverage report." ) endfunction() if(BLT_CODE_COVERAGE_REPORTS) # Add code coverage target - add_code_coverage_target(coverage make test) + blt_add_code_coverage_target(NAME coverage RUNNER make test) message(STATUS "Code coverage: reports enabled via lcov, genthml, and gcov.") endif() - diff --git a/cmake/SetupCodeMetrics.cmake b/cmake/SetupCodeMetrics.cmake index 720136094..59e6dbb0b 100644 --- a/cmake/SetupCodeMetrics.cmake +++ b/cmake/SetupCodeMetrics.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) ################################################# diff --git a/cmake/SetupCompilerOptions.cmake b/cmake/SetupCompilerOptions.cmake index 49d92c953..db38469bd 100644 --- a/cmake/SetupCompilerOptions.cmake +++ b/cmake/SetupCompilerOptions.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -84,6 +84,14 @@ else() endif() +################################################################################# +# PGI doesn't support a SYSTEM flag for include directories. Since this is CMake's +# default for imported targets, we need to disable this feature for PGI. +################################################################################# +if(${C_COMPILER_FAMILY_IS_PGI}) + set(CMAKE_NO_SYSTEM_FROM_IMPORTED TRUE) +endif() + ################################################ # Support for extra compiler flags and defines ################################################ @@ -236,8 +244,10 @@ endif() ################################ # C++ Standard ################################ - -SET( CMAKE_CXX_EXTENSIONS OFF ) +if (NOT DEFINED CMAKE_CXX_EXTENSIONS) + message(STATUS "Setting CMAKE_CXX_EXTENSIONS to Off") + set( CMAKE_CXX_EXTENSIONS OFF ) +endif () SET( CMAKE_CXX_STANDARD_REQUIRED ON ) set(BLT_CXX_STD "" CACHE STRING "Version of C++ standard") @@ -265,7 +275,7 @@ if (BLT_CXX_STD) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "XL") message(FATAL_ERROR "XL does not support C++17.") endif() - if (ENABLE_CUDA) + if (ENABLE_CUDA AND (NOT DEFINED CMAKE_CUDA_COMPILE_FEATURES OR (NOT "cuda_std_17" IN_LIST CMAKE_CUDA_COMPILE_FEATURES))) message(FATAL_ERROR "CMake's CUDA_STANDARD does not support C++17.") endif() @@ -418,3 +428,22 @@ endif() foreach(flagVar ${langFlags} "CMAKE_EXE_LINKER_FLAGS" ) message(STATUS "${flagVar} flags are: ${${flagVar}}") endforeach() + +################################## +# Remove implicit link directories +################################## +if(BLT_CMAKE_IMPLICIT_LINK_DIRECTORIES_EXCLUDE) + message(STATUS "Removing implicit link directories: ${BLT_CMAKE_IMPLICIT_LINK_DIRECTORIES_EXCLUDE}") + list(REMOVE_ITEM CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES ${BLT_CMAKE_IMPLICIT_LINK_DIRECTORIES_EXCLUDE}) + message(STATUS "Updated CXX implicit Link Directories: ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}") + list(REMOVE_ITEM CMAKE_C_IMPLICIT_LINK_DIRECTORIES ${BLT_CMAKE_IMPLICIT_LINK_DIRECTORIES_EXCLUDE}) + message(STATUS "Updated C implicit Link Directories: ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}") + if (ENABLE_FORTRAN) + list(REMOVE_ITEM CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES ${BLT_CMAKE_IMPLICIT_LINK_DIRECTORIES_EXCLUDE}) + message(STATUS "Updated Fortran implicit Link Directories: ${CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES}") + endif () + if (ENABLE_CUDA) + list(REMOVE_ITEM CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES ${BLT_CMAKE_IMPLICIT_LINK_DIRECTORIES_EXCLUDE}) + message(STATUS "Updated CUDA implicit Link Directories: ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}") + endif () +endif() diff --git a/cmake/SetupDocs.cmake b/cmake/SetupDocs.cmake index 6b99b0769..d1ba9cda1 100644 --- a/cmake/SetupDocs.cmake +++ b/cmake/SetupDocs.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) #------------------------------------------------------------------------------ diff --git a/cmake/WrapAstyle.cmake.in b/cmake/WrapAstyle.cmake.in index 1ea3dea30..dea031e81 100644 --- a/cmake/WrapAstyle.cmake.in +++ b/cmake/WrapAstyle.cmake.in @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -16,11 +16,11 @@ # Set up required variables set(ASTYLE_TARGET @arg_NAME@) set(ASTYLE_EXECUTABLE @ASTYLE_EXECUTABLE@) -set(ASTYLE_PREPEND_FLAGS @arg_PREPREND_FLAGS@) +set(ASTYLE_PREPEND_FLAGS @arg_PREPEND_FLAGS@) set(ASTYLE_CFG_FILE @arg_CFG_FILE@) set(ASTYLE_MODIFY_FILES_FLAGS @MODIFY_FILES_FLAG@) set(ASTYLE_SOURCE_FILES @arg_SRC_FILES@) -set(ASTYLE_APPEND_FLAGS @arg_PREPREND_FLAGS@) +set(ASTYLE_APPEND_FLAGS @arg_APPEND_FLAGS@) set(ASTYLE_WORKING_DIRECTORY @_wd@) # Invoke AStyle @@ -58,4 +58,4 @@ if(NOT ${_astyle_output_var} STREQUAL "") if(NOT ${len} EQUAL 0) message(FATAL_ERROR "AStyle found ${len} improperly formatted files.") endif() -endif() \ No newline at end of file +endif() diff --git a/cmake/clang-query-wrapper.py b/cmake/clang-query-wrapper.py index 005d4ef58..74026a6cb 100644 --- a/cmake/clang-query-wrapper.py +++ b/cmake/clang-query-wrapper.py @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) diff --git a/cmake/run-clang-format.py b/cmake/run-clang-format.py index ef3fa0f47..2966381de 100755 --- a/cmake/run-clang-format.py +++ b/cmake/run-clang-format.py @@ -1,4 +1,18 @@ -#!/usr/bin/env python +#!/bin/sh + +# This file is bilingual. The following shell code finds our preferred python. +# Following line is a shell no-op, and starts a multi-line Python comment. +# See https://stackoverflow.com/a/47886254 +""":" +# prefer python3, then python, then python2 +for cmd in python3 python python2; do + command -v > /dev/null $cmd && exec $cmd $0 "$@" +done +echo "==> Error: run-clang-format could not find a python interpreter!" >&2 +exit 1 +":""" +# Line above is a shell no-op, and ends a python multi-line comment. +# The code above runs this file with our preferred python interpreter. from __future__ import print_function, unicode_literals diff --git a/cmake/run-clang-tidy.py b/cmake/run-clang-tidy.py new file mode 100755 index 000000000..1d4fc544f --- /dev/null +++ b/cmake/run-clang-tidy.py @@ -0,0 +1,350 @@ +#!/bin/sh + +# This file is bilingual. The following shell code finds our preferred python. +# Following line is a shell no-op, and starts a multi-line Python comment. +# See https://stackoverflow.com/a/47886254 +""":" +# prefer python3, then python, then python2 +for cmd in python3 python python2; do + command -v > /dev/null $cmd && exec $cmd $0 "$@" +done +echo "==> Error: run-clang-format could not find a python interpreter!" >&2 +exit 1 +":""" +# Line above is a shell no-op, and ends a python multi-line comment. +# The code above runs this file with our preferred python interpreter. + +#===- run-clang-tidy.py - Parallel clang-tidy runner --------*- python -*--===# +# +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# +#===-----------------------------------------------------------------------===# +# FIXME: Integrate with clang-tidy-diff.py + +from __future__ import print_function + +""" +Parallel clang-tidy runner +========================== + +Runs clang-tidy over all files in a compilation database. Requires clang-tidy +and clang-apply-replacements in $PATH. + +Example invocations. +- Run clang-tidy on all files in the current working directory with a default + set of checks and show warnings in the cpp files and all project headers. + run-clang-tidy.py $PWD + +- Fix all header guards. + run-clang-tidy.py -fix -checks=-*,llvm-header-guard + +- Fix all header guards included from clang-tidy and header guards + for clang-tidy headers. + run-clang-tidy.py -fix -checks=-*,llvm-header-guard extra/clang-tidy \ + -header-filter=extra/clang-tidy + +Compilation database setup: +http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html +""" + +import argparse +import glob +import json +import multiprocessing +import os +import re +import shutil +import subprocess +import sys +import tempfile +import threading +import traceback + +try: + import yaml +except ImportError: + yaml = None + +is_py2 = sys.version[0] == '2' + +if is_py2: + import Queue as queue +else: + import queue as queue + + +def find_compilation_database(path): + """Adjusts the directory until a compilation database is found.""" + result = './' + while not os.path.isfile(os.path.join(result, path)): + if os.path.realpath(result) == '/': + print('Error: could not find compilation database.') + sys.exit(1) + result += '../' + return os.path.realpath(result) + + +def make_absolute(f, directory): + if os.path.isabs(f): + return f + return os.path.normpath(os.path.join(directory, f)) + + +def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path, + header_filter, allow_enabling_alpha_checkers, + extra_arg, extra_arg_before, quiet, config): + """Gets a command line for clang-tidy.""" + start = [clang_tidy_binary] + if allow_enabling_alpha_checkers: + start.append('-allow-enabling-analyzer-alpha-checkers') + if header_filter is not None: + start.append('-header-filter=' + header_filter) + if checks: + start.append('-checks=' + checks) + if tmpdir is not None: + start.append('-export-fixes') + # Get a temporary file. We immediately close the handle so clang-tidy can + # overwrite it. + (handle, name) = tempfile.mkstemp(suffix='.yaml', dir=tmpdir) + os.close(handle) + start.append(name) + for arg in extra_arg: + start.append('-extra-arg=%s' % arg) + for arg in extra_arg_before: + start.append('-extra-arg-before=%s' % arg) + start.append('-p=' + build_path) + if quiet: + start.append('-quiet') + if config: + start.append('-config=' + config) + start.append(f) + return start + + +def merge_replacement_files(tmpdir, mergefile): + """Merge all replacement files in a directory into a single file""" + # The fixes suggested by clang-tidy >= 4.0.0 are given under + # the top level key 'Diagnostics' in the output yaml files + mergekey = "Diagnostics" + merged=[] + for replacefile in glob.iglob(os.path.join(tmpdir, '*.yaml')): + content = yaml.safe_load(open(replacefile, 'r')) + if not content: + continue # Skip empty files. + merged.extend(content.get(mergekey, [])) + + if merged: + # MainSourceFile: The key is required by the definition inside + # include/clang/Tooling/ReplacementsYaml.h, but the value + # is actually never used inside clang-apply-replacements, + # so we set it to '' here. + output = {'MainSourceFile': '', mergekey: merged} + with open(mergefile, 'w') as out: + yaml.safe_dump(output, out) + else: + # Empty the file: + open(mergefile, 'w').close() + + +def check_clang_apply_replacements_binary(args): + """Checks if invoking supplied clang-apply-replacements binary works.""" + try: + subprocess.check_call([args.clang_apply_replacements_binary, '--version']) + except: + print('Unable to run clang-apply-replacements. Is clang-apply-replacements ' + 'binary correctly specified?', file=sys.stderr) + traceback.print_exc() + sys.exit(1) + + +def apply_fixes(args, tmpdir): + """Calls clang-apply-fixes on a given directory.""" + invocation = [args.clang_apply_replacements_binary] + if args.format: + invocation.append('-format') + if args.style: + invocation.append('-style=' + args.style) + invocation.append(tmpdir) + subprocess.call(invocation) + + +def run_tidy(args, tmpdir, build_path, queue, lock, failed_files): + """Takes filenames out of queue and runs clang-tidy on them.""" + while True: + name = queue.get() + invocation = get_tidy_invocation(name, args.clang_tidy_binary, args.checks, + tmpdir, build_path, args.header_filter, + args.allow_enabling_alpha_checkers, + args.extra_arg, args.extra_arg_before, + args.quiet, args.config) + + proc = subprocess.Popen(invocation, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + output, err = proc.communicate() + if proc.returncode != 0: + failed_files.append(name) + with lock: + sys.stdout.write(' '.join(invocation) + '\n' + output.decode('utf-8')) + if len(err) > 0: + sys.stdout.flush() + sys.stderr.write(err.decode('utf-8')) + queue.task_done() + + +def main(): + parser = argparse.ArgumentParser(description='Runs clang-tidy over all files ' + 'in a compilation database. Requires ' + 'clang-tidy and clang-apply-replacements in ' + '$PATH.') + parser.add_argument('-allow-enabling-alpha-checkers', + action='store_true', help='allow alpha checkers from ' + 'clang-analyzer.') + parser.add_argument('-clang-tidy-binary', metavar='PATH', + default='clang-tidy', + help='path to clang-tidy binary') + parser.add_argument('-clang-apply-replacements-binary', metavar='PATH', + default='clang-apply-replacements', + help='path to clang-apply-replacements binary') + parser.add_argument('-checks', default=None, + help='checks filter, when not specified, use clang-tidy ' + 'default') + parser.add_argument('-config', default=None, + help='Specifies a configuration in YAML/JSON format: ' + ' -config="{Checks: \'*\', ' + ' CheckOptions: [{key: x, ' + ' value: y}]}" ' + 'When the value is empty, clang-tidy will ' + 'attempt to find a file named .clang-tidy for ' + 'each source file in its parent directories.') + parser.add_argument('-header-filter', default=None, + help='regular expression matching the names of the ' + 'headers to output diagnostics from. Diagnostics from ' + 'the main file of each translation unit are always ' + 'displayed.') + if yaml: + parser.add_argument('-export-fixes', metavar='filename', dest='export_fixes', + help='Create a yaml file to store suggested fixes in, ' + 'which can be applied with clang-apply-replacements.') + parser.add_argument('-j', type=int, default=0, + help='number of tidy instances to be run in parallel.') + parser.add_argument('files', nargs='*', default=['.*'], + help='files to be processed (regex on path)') + parser.add_argument('-fix', action='store_true', help='apply fix-its') + parser.add_argument('-format', action='store_true', help='Reformat code ' + 'after applying fixes') + parser.add_argument('-style', default='file', help='The style of reformat ' + 'code after applying fixes') + parser.add_argument('-p', dest='build_path', + help='Path used to read a compile command database.') + parser.add_argument('-extra-arg', dest='extra_arg', + action='append', default=[], + help='Additional argument to append to the compiler ' + 'command line.') + parser.add_argument('-extra-arg-before', dest='extra_arg_before', + action='append', default=[], + help='Additional argument to prepend to the compiler ' + 'command line.') + parser.add_argument('-quiet', action='store_true', + help='Run clang-tidy in quiet mode') + args = parser.parse_args() + + db_path = 'compile_commands.json' + + if args.build_path is not None: + build_path = args.build_path + else: + # Find our database + build_path = find_compilation_database(db_path) + + try: + invocation = [args.clang_tidy_binary, '-list-checks'] + if args.allow_enabling_alpha_checkers: + invocation.append('-allow-enabling-analyzer-alpha-checkers') + invocation.append('-p=' + build_path) + if args.checks: + invocation.append('-checks=' + args.checks) + invocation.append('-') + if args.quiet: + # Even with -quiet we still want to check if we can call clang-tidy. + with open(os.devnull, 'w') as dev_null: + subprocess.check_call(invocation, stdout=dev_null) + else: + subprocess.check_call(invocation) + except: + print("Unable to run clang-tidy.", file=sys.stderr) + sys.exit(1) + + # Load the database and extract all files. + database = json.load(open(os.path.join(build_path, db_path))) + files = [make_absolute(entry['file'], entry['directory']) + for entry in database] + + max_task = args.j + if max_task == 0: + max_task = multiprocessing.cpu_count() + + tmpdir = None + if args.fix or (yaml and args.export_fixes): + check_clang_apply_replacements_binary(args) + tmpdir = tempfile.mkdtemp() + + # Build up a big regexy filter from all command line arguments. + file_name_re = re.compile('|'.join(args.files)) + + return_code = 0 + try: + # Spin up a bunch of tidy-launching threads. + task_queue = queue.Queue(max_task) + # List of files with a non-zero return code. + failed_files = [] + lock = threading.Lock() + for _ in range(max_task): + t = threading.Thread(target=run_tidy, + args=(args, tmpdir, build_path, task_queue, lock, failed_files)) + t.daemon = True + t.start() + + # Fill the queue with files. + for name in files: + if file_name_re.search(name): + task_queue.put(name) + + # Wait for all threads to be done. + task_queue.join() + if len(failed_files): + return_code = 1 + + except KeyboardInterrupt: + # This is a sad hack. Unfortunately subprocess goes + # bonkers with ctrl-c and we start forking merrily. + print('\nCtrl-C detected, goodbye.') + if tmpdir: + shutil.rmtree(tmpdir) + os.kill(0, 9) + + if yaml and args.export_fixes: + print('Writing fixes to ' + args.export_fixes + ' ...') + try: + merge_replacement_files(tmpdir, args.export_fixes) + except: + print('Error exporting fixes.\n', file=sys.stderr) + traceback.print_exc() + return_code=1 + + if args.fix: + print('Applying fixes ...') + try: + apply_fixes(args, tmpdir) + except: + print('Error applying fixes.\n', file=sys.stderr) + traceback.print_exc() + return_code = 1 + + if tmpdir: + shutil.rmtree(tmpdir) + sys.exit(return_code) + + +if __name__ == '__main__': + main() diff --git a/cmake/thirdparty/FindHIP.cmake b/cmake/thirdparty/FindHIP.cmake index 165bbd7c6..3bc2235fc 100644 --- a/cmake/thirdparty/FindHIP.cmake +++ b/cmake/thirdparty/FindHIP.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -16,6 +16,7 @@ set(HIP_HCC_FLAGS "" CACHE STRING "Semicolon delimited flags for HCC") set(HIP_CLANG_FLAGS "" CACHE STRING "Semicolon delimited flags for CLANG") set(HIP_NVCC_FLAGS "" CACHE STRING "Semicolon delimted flags for NVCC") mark_as_advanced(HIP_HIPCC_FLAGS HIP_HCC_FLAGS HIP_CLANG_FLAGS HIP_NVCC_FLAGS) + set(_hip_configuration_types ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} Debug MinSizeRel Release RelWithDebInfo) list(REMOVE_DUPLICATES _hip_configuration_types) foreach(config ${_hip_configuration_types}) @@ -210,8 +211,13 @@ set(CMAKE_SHARED_LIBRARY_LINK_DYNAMIC_HIP_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_DYNA set(HIP_CLANG_PARALLEL_BUILD_COMPILE_OPTIONS "") set(HIP_CLANG_PARALLEL_BUILD_LINK_OPTIONS "") -if("${HIP_COMPILER}" STREQUAL "hcc") - # Set the CMake Flags to use the HCC Compiler. +if("${HIP_COMPILER}" STREQUAL "nvcc") + # Set the CMake Flags to use the nvcc Compiler. + set(CMAKE_HIP_CREATE_SHARED_LIBRARY "${HIP_HIPCC_CMAKE_LINKER_HELPER} -o ") + set(CMAKE_HIP_CREATE_SHARED_MODULE "${HIP_HIPCC_CMAKE_LINKER_HELPER} -o -shared" ) + set(CMAKE_HIP_LINK_EXECUTABLE "${HIP_HIPCC_CMAKE_LINKER_HELPER} -o ") +elseif("${HIP_COMPILER}" STREQUAL "hcc") + # Set the CMake Flags to use the hcc Compiler. set(CMAKE_HIP_CREATE_SHARED_LIBRARY "${HIP_HIPCC_CMAKE_LINKER_HELPER} ${HCC_HOME} -o ") set(CMAKE_HIP_CREATE_SHARED_MODULE "${HIP_HIPCC_CMAKE_LINKER_HELPER} ${HCC_HOME} -o -shared" ) set(CMAKE_HIP_LINK_EXECUTABLE "${HIP_HIPCC_CMAKE_LINKER_HELPER} ${HCC_HOME} -o ") @@ -226,7 +232,7 @@ elseif("${HIP_COMPILER}" STREQUAL "clang") endif() if(HIP_CLANG_NUM_PARALLEL_JOBS GREATER 1) if(${HIP_CLANG_SUPPORTS_PARALLEL_JOBS}) - set(HIP_CLANG_PARALLEL_BUILD_COMPILE_OPTIONS "-parallel-jobs=${HIP_CLANG_NUM_PARALLEL_JOBS} -Wno-format-nonliteral") + set(HIP_CLANG_PARALLEL_BUILD_COMPILE_OPTIONS "-Wno-format-nonliteral -parallel-jobs=${HIP_CLANG_NUM_PARALLEL_JOBS}") set(HIP_CLANG_PARALLEL_BUILD_LINK_OPTIONS "-parallel-jobs=${HIP_CLANG_NUM_PARALLEL_JOBS}") else() message("clang compiler doesn't support parallel jobs") @@ -237,6 +243,13 @@ elseif("${HIP_COMPILER}" STREQUAL "clang") set(CMAKE_HIP_CREATE_SHARED_LIBRARY "${HIP_HIPCC_CMAKE_LINKER_HELPER} ${HIP_CLANG_PATH} ${HIP_CLANG_PARALLEL_BUILD_LINK_OPTIONS} -o ") set(CMAKE_HIP_CREATE_SHARED_MODULE "${HIP_HIPCC_CMAKE_LINKER_HELPER} ${HIP_CLANG_PATH} ${HIP_CLANG_PARALLEL_BUILD_LINK_OPTIONS} -o -shared" ) set(CMAKE_HIP_LINK_EXECUTABLE "${HIP_HIPCC_CMAKE_LINKER_HELPER} ${HIP_CLANG_PATH} ${HIP_CLANG_PARALLEL_BUILD_LINK_OPTIONS} -o ") + + if("${HIP_RUNTIME}" STREQUAL "rocclr") + if(TARGET host) + message(STATUS "host interface - found") + set(HIP_HOST_INTERFACE host) + endif() + endif() endif() ############################################################################### @@ -620,29 +633,42 @@ macro(HIP_ADD_EXECUTABLE hip_target) endif() if("${HIP_COMPILER}" STREQUAL "hcc") if("x${HCC_HOME}" STREQUAL "x") - if (DEFINED $ENV{ROCM_PATH}) - set(HCC_HOME "$ENV{ROCM_PATH}/hcc") - elseif( DEFINED $ENV{HIP_PATH}) - set(HCC_HOME "$ENV{HIP_PATH}/../hcc") + if (DEFINED ENV{ROCM_PATH}) + set(HCC_HOME "$ENV{ROCM_PATH}/hcc") + elseif(DEFINED ENV{HIP_PATH}) + set(HCC_HOME "$ENV{HIP_PATH}/../hcc") else() - set(HCC_HOME "/opt/rocm/hcc") + set(HCC_HOME "/opt/rocm/hcc") endif() endif() set(CMAKE_HIP_LINK_EXECUTABLE "${HIP_HIPCC_CMAKE_LINKER_HELPER} ${HCC_HOME} -o ") elseif("${HIP_COMPILER}" STREQUAL "clang") - if("x${HIP_CLANG_PATH}" STREQUAL "x") - if (DEFINED $ENV{ROCM_PATH}) - set(HIP_CLANG_PATH "$ENV{ROCM_PATH}/llvm/bin") - elseif( DEFINED $ENV{HIP_PATH}) - set(HIP_CLANG_PATH "$ENV{HIP_PATH}/../llvm/bin") + if("x${HIP_CLANG_PATH}" STREQUAL "x") + if(DEFINED ENV{HIP_CLANG_PATH}) + set(HIP_CLANG_PATH $ENV{HIP_CLANG_PATH}) + elseif(DEFINED ENV{ROCM_PATH}) + set(HIP_CLANG_PATH "$ENV{ROCM_PATH}/llvm/bin") + elseif(DEFINED ENV{HIP_PATH}) + set(HIP_CLANG_PATH "$ENV{HIP_PATH}/../llvm/bin") else() - set(HIP_CLANG_PATH "/opt/rocm/llvm/bin") + set(HIP_CLANG_PATH "/opt/rocm/llvm/bin") endif() endif() set(CMAKE_HIP_LINK_EXECUTABLE "${HIP_HIPCC_CMAKE_LINKER_HELPER} ${HIP_CLANG_PATH} ${HIP_CLANG_PARALLEL_BUILD_LINK_OPTIONS} -o ") + else() + set(CMAKE_HIP_LINK_EXECUTABLE "${HIP_HIPCC_CMAKE_LINKER_HELPER} -o ") + endif() + if ("${_sources}" STREQUAL "") + add_executable(${hip_target} ${_cmake_options} ${_generated_files} "") + else() + add_executable(${hip_target} ${_cmake_options} ${_generated_files} ${_sources}) endif() - add_executable(${hip_target} ${_cmake_options} ${_generated_files} ${_sources}) set_target_properties(${hip_target} PROPERTIES LINKER_LANGUAGE HIP) + # Link with host + if (HIP_HOST_INTERFACE) + # hip rt should be rocclr, compiler should be clang + target_link_libraries(${hip_target} ${HIP_HOST_INTERFACE}) + endif() endmacro() ############################################################################### @@ -655,8 +681,17 @@ macro(HIP_ADD_LIBRARY hip_target) if(_source_files) list(REMOVE_ITEM _sources ${_source_files}) endif() - add_library(${hip_target} ${_cmake_options} ${_generated_files} ${_sources}) + if ("${_sources}" STREQUAL "") + add_library(${hip_target} ${_cmake_options} ${_generated_files} "") + else() + add_library(${hip_target} ${_cmake_options} ${_generated_files} ${_sources}) + endif() set_target_properties(${hip_target} PROPERTIES LINKER_LANGUAGE ${HIP_C_OR_CXX}) + # Link with host + if (HIP_HOST_INTERFACE) + # hip rt should be rocclr, compiler should be clang + target_link_libraries(${hip_target} ${HIP_HOST_INTERFACE}) + endif() endmacro() # vim: ts=4:sw=4:expandtab:smartindent diff --git a/cmake/thirdparty/FindHIP/run_hipcc.cmake b/cmake/thirdparty/FindHIP/run_hipcc.cmake index ec8f91da5..7c3b46c6b 100644 --- a/cmake/thirdparty/FindHIP/run_hipcc.cmake +++ b/cmake/thirdparty/FindHIP/run_hipcc.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -53,7 +53,9 @@ execute_process(COMMAND ${HIP_HIPCONFIG_EXECUTABLE} --compiler OUTPUT_VARIABLE H execute_process(COMMAND ${HIP_HIPCONFIG_EXECUTABLE} --runtime OUTPUT_VARIABLE HIP_RUNTIME OUTPUT_STRIP_TRAILING_WHITESPACE) if(NOT host_flag) set(__CC ${HIP_HIPCC_EXECUTABLE}) - if("${HIP_PLATFORM}" STREQUAL "hcc") + # ROCm version 4.0 and higher will use amd for the platform, but older + # versions use hcc. Keep both for backwards compatibility. + if("${HIP_PLATFORM}" STREQUAL "hcc" OR "${HIP_PLATFORM}" STREQUAL "amd") if("${HIP_COMPILER}" STREQUAL "hcc") if(NOT "x${HCC_HOME}" STREQUAL "x") set(ENV{HCC_HOME} ${HCC_HOME}) @@ -64,7 +66,7 @@ if(NOT host_flag) set(ENV{HIP_CLANG_PATH} ${HIP_CLANG_PATH}) endif() # Temporarily include HIP_HCC_FLAGS for HIP-Clang for PyTorch builds - set(__CC_FLAGS ${HIP_CLANG_PARALLEL_BUILD_COMPILE_OPTIONS} ${HIP_HIPCC_FLAGS} ${HIP_HCC_FLAGS} ${HIP_CLANG_FLAGS} ${HIP_HIPCC_FLAGS_${build_configuration}} ${HIP_CLANG_FLAGS_${build_configuration}}) + set(__CC_FLAGS ${HIP_CLANG_PARALLEL_BUILD_COMPILE_OPTIONS} ${HIP_HIPCC_FLAGS} ${HIP_HCC_FLAGS} ${HIP_CLANG_FLAGS} ${HIP_HIPCC_FLAGS_${build_configuration}} ${HIP_HCC_FLAGS_${build_configuration}} ${HIP_CLANG_FLAGS_${build_configuration}}) endif() else() set(__CC_FLAGS ${HIP_HIPCC_FLAGS} ${HIP_NVCC_FLAGS} ${HIP_HIPCC_FLAGS_${build_configuration}} ${HIP_NVCC_FLAGS_${build_configuration}}) diff --git a/cmake/thirdparty/FindHIP/run_make2cmake.cmake b/cmake/thirdparty/FindHIP/run_make2cmake.cmake index 22c9790e3..db23cc33d 100644 --- a/cmake/thirdparty/FindHIP/run_make2cmake.cmake +++ b/cmake/thirdparty/FindHIP/run_make2cmake.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) diff --git a/cmake/thirdparty/FindROCm.cmake b/cmake/thirdparty/FindROCm.cmake index 56b5deb9f..9c0efe403 100644 --- a/cmake/thirdparty/FindROCm.cmake +++ b/cmake/thirdparty/FindROCm.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) diff --git a/cmake/thirdparty/SetupCUDA.cmake b/cmake/thirdparty/SetupCUDA.cmake index 9453ae02d..d78ef37f8 100644 --- a/cmake/thirdparty/SetupCUDA.cmake +++ b/cmake/thirdparty/SetupCUDA.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -112,6 +112,8 @@ message(STATUS "CUDA Compile Flags: ${CMAKE_CUDA_FLAGS}") message(STATUS "CUDA Link Flags: ${CMAKE_CUDA_LINK_FLAGS}") message(STATUS "CUDA Separable Compilation: ${CUDA_SEPARABLE_COMPILATION}") message(STATUS "CUDA Link with NVCC: ${CUDA_LINK_WITH_NVCC}") +message(STATUS "CUDA Implicit Link Libraries: ${CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES}") +message(STATUS "CUDA Implicit Link Directories: ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}") # don't propagate host flags - too easy to break stuff! set (CUDA_PROPAGATE_HOST_FLAGS Off) @@ -121,6 +123,14 @@ else() set(CUDA_HOST_COMPILER ${CMAKE_C_COMPILER}) endif() +# Set PIE options to empty for PGI since it doesn't understand -fPIE This +# option is set in the CUDA toolchain file so must be unset after +# enable_language(CUDA) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "PGI") + set(CMAKE_CUDA_COMPILE_OPTIONS_PIE "") +endif() + + set(_cuda_compile_flags " ") if (ENABLE_CLANG_CUDA) set (_cuda_compile_flags -x cuda --cuda-gpu-arch=${BLT_CLANG_CUDA_ARCH} --cuda-path=${CUDA_TOOLKIT_ROOT_DIR}) @@ -133,12 +143,13 @@ endif() # leaving it to the default source file language. # This logic is handled in the blt_add_library/executable # macros -blt_register_library(NAME cuda - COMPILE_FLAGS ${_cuda_compile_flags} - INCLUDES ${CUDA_INCLUDE_DIRS} - LIBRARIES ${CUDA_LIBRARIES} - LINK_FLAGS "${CMAKE_CUDA_LINK_FLAGS}" - ) +blt_import_library(NAME cuda + COMPILE_FLAGS ${_cuda_compile_flags} + INCLUDES ${CUDA_INCLUDE_DIRS} + LIBRARIES ${CUDA_LIBRARIES} + LINK_FLAGS "${CMAKE_CUDA_LINK_FLAGS}" + EXPORTABLE ${BLT_EXPORT_THIRDPARTY} + ) # same as 'cuda' but we don't flag your source files as # CUDA language. This causes your source files to use @@ -146,6 +157,7 @@ blt_register_library(NAME cuda # linking with nvcc. # This logic is handled in the blt_add_library/executable # macros -blt_register_library(NAME cuda_runtime - INCLUDES ${CUDA_INCLUDE_DIRS} - LIBRARIES ${CUDA_LIBRARIES}) +blt_import_library(NAME cuda_runtime + INCLUDES ${CUDA_INCLUDE_DIRS} + LIBRARIES ${CUDA_LIBRARIES} + EXPORTABLE ${BLT_EXPORT_THIRDPARTY}) diff --git a/cmake/thirdparty/SetupHCC.cmake b/cmake/thirdparty/SetupHCC.cmake index f82524d9a..9b4367bba 100644 --- a/cmake/thirdparty/SetupHCC.cmake +++ b/cmake/thirdparty/SetupHCC.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) diff --git a/cmake/thirdparty/SetupHIP.cmake b/cmake/thirdparty/SetupHIP.cmake index cdc917553..5437fb580 100644 --- a/cmake/thirdparty/SetupHIP.cmake +++ b/cmake/thirdparty/SetupHIP.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -14,33 +14,32 @@ find_package(HIP REQUIRED) message(STATUS "HIP version: ${HIP_VERSION_STRING}") message(STATUS "HIP platform: ${HIP_PLATFORM}") -#message(STATUS "HIP Include Path: ${HIP_INCLUDE_DIRS}") -#message(STATUS "HIP Libraries: ${HIP_LIBRARIES}") -if(${HIP_PLATFORM} STREQUAL "hcc") +if("${HIP_PLATFORM}" STREQUAL "hcc" OR "${HIP_PLATFORM}" STREQUAL "amd") set(HIP_RUNTIME_DEFINE "__HIP_PLATFORM_HCC__") -elseif(${HIP_PLATFORM} STREQUAL "nvcc") +elseif("${HIP_PLATFORM}" STREQUAL "nvcc") set(HIP_RUNTIME_DEFINE "__HIP_PLATFORM_NVCC__") endif() -set(HIP_RUNTIME_INCLUDE_DIRS "${HIP_ROOT_DIR}/include;${HIP_ROOT_DIR}/hcc/include") +if ( IS_DIRECTORY "${HIP_ROOT_DIR}/hcc/include" ) # this path only exists on older rocm installs + set(HIP_RUNTIME_INCLUDE_DIRS "${HIP_ROOT_DIR}/include;${HIP_ROOT_DIR}/hcc/include" CACHE STRING "") +else() + set(HIP_RUNTIME_INCLUDE_DIRS "${HIP_ROOT_DIR}/include" CACHE STRING "") +endif() set(HIP_RUNTIME_COMPILE_FLAGS "${HIP_RUNTIME_COMPILE_FLAGS};-D${HIP_RUNTIME_DEFINE};-Wno-unused-parameter") -# set(HIP_RUNTIME_LIBRARIES "${HIP_ROOT_DIR}/hcc/lib") -# set(HIP_RUNTIME_LIBRARIES "${HIP_ROOT_DIR}/hcc/lib") # depend on 'hip', if you need to use hip # headers, link to hip libs, and need to run your source # through a hip compiler (hipcc) -blt_register_library(NAME hip - INCLUDES ${HIP_INCLUDE_DIRS} - LIBRARIES ${HIP_LIBRARIES} - TREAT_INCLUDES_AS_SYSTEM ON) +# This is currently used only as an indicator for blt_add_hip* -- FindHIP/hipcc will handle resolution +# of all required HIP-related includes/libraries/flags. +blt_import_library(NAME hip) # depend on 'hip_runtime', if you only need to use hip # headers or link to hip libs, but don't need to run your source # through a hip compiler (hipcc) -blt_register_library(NAME hip_runtime - INCLUDES ${HIP_RUNTIME_INCLUDE_DIRS} - DEFINES ${HIP_RUNTIME_DEFINES} - COMPILE_FLAGS ${HIP_RUNTIME_COMPILE_FLAGS} - LIBRARIES ${HIP_RUNTIME_LIBRARIES} - TREAT_INCLUDES_AS_SYSTEM ON) +blt_import_library(NAME hip_runtime + INCLUDES ${HIP_RUNTIME_INCLUDE_DIRS} + DEFINES ${HIP_RUNTIME_DEFINES} + COMPILE_FLAGS ${HIP_RUNTIME_COMPILE_FLAGS} + TREAT_INCLUDES_AS_SYSTEM ON + EXPORTABLE ${BLT_EXPORT_THIRDPARTY}) diff --git a/cmake/thirdparty/SetupMPI.cmake b/cmake/thirdparty/SetupMPI.cmake index c618dc3c2..812df35e0 100644 --- a/cmake/thirdparty/SetupMPI.cmake +++ b/cmake/thirdparty/SetupMPI.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -136,6 +136,15 @@ if (BLT_MPI_LINK_FLAGS) set(_mpi_link_flags ${BLT_MPI_LINK_FLAGS}) endif() +# +# We use `LINK_OPTIONS` for CMake 3.13 and beyond. +# To make sure that de-duping doesn't undermine our MPI flags +# use a string with SHELL: prefix +# +if( ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.13.0" ) + string(REPLACE ";" " " _mpi_link_flags "${_mpi_link_flags}") + set(_mpi_link_flags "SHELL:${_mpi_link_flags}") +endif() # Output all MPI information message(STATUS "BLT MPI Compile Flags: ${_mpi_compile_flags}") @@ -168,10 +177,10 @@ if (ENABLE_FORTRAN) endif() endif() -# Create the registered library -blt_register_library(NAME mpi - INCLUDES ${_mpi_includes} - TREAT_INCLUDES_AS_SYSTEM ON - LIBRARIES ${_mpi_libraries} - COMPILE_FLAGS ${_mpi_compile_flags} - LINK_FLAGS ${_mpi_link_flags} ) +blt_import_library(NAME mpi + INCLUDES ${_mpi_includes} + TREAT_INCLUDES_AS_SYSTEM ON + LIBRARIES ${_mpi_libraries} + COMPILE_FLAGS ${_mpi_compile_flags} + LINK_FLAGS ${_mpi_link_flags} + EXPORTABLE ${BLT_EXPORT_THIRDPARTY}) diff --git a/cmake/thirdparty/SetupOpenMP.cmake b/cmake/thirdparty/SetupOpenMP.cmake index 1d7b617e8..0620a8554 100644 --- a/cmake/thirdparty/SetupOpenMP.cmake +++ b/cmake/thirdparty/SetupOpenMP.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -52,6 +52,7 @@ endif() message(STATUS "OpenMP Compile Flags: ${_compile_flags}") message(STATUS "OpenMP Link Flags: ${_link_flags}") -blt_register_library(NAME openmp - COMPILE_FLAGS ${_compile_flags} - LINK_FLAGS ${_link_flags}) +blt_import_library(NAME openmp + COMPILE_FLAGS ${_compile_flags} + LINK_FLAGS ${_link_flags} + EXPORTABLE ${BLT_EXPORT_THIRDPARTY}) diff --git a/cmake/thirdparty/SetupThirdParty.cmake b/cmake/thirdparty/SetupThirdParty.cmake index ffc92ad3e..2cf788a20 100644 --- a/cmake/thirdparty/SetupThirdParty.cmake +++ b/cmake/thirdparty/SetupThirdParty.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -95,6 +95,12 @@ blt_find_executable(NAME ClangFormat blt_find_executable(NAME Uncrustify EXECUTABLES uncrustify) +blt_find_executable(NAME Yapf + EXECUTABLES yapf) + +blt_find_executable(NAME CMakeFormat + EXECUTABLES cmake-format) + #------------------------------------ # Static analysis via Cppcheck @@ -104,9 +110,31 @@ blt_find_executable(NAME Cppcheck #------------------------------------ -# Static analysis via clang-query +# Static analysis via clang-query and clang-tidy #------------------------------------ if(CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL "Ninja") blt_find_executable(NAME ClangQuery EXECUTABLES clang-query) + + blt_find_executable(NAME ClangTidy + EXECUTABLES clang-tidy) +endif() + +#------------------------------------ +# Code coverage +#------------------------------------ +if (ENABLE_COVERAGE) + # Attempt to find the executables associated with gcov, lcov and genhtml. + # This requires that the associated features are enabled. + set(ENABLE_GCOV ON CACHE BOOL "") + set(ENABLE_LCOV ON CACHE BOOL "") + set(ENABLE_GENHTML ON CACHE BOOL "") + blt_find_executable(NAME gcov + EXECUTABLES gcov) + + blt_find_executable(NAME lcov + EXECUTABLES lcov) + + blt_find_executable(NAME genhtml + EXECUTABLES genhtml) endif() diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 2d70ebc48..92c95d1dc 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -7,16 +7,26 @@ cmake_minimum_required(VERSION 3.8) project( blt_docs ) -############################################################################### +#------------------------------------------------------------------------------ # Setup BLT -############################################################################### +#------------------------------------------------------------------------------ +# Set BLT_SOURCE_DIR to default location, if not set by user if(NOT BLT_SOURCE_DIR) - set(BLT_SOURCE_DIR "blt") + set(BLT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/..") endif() include(${BLT_SOURCE_DIR}/SetupBLT.cmake) +#------------------------------------------------------------------------------ +# Calc PI Tutorial +#------------------------------------------------------------------------------ +add_subdirectory(tutorial/calc_pi) + +#------------------------------------------------------------------------------ +# Docs +#------------------------------------------------------------------------------ + if (SPHINX_FOUND) blt_add_sphinx_target(blt_sphinx_tutorial_docs) endif() diff --git a/docs/_static/style.css b/docs/_static/style.css new file mode 100644 index 000000000..775d1a851 --- /dev/null +++ b/docs/_static/style.css @@ -0,0 +1,37 @@ +.toggle .label { + display: block; + clear: both; +} + +.toggle .label:before { + font-family: FontAwesome; + content: "\f196 "; + color: #b3b3b3; +} + +.toggle .label.expanded:hover:before { + color: #d9d9d9; +} + +.toggle .label.expanded:before { + font-family: FontAwesome; + content: "\f147 "; + color: #b3b3b3; +} + +.toggle .label:hover:before { + color: #d9d9d9; +} + +.linebreak { + opacity: 0.0; +} + +/* Sidebar header (and topbar for mobile) */ +.wy-side-nav-search, .wy-nav-top { + background: #343131; +} + +a img.logo { + scale: 75% +} diff --git a/docs/_templates/page.html b/docs/_templates/page.html new file mode 100644 index 000000000..687c1150c --- /dev/null +++ b/docs/_templates/page.html @@ -0,0 +1,27 @@ +{% extends "!page.html" %} + +{% set css_files = css_files + ["_static/style.css"] %} + +{% block footer %} + +{% endblock %} diff --git a/docs/api/code_check.rst b/docs/api/code_check.rst index dc9e8867f..b94a8d75a 100644 --- a/docs/api/code_check.rst +++ b/docs/api/code_check.rst @@ -1,11 +1,13 @@ -.. # Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -.. # other BLT Project Developers. See the top-level COPYRIGHT file for details -.. # +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details +.. # .. # SPDX-License-Identifier: (BSD-3-Clause) Code Check Macros ================== +.. _blt_add_code_checks: + blt_add_code_checks ~~~~~~~~~~~~~~~~~~~ @@ -16,7 +18,10 @@ blt_add_code_checks ASTYLE_CFG_FILE CLANGFORMAT_CFG_FILE UNCRUSTIFY_CFG_FILE - CPPCHECK_FLAGS ) + YAPF_CFG_FILE + CMAKEFORMAT_CFG_FILE + CPPCHECK_FLAGS + CLANGQUERY_CHECKER_DIRECTORIES [dir1 [dir2]]) This macro adds all enabled code check targets for the given SOURCES. @@ -36,75 +41,118 @@ CLANGFORMAT_CFG_FILE UNCRUSTIFY_CFG_FILE Path to Uncrustify config file +YAPF_CFG_FILE + Path to Yapf config file + +CMAKEFORMAT_CFG_FILE + Path to CMakeFormat config file + CPPCHECK_FLAGS List of flags added to Cppcheck +CLANGQUERY_CHECKER_DIRECTORIES + List of directories where clang-query's checkers are located + The purpose of this macro is to enable all code checks in the default manner. It runs -all code checks from the working directory `CMAKE_BINARY_DIR`. If you need more specific +all code checks from the working directory ``CMAKE_BINARY_DIR``. If you need more specific functionality you will need to call the individual code check macros yourself. .. note:: For library projects that may be included as a subproject of another code via CMake's - add_subproject(), we recommend guarding "code check" targets against being included in - other codes. The following check `if ("${PROJECT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")` + ``add_subproject()``, we recommend guarding "code check" targets against being included in + other codes. The following check ``if ("${PROJECT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")`` will stop your code checks from running unless you are the main CMake project. -Sources are filtered based on file extensions for use in these code checks. If you need -additional file extensions defined add them to BLT_C_FILE_EXTS and BLT_Fortran_FILE_EXTS. -Currently this macro only has code checks for C/C++ and simply filters out the Fortran files. +Sources are filtered based on file extensions for use in these code +checks. If you need additional file extensions defined add them to +``BLT_C_FILE_EXTS``, ``BLT_Python_FILE_EXTS``, ``BLT_CMAKE_FILE_EXTS``, and +``BLT_Fortran_FILE_EXTS``. Currently this macro only has code checks for +C/C++ and Python; it simply filters out the Fortran files. -This macro supports code formatting with either AStyle, ClangFormat, or Uncrustify +This macro supports C/C++ code formatting with either AStyle, ClangFormat, or Uncrustify (but not all at the same time) only if the following requirements are met: - AStyle - * ASTYLE_CFG_FILE is given - * ASTYLE_EXECUTABLE is defined and found prior to calling this macro + * ``ASTYLE_CFG_FILE`` is given + * ``ASTYLE_EXECUTABLE`` is defined and found prior to calling this macro - ClangFormat - * CLANGFORMAT_CFG_FILE is given - * CLANGFORMAT_EXECUTABLE is defined and found prior to calling this macro + * ``CLANGFORMAT_CFG_FILE`` is given + * ``CLANGFORMAT_EXECUTABLE`` is defined and found prior to calling this macro - Uncrustify - * UNCRUSTIFY_CFG_FILE is given - * UNCRUSTIFY_EXECUTABLE is defined and found prior to calling this macro + * ``UNCRUSTIFY_CFG_FILE`` is given + * ``UNCRUSTIFY_EXECUTABLE`` is defined and found prior to calling this macro .. note:: ClangFormat does not support a command line option for config files. To work around this, we copy the given config file to the build directory where this macro runs from. -Enabled code formatting checks produce a `check` build target that will test to see if you -are out of compliance with your code formatting and a `style` build target that will actually +This macro also supports Python code formatting with Yapf only if the following requirements +are met: + +* ``YAPF_CFG_FILE`` is given +* ``YAPF_EXECUTABLE`` is defined and found prior to calling this macro + +This macro also supports CMake code formatting with CMakeFormat only if the following requirements are met: + +* ``CMAKEFORMAT_CFG_FILE`` is given +* ``CMAKEFORMAT_EXECUTABLE`` is defined and found prior to calling this macro + +Enabled code formatting checks produce a ``check`` build target that will test to see if you +are out of compliance with your code formatting and a ``style`` build target that will actually modify your source files. It also creates smaller child build targets that follow the pattern -`__`. +``__``. + +If a particular version of a code formatting tool is required, you can +configure BLT to enforce that version by setting +``BLT_REQUIRED__VERSION`` +to as much of the version as you need. For example: + +.. code-block:: cmake + + # If astyle major version 3 is required (3.0, 3.1, etc are acceptable) + set(BLT_REQUIRED_ASTYLE_VERSION "3") + # Or, if exactly 3.1 is needed + set(BLT_REQUIRED_ASTYLE_VERSION "3.1") This macro supports the following static analysis tools with their requirements: - CppCheck - * CPPCHECK_EXECUTABLE is defined and found prior to calling this macro - * CPPCHECK_FLAGS added to the cppcheck command line before the sources + * ``CPPCHECK_EXECUTABLE`` is defined and found prior to calling this macro + * ``CPPCHECK_FLAGS`` added to the cppcheck command line before the sources - Clang-Query - * CLANGQUERY_EXECUTABLE is defined and found prior to calling this macro + * ``CLANGQUERY_EXECUTABLE`` is defined and found prior to calling this macro + * ``CLANGQUERY_CHECKER_DIRECTORIES`` parameter given or ``BLT_CLANGQUERY_CHECKER_DIRECTORIES`` is defined + +- clang-tidy + + * ``CLANGTIDY_EXECUTABLE`` is defined and found prior to calling this macro + +These are added as children to the ``check`` build target and produce child build targets +that follow the pattern ``__check``. + -These are added as children to the `check` build target and produce child build targets -that follow the pattern `__check`. +.. _blt_add_clang_query_target: blt_add_clang_query_target ~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: cmake - blt_add_clang_query_target( NAME - WORKING_DIRECTORY - COMMENT - CHECKERS - DIE_ON_MATCH - SRC_FILES [source1 [source2 ...]]) + blt_add_clang_query_target( NAME + WORKING_DIRECTORY + COMMENT + CHECKERS + DIE_ON_MATCH + SRC_FILES [source1 [source2 ...]] + CHECKER_DIRECTORIES [dir1 [dir2]]) Creates a new build target for running clang-query. @@ -126,20 +174,28 @@ DIE_ON_MATCH SRC_FILES Source list that clang-query will be ran on +CHECKER_DIRECTORIES + List of directories where clang-query's checkers are located + Clang-query is a tool used for examining and matching the Clang AST. It is useful for enforcing coding standards and rules on your source code. A good primer on how to use clang-query can be -found `here `_. +found `here `__. + +A list of checker directories is required for clang-query, this can be defined either by +the parameter ``CHECKER_DIRECTORIES`` or the variable ``BLT_CLANGQUERY_CHECKER_DIRECTORIES``. -Turning on DIE_ON_MATCH is useful if you're using this in CI to enforce rules about your code. +Turning on ``DIE_ON_MATCH`` is useful if you're using this in CI to enforce rules about your code. -CHECKERS are the static analysis passes to specifically run on the target. The following checker options -can be given: +``CHECKERS`` are the static analysis passes to specifically run on the target. The following checker +options can be given: * (no value) : run all available static analysis checks found * (checker1:checker2) : run checker1 and checker2 * (interpreter) : run the clang-query interpeter to interactively develop queries +.. _blt_add_cppcheck_target: + blt_add_cppcheck_target ~~~~~~~~~~~~~~~~~~~~~~~ @@ -173,8 +229,52 @@ SRC_FILES Source list that cppcheck will be ran on Cppcheck is a static analysis tool for C/C++ code. More information about -Cppcheck can be found `here `_. +Cppcheck can be found `here `__. + + +.. _blt_add_clang_tidy_target: + +blt_add_clang_tidy_target +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: cmake + + blt_add_clang_tidy_target( NAME + WORKING_DIRECTORY + COMMENT + CHECKS + FIX + SRC_FILES [source1 [source2 ...]] ) +Creates a new build target for running clang-tidy. + +NAME + Name of created build target + +WORKING_DIRECTORY + Directory in which the clang-tidy command is run. Defaults to where macro is called. + +COMMENT + Comment prepended to the build target output + +CHECKS + List of checks to be run on the selected source files, available checks are listed + `here `__. + +FIX + Applies fixes for checks (a subset of clang-tidy checks specify how they should be resolved) + +SRC_FILES + Source list that clang-tidy will be ran on + +Clang-tidy is a tool used for diagnosing and fixing typical programming errors. It is useful for enforcing +coding standards and rules on your source code. Clang-tidy is documented `here `__. + +``CHECKS`` are the static analysis "rules" to specifically run on the target. +If no checks are specified, clang-tidy will run the default available static analysis checks. + + +.. _blt_add_astyle_target: blt_add_astyle_target ~~~~~~~~~~~~~~~~~~~~~ @@ -183,7 +283,7 @@ blt_add_astyle_target blt_add_astyle_target( NAME MODIFY_FILES [TRUE | FALSE (default)] - CFG_FILE + CFG_FILE PREPEND_FLAGS APPEND_FLAGS COMMENT @@ -217,25 +317,27 @@ SRC_FILES Source list that AStyle will be ran on AStyle is a Source Code Beautifier for C/C++ code. More information about -AStyle can be found `here `_. +AStyle can be found `here `__. -When MODIFY_FILES is set to TRUE, modifies the files in place and adds the created build +When ``MODIFY_FILES`` is set to ``TRUE``, modifies the files in place and adds the created build target to the parent `style` build target. Otherwise the files are not modified and the -created target is added to the parent `check` build target. This target will notify you +created target is added to the parent ``check`` build target. This target will notify you which files do not conform to your style guide. .. Note:: - Setting MODIFY_FILES to FALSE is only supported in AStyle v2.05 or greater. + Setting ``MODIFY_FILES`` to ``FALSE`` is only supported in AStyle v2.05 or greater. +.. _blt_add_clangformat_target: + blt_add_clangformat_target -~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: cmake blt_add_clangformat_target( NAME MODIFY_FILES [TRUE | FALSE (default)] - CFG_FILE + CFG_FILE PREPEND_FLAGS APPEND_FLAGS COMMENT @@ -269,26 +371,29 @@ SRC_FILES Source list that ClangFormat will be ran on ClangFormat is a Source Code Beautifier for C/C++ code. More information about -ClangFormat can be found `here `_. +ClangFormat can be found `here `__. -When MODIFY_FILES is set to TRUE, modifies the files in place and adds the created build -target to the parent `style` build target. Otherwise the files are not modified and the +When ``MODIFY_FILES`` is set to ``TRUE``, modifies the files in place and adds the created build +target to the parent ``style`` build target. Otherwise the files are not modified and the created target is added to the parent `check` build target. This target will notify you which files do not conform to your style guide. .. note:: ClangFormat does not support a command line option for config files. To work around this, we copy the given config file to the given working directory. We recommend using the build - directory `${PROJECT_BINARY_DIR}`. Also if someone is directly including your CMake project + directory ``${PROJECT_BINARY_DIR}``. Also if someone is directly including your CMake project in theirs, you may conflict with theirs. We recommend guarding your code checks against this - with the following check `if ("${PROJECT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")`. + with the following check ``if ("${PROJECT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")``. .. note:: - ClangFormat does not support a command line option for check (--dry-run) until version 10. - This version is not widely used or available at this time. To work around this, we use an - included script called run-clang-format.py that does not use PREPEND_FLAGS or APPEND_FLAGS - in the `check` build target because the script does not support command line flags passed - to `clang-format`. This script is not used in the `style` build target. + ClangFormat does not support a command line option for check ``--dry-run`` until version 10. + This version is not widely used or available at this time. To work around this, we use an + included script called ``run-clang-format.py`` that does not use ``PREPEND_FLAGS`` or ``APPEND_FLAGS`` + in the ``check`` build target because the script does not support command line flags passed + to ``clang-format``. This script is not used in the ``style`` build target. + + +.. _blt_add_uncrustify_target: blt_add_uncrustify_target ~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -297,7 +402,7 @@ blt_add_uncrustify_target blt_add_uncrustify_target( NAME MODIFY_FILES [TRUE | FALSE (default)] - CFG_FILE + CFG_FILE PREPEND_FLAGS APPEND_FLAGS COMMENT @@ -331,11 +436,114 @@ SRC_FILES Source list that Uncrustify will be ran on Uncrustify is a Source Code Beautifier for C/C++ code. More information about -Uncrustify can be found `here `_. +Uncrustify can be found `here `__. -When MODIFY_FILES is set to TRUE, modifies the files in place and adds the created build -target to the parent `style` build target. Otherwise the files are not modified and the -created target is added to the parent `check` build target. This target will notify you +When ``MODIFY_FILES`` is set to ``TRUE``, modifies the files in place and adds the created build +target to the parent ``style`` build target. Otherwise the files are not modified and the +created target is added to the parent ``check`` build target. This target will notify you which files do not conform to your style guide. + .. Note:: - Setting MODIFY_FILES to FALSE is only supported in Uncrustify v0.61 or greater. + Setting ``MODIFY_FILES`` to ``FALSE`` is only supported in Uncrustify v0.61 or greater. + + +.. _blt_add_yapf_target: + +blt_add_yapf_target +~~~~~~~~~~~~~~~~~~~ + +.. code-block:: cmake + + blt_add_yapf_target( NAME + MODIFY_FILES [TRUE | FALSE (default)] + CFG_FILE + PREPEND_FLAGS + APPEND_FLAGS + COMMENT + WORKING_DIRECTORY + SRC_FILES [source1 [source2 ...]] ) + +Creates a new build target for running Yapf + +NAME + Name of created build target + +MODIFY_FILES + Modify the files in place. Defaults to FALSE. + +CFG_FILE + Path to Yapf config file + +PREPEND_FLAGS + Additional flags added to the front of the Yapf flags + +APPEND_FLAGS + Additional flags added to the end of the Yapf flags + +COMMENT + Comment prepended to the build target output + +WORKING_DIRECTORY + Directory in which the Yapf command is run. Defaults to where macro is called. + +SRC_FILES + Source list that Yapf will be ran on + +Yapf is a Source Code Beautifier for Python code. More information about +Yapf can be found `here `__. + +When ``MODIFY_FILES`` is set to ``TRUE``, modifies the files in place and adds the created build +target to the parent ``style`` build target. Otherwise the files are not modified and the +created target is added to the parent ``check`` build target. This target will notify you +which files do not conform to your style guide. + + +.. _blt_add_cmake_format_target: + +blt_add_cmakeformat_target +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: cmake + + blt_add_cmakeformat_target( NAME + MODIFY_FILES [TRUE | FALSE (default)] + CFG_FILE + PREPEND_FLAGS + APPEND_FLAGS + COMMENT + WORKING_DIRECTORY + SRC_FILES [FILE1 [FILE2 ...]] ) + +Creates a new build target for running CMakeFormat + +NAME + Name of created build target + +MODIFY_FILES + Modify the files in place. Defaults to FALSE. + +CFG_FILE + Path to CMakeFormat config file + +PREPEND_FLAGS + Additional flags added to the front of the CMakeFormat flags + +APPEND_FLAGS + Additional flags added to the end of the CMakeFormat flags + +COMMENT + Comment prepended to the build target output + +WORKING_DIRECTORY + Directory in which the CMakeFormat command is run. Defaults to where macro is called. + +SRC_FILES + Source list that CMakeFormat will be ran on + +CMakeFormat is a Source Code Beautifier for CMake code. More information about +CMakeFormat can be found `here `__. + +When ``MODIFY_FILES`` is set to ``TRUE``, modifies the files in place and adds the created build +target to the parent ``style`` build target. Otherwise the files are not modified and the +created target is added to the parent `check` build target. This target will notify you +which files do not conform to your style guide. diff --git a/docs/api/code_metric.rst b/docs/api/code_metric.rst new file mode 100644 index 000000000..e2646ac44 --- /dev/null +++ b/docs/api/code_metric.rst @@ -0,0 +1,46 @@ +.. # Copyright (c) 2017-2020, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details +.. # +.. # SPDX-License-Identifier: (BSD-3-Clause) + +Code Metric Macros +================== + +.. _blt_add_code_coverage_target: + +blt_add_code_coverage_target +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: cmake + + blt_add_code_coverage_target( NAME + RUNNER + SOURCE_DIRECTORIES [dir1 [dir2 ...]] ) + +Creates a new build target for generating a code coverage report. + +NAME + Name of created build target + +RUNNER + The command used to run the tests, e.g., ``make test`` + +SOURCE_DIRECTORIES + The directories containing the source code whose test coverage is to be evaluated + +Code coverage is the degree to which the tests for a piece of software "cover" functions +and/or individual lines of code. It can be used to identify gaps in testing, namely, code +that is not tested. GCC's ``gcov`` tool is used to generate the coverage data, and its accompanying +``lcov`` tool is used to generate an HTML report containing coverage percentage information and +highlighted source code that indicates which code was or was not executed as part of the test suite. + +.. note:: + Coverage analysis is only supported by GNU/Clang compilers. + +This functionality requires that BLT's ``ENABLE_COVERAGE`` option is enabled and that ``gcov``, ``lcov``, +and ``genhtml`` are present on your system. To use a specific version of one of these tools, you can set +``GCOV_EXECUTABLE``, ``LCOV_EXECUTABLE``, and ``GENHTML_EXECUTABLE`` to point at the desired version(s). + +.. note:: + The ``ENABLE_COVERAGE`` option will add compiler flags that instrument your code (and slow it down). + The option should never be enabled by default in a project for performance reasons. diff --git a/docs/api/documentation.rst b/docs/api/documentation.rst index f1b521cd9..ddc115cec 100644 --- a/docs/api/documentation.rst +++ b/docs/api/documentation.rst @@ -1,11 +1,12 @@ -.. # Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -.. # other BLT Project Developers. See the top-level COPYRIGHT file for details -.. # +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details +.. # .. # SPDX-License-Identifier: (BSD-3-Clause) Documenation Macros =================== +.. _blt_add_doxygen_target: blt_add_doxygen_target ~~~~~~~~~~~~~~~~~~~~~~ @@ -14,14 +15,16 @@ blt_add_doxygen_target blt_add_doxygen_target(doxygen_target_name) -Creates a build target for invoking doxygen to generate docs. Expects to -find a Doxyfile.in in the directory the macro is called in. +Creates a build target for invoking Doxygen to generate docs. Expects to +find a ``Doxyfile.in`` in the directory the macro is called in. -This macro sets up the doxygen paths so that the doc builds happen -out of source. For ``make install``, this will place the resulting docs in -docs/doxygen/. +This macro sets up the doxygen paths so that the doc builds happen +out of source. For ``make install``, this will place the resulting docs in +``docs/doxygen/``. +.. _blt_add_sphinx_target: + blt_add_sphinx_target ~~~~~~~~~~~~~~~~~~~~~ @@ -29,14 +32,16 @@ blt_add_sphinx_target blt_add_sphinx_target(sphinx_target_name) -Creates a build target for invoking sphinx to generate docs. Expects to -find a conf.py or conf.py.in in the directory the macro is called in. +Creates a build target for invoking Sphinx to generate docs. Expects +to find a ``conf.py`` or ``conf.py.in`` in the directory the macro is called +in. Requires that a CMake variable named ``SPHINX_EXECUTABLE`` +contains the path to the ``sphinx-build`` executable. -If conf.py is found, it is directly used as input to sphinx. +If ``conf.py`` is found, it is directly used as input to Sphinx. -If conf.py.in is found, this macro uses CMake's configure_file() command -to generate a conf.py, which is then used as input to sphinx. +If ``conf.py.in`` is found, this macro uses CMake's ``configure_file()`` command +to generate a ``conf.py``, which is then used as input to Sphinx. -This macro sets up the sphinx paths so that the doc builds happen -out of source. For ``make install``, this will place the resulting docs in -docs/sphinx/. +This macro sets up the sphinx paths so that the doc builds happen +out of source. For ``make install``, this will place the resulting docs in +``docs/sphinx/``. diff --git a/docs/api/git.rst b/docs/api/git.rst index dade2986d..f05d8558b 100644 --- a/docs/api/git.rst +++ b/docs/api/git.rst @@ -1,11 +1,12 @@ -.. # Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -.. # other BLT Project Developers. See the top-level COPYRIGHT file for details +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details .. # .. # SPDX-License-Identifier: (BSD-3-Clause) Git Macros ========== +.. _blt_git: blt_git ~~~~~~~ @@ -20,23 +21,23 @@ blt_git Runs the supplied git command on the given Git repository. -This macro runs the user-supplied Git command, given by GIT_COMMAND, on the -given Git repository corresponding to SOURCE_DIR. The supplied GIT_COMMAND +This macro runs the user-supplied Git command, given by ``GIT_COMMAND``, on the +given Git repository corresponding to ``SOURCE_DIR``. The supplied ``GIT_COMMAND`` is just a string consisting of the Git command and its arguments. The resulting output is returned to the supplied CMake variable provided by -the OUTPUT_VARIABLE argument. +the ``OUTPUT_VARIABLE`` argument. A return code for the Git command is returned to the caller via the CMake -variable provided with the RETURN_CODE argument. A non-zero return code +variable provided with the ``RETURN_CODE`` argument. A non-zero return code indicates that an error has occured. -Note, this macro assumes FindGit() was invoked and was successful. It relies -on the following variables set by FindGit(): +Note, this macro assumes ``FindGit()`` was invoked and was successful. It relies +on the following variables set by ``FindGit()``: - * Git_FOUND flag that indicates if git is found - * GIT_EXECUTABLE points to the Git binary + * ``Git_FOUND`` flag that indicates if git is found + * ``GIT_EXECUTABLE`` points to the Git binary -If Git_FOUND is "false" this macro will throw a FATAL_ERROR message. +If ``Git_FOUND`` is ``False`` this macro will throw a ``FATAL_ERROR`` message. .. code-block:: cmake :caption: **Example** @@ -51,6 +52,8 @@ If Git_FOUND is "false" this macro will throw a FATAL_ERROR message. endif() +.. _blt_is_git_repo: + blt_is_git_repo ~~~~~~~~~~~~~~~ @@ -63,11 +66,11 @@ Checks if we are working with a valid Git repository. This macro checks if the corresponding source directory is a valid Git repo. Nominally, the corresponding source directory that is used is set to -${CMAKE_CURRENT_SOURCE_DIR}. A different source directory may be optionally -specified using the SOURCE_DIR argument. +``CMAKE_CURRENT_SOURCE_DIR``. A different source directory may be optionally +specified using the ``SOURCE_DIR`` argument. The resulting state is stored in the CMake variable specified by the caller -using the OUTPUT_STATE parameter. +using the ``OUTPUT_STATE`` parameter. .. code-block:: cmake :caption: **Example** @@ -81,6 +84,8 @@ using the OUTPUT_STATE parameter. endif() +.. _blt_git_tag: + blt_git_tag ~~~~~~~~~~~ @@ -94,16 +99,16 @@ blt_git_tag Returns the latest tag on a corresponding Git repository. This macro gets the latest tag from a Git repository that can be specified -via the SOURCE_DIR argument. If SOURCE_DIR is not supplied, the macro will -use ${CMAKE_CURRENT_SOURCE_DIR}. By default the macro will return the latest +via the ``SOURCE_DIR`` argument. If ``SOURCE_DIR`` is not supplied, the macro will +use ``CMAKE_CURRENT_SOURCE_DIR``. By default the macro will return the latest tag on the branch that is currently checked out. A particular branch may be -specified using the ON_BRANCH option. +specified using the ``ON_BRANCH`` option. The tag is stored in the CMake variable specified by the caller using the -the OUTPUT_TAG parameter. +the ``OUTPUT_TAG`` parameter. A return code for the Git command is returned to the caller via the CMake -variable provided with the RETURN_CODE argument. A non-zero return code +variable provided with the ``RETURN_CODE`` argument. A non-zero return code indicates that an error has occured. .. code-block:: cmake @@ -117,6 +122,8 @@ indicates that an error has occured. message( STATUS "tag=${tag}" ) +.. _blt_git_branch: + blt_git_branch ~~~~~~~~~~~~~~ @@ -129,12 +136,12 @@ blt_git_branch Returns the name of the active branch in the checkout space. This macro gets the name of the current active branch in the checkout space -that can be specified using the SOURCE_DIR argument. If SOURCE_DIR is not +that can be specified using the ``SOURCE_DIR`` argument. If ``SOURCE_DIR`` is not supplied by the caller, this macro will point to the checkout space -corresponding to ${CMAKE_CURRENT_SOURCE_DIR}. +corresponding to ``CMAKE_CURRENT_SOURCE_DIR``. A return code for the Git command is returned to the caller via the CMake -variable provided with the RETURN_CODE argument. A non-zero return code +variable provided with the ``RETURN_CODE`` argument. A non-zero return code indicates that an error has occured. .. code-block:: cmake @@ -148,6 +155,8 @@ indicates that an error has occured. message( STATUS "active_branch=${active_branch}" ) +.. _blt_git_hashcode: + blt_git_hashcode ~~~~~~~~~~~~~~~~ @@ -161,14 +170,14 @@ blt_git_hashcode Returns the SHA-1 hashcode at the tip of a branch. This macro returns the SHA-1 hashcode at the tip of a branch that may be -specified with the ON_BRANCH argument. If the ON_BRANCH argument is not +specified with the ``ON_BRANCH`` argument. If the ``ON_BRANCH`` argument is not supplied, the macro will return the SHA-1 hash at the tip of the current branch. In addition, the caller may specify the target Git repository using -the SOURCE_DIR argument. Otherwise, if SOURCE_DIR is not specified, the -macro will use ${CMAKE_CURRENT_SOURCE_DIR}. +the ``SOURCE_DIR`` argument. Otherwise, if ``SOURCE_DIR`` is not specified, the +macro will use ``CMAKE_CURRENT_SOURCE_DIR``. A return code for the Git command is returned to the caller via the CMake -variable provided with the RETURN_CODE argument. A non-zero return code +variable provided with the ``RETURN_CODE`` argument. A non-zero return code indicates that an error has occured. .. code-block:: cmake diff --git a/docs/api/index.rst b/docs/api/index.rst index cee8969f4..cb31bb6ad 100644 --- a/docs/api/index.rst +++ b/docs/api/index.rst @@ -1,5 +1,5 @@ -.. # Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -.. # other BLT Project Developers. See the top-level COPYRIGHT file for details +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details .. # .. # SPDX-License-Identifier: (BSD-3-Clause) @@ -14,4 +14,5 @@ API Documentation utility git code_check + code_metric documentation diff --git a/docs/api/target.rst b/docs/api/target.rst index 075fcfad8..ec8b80dca 100644 --- a/docs/api/target.rst +++ b/docs/api/target.rst @@ -1,5 +1,5 @@ -.. # Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -.. # other BLT Project Developers. See the top-level COPYRIGHT file for details +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details .. # .. # SPDX-License-Identifier: (BSD-3-Clause) @@ -38,14 +38,14 @@ information see :ref:`blt_add_test`. The underlying executable should be previously added to the build system with :ref:`blt_add_executable`. It should include the necessary benchmarking -library in its DEPENDS_ON list. +library in its ``DEPENDS_ON`` list. -Any calls to this macro should be guarded with ENABLE_BENCHMARKS unless this option +Any calls to this macro should be guarded with ``ENABLE_BENCHMARKS`` unless this option is always on in your build project. .. note:: BLT provides a built-in Google Benchmark that is enabled by default if you set - ENABLE_BENCHMARKS=ON and can be turned off with the option ENABLE_GBENCHMARK. + ``ENABLE_BENCHMARKS=ON`` and can be turned off with the option ``ENABLE_GBENCHMARK``. .. code-block:: cmake :caption: **Example** @@ -60,6 +60,7 @@ is always on in your build project. COMMAND component_benchmark "--benchmark_min_time=0.0 --v=3 --benchmark_format=json") endif() + .. _blt_add_executable: blt_add_executable @@ -67,13 +68,15 @@ blt_add_executable .. code-block:: cmake - blt_add_executable( NAME - SOURCES [source1 [source2 ...]] - INCLUDES [dir1 [dir2 ...]] - DEFINES [define1 [define2 ...]] - DEPENDS_ON [dep1 [dep2 ...]] - OUTPUT_DIR [dir] - FOLDER [name]) + blt_add_executable( NAME + SOURCES [source1 [source2 ...]] + HEADERS [header1 [header2 ...]] + INCLUDES [dir1 [dir2 ...]] + DEFINES [define1 [define2 ...]] + DEPENDS_ON [dep1 [dep2 ...]] + OUTPUT_DIR [dir] + OUTPUT_NAME [name] + FOLDER [name]) Adds an executable target to the project. @@ -83,6 +86,9 @@ NAME SOURCES List of all sources to be added +HEADERS + List of all headers to be added + INCLUDES List of include directories both used by this target and inherited by dependent targets @@ -98,23 +104,29 @@ DEPENDS_ON OUTPUT_DIR Directory that this target will built to, defaults to bin +OUTPUT_NAME + Override built file name of the executable (defaults to ````) + FOLDER Name of the IDE folder to ease organization -Adds an executable target, called , to be built from the given sources. -It also adds the given INCLUDES and DEFINES from the parameters to this macro -and adds all inherited information from the list given by DEPENDS_ON. This +Adds an executable target, called ````, to be built from the given sources. +It also adds the given ``INCLUDES`` and ``DEFINES`` from the parameters to this macro +and adds all inherited information from the list given by ``DEPENDS_ON``. This macro creates a true CMake target that can be altered by other CMake commands -like normal, such as `set_target_property()`. +like normal, such as ``set_target_property()``. It also adds ``SOURCES`` and ``HEADERS`` +to the library for build system dependency tracking and IDE folder support. -.. note:: - If the first entry in SOURCES is a Fortran source file, the fortran linker - is used. (via setting the CMake target property LINKER_LANGUAGE to Fortran ) +``OUTPUT_NAME`` is useful when multiple CMake targets with the same name need to be +created by different targets. .. note:: - The FOLDER option is only used when ENABLE_FOLDERS is ON and when the CMake generator - supports this feature and will otherwise be ignored. + If the first entry in ``SOURCES`` is a Fortran source file, the fortran linker + is used, via setting the CMake target property ``LINKER_LANGUAGE`` to Fortran. +.. note:: + The ``FOLDER`` option is only used when ``ENABLE_FOLDERS`` is ``ON`` and when the + CMake generator supports this feature and will otherwise be ignored. .. _blt_add_library: @@ -161,25 +173,26 @@ DEPENDS_ON depends on OUTPUT_NAME - Override built file name of library (defaults to ) + Override built file name of the library (defaults to ````) OUTPUT_DIR Directory that this target will built to SHARED - Builds library as shared and overrides global BUILD_SHARED_LIBS (defaults to OFF) + Builds library as shared and overrides global ``BUILD_SHARED_LIBS`` (defaults to ``OFF``) OBJECT Create an Object library CLEAR_PREFIX - Removes library prefix (defaults to 'lib' on linux) + Removes library prefix (defaults to ``lib`` on linux) FOLDER Name of the IDE folder to ease organization This macro creates a true CMake target that can be altered by other CMake commands -like normal, such as `set_target_property()`. +like normal, such as ``set_target_property()``. It also adds ``SOURCES`` and ``HEADERS`` +to the library for build system dependency tracking and IDE folder support. This macro supports three types of libraries automatically: normal, header-only, or object. @@ -188,39 +201,42 @@ Normal libraries are libraries that have sources that are compiled and linked in library and have headers that go along with them (unless it's a Fortran library). Header-only libraries are useful when you do not want the library separately compiled or -are using C++ templates that require the library's user to instatiate them. These libraries -have headers but no sources. To create a header-only library (CMake calls them INTERFACE libraries), -simply list all headers under the HEADER argument and do not specify SOURCES (because there aren't any). +are using C++ templates that require the library's user to instantiate them. These libraries +have headers but no sources. To create a header-only library (CMake calls them ``INTERFACE`` libraries), +simply list all headers under the ``HEADERS`` argument and do not specify ``SOURCES`` +(because there aren't any). Header-only libraries can have dependencies like compiled libraries. +These will be propagated to targets that depend on the header-only library. Object libraries are basically a collection of compiled source files that are not archived or linked. They are sometimes useful when you want to solve compilicated linking problems (like circular dependencies) or when you want to combine smaller libraries into one larger library but don't want the linker to remove unused symbols. Unlike regular CMake object libraries you do not have to use the ``$>`` syntax, you can just -use with BLT macros. Unless you have a good reason don't use Object libraries. +use ```` with BLT macros. Unless you have a good reason don't use Object libraries. .. note:: - BLT Object libraries do not follow CMake's normal transitivity rules. Due to CMake requiring - you install the individual object files if you install the target that uses them. BLT manually - adds the INTERFACE target properties to get around this. + Due to necessary record keeping, BLT Object libraries need to be defined by :ref:`blt_add_library` before + they are used in any ``DEPENDS_ON`` list. They also do not follow CMake's normal transitivity rules. + This is due to CMake requiring you install the individual object files if you install the + target that uses them. BLT manually adds the ``INTERFACE`` target properties to get around this. -This macro uses the BUILD_SHARED_LIBS, which is defaulted to OFF, to determine +This macro uses the ``BUILD_SHARED_LIBS``, which is defaulted to ``OFF``, to determine whether the library will be built as shared or static. The optional boolean -SHARED argument can be used to override this choice. +``SHARED`` argument can be used to override this choice. -If given a DEPENDS_ON argument, this macro will inherit the necessary information +If given a ``DEPENDS_ON`` argument, this macro will inherit the necessary information from all targets given in the list. This includes CMake targets as well as any BLT registered libraries already defined via :ref:`blt_register_library`. To ease use, all information is used by this library and inherited by anything depending on this -library (CMake PUBLIC inheritance). +library (CMake ``PUBLIC`` inheritance). -OUTPUT_NAME is useful when multiple libraries with the same name need to be created +``OUTPUT_NAME`` is useful when multiple libraries with the same name need to be created by different targets. For example, you might want to build both a shared and static -library in the same build instead of building twice, once with BUILD_SHARED_LIBS set to ON -and then with OFF. NAME is the CMake target name, OUTPUT_NAME is the created library name. +library in the same build instead of building twice, once with ``BUILD_SHARED_LIBS`` set to ``ON`` +and then with ``OFF``. ``NAME`` is the CMake target name, ``OUTPUT_NAME`` is the created library name. .. note:: - The FOLDER option is only used when ENABLE_FOLDERS is ON and when the CMake generator + The ``FOLDER`` option is only used when ``ENABLE_FOLDERS`` is ``ON`` and when the CMake generator supports this feature and will otherwise be ignored. @@ -249,7 +265,8 @@ NUM_MPI_TASKS Indicates this is an MPI test and how many MPI tasks to use. NUM_OMP_THREADS - Indicates this test requires the defined environment variable OMP_NUM_THREADS set to the given variable. + Indicates this test requires the defined environment variable ``OMP_NUM_THREADS`` + set to the given variable. CONFIGURATIONS Set the CTest configuration for this test. When not specified, the test @@ -259,17 +276,17 @@ This macro adds the named test to CTest, which is run by the build target ``test does not build the executable and requires a prior call to :ref:`blt_add_executable`. This macro assists with building up the correct command line. It will prepend -the RUNTIME_OUTPUT_DIRECTORY target property to the executable. +the ``RUNTIME_OUTPUT_DIRECTORY`` target property to the executable. -If NUM_MPI_TASKS is given or ENABLE_WRAP_ALL_TESTS_WITH_MPIEXEC is set, the macro -will appropiately use MPIEXEC, MPIEXEC_NUMPROC_FLAG, and BLT_MPI_COMMAND_APPEND +If ``NUM_MPI_TASKS`` is given or ``ENABLE_WRAP_ALL_TESTS_WITH_MPIEXEC`` is set, the macro +will appropriately use ``MPIEXEC``, ``MPIEXEC_NUMPROC_FLAG``, and ``BLT_MPI_COMMAND_APPEND`` to create the MPI run line. -MPIEXEC and MPIEXEC_NUMPROC_FLAG are filled in by CMake's FindMPI.cmake but can -be overwritten in your host-config specific to your platform. BLT_MPI_COMMAND_APPEND -is useful on machines that require extra arguments to MPIEXEC. +``MPIEXEC`` and ``MPIEXEC_NUMPROC_FLAG`` are filled in by CMake's ``FindMPI.cmake`` but can +be overwritten in your host-config specific to your platform. ``BLT_MPI_COMMAND_APPEND`` +is useful on machines that require extra arguments to ``MPIEXEC``. -If NUM_OMP_THREADS is given, this macro will set the environment variable OMP_NUM_THREADS +If ``NUM_OMP_THREADS`` is given, this macro will set the environment variable ``OMP_NUM_THREADS`` before running this test. This is done by appending to the CMake tests property. .. note:: @@ -278,7 +295,7 @@ before running this test. This is done by appending to the CMake tests property repository you wish to run as a test instead of an executable you built as a part of your build system. -Any calls to this macro should be guarded with ENABLE_TESTS unless this option +Any calls to this macro should be guarded with ``ENABLE_TESTS`` unless this option is always on in your build project. .. code-block:: cmake @@ -293,6 +310,160 @@ is always on in your build project. endif() +.. _blt_patch_target: + +blt_patch_target +~~~~~~~~~~~~~~~~ + +.. code-block:: cmake + + blt_patch_target( NAME + DEPENDS_ON [dep1 [dep2 ...]] + INCLUDES [include1 [include2 ...]] + TREAT_INCLUDES_AS_SYSTEM [ON|OFF] + FORTRAN_MODULES [path1 [path2 ..]] + LIBRARIES [lib1 [lib2 ...]] + COMPILE_FLAGS [flag1 [flag2 ..]] + LINK_FLAGS [flag1 [flag2 ..]] + DEFINES [def1 [def2 ...]] ) + +Modifies the properties of an existing target. ``PUBLIC`` visibility +is used unless the target is an ``INTERFACE`` library, in which case +``INTERFACE`` visibility is used. + +NAME + Name of the CMake target to patch + +DEPENDS_ON + List of CMake targets that this target depends on + +INCLUDES + List of include directories to be inherited by dependent targets + +TREAT_INCLUDES_AS_SYSTEM + Whether to inform the compiler to treat this target's include paths + as system headers - this applies to all include paths for the target, + not just those specifies in the ``INCLUDES`` parameter. Only some + compilers support this. This is useful if the headers generate warnings + you want to not have them reported in your build. This defaults to ``OFF``. + +FORTRAN_MODULES + Fortran module directories to be inherited by dependent targets + +LIBRARIES + List of CMake targets and library files (.a/.so/.lib/.dll) that make up + this target, used for libraries + +COMPILE_FLAGS + List of compiler flags to be inherited by dependent targets + +LINK_FLAGS + List of linker flags to be inherited by dependent targets + +DEFINES + List of compiler defines to be inherited by dependent targets + +This macro does not create a target, it is intended to be used with CMake +targets created via another BLT macro or CMake command. Unlike :ref:`blt_register_library`, +it modifies the specified target, updating the CMake properties of the target that correspond +to each of the parameters. + +.. warning:: + The ``DEPENDS_ON`` and ``LIBRARIES`` parameters cannot be used when patching a target + declared in a separate directory unless CMake policy CMP0079 has been set. + + +.. _blt_import_library: + +blt_import_library +~~~~~~~~~~~~~~~~~~ + +.. code-block:: cmake + + blt_import_library( NAME + DEPENDS_ON [dep1 [dep2 ...]] + INCLUDES [include1 [include2 ...]] + TREAT_INCLUDES_AS_SYSTEM [ON|OFF] + FORTRAN_MODULES [path1 [path2 ..]] + LIBRARIES [lib1 [lib2 ...]] + COMPILE_FLAGS [flag1 [flag2 ..]] + LINK_FLAGS [flag1 [flag2 ..]] + DEFINES [def1 [def2 ...]] + GLOBAL [ON|OFF] + EXPORTABLE [ON|OFF]) + +Creates a CMake target from build artifacts and system files generated outside of this build system. + +NAME + Name of the created CMake target + +DEPENDS_ON + List of CMake targets that this library depends on + +INCLUDES + List of include directories to be inherited by dependent targets + +TREAT_INCLUDES_AS_SYSTEM + Whether to inform the compiler to treat this library's include paths + as system headers + +FORTRAN_MODULES + Fortran module directories to be inherited by dependent targets + +LIBRARIES + List of CMake targets and library files (.a/.so/.lib/.dll) that make up + this library + +COMPILE_FLAGS + List of compiler flags to be inherited by dependent targets + +LINK_FLAGS + List of linker flags to be inherited by dependent targets + +DEFINES + List of compiler defines to be inherited by dependent targets + +GLOBAL + Whether to extend the visibility of the created library to global scope + +EXPORTABLE + Whether the created target should be exportable and ``install``-able + +Allows libraries not built with CMake to be imported as native CMake targets +in order to take full advantage of CMake's transitive dependency resolution. + +For example, a ``Find.cmake`` may set only the variables ``_LIBRARIES`` +(which might contain the .a/.so/.lib/.dll file for the library itself, and the libraries it +depends on) and ``_INCLUDES`` (which might contain the include directories required +to use the library). Instead of using these variables directly every time they are needed, +they could instead be built into a CMake target. It also allows for compiler and linker +options to be associated with the library. + +As with BLT-registered libraries, it can be added to the ``DEPENDS_ON`` parameter +when building another target or to ``target_link_libraries()`` to transitively add in +all includes, libraries, flags, and definitions associated with the imported library. + +The ``EXPORTABLE`` option is intended to be used to simplify the process of exporting a project. +Instead of handwriting package location logic in a CMake package configuration file, the +``EXPORTABLE`` targets can be exported with the targets defined by the project. + +.. note:: + Libraries marked ``EXPORTABLE`` cannot also be marked ``GLOBAL``. They also + must be added to any export set that includes a target that depends on the + ``EXPORTABLE`` library. + +.. note:: + It is highly recommended that ``EXPORTABLE`` imported targets be installed with a + project-specific namespace/prefix, either with the ``NAMESPACE`` option of CMake's + ``install()`` command, or the ``EXPORT_NAME`` target property. This mitigates the + risk of conflicting target names. + +In CMake terms, the imported libraries will be ``INTERFACE`` libraries. + +This does not actually build a library. This is strictly to ease use after +discovering it on your system or building it yourself inside your project. + + .. _blt_register_library: blt_register_library @@ -314,28 +485,32 @@ Registers a library to the project to ease use in other BLT macro calls. Stores information about a library in a specific way that is easily recalled in other macros. For example, after registering gtest, you can add gtest to -the DEPENDS_ON in your blt_add_executable call and it will add the INCLUDES -and LIBRARIES to that executable. +the ``DEPENDS_ON`` in your :ref:`blt_add_executable` call and it will add the +``INCLUDES`` and ``LIBRARIES`` to that executable. -TREAT_INCLUDES_AS_SYSTEM informs the compiler to treat this library's include paths -as system headers. Only some compilers support this. This is useful if the headers -generate warnings you want to not have them reported in your build. This defaults -to OFF. - -This does not actually build the library. This is strictly to ease use after -discovering it on your system or building it yourself inside your project. +.. note:: + In general, this macro should be avoided unless absolutely necessary, as it + does not create a native CMake target. If the library to register already exists + as a CMake target, consider using :ref:`blt_patch_target`. Otherwise, consider using + :ref:`blt_import_library`. These options are insufficient in some circumstances, for example, + if it is necessary to add libraries to a CMake library target declared in another + directory while keeping the modified target usable with the same name as the original + target. In this case :ref:`blt_register_library` is the only option. -Note: The OBJECT parameter is for internal BLT support for object libraries -and is not for users. Object libraries are created using blt_add_library(). +.. note:: + The ``OBJECT`` parameter is for internal BLT support for object libraries + and is not for users. Object libraries are created using :ref:`blt_add_library`. Internally created variables (NAME = "foo"): - | BLT_FOO_IS_REGISTERED_LIBRARY - | BLT_FOO_IS_OBJECT_LIBRARY - | BLT_FOO_DEPENDS_ON - | BLT_FOO_INCLUDES - | BLT_FOO_TREAT_INCLUDES_AS_SYSTEM - | BLT_FOO_FORTRAN_MODULES - | BLT_FOO_LIBRARIES - | BLT_FOO_COMPILE_FLAGS - | BLT_FOO_LINK_FLAGS - | BLT_FOO_DEFINES + | _BLT_FOO_IS_REGISTERED_LIBRARY + | _BLT_FOO_IS_OBJECT_LIBRARY + | _BLT_FOO_DEPENDS_ON + | _BLT_FOO_INCLUDES + | _BLT_FOO_TREAT_INCLUDES_AS_SYSTEM + | _BLT_FOO_FORTRAN_MODULES + | _BLT_FOO_LIBRARIES + | _BLT_FOO_COMPILE_FLAGS + | _BLT_FOO_LINK_FLAGS + | _BLT_FOO_DEFINES + +Internal variable names are prefixed with ``_`` to avoid collision with input parameters. diff --git a/docs/api/target_properties.rst b/docs/api/target_properties.rst index be34158f6..abfeebaf7 100644 --- a/docs/api/target_properties.rst +++ b/docs/api/target_properties.rst @@ -1,11 +1,12 @@ -.. # Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -.. # other BLT Project Developers. See the top-level COPYRIGHT file for details +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details .. # .. # SPDX-License-Identifier: (BSD-3-Clause) Target Property Macros ====================== +.. _blt_add_target_compile_flags: blt_add_target_compile_flags ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -28,20 +29,22 @@ FLAGS List of compile flags This macro provides very similar functionality to CMake's native -``add_compile_options`` and ``target_compile_options`` commands, but +``add_compile_options()`` and ``target_compile_options()`` commands, but provides more fine-grained scoping for the compile flags on a per target basis. -The given target must be added via CMake's ``add_executable`` or ``add_library`` commands -or with the corresponding ``blt_add_executable`` and ``blt_add_library`` macros. +The given target must be added via CMake's ``add_executable()`` or ``add_library()`` commands +or with the corresponding :ref:`blt_add_executable` and :ref:`blt_add_library` macros. -PRIVATE flags are used for the given target. INTERFACE flags are inherited -by any target that depends on this target. PUBLIC flags are both INTERFACE and PRIVATE. +``PRIVATE`` flags are used for the given target. ``INTERFACE`` flags are inherited +by any target that depends on this target. ``PUBLIC`` flags are both ``INTERFACE`` and ``PRIVATE``. .. note:: This macro will strip away leading and trailing whitespace from each flag. +.. _blt_add_target_definitions: + blt_add_target_definitions ~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -57,28 +60,28 @@ TO Name of CMake target SCOPE - Defines the scope of the given definitions. Defaults to PUBLIC and is case insensitive. + Defines the scope of the given definitions. Defaults to ``PUBLIC`` and is case insensitive. FLAGS List of definitions flags This macro provides very similar functionality to CMake's native -``add_definitions`` and ``target_add_defintions`` commands, but provides +``add_definitions()`` and ``target_add_defintions()`` commands, but provides more fine-grained scoping for the compile definitions on a per target basis. -Given a list of definitions, e.g., FOO and BAR, this macro adds compiler +Given a list of definitions, e.g., ``FOO`` and ``BAR``, this macro adds compiler definitions to the compiler command for the given target, i.e., it will pass --DFOO and -DBAR. +``-DFOO`` and ``-DBAR``. -The given target must be added via CMake's ``add_executable`` or ``add_library`` commands -or with the corresponding ``blt_add_executable`` and ``blt_add_library`` macros. +The given target must be added via CMake's ``add_executable()`` or ``add_library()`` commands +or with the corresponding :ref:`blt_add_executable` and :ref:`blt_add_library` macros. -PRIVATE flags are used for the given target. INTERFACE flags are inherited -by any target that depends on this target. PUBLIC flags are both INTERFACE and PRIVATE. +``PRIVATE`` flags are used for the given target. ``INTERFACE`` flags are inherited +by any target that depends on this target. ``PUBLIC`` flags are both ``INTERFACE`` and ``PRIVATE``. .. note:: The target definitions can either include or omit the "-D" characters. E.g. the following are all valid ways to add two compile definitions - (A=1 and B) to target 'foo'. + (A=1 and B) to target ``foo``. .. note:: This macro will strip away leading and trailing whitespace from each definition. @@ -93,6 +96,8 @@ by any target that depends on this target. PUBLIC flags are both INTERFACE and P blt_add_target_definitions(TO foo TARGET_DEFINITIONS " " -DA=1;B) +.. _blt_add_target_link_flags: + blt_add_target_link_flags ~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -114,21 +119,21 @@ FLAGS List of linker flags This macro provides very similar functionality to CMake's native -``add_link_options`` and ``target_link_options`` commands, but provides +``add_link_options()`` and ``target_link_options()`` commands, but provides more fine-grained scoping for the compile definitions on a per target basis. -The given target must be added via CMake's ``add_executable`` or ``add_library`` commands -or with the corresponding ``blt_add_executable`` and ``blt_add_library`` macros. +The given target must be added via CMake's ``add_executable()`` or ``add_library()`` commands +or with the corresponding :ref:`blt_add_executable` and :ref:`blt_add_library` macros. -PRIVATE flags are used for the given target. INTERFACE flags are inherited -by any target that depends on this target. PUBLIC flags are both INTERFACE and PRIVATE. +``PRIVATE`` flags are used for the given target. ``INTERFACE`` flags are inherited +by any target that depends on this target. ``PUBLIC`` flags are both ``INTERFACE`` and ``PRIVATE``. -If `CUDA_LINK_WITH_NVCC` is set to ON, this macro will automatically convert -"-Wl,-rpath," to "-Xlinker -rpath -Xlinker ". +If ``CUDA_LINK_WITH_NVCC`` is set to ``ON``, this macro will automatically +convert ``-Wl,-rpath,`` to :literal:`-Xlinker -rpath -Xlinker\ `. .. note:: This macro also handles the various changes that CMake made in 3.13. For example, - the target property LINK_FLAGS was changes to LINK_OPTIONS and was changed from a + the target property ``LINK_FLAGS`` was changes to ``LINK_OPTIONS`` and was changed from a string to a list. New versions now support Generator Expressions. Also pre-3.13, there were no macros to add link flags to targets so we do this by setting the properties directly. @@ -138,11 +143,13 @@ If `CUDA_LINK_WITH_NVCC` is set to ON, this macro will automatically convert and any ; characters will be removed. .. note:: - In CMake versions 3.13 and above, this list is prepended with "SHELL:" which stops + In CMake versions 3.13 and above, this list is prepended with ``SHELL:`` which stops CMake from de-duplicating flags. This is especially bad when linking with NVCC when - you have groups of flags like "-Xlinker -rpath -Xlinker ". + you have groups of flags like ``-Xlinker -rpath -Xlinker ``. +.. _blt_print_target_properties: + blt_print_target_properties ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -155,14 +162,16 @@ Prints out all properties of the given target. TARGET Name of CMake target -The given target must be added via ``add_executable`` or ``add_library`` or -with the corresponding ``blt_add_executable``, ``blt_add_library``, or -``blt_register_library`` macros. +The given target must be added via ``add_executable()`` or ``add_library()`` or +with the corresponding :ref:`blt_add_executable`, :ref:`blt_add_library`, +:ref:`blt_import_library`, or :ref:`blt_register_library` macros. Output is of the form for each property: | [ property] : +.. _blt_set_target_folder: + blt_set_target_folder ~~~~~~~~~~~~~~~~~~~~~ @@ -181,11 +190,11 @@ FOLDER This is used to organize properties in an IDE. -This feature is only available when BLT's `ENABLE_FOLDERS` option is ON and +This feature is only available when BLT's ``ENABLE_FOLDERS`` option is ``ON`` and in CMake generators that support folders (but is safe to call regardless -of the generator or value of ENABLE_FOLDERS). +of the generator or value of ``ENABLE_FOLDERS``). .. note:: - Do not use this macro on header-only (INTERFACE) library targets, since + Do not use this macro on header-only, ``INTERFACE`` library targets, since this will generate a CMake configuration error. diff --git a/docs/api/utility.rst b/docs/api/utility.rst index f9eb6e977..6d7fd89ab 100644 --- a/docs/api/utility.rst +++ b/docs/api/utility.rst @@ -1,11 +1,12 @@ -.. # Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -.. # other BLT Project Developers. See the top-level COPYRIGHT file for details +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details .. # .. # SPDX-License-Identifier: (BSD-3-Clause) Utility Macros ============== +.. _blt_assert_exists: blt_assert_exists ~~~~~~~~~~~~~~~~~~~ @@ -21,7 +22,6 @@ Checks if the specified directory, file and/or cmake target exists and throws an error message. .. note:: - The behavior for checking if a given file or directory exists is well-defined only for absolute paths. @@ -43,6 +43,8 @@ an error message. blt_assert_exists( TARGETS foo bar ) +.. _blt_append_custom_compiler_flag: + blt_append_custom_compiler_flag ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -64,16 +66,18 @@ blt_append_custom_compiler_flag Appends compiler-specific flags to a given variable of flags If a custom flag is given for the current compiler, we use that. -Otherwise, we will use the DEFAULT flag (if present). +Otherwise, we will use the ``DEFAULT`` flag (if present). -If ENABLE_FORTRAN is On, any flagsVar with "fortran" (any capitalization) +If ``ENABLE_FORTRAN`` is ``ON``, any flagsVar with ``fortran`` (any capitalization) in its name will pick the compiler family (GNU,CLANG, INTEL, etc) based on the fortran compiler family type. This allows mixing C and Fortran compiler families, e.g. using Intel fortran compilers with clang C compilers. -When using the Intel toolchain within visual studio, we use the -MSVC_INTEL flag, when provided, with a fallback to the MSVC flag. +When using the Intel toolchain within Visual Studio, we use the +``MSVC_INTEL`` flag, when provided, with a fallback to the ``MSVC`` flag. + +.. _blt_find_libraries: blt_find_libraries ~~~~~~~~~~~~~~~~~~ @@ -87,15 +91,17 @@ blt_find_libraries This command is used to find a list of libraries. -If the libraries are found the results are appended to the given FOUND_LIBS variable name. -NAMES lists the names of the libraries that will be searched for in the given PATHS. +If the libraries are found the results are appended to the given ``FOUND_LIBS`` variable name. +``NAMES`` lists the names of the libraries that will be searched for in the given ``PATHS``. -If REQUIRED is set to TRUE, BLT will produce an error message if any of the -given libraries are not found. The default value is TRUE. +If ``REQUIRED`` is set to ``TRUE``, BLT will produce an error message if any of the +given libraries are not found. The default value is ``TRUE``. -PATH lists the paths in which to search for NAMES. No system paths will be searched. +``PATH`` lists the paths in which to search for ``NAMES``. No system paths will be searched. +.. _blt_list_append: + blt_list_append ~~~~~~~~~~~~~~~ @@ -117,8 +123,9 @@ This macro requires specifying: * A condition to check by passing ``IF `` * The list of elements to append by passing ``ELEMENTS [...]`` -Note, the argument passed to the IF option has to be a single boolean value -and cannot be a boolean expression since CMake cannot evaluate those inline. +.. note:: + The argument passed to the ``IF`` option has to be a single boolean value + and cannot be a boolean expression since CMake cannot evaluate those inline. .. code-block:: cmake :caption: **Example** @@ -139,6 +146,8 @@ and cannot be a boolean expression since CMake cannot evaluate those inline. blt_list_append( TO mylist ELEMENTS F IF _undefined ) # Does not append 'F' +.. _blt_list_remove_duplicates: + blt_list_remove_duplicates ~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -146,7 +155,7 @@ blt_list_remove_duplicates blt_list_remove_duplicates(TO ) -Removes duplicate elements from the given TO list. +Removes duplicate elements from the given ``TO`` list. This macro is essentially a wrapper around CMake's ``list(REMOVE_DUPLICATES ...)`` command but doesn't throw an error if the list is empty or not defined. diff --git a/docs/conf.py b/docs/conf.py index 1134ebf06..2eb0f29c6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -47,7 +47,7 @@ # General information about the project. project = u'BLT: Build, Link, and Test' -copyright = u'2017-2019, BLT Development Team' +copyright = u'2017-2021, BLT Development Team' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -87,7 +87,7 @@ #show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = 'default' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] @@ -118,7 +118,7 @@ # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +html_logo = '../share/blt/logo/blt_logo_transparent.png' # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 @@ -128,7 +128,7 @@ # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -#html_static_path = ['_static'] +html_static_path = ['_static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. diff --git a/docs/developer/index.rst b/docs/developer/index.rst new file mode 100644 index 000000000..e144756d7 --- /dev/null +++ b/docs/developer/index.rst @@ -0,0 +1,14 @@ +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details +.. # +.. # SPDX-License-Identifier: (BSD-3-Clause) + +Developer Guide +=============== + +This section contains information for BLT developers. + +.. toctree:: + :titlesonly: + + release_process diff --git a/docs/developer/release_process.rst b/docs/developer/release_process.rst new file mode 100644 index 000000000..587aea94c --- /dev/null +++ b/docs/developer/release_process.rst @@ -0,0 +1,121 @@ +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details +.. # +.. # SPDX-License-Identifier: (BSD-3-Clause) + +Release Process +=============== + +.. note:: No significant code development is performed on a release branch. + In addition to preparing release notes and other documentation, the + only code changes that should be done are bug fixes identified + during release preparations + +Here are the steps to follow when creating a BLT release. + +1: Start Release Candidate Branch +--------------------------------- + +Create a release candidate branch off of the develop branch to initiate a +release. The name of a release branch must contain the associated release version +number. Typically, we use a name like v0.4.0-rc +(i.e., version 0.4.0 release candidate). + +.. code:: bash + + git checkout -b v0.4.0-rc + +2: Update Versions in Code +-------------------------- + +**Update BLT_VERSION** + + * ``SetupBLT.cmake``: ``set(BLT_VERSION "0.4.0" CACHE STRING "")`` + + +**Update Release Notes** + +#. Update ``RELEASE-NOTES.md`` by changing the + ``unreleased`` section from: + +.. code:: text + + ## [Unreleased] - Release date yyyy-mm-dd + +Also add to a versioned section with the current date while leaving the unreleased section: + +.. code:: + + ## [Unreleased] - Release date yyyy-mm-dd + + ## [Version 0.4.0] - Release date 2021-04-09 + +Finally, add a link to the bottom as well: + +.. code:: text + + [Unreleased]: https://github.com/LLNL/blt/compare/v0.3.6...develop + +to: + +.. code:: text + + [Unreleased]: https://github.com/LLNL/blt/compare/v0.4.0...develop + [Version 0.4.0]: https://github.com/LLNL/blt/compare/v0.3.6...v0.4.0 + + +3: Create Pull Request and push a git `tag` for the release +----------------------------------------------------------- + +#. Commit the changes and push them to Github. +#. Create a pull request from release candidate branch to ``main`` branch. +#. Merge pull request after reviewed and passing tests. +#. Checkout main locally: ``git checkout main && git pull`` +#. Create release tag: ``git tag v0.4.0`` +#. Push tag to Github: ``git push --tags`` + + +4: Draft a Github Release +------------------------- + +`Draft a new Release on Github `_ + +#. Enter the desired tag version, e.g., *v0.4.0* + +#. Select **main** as the target branch to tag a release. + +#. Enter a Release title with the same as the tag *v0.4.0* + +#. Copy and paste the information for the release from the + ``RELEASE-NOTES.md`` into the release description (omit any sections if empty). + +#. Publish the release. This will add a corresponding entry in the + `Releases section `_ + +.. note:: + + Github will add a corresponding tarball and zip archives consisting of the + source files for each release. + + +5: Create Release Branch and Mergeback to develop +------------------------------------------------- + +1. Create a branch off main that is for the release branch. + +.. code:: bash + + git pull + git checkout main + git checkout -b release-v0.4.0 + git push --set-upstream origin release-v0.4.0 + + +2. Create a pull request to merge ``main`` into ``develop`` through Github. When approved, merge it. + + +7: Build Release Documentation +------------------------------ + +Enable the build on `readthedocs version page `_ +for the version branch created in step 5. diff --git a/docs/index.rst b/docs/index.rst index aad69cf40..7fa4c8b48 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,18 +1,16 @@ -.. # Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -.. # other BLT Project Developers. See the top-level COPYRIGHT file for details +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details .. # .. # SPDX-License-Identifier: (BSD-3-Clause) -BLT -=== - -**Build, Link, and Test** +BLT: Build, Link, and Test +========================== BLT is a composition of CMake macros and several widely used open source tools assembled to simplify HPC software development. BLT was released by Lawrence Livermore National Laboratory (LLNL) under a BSD-style open source license. -It is developed on github under LLNL's github organization: https://github.com/llnl/blt +It is developed on GitHub under `LLNL's GitHub organization `_. .. note:: BLT officially supports CMake 3.8 and above. However we only print a warning if you @@ -20,7 +18,7 @@ It is developed on github under LLNL's github organization: https://github.com/l BLT at a Glance -~~~~~~~~~~~~~~~~~~ +--------------- * Simplifies setting up a CMake-based build system @@ -30,11 +28,13 @@ BLT at a Glance * Managing compiler flags * Managing external dependencies + * Handles differences across CMake versions + * Multi-platform support (HPC Platforms, OSX, Windows) * Batteries included - * Built-in support for HPC Basics: MPI, OpenMP, and CUDA + * Built-in support for HPC Basics: MPI, OpenMP, CUDA, and HIP * Built-in support for unit testing in C/C++ and Fortran * Streamlines development processes @@ -44,26 +44,36 @@ BLT at a Glance * Runtime and static analysis, benchmarking -Developers -~~~~~~~~~~ - * Chris White (white238@llnl.gov) - * Cyrus Harrison (harrison37@llnl.gov) - * George Zagaris (zagaris2@llnl.gov) - * Kenneth Weiss (kweiss@llnl.gov) - * Lee Taylor (taylor16@llnl.gov) - * Aaron Black (black27@llnl.gov) - * David A. Beckingsale (beckingsale1@llnl.gov) - * Richard Hornung (hornung1@llnl.gov) - * Randolph Settgast (settgast1@llnl.gov) - * Peter Robinson (robinson96@llnl.gov) +Questions +--------- + +Any questions can be sent to blt-dev@llnl.gov. If you are an LLNL employee or collaborator, we have an +internal Microsoft Teams group chat named "BLT" as well. + + +Contributions +------------- + +We welcome all kinds of contributions: new features, bug fixes, documentation edits. + +To contribute, make a `pull request `_, with ``develop`` +as the destination branch. We use CI testing and your branch must pass these tests before +being merged. + +For more information, see the `contributing guide `_. + + +Authors +------- +Thanks to all of BLT's `contributors `_. -Documentation -~~~~~~~~~~~~~ .. toctree:: + :caption: Table of Contents :maxdepth: 2 User Tutorial API Documentation + Developer Guide diff --git a/docs/tutorial/unit_testing.rst b/docs/tutorial/adding_tests.rst similarity index 62% rename from docs/tutorial/unit_testing.rst rename to docs/tutorial/adding_tests.rst index 5a4d1a3b7..b46d1d41d 100644 --- a/docs/tutorial/unit_testing.rst +++ b/docs/tutorial/adding_tests.rst @@ -1,27 +1,27 @@ -.. # Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -.. # other BLT Project Developers. See the top-level COPYRIGHT file for details +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details .. # .. # SPDX-License-Identifier: (BSD-3-Clause) -.. _UnitTesting: +.. _AddingTests: -Unit Testing +Adding Tests ============ BLT has a built-in copy of the -`Google Test framework (gtest) `_ for C +`GoogleTest framework (gtest) `_ for C and C++ unit tests and the `Fortran Unit Test Framework (FRUIT) `_ for Fortran unit tests. -Each Google Test or FRUIT file may contain multiple tests and is compiled into +Each GoogleTest or FRUIT file may contain multiple tests and is compiled into its own executable that can be run directly or as a ``make`` target. -In this section, we give a brief overview of GTest and discuss how to add unit +In this section, we give a brief overview of GoogleTest and discuss how to add unit tests using the ``blt_add_test()`` macro. -Configuring tests within BLT +Configuring Tests within BLT ---------------------------- Unit testing in BLT is controlled by the ``ENABLE_TESTS`` cmake option and is on @@ -41,10 +41,10 @@ options are available when ``ENABLE_TESTS`` is on: Option to control FRUIT (Default ``ON``). It is only active when ``ENABLE_FORTRAN`` is enabled. -Google Test (C++/C Tests) --------------------------- +GoogleTest (C/C++ Tests) +------------------------ -The contents of a typical Google Test file look like this: +The contents of a typical GoogleTest file look like this: .. code:: cpp @@ -66,9 +66,8 @@ The contents of a typical Google Test file look like this: // EXPECT_TRUE(...); } - // Etc. -Each unit test is defined by the Google Test ``TEST()`` macro which accepts a +Each unit test is defined by the GoogleTest ``TEST()`` macro which accepts a *test case name* identifier, such as the name of the C++ class being tested, and a *test name*, which indicates the functionality being verified by the test. Within a test, failure of logical assertions (macros prefixed by ``ASSERT_``) @@ -76,7 +75,7 @@ will cause the test to fail immediately, while failures of expected values (macros prefixed by ``EXPECT_``) will cause the test to fail, but will continue running code within the test. -Note that the Google Test framework will generate a ``main()`` routine for +Note that the GoogleTest framework will generate a ``main()`` routine for each test file if it is not explicitly provided. However, sometimes it is necessary to provide a ``main()`` routine that contains operation to run before or after the unit tests in a file; e.g., initialization code or @@ -84,22 +83,24 @@ pre-/post-processing operations. A ``main()`` routine provided in a test file should be placed at the end of the file in which it resides. -Note that Google Test is initialized before ``MPI_Init()`` is called. +Note that GoogleTest is initialized before ``MPI_Init()`` is called. -Other Google Test features, such as *fixtures* and *mock* objects (gmock) may +Other GoogleTest features, such as *fixtures* and *mock* objects (gmock) may be used as well. -See the `Google Test Primer `_ -for a discussion of Google Test concepts, how to use them, and a listing of +See the `GoogleTest Primer `_ +for a discussion of GoogleTest concepts, how to use them, and a listing of available assertion macros, etc. FRUIT (Fortran Tests) --------------------------- +--------------------- Fortran unit tests using the FRUIT framework are similar in structure to -the Google Test tests for C and C++ described above. +the GoogleTest tests for C and C++ described above. + +The contents of a typical FRUIT test file look like this: -The contents of a typical FRUIT test file look like this:: +.. code-block:: fortran module use iso_c_binding @@ -119,7 +120,6 @@ The contents of a typical FRUIT test file look like this:: ! call assert_true(...) end subroutine test_name_2 - ! Etc. The tests in a FRUIT test file are placed in a Fortran *module* named for the *test case name*, such as the name of the C++ class whose Fortran interface @@ -130,30 +130,32 @@ FRUIT methods. Failure of expected values will cause the test to fail, but other tests will continue to run. Note that each FRUIT test file defines an executable Fortran program. The -program is defined at the end of the test file and is organized as follows:: - - program fortran_test - use fruit - use - implicit none - logical ok - - ! initialize fruit - call init_fruit - - ! run tests - call test_name_1 - call test_name_2 - - ! compile summary and finalize fruit - call fruit_summary - call fruit_finalize - - call is_all_successful(ok) - if (.not. ok) then - call exit(1) - endif - end program fortran_test +program is defined at the end of the test file and is organized as follows: + +.. code-block:: fortran + + program fortran_test + use fruit + use + implicit none + logical ok + + ! initialize fruit + call init_fruit + + ! run tests + call test_name_1 + call test_name_2 + + ! compile summary and finalize fruit + call fruit_summary + call fruit_finalize + + call is_all_successful(ok) + if (.not. ok) then + call exit(1) + endif + end program fortran_test Please refer to the `FRUIT documentation `_ for more information. @@ -174,11 +176,11 @@ by first generating an executable for the test using the and allows users to pass in command line arguments. -Returning to our running example (see :ref:`AddTarget`), +Returning to our running example (see :ref:`CreatingTargets`), let's add a simple test for the ``calc_pi`` library, which has a single function with signature: - .. code-block:: cpp +.. code-block:: cpp double calc_pi(int num_intervals); @@ -207,18 +209,15 @@ We then register this executable as a test: :end-before: _blt_tutorial_calcpi_test1_test_end :language: cmake -.. Hide these for now until we bring into an example -.. .. note:: -.. The ``COMMAND`` parameter can be used to pass arguments into a test executable. -.. This feature is not exercised in this example. -.. -.. .. note:: -.. The ``NAME`` of the test can be different from the test executable, -.. which is passed in through the ``COMMAND`` parameter. -.. This feature is not exercised in this example. +.. note:: + The ``COMMAND`` parameter can be used to pass arguments into a test executable. +.. note:: + The ``NAME`` of the test can be different from the test executable, + which is passed in through the ``COMMAND`` parameter. -Running tests and examples + +Running Tests and Examples -------------------------- To run the tests, type the following command in the build directory: @@ -237,15 +236,41 @@ you are modifying or adding code and need to understand how unit test details are working, for example. .. note:: - You can pass arguments to ctest via the ``TEST_ARGS`` parameter, e.g. - ``make test TEST_ARGS="..."`` - Useful arguments include: - - -R - Regular expression filtering of tests. - E.g. ``-R foo`` only runs tests whose names contain ``foo`` - -j - Run tests in parallel, E.g. ``-j 16`` will run tests using 16 processors - -VV - (Very verbose) Dump test output to stdout + You can pass arguments to ctest via the ``TEST_ARGS`` parameter, e.g. + ``make test TEST_ARGS="..."`` + Useful arguments include: + + -R + Regular expression filtering of tests. + E.g. ``-R foo`` only runs tests whose names contain ``foo`` + -j + Run tests in parallel, E.g. ``-j 16`` will run tests using 16 processors + -VV + (Very verbose) Dump test output to stdout + + +Converting CTest XML to JUnit +----------------------------- + +It is often useful to convert CTest's XML output to JUnit for various +reporting tools such as CI. This is a two step process. + +First run your test suite with one of the following commands to output with +CTest's XML and to turn off compressed output: + +.. code-block:: bash + + make CTEST_OUTPUT_ON_FAILURE=1 test ARGS="--no-compress-output -T Test -VV -j8" + ctest -DCTEST_OUTPUT_ON_FAILURE=1 --no-compress-output -T Test -VV -j8 + +Then convert the CTest XML file to JUnit's format with the XSL file included +in BLT. This can be done in many ways, but most Linux or Unix machines come with +a program called ``xsltproc`` + + +.. code-block:: bash + + cd build-dir + xsltproc -o junit.xml path/to/blt/tests/ctest-to-junit.xsl Testing/*/Test.xml +Then point the reporting tool to the outputted ``junit.xml`` file. diff --git a/docs/tutorial/advanced_topics.rst b/docs/tutorial/advanced_topics.rst new file mode 100644 index 000000000..c772b7c31 --- /dev/null +++ b/docs/tutorial/advanced_topics.rst @@ -0,0 +1,21 @@ +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details +.. # +.. # SPDX-License-Identifier: (BSD-3-Clause) + +Advanced Topics +=============== + +This section includes subpages on advanced topics such as: + + * :ref:`PortableCompilerFlags` : Managing compiler flags across compiler families + * :ref:`ExportingTargets` : Exporting your project's CMake Targets for others to use + * :ref:`ObjectLibraries` : A collection of object files that are not linked or archived into a library + + +.. toctree:: + :hidden: + + portable_compiler_flags + exporting_targets + object_libraries diff --git a/docs/tutorial/blank_project/CMakeLists.txt b/docs/tutorial/bare_bones/CMakeLists.txt similarity index 95% rename from docs/tutorial/blank_project/CMakeLists.txt rename to docs/tutorial/bare_bones/CMakeLists.txt index 9631f6808..1ce7baef6 100644 --- a/docs/tutorial/blank_project/CMakeLists.txt +++ b/docs/tutorial/bare_bones/CMakeLists.txt @@ -1,9 +1,9 @@ #------------------------------------------------------------------------------ -# BLT Tutorial Example: Blank Project. +# BLT Tutorial Example: Bare Bones Project. #------------------------------------------------------------------------------ cmake_minimum_required(VERSION 3.8) -project( blank ) +project( bare_bones ) # Note: This is specific to running our tests and shouldn't be exported to documentation if(NOT BLT_SOURCE_DIR) diff --git a/docs/tutorial/calc_pi/CMakeLists.txt b/docs/tutorial/calc_pi/CMakeLists.txt index 5fa6f4a39..ff353d603 100644 --- a/docs/tutorial/calc_pi/CMakeLists.txt +++ b/docs/tutorial/calc_pi/CMakeLists.txt @@ -95,8 +95,6 @@ endif() #------------------------------------------------------------------------------ if(CUDA_FOUND) # _blt_tutorial_calcpi_cuda_start - # avoid warnings about sm_20 deprecated - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-arch=sm_30) blt_add_library( NAME calc_pi_cuda HEADERS calc_pi_cuda.hpp calc_pi_cuda_exports.h @@ -107,8 +105,6 @@ if(CUDA_FOUND) target_compile_definitions(calc_pi_cuda PUBLIC WIN32_SHARED_LIBS) endif() - - blt_add_executable( NAME test_3 SOURCES test_3.cpp DEPENDS_ON calc_pi calc_pi_cuda gtest cuda_runtime) @@ -122,7 +118,6 @@ endif() #------------------------------------------------------------------------------ # Add Documentation Examples #------------------------------------------------------------------------------ -add_subdirectory(docs) - - - +if (ENABLE_DOCS) + add_subdirectory(docs) +endif() diff --git a/docs/tutorial/calc_pi/test_2.cpp b/docs/tutorial/calc_pi/test_2.cpp index 0b6cbaa73..3977aff28 100644 --- a/docs/tutorial/calc_pi/test_2.cpp +++ b/docs/tutorial/calc_pi/test_2.cpp @@ -37,7 +37,7 @@ TEST(calc_pi_mpi, compare_mpi_serial) } // _blt_tutorial_calcpi_test2_main_start -// main driver that allows using mpi w/ google test +// main driver that allows using mpi w/ GoogleTest int main(int argc, char * argv[]) { int result = 0; diff --git a/docs/tutorial/common_hpc_dependencies.rst b/docs/tutorial/common_hpc_dependencies.rst new file mode 100644 index 000000000..d16ebf8c9 --- /dev/null +++ b/docs/tutorial/common_hpc_dependencies.rst @@ -0,0 +1,181 @@ +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details +.. # +.. # SPDX-License-Identifier: (BSD-3-Clause) + +.. _CommonHPCDependencies: + +Common HPC Dependencies +======================= + +BLT creates named targets for the common HPC dependencies that most HPC projects need, such as +MPI, CUDA, HIP, and OpenMP. Something BLT assists it's users with is getting these dependencies +to interoperate within the same library or executable. + +As previously mentioned in :ref:`AddingTests`, BLT also provides +bundled versions of GoogleTest, GoogleMock, GoogleBenchmark, and FRUIT. Not only are the source +for these included, we provide named CMake targets for them as well. + +BLT's ``mpi``, ``cuda``, ``cuda_runtime``, ``hip``, ``hip_runtime``,and ``openmp`` targets are +all defined via the :ref:`blt_import_library` macro. This creates a true CMake imported target that is inherited +properly through the CMake's dependency graph. + +.. note:: + BLT also supports exporting its third-party targets via the ``BLT_EXPORT_THIRDPARTY`` option. + See :ref:`ExportingTargets` for more information. + +You have already seen one use of ``DEPENDS_ON`` for a BLT dependency, ``gtest``, in ``test_1``: + +.. literalinclude:: calc_pi/CMakeLists.txt + :start-after: _blt_tutorial_calcpi_test1_executable_start + :end-before: _blt_tutorial_calcpi_test1_executable_end + :language: cmake + +MPI +~~~ + +Our next example, ``test_2``, builds and tests the ``calc_pi_mpi`` library, +which uses MPI to parallelize the calculation over the integration intervals. + +To enable MPI, we set ``ENABLE_MPI``, ``MPI_C_COMPILER``, and ``MPI_CXX_COMPILER`` +in our host config file. Here is a snippet with these settings for LLNL's Pascal Cluster: + +.. literalinclude:: ../../host-configs/llnl/toss_3_x86_64_ib/gcc@4.9.3_nvcc.cmake + :start-after: _blt_tutorial_mpi_config_start + :end-before: _blt_tutorial_mpi_config_end + :language: cmake + + +Here, you can see how ``calc_pi_mpi`` and ``test_2`` use ``DEPENDS_ON``: + +.. literalinclude:: calc_pi/CMakeLists.txt + :start-after: _blt_tutorial_calcpi_test2_executable_start + :end-before: _blt_tutorial_calcpi_test2_executable_end + :language: cmake + + +For MPI unit tests, you also need to specify the number of MPI Tasks +to launch. We use the ``NUM_MPI_TASKS`` argument to :ref:`blt_add_test` macro. + +.. literalinclude:: calc_pi/CMakeLists.txt + :start-after: _blt_tutorial_calcpi_test2_test_start + :end-before: _blt_tutorial_calcpi_test2_test_end + :language: cmake + + +As mentioned in :ref:`AddingTests`, GoogleTest provides a default ``main()`` +driver that will execute all unit tests defined in the source. To test MPI code, +we need to create a main that initializes and finalizes MPI in addition to Google +Test. ``test_2.cpp`` provides an example driver for MPI with GoogleTest. + +.. literalinclude:: calc_pi/test_2.cpp + :start-after: _blt_tutorial_calcpi_test2_main_start + :end-before: _blt_tutorial_calcpi_test2_main_end + :language: cpp + +.. note:: + While we have tried to ensure that BLT chooses the correct setup information + for MPI, there are several niche cases where the default behavior is + insufficient. We have provided several available override variables: + + * ``BLT_MPI_COMPILE_FLAGS`` + * ``BLT_MPI_INCLUDES`` + * ``BLT_MPI_LIBRARIES`` + * ``BLT_MPI_LINK_FLAGS`` + + BLT also has the variable ``ENABLE_FIND_MPI`` which turns off all CMake's ``FindMPI`` + logic and then uses the MPI wrapper directly when you provide them as the default + compilers. + + +CUDA +~~~~ + +Finally, ``test_3`` builds and tests the ``calc_pi_cuda`` library, +which uses CUDA to parallelize the calculation over the integration intervals. + +To enable CUDA, we set ``ENABLE_CUDA``, ``CMAKE_CUDA_COMPILER``, and +``CUDA_TOOLKIT_ROOT_DIR`` in our host config file. Also before enabling the +CUDA language in CMake, you need to set ``CMAKE_CUDA_HOST_COMPILER`` in CMake 3.9+ +or ``CUDA_HOST_COMPILER`` in previous versions. If you do not call +``enable_language(CUDA)``, BLT will set the appropriate host compiler variable +for you and enable the CUDA language. + +Here is a snippet with these settings for LLNL's Pascal Cluster: + +.. literalinclude:: ../../host-configs/llnl/toss_3_x86_64_ib/gcc@4.9.3_nvcc.cmake + :start-after: _blt_tutorial_cuda_config_start + :end-before: _blt_tutorial_cuda_config_end + :language: cmake + +Here, you can see how ``calc_pi_cuda`` and ``test_3`` use ``DEPENDS_ON``: + +.. literalinclude:: calc_pi/CMakeLists.txt + :start-after: _blt_tutorial_calcpi_cuda_start + :end-before: _blt_tutorial_calcpi_cuda_end + :language: cmake + +The ``cuda`` dependency for ``calc_pi_cuda`` is a little special, +along with adding the normal CUDA library and headers to your library or executable, +it also tells BLT that this target's C/C++/CUDA source files need to be compiled via +``nvcc`` or ``cuda-clang``. If this is not a requirement, you can use the dependency +``cuda_runtime`` which also adds the CUDA runtime library and headers but will not +compile each source file with ``nvcc``. + +Some other useful CUDA flags are: + +.. literalinclude:: ../../host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_xlf.cmake + :start-after: _blt_tutorial_useful_cuda_flags_start + :end-before: _blt_tutorial_useful_cuda_flags_end + :language: cmake + + +OpenMP +~~~~~~ + +To enable OpenMP, set ``ENABLE_OPENMP`` in your host-config file or before loading +``SetupBLT.cmake``. Once OpenMP is enabled, simply add ``openmp`` to your library +executable's ``DEPENDS_ON`` list. + +Here is an example of how to add an OpenMP enabled executable: + +.. literalinclude:: ../../tests/smoke/CMakeLists.txt + :start-after: _blt_tutorial_openmp_executable_start + :end-before: _blt_tutorial_openmp_executable_end + :language: cmake + +.. note:: + While we have tried to ensure that BLT chooses the correct compile and link flags for + OpenMP, there are several niche cases where the default options are insufficient. + For example, linking with NVCC requires to link in the OpenMP libraries directly instead + of relying on the compile and link flags returned by CMake's FindOpenMP package. An + example of this is in ``host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_link_with_nvcc.cmake``. + We provide two variables to override BLT's OpenMP flag logic: + + * ``BLT_OPENMP_COMPILE_FLAGS`` + * ``BLT_OPENMP_LINK_FLAGS`` + +Here is an example of how to add an OpenMP enabled test that sets the amount of threads used: + +.. literalinclude:: ../../tests/smoke/CMakeLists.txt + :start-after: _blt_tutorial_openmp_test_start + :end-before: _blt_tutorial_openmp_test_end + :language: cmake + + +HIP +~~~ + +**HIP tutorial coming soon!** + +BLT also supports AMD's HIP via a mechanism very similar to our CUDA support. + +**Important Setup Variables** + +* ``ENABLE_HIP`` : Enables HIP support in BLT +* ``HIP_ROOT_DIR`` : Root directory for HIP installation + +**BLT Targets** + +* ``hip`` : Adds include directories, hip runtime libraries, and compiles source with hipcc +* ``hip_runtime`` : Adds include directories and hip runtime libraries diff --git a/docs/tutorial/creating_documentation.rst b/docs/tutorial/creating_documentation.rst index fa1068d7f..b4f82e5f2 100644 --- a/docs/tutorial/creating_documentation.rst +++ b/docs/tutorial/creating_documentation.rst @@ -1,8 +1,10 @@ -.. # Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -.. # other BLT Project Developers. See the top-level COPYRIGHT file for details +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details .. # .. # SPDX-License-Identifier: (BSD-3-Clause) +.. _CreatingDocumentation: + Creating Documentation ====================== @@ -34,7 +36,7 @@ The ``calc_pi`` example provides examples of both Sphinx and Doxygen documentati Calc Pi Sphinx Example -~~~~~~~~~~~~~~~~~~~~~~~~~ +---------------------- Sphinx is a python package that depends on several other packages. It can be installed via `spack `_, pip, anaconda, etc... @@ -44,7 +46,7 @@ The Sphinx ``sphinx-quickstart`` utility helps you generate a new sphinx project selecting common settings for the ``config.py``. -BLT provides a ``blt_add_sphinx_target()`` macro which, which will look for a ``conf.py`` file +BLT provides a :ref:`blt_add_sphinx_target` macro which, which will look for a ``conf.py`` file in the current directory and add a command to build the Sphinx docs using this file to the ``docs`` CMake target. @@ -56,7 +58,7 @@ CMake target. This macro is active when BLT is configured with a valid ``SPHINX_EXECUTABLE`` path. -Here is an example of using ``blt_add_sphinx_target()`` in a CMakeLists.txt file: +Here is an example of using :ref:`blt_add_sphinx_target` in a CMakeLists.txt file: .. literalinclude:: calc_pi/docs/sphinx/CMakeLists.txt :language: rst @@ -69,14 +71,14 @@ Here is the example reStructuredText file that contains documentation for the *c Calc Pi Doxygen Example -~~~~~~~~~~~~~~~~~~~~~~~~~ +----------------------- Doxygen is a compiled executable that can be installed via spack, built-by-hand, etc... ``doxygen`` processes a ``Doxyfile`` which specifies options, including where to look for annotated source files. -BLT provides a ``blt_add_doxygen_target()`` macro which, which will look for a ``Doxyfile.in`` +BLT provides a :ref:`blt_add_doxygen_target` macro which, which will look for a ``Doxyfile.in`` file in the current directory, configure this file to create a ``Doxyfile`` in the build directory, and add a command to build the Doxygen docs using this file to the ``docs`` CMake target. @@ -88,7 +90,7 @@ and add a command to build the Doxygen docs using this file to the ``docs`` CMak This macro is active when BLT is configured with a valid ``DOXYGEN_EXECUTABLE`` path. -Here is an example of using ``blt_add_doxygen_target()`` in a CMakeLists.txt file: +Here is an example of using :ref:`blt_add_doxygen_target` in a CMakeLists.txt file: .. literalinclude:: calc_pi/docs/doxygen/CMakeLists.txt :language: rst @@ -100,10 +102,8 @@ Here is the example ``Doxyfile.in`` file that is configured by CMake and passed :language: rst - Building the Calc Pi Example Documentation -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - +------------------------------------------ Here is an example of building both the calc_pi Sphinx and Doxygen docs using the ``docs`` CMake target: @@ -128,13 +128,7 @@ Here is an example of building both the calc_pi Sphinx and Doxygen docs using th [100%] Built target docs +After this your local build directory will contain the following for viewing: - -After this, you can view the Sphinx docs at: - -* ``build-calc-pi/docs/sphinx/html/index.html`` - -and the Doxygen docs at: - -* ``build-calc-pi/docs/doxygen/html/index.html`` - +* Sphinx: ``build-calc-pi/docs/sphinx/html/index.html`` +* Doxygen: ``build-calc-pi/docs/doxygen/html/index.html`` diff --git a/docs/tutorial/creating_execs_and_libs.rst b/docs/tutorial/creating_execs_and_libs.rst deleted file mode 100644 index 6f02cfa39..000000000 --- a/docs/tutorial/creating_execs_and_libs.rst +++ /dev/null @@ -1,124 +0,0 @@ -.. # Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -.. # other BLT Project Developers. See the top-level COPYRIGHT file for details -.. # -.. # SPDX-License-Identifier: (BSD-3-Clause) - -.. _AddTarget: - -Creating Libraries and Executables -================================== - -In the previous section, we learned the basics about how to create a CMake -project with BLT, how to configure the project and how to build and test BLT's built-in third party libraries. - -We now move on to creating libraries and executables -using two of BLT's core macros: ``blt_add_library()`` and ``blt_add_executable()``. - -We begin with a simple executable that calculates :math:`\pi` by numerical integration -(``example_1``). We will then extract that code into a library, which we link -into a new executable (``example_2``). - - -Example 1: Basic executable ---------------------------- - -This example is as basic as it gets. After setting up a BLT CMake project, -like ``blank_project`` in the previous section, we can start using BLT's macros. -Creating an executable is as simple as calling the following macro: - -.. literalinclude:: calc_pi/CMakeLists.txt - :start-after: _blt_tutorial_example_executable_start - :end-before: _blt_tutorial_example_executable_end - :language: cmake - -This tells CMake to create an executable named ``example_1`` with one source file -(``example_1.cpp``). - -You can create this project yourself or you can run the already provided -``tutorial/calc_pi`` project. For ease of use, we have combined many examples -into this one CMake project. After running the following commands, you will -create the executable ``/bin/example_1``: - -.. code-block:: bash - - cd /bin`` - (unless overridden with the macro parameter ``OUTPUT_DIR``) and handles - internal and external dependencies in a greatly simplified manner. There - will be more on that in the following section. - - -Example 2: One library, one executable --------------------------------------- - -This example is a bit more exciting. This time we are creating a library -that calculates the value of pi and then linking that library into an executable. - -First, we create the library with the following BLT code: - -.. literalinclude:: calc_pi/CMakeLists.txt - :start-after: _blt_tutorial_calcpi_library_start - :end-before: _blt_tutorial_calcpi_library_end - :language: cmake - -Just like before, this creates a CMake library target that will get built to -``/lib/libcalc_pi.a``. - -Next, we create an executable named ``example_2`` and link in the previously -created library target: - -.. literalinclude:: calc_pi/CMakeLists.txt - :start-after: _blt_tutorial_calcpi_example2_start - :end-before: _blt_tutorial_calcpi_example2_end - :language: cmake - -The ``DEPENDS_ON`` parameter properly links the previously defined library -into this executable without any more work or CMake function calls. - - -.. admonition:: blt_add_library - :class: hint - - This is another core BLT macro. It creates a CMake library target and associates - the given sources and headers along with handling dependencies the same way as - ``blt_add_executable`` does. It also provides a few commonly used build options, - such as overriding the output name of the library and the output directory. - It defaults to building a static library unless you override it with - ``SHARED`` or with the global CMake option ``BUILD_SHARED_LIBS``. - -Object Libraries ----------------- - -BLT has simplified the use of CMake object libraries through the -``blt_add_library`` macro. Object libraries are a collection of object files -that are not linked or archived into a library. They are used in other libraries -or executables through the ``DEPENDS_ON`` macro argument. This is generally -useful for combining smaller libraries into a larger library without -the linker removing unused symbols in the larger library. - -.. code-block:: cmake - - blt_add_library(NAME myObjectLibrary - SOURCES source1.cpp - HEADERS header1.cpp - OBJECT TRUE) - - blt_add_exectuble(NAME helloWorld - SOURCES main.cpp - DEPENDS_ON myObjectLibrary) - -.. note:: - Due to record keeping on BLT's part to make object libraries as easy to use - as possible, you need to define object libraries before you use them - if you need their inheritable information to be correct. diff --git a/docs/tutorial/creating_targets.rst b/docs/tutorial/creating_targets.rst new file mode 100644 index 000000000..84d6b43d4 --- /dev/null +++ b/docs/tutorial/creating_targets.rst @@ -0,0 +1,99 @@ +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details +.. # +.. # SPDX-License-Identifier: (BSD-3-Clause) + +.. _CreatingTargets: + +Creating Targets +================ + +In the previous section, we learned the basics about how to create a CMake +project with BLT, how to configure the project and how to build, and test +BLT's built-in third party libraries. + +We now move on to creating CMake targets using two of BLT's core macros: +:ref:`blt_add_library` and :ref:`blt_add_executable`. + +We begin with a simple executable that calculates :math:`\pi` by numerical integration, +``example_1``. We then extract that code into a library, which we link +into a new executable, ``example_2``. + + +Example 1: Stand-alone Executable +--------------------------------- + +This example is as basic as it gets. After setting up a BLT CMake project, +like the Bare Bones project in the previous section, we can start using BLT's macros. + +Creating a stand-alone executable is as simple as calling the following macro: + +.. literalinclude:: calc_pi/CMakeLists.txt + :start-after: _blt_tutorial_example_executable_start + :end-before: _blt_tutorial_example_executable_end + :language: cmake + +This tells CMake to create an executable, named ``example_1``, with one source file, +``example_1.cpp``. + +You can create this project yourself or you can run the already provided +``tutorial/calc_pi`` project. For ease of use, we have combined many examples +into this one CMake project. You can create the executable ``/bin/example_1``, +by running the following commands: + +.. code-block:: bash + + cd /docs/tutorial/calc_pi + mkdir build + cd build + cmake -DBLT_SOURCE_DIR=../../.. .. + make + +.. admonition:: blt_add_executable + :class: hint + + This is one of the core macros that enables BLT to simplify our CMake-based + project. It unifies many CMake calls into one easy to use macro while creating + a CMake executable target with the given parameters. It also greatly simplifies the usage of + internal and external dependencies. The full list of supported parameters + can be found on the :ref:`blt_add_executable` API documentation. + + + +Example 2: Executable with a Library +------------------------------------ + +This example is a bit more exciting. This time we are creating a library +that calculates the value of pi and then linking that library into an executable. + +First, we create the library with the following BLT code: + +.. literalinclude:: calc_pi/CMakeLists.txt + :start-after: _blt_tutorial_calcpi_library_start + :end-before: _blt_tutorial_calcpi_library_end + :language: cmake + +Just like before, this creates a CMake library target that will get built to +``/lib/libcalc_pi.a``. + +Next, we create an executable named ``example_2`` and link in the previously +created library target: + +.. literalinclude:: calc_pi/CMakeLists.txt + :start-after: _blt_tutorial_calcpi_example2_start + :end-before: _blt_tutorial_calcpi_example2_end + :language: cmake + +The ``DEPENDS_ON`` parameter properly links the previously defined library +into this executable without any more work or extra CMake function calls. + + +.. admonition:: blt_add_library + :class: hint + + This is another core BLT macro. It creates a CMake library target and associates + the given sources and headers along with handling dependencies the same way as + :ref:`blt_add_executable` does. It defaults to building a static library unless + you override it with ``SHARED`` or with the global CMake option ``BUILD_SHARED_LIBS``. + The full list of supported parameters can be found on the :ref:`blt_add_library` + API documentation. diff --git a/docs/tutorial/exporting_targets.rst b/docs/tutorial/exporting_targets.rst new file mode 100644 index 000000000..04c358470 --- /dev/null +++ b/docs/tutorial/exporting_targets.rst @@ -0,0 +1,85 @@ +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details +.. # +.. # SPDX-License-Identifier: (BSD-3-Clause) + +.. _ExportingTargets: + +Exporting Targets +================= + +BLT provides several built-in targets for commonly used libraries: + +``mpi`` + Available when ``ENABLE_MPI`` is ``ON`` + +``openmp`` + Available when ``ENABLE_OPENMP`` is ``ON`` + +``cuda`` and ``cuda_runtime`` + Available when ``ENABLE_CUDA`` is ``ON`` + +``hip`` and ``hip_runtime`` + Available when ``ENABLE_HIP`` is ``ON`` + +These targets can be made exportable in order to make them available to users of +your project via CMake's ``install()`` command. Setting BLT's ``BLT_EXPORT_THIRDPARTY`` +option to ``ON`` will mark all active targets in the above list as ``EXPORTABLE`` +(see the :ref:`blt_import_library` API documentation for more info). + +.. note:: As with other ``EXPORTABLE`` targets created by :ref:`blt_import_library`, + these targets should be prefixed with the name of the project. Either the ``EXPORT_NAME`` + target property or the ``NAMESPACE`` option to CMake's ``install`` + command can be used to modify the name of an installed target. + +.. note:: If a target in your project is added to an export set, any of its dependencies + marked ``EXPORTABLE`` must be added to the same export set. Failure to add them will + result in a CMake error in the exporting project. + +Typical usage of the ``BLT_EXPORT_THIRDPARTY`` option is as follows: + +.. code-block:: cmake + + # BLT configuration - enable MPI + set(ENABLE_MPI ON CACHE BOOL "") + # and mark the subsequently created MPI target as exportable + set(BLT_EXPORT_THIRDPARTY ON CACHE BOOL "") + # Both of the above must happen before SetupBLT.cmake is included + include(/path/to/SetupBLT.cmake) + + # Later, a project might mark a target as dependent on MPI + blt_add_executable( NAME example_1 + SOURCES example_1.cpp + DEPENDS_ON mpi ) + + # Add the example_1 target to the example-targets export set + install(TARGETS example_1 EXPORT example-targets) + + # Add the MPI target to the same export set - this is required + # because the mpi target was marked exportable + install(TARGETS mpi EXPORT example-targets) + +To avoid collisions with projects that import "example-targets", there are +two options for adjusting the exported name of the ``mpi`` target. + +The first is to rename only the ``mpi`` target's exported name: + +.. code-block:: cmake + + set_target_properties(mpi PROPERTIES EXPORT_NAME example::mpi) + install(EXPORT example-targets) + +With this approach the ``example_1`` target's exported name is unchanged - a +project that imports the ``example-targets`` export set will have ``example_1`` +and ``example::mpi`` targets made available. The imported ``example_1`` will +depend on ``example::mpi``. + +Another approach is to install all targets in the export set behind a namespace: + +.. code-block:: cmake + + install(EXPORT example-targets NAMESPACE example::) + +With this approach all targets in the export set are prefixed, so an importing +project will have ``example::example_1`` and ``example::mpi`` targets made available. +The imported ``example::example_1`` will depend on ``example::mpi``. diff --git a/docs/tutorial/external_dependencies.rst b/docs/tutorial/external_dependencies.rst deleted file mode 100644 index 9f3d30c3d..000000000 --- a/docs/tutorial/external_dependencies.rst +++ /dev/null @@ -1,319 +0,0 @@ -.. # Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -.. # other BLT Project Developers. See the top-level COPYRIGHT file for details -.. # -.. # SPDX-License-Identifier: (BSD-3-Clause) - -External Dependencies -===================== - -One key goal for BLT is to simplify the use of external dependencies when building your libraries and executables. - -To accomplish this BLT provides a ``DEPENDS_ON`` option for the -``blt_add_library()`` and ``blt_add_executable()`` macros that supports both CMake targets -and external dependencies registered using the ``blt_register_library()`` macro. - -The ``blt_register_library()`` macro allows you to reuse all information needed -for an external dependency under a single name. This includes any include -directories, libraries, compile flags, link flags, defines, etc. You can also -hide any warnings created by their headers by setting the -``TREAT_INCLUDES_AS_SYSTEM`` argument. - -For example, to find and register the external dependency *axom* as a BLT registered library, you can simply use: - -.. code-block:: cmake - - # FindAxom.cmake takes in AXOM_DIR, which is a installed Axom build and - # sets variables AXOM_INCLUDES, AXOM_LIBRARIES - include(FindAxom.cmake) - blt_register_library(NAME axom - TREAT_INCLUDES_AS_SYSTEM ON - DEFINES HAVE_AXOM=1 - INCLUDES ${AXOM_INCLUDES} - LIBRARIES ${AXOM_LIBRARIES}) - -Then *axom* is available to be used in the DEPENDS_ON list in the following -``blt_add_executable()`` or ``blt_add_library()`` calls. - -This is especially helpful for external libraries that are not built with CMake -and don't provide CMake-friendly imported targets. Our ultimate goal is to use ``blt_register_library()`` -to import all external dependencies as first-class imported CMake targets to take full advanced of CMake's dependency lattice. - -MPI, CUDA, and OpenMP are all registered via ``blt_register_library()``. -You can see how in ``blt/thirdparty_builtin/CMakelists.txt``. - -BLT also supports using ``blt_register_library()`` to provide additional options for existing CMake targets. -The implementation doesn't modify the properties of the existing targets, -it just exposes these options via BLT's support for ``DEPENDS_ON``. - -.. admonition:: blt_register_library - :class: hint - - A macro to register external libraries and dependencies with BLT. - The named target can be added to the ``DEPENDS_ON`` argument of other BLT macros, - like ``blt_add_library()`` and ``blt_add_executable()``. - - -You have already seen one use of ``DEPENDS_ON`` for a BLT -registered dependency in test_1: ``gtest`` - -.. literalinclude:: calc_pi/CMakeLists.txt - :start-after: _blt_tutorial_calcpi_test1_executable_start - :end-before: _blt_tutorial_calcpi_test1_executable_end - :language: cmake - - -``gtest`` is the name for the Google Test dependency in BLT registered via -``blt_register_library()``. Even though Google Test is built-in and uses CMake, -``blt_register_library()`` allows us to easily set defines needed by all dependent -targets. - - -MPI Example -~~~~~~~~~~~~~~~~~~~~~ - -Our next example, ``test_2``, builds and tests the ``calc_pi_mpi`` library, -which uses MPI to parallelize the calculation over the integration intervals. - - -To enable MPI, we set ``ENABLE_MPI``, ``MPI_C_COMPILER``, and ``MPI_CXX_COMPILER`` in our host config file. Here is a snippet with these settings for LLNL's Surface Cluster: - -.. literalinclude:: ../../host-configs/other/llnl-surface-chaos_5_x86_64_ib-gcc@4.9.3.cmake - :start-after: _blt_tutorial_surface_mpi_config_start - :end-before: _blt_tutorial_surface_mpi_config_end - :language: cmake - - -Here, you can see how ``calc_pi_mpi`` and ``test_2`` use ``DEPENDS_ON``: - -.. literalinclude:: calc_pi/CMakeLists.txt - :start-after: _blt_tutorial_calcpi_test2_executable_start - :end-before: _blt_tutorial_calcpi_test2_executable_end - :language: cmake - - -For MPI unit tests, you also need to specify the number of MPI Tasks -to launch. We use the ``NUM_MPI_TASKS`` argument to ``blt_add_test()`` macro. - -.. literalinclude:: calc_pi/CMakeLists.txt - :start-after: _blt_tutorial_calcpi_test2_test_start - :end-before: _blt_tutorial_calcpi_test2_test_end - :language: cmake - - -As mentioned in :ref:`UnitTesting`, google test provides a default ``main()`` -driver that will execute all unit tests defined in the source. To test MPI code, -we need to create a main that initializes and finalizes MPI in addition to Google -Test. ``test_2.cpp`` provides an example driver for MPI with Google Test. - -.. literalinclude:: calc_pi/test_2.cpp - :start-after: _blt_tutorial_calcpi_test2_main_start - :end-before: _blt_tutorial_calcpi_test2_main_end - :language: cpp - -.. note:: - While we have tried to ensure that BLT chooses the correct setup information - for MPI, there are several niche cases where the default behavior is - insufficient. We have provided several available override variables: - - * ``BLT_MPI_COMPILE_FLAGS`` - * ``BLT_MPI_INCLUDES`` - * ``BLT_MPI_LIBRARIES`` - * ``BLT_MPI_LINK_FLAGS`` - - BLT also has the variable ``ENABLE_FIND_MPI`` which turns off all CMake's ``FindMPI`` - logic and then uses the MPI wrapper directly when you provide them as the default - compilers. - - -CUDA Example -~~~~~~~~~~~~~~~~~~~~~ - -Finally, ``test_3`` builds and tests the ``calc_pi_cuda`` library, -which uses CUDA to parallelize the calculation over the integration intervals. - -To enable CUDA, we set ``ENABLE_CUDA``, ``CMAKE_CUDA_COMPILER``, and -``CUDA_TOOLKIT_ROOT_DIR`` in our host config file. Also before enabling the -CUDA language in CMake, you need to set ``CMAKE_CUDA_HOST_COMPILER`` in CMake 3.9+ -or ``CUDA_HOST_COMPILER`` in previous versions. If you do not call -``enable_language(CUDA)``, BLT will set the appropriate host compiler variable -for you and enable the CUDA language. - -Here is a snippet with these settings for LLNL's Surface Cluster: - -.. literalinclude:: ../../host-configs/other/llnl-surface-chaos_5_x86_64_ib-gcc@4.9.3.cmake - :start-after: _blt_tutorial_surface_cuda_config_start - :end-before: _blt_tutorial_surface_cuda_config_end - :language: cmake - -Here, you can see how ``calc_pi_cuda`` and ``test_3`` use ``DEPENDS_ON``: - -.. literalinclude:: calc_pi/CMakeLists.txt - :start-after: _blt_tutorial_calcpi_cuda_start - :end-before: _blt_tutorial_calcpi_cuda_end - :language: cmake - -The ``cuda`` dependency for ``calc_pi_cuda`` is a little special, -along with adding the normal CUDA library and headers to your library or executable, -it also tells BLT that this target's C/CXX/CUDA source files need to be compiled via -``nvcc`` or ``cuda-clang``. If this is not a requirement, you can use the dependency -``cuda_runtime`` which also adds the CUDA runtime library and headers but will not -compile each source file with ``nvcc``. - -Some other useful CUDA flags are: - -.. code-block:: cmake - - # Enable separable compilation of all CUDA files for given target or all following targets - set(CUDA_SEPARABLE_COMPILIATION ON CACHE BOOL “”) - set(CUDA_ARCH “sm_60” CACHE STRING “”) - set(CMAKE_CUDA_FLAGS “-restrict –arch ${CUDA_ARCH} –std=c++11” CACHE STRING “”) - set(CMAKE_CUDA_LINK_FLAGS “-Xlinker –rpath –Xlinker /path/to/mpi” CACHE STRING “”) - # Needed when you have CUDA decorations exposed in libraries - set(CUDA_LINK_WITH_NVCC ON CACHE BOOL “”) - - -OpenMP -~~~~~~ - -To enable OpenMP, set ``ENABLE_OPENMP`` in your host-config file or before loading -``SetupBLT.cmake``. Once OpenMP is enabled, simply add ``openmp`` to your library -executable's ``DEPENDS_ON`` list. - -Here is an example of how to add an OpenMP enabled executable: - - .. literalinclude:: ../../tests/smoke/CMakeLists.txt - :start-after: _blt_tutorial_openmp_executable_start - :end-before: _blt_tutorial_openmp_executable_end - :language: cmake - -.. note:: - While we have tried to ensure that BLT chooses the correct compile and link flags for - OpenMP, there are several niche cases where the default options are insufficient. - For example, linking with NVCC requires to link in the OpenMP libraries directly instead - of relying on the compile and link flags returned by CMake's FindOpenMP package. An - example of this is in ``host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_link_with_nvcc.cmake``. - We provide two variables to override BLT's OpenMP flag logic: - - * ``BLT_OPENMP_COMPILE_FLAGS`` - * ``BLT_OPENMP_LINK_FLAGS`` - -Here is an example of how to add an OpenMP enabled test that sets the amount of threads used: - - .. literalinclude:: ../../tests/smoke/CMakeLists.txt - :start-after: _blt_tutorial_openmp_test_start - :end-before: _blt_tutorial_openmp_test_end - :language: cmake - - -Example Host-configs -~~~~~~~~~~~~~~~~~~~~ - -Here are the full example host-config files that use gcc 4.9.3 for LLNL's Surface, Ray and Quartz Clusters. - -:download:`llnl-surface-chaos_5_x86_64_ib-gcc@4.9.3.cmake <../../host-configs/other/llnl-surface-chaos_5_x86_64_ib-gcc@4.9.3.cmake>` - -:download:`llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_xlf <../../host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_xlf.cmake>` - -:download:`llnl/toss_3_x86_64_ib/gcc@4.9.3.cmake <../../host-configs/llnl/toss_3_x86_64_ib/gcc@4.9.3.cmake>` - -.. note:: Quartz does not have GPUs, so CUDA is not enabled in the Quartz host-config. - -Here is a full example host-config file for an OSX laptop, using a set of dependencies built with spack. - -:download:`darwin/elcapitan-x86_64/naples-clang@7.3.0.cmake <../../host-configs/darwin/elcapitan-x86_64/naples-clang@7.3.0.cmake>` - - -Building and testing on Surface -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Here is how you can use the host-config file to configure a build of the ``calc_pi`` project with MPI and CUDA enabled on Surface: - -.. code-block:: bash - - # load new cmake b/c default on surface is too old - ml cmake/3.9.2 - # create build dir - mkdir build - cd build - # configure using host-config - cmake -C ../../host-configs/other/llnl-surface-chaos_5_x86_64_ib-gcc@4.9.3.cmake \ - -DBLT_SOURCE_DIR=../../../../blt .. - -After building (``make``), you can run ``make test`` on a batch node (where the GPUs reside) -to run the unit tests that are using MPI and CUDA: - -.. code-block:: console - - bash-4.1$ salloc -A - bash-4.1$ make - bash-4.1$ make test - - Running tests... - Test project blt/docs/tutorial/calc_pi/build - Start 1: test_1 - 1/8 Test #1: test_1 ........................... Passed 0.01 sec - Start 2: test_2 - 2/8 Test #2: test_2 ........................... Passed 2.79 sec - Start 3: test_3 - 3/8 Test #3: test_3 ........................... Passed 0.54 sec - Start 4: blt_gtest_smoke - 4/8 Test #4: blt_gtest_smoke .................. Passed 0.01 sec - Start 5: blt_fruit_smoke - 5/8 Test #5: blt_fruit_smoke .................. Passed 0.01 sec - Start 6: blt_mpi_smoke - 6/8 Test #6: blt_mpi_smoke .................... Passed 2.82 sec - Start 7: blt_cuda_smoke - 7/8 Test #7: blt_cuda_smoke ................... Passed 0.48 sec - Start 8: blt_cuda_runtime_smoke - 8/8 Test #8: blt_cuda_runtime_smoke ........... Passed 0.11 sec - - 100% tests passed, 0 tests failed out of 8 - - Total Test time (real) = 6.80 sec - - -Building and testing on Ray -~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Here is how you can use the host-config file to configure a build of the ``calc_pi`` project with MPI and CUDA -enabled on the blue_os Ray cluster: - -.. code-block:: bash - - # load new cmake b/c default on ray is too old - ml cmake - # create build dir - mkdir build - cd build - # configure using host-config - cmake -C ../../host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_xlf.cmake \ - -DBLT_SOURCE_DIR=../../../../blt .. - -And here is how to build and test the code on Ray: - -.. code-block:: console - - bash-4.2$ lalloc 1 -G - bash-4.2$ make - bash-4.2$ make test - - Running tests... - Test project projects/blt/docs/tutorial/calc_pi/build - Start 1: test_1 - 1/7 Test #1: test_1 ........................... Passed 0.01 sec - Start 2: test_2 - 2/7 Test #2: test_2 ........................... Passed 1.24 sec - Start 3: test_3 - 3/7 Test #3: test_3 ........................... Passed 0.17 sec - Start 4: blt_gtest_smoke - 4/7 Test #4: blt_gtest_smoke .................. Passed 0.01 sec - Start 5: blt_mpi_smoke - 5/7 Test #5: blt_mpi_smoke .................... Passed 0.82 sec - Start 6: blt_cuda_smoke - 6/7 Test #6: blt_cuda_smoke ................... Passed 0.15 sec - Start 7: blt_cuda_runtime_smoke - 7/7 Test #7: blt_cuda_runtime_smoke ........... Passed 0.04 sec - - 100% tests passed, 0 tests failed out of 7 - - Total Test time (real) = 2.47 sec diff --git a/docs/tutorial/setup_blt.rst b/docs/tutorial/getting_started.rst similarity index 53% rename from docs/tutorial/setup_blt.rst rename to docs/tutorial/getting_started.rst index 645db8b2f..3f4280b98 100644 --- a/docs/tutorial/setup_blt.rst +++ b/docs/tutorial/getting_started.rst @@ -1,31 +1,24 @@ -.. # Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -.. # other BLT Project Developers. See the top-level COPYRIGHT file for details +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details .. # .. # SPDX-License-Identifier: (BSD-3-Clause) -Setup BLT in your CMake Project -================================= +.. _GettingStarted: -BLT is easy to include in your CMake project whether it is an existing project or -you are starting from scratch. You simply pull it into your project using a CMake -``include()`` command. +Getting Started +=============== -.. code-block:: cmake +BLT is easy to include in your CMake project whether it is an existing project or +you are starting from scratch. This tutorial assumes you are using git and the CMake +Makefile generator but those commands can easily be changed or ignored. - include(path/to/blt/SetupBLT.cmake) -You can include the BLT source in your repository or pass the location -of BLT at CMake configure time through the optional ``BLT_SOURCE_DIR`` -CMake variable. +Include BLT in your Git Repository +---------------------------------- There are two standard choices for including the BLT source in your repository: -1. Add BLT as a git submodule -2. Copy BLT into a subdirectory in your repository - - -BLT as a Git Submodule --------------------------- +**Add BLT as a git submodule** This example adds BLT as a submodule, commits, and pushes the changes to your repository. @@ -36,10 +29,9 @@ This example adds BLT as a submodule, commits, and pushes the changes to your re git commit -m "Adding BLT" git push -Copy BLT into your repository ------------------------------ +**Copy BLT into a subdirectory in your repository** -This example will clone BLT into your repository and remove the unneeded +This example will clone a copy of BLT into your repository and remove the unneeded git files from the clone. It then commits and pushes the changes to your repository. @@ -52,8 +44,8 @@ repository. git push -Include BLT in your project ---------------------------- +Include BLT in your CMake Project +--------------------------------- In most projects, including BLT is as simple as including the following CMake line in your base ``CMakeLists.txt`` after your ``project()`` call. @@ -62,26 +54,22 @@ line in your base ``CMakeLists.txt`` after your ``project()`` call. include(blt/SetupBLT.cmake) -This enables all of BLT's features in your project. +This enables all of BLT's features in your project. However if your project is likely to be used by other projects. The following is recommended: -.. literalinclude:: blank_project/CMakeLists.txt +.. literalinclude:: bare_bones/CMakeLists.txt :start-after: _blt_tutorial_include_blt_start :end-before: _blt_tutorial_include_blt_end :language: cmake This is a robust way of setting up BLT and supports an optional external BLT source -directory. This allows the use of a common BLT across large projects. There are some -helpful error messages if the BLT submodule is missing as well as the commands to solve -it. - -.. note:: - Throughout this tutorial, we pass the path to BLT using ``BLT_SOURCE_DIR`` since - our tutorial is part of the blt repository and we want this project to be - automatically tested using a single clone of our repository. - +directory via the command line option ``BLT_SOURCE_DIR``. +Using the external BLT source directory allows you to use single BLT +instance across multiple independent CMake projects. +This also adds helpful error messages if the BLT submodule is missing +as well as the commands to solve it. Running CMake @@ -106,16 +94,22 @@ If you are using BLT outside of your project pass the location of BLT as follows cd build cmake -DBLT_SOURCE_DIR="path/to/blt" .. -Example: blank_project ----------------------- -The ``blank_project`` example is provided to show you some of BLT's built-in +Example: Bare Bones BLT Project +------------------------------- + +The ``bare_bones`` example project shows you some of BLT's built-in features. It demonstrates the bare minimum required for testing purposes. -Here is the entire CMakeLists.txt file for ``blank_project``: +Here is the entire CMakeLists.txt file needed for a bare bones project: + +.. code-block:: cmake + + cmake_minimum_required(VERSION 3.8) + project( bare_bones ) + + include(/path/to/blt/SetupBLT.cmake) -.. literalinclude:: blank_project/CMakeLists.txt - :language: cmake BLT also enforces some best practices for building, such as not allowing in-source builds. This means that BLT prevents you from generating a @@ -125,8 +119,8 @@ For example if you run the following commands: .. code-block:: bash - cd /docs/tutorial/blank_project - cmake -DBLT_SOURCE_DIR=../.. + cd /docs/tutorial/bare_bones + cmake . you will get the following error: @@ -145,15 +139,21 @@ To correctly run cmake, create a build directory and run cmake from there: .. code-block:: bash - cd /docs/blank_project + cd /docs/bare_bones mkdir build cd build - cmake -DBLT_SOURCE_DIR=../../.. .. + cmake .. This will generate a configured ``Makefile`` in your build directory to build -``blank_project``. The generated makefile includes gtest and several built-in +Bare Bones project. The generated makefile includes gtest and several built-in BLT *smoke* tests, depending on the features that you have enabled in your build. +.. note:: Smoke tests are designed to show when basic functionality is not working. + For example, if you have turned on MPI in your project but the MPI compiler wrapper + cannot produce an executable that runs even the most basic MPI code, the + ``blt_mpi_smoke`` test will fail. This helps you know that the problem doesn't + lie in your own code but in the building/linking of MPI. + To build the project, use the following command: .. code-block:: bash @@ -178,7 +178,7 @@ If everything went correctly, you should have the following output: .. code-block:: bash Running tests... - Test project blt/docs/tutorial/blank_project/build + Test project blt/docs/tutorial/bare_bones/build Start 1: blt_gtest_smoke 1/1 Test #1: blt_gtest_smoke .................. Passed 0.01 sec @@ -186,42 +186,23 @@ If everything went correctly, you should have the following output: Total Test time (real) = 0.10 sec -Note that the default options for ``blank_project`` only include a single test +Note that the default options for ``bare_bones`` only include a single test ``blt_gtest_smoke``. As we will see later on, BLT includes additional smoke tests that are activated when BLT is configured with other options enabled, -like Fortran, MPI, OpenMP, and Cuda. - -Host-configs ------------- - -To capture (and revision control) build options, third party library paths, etc., -we recommend using CMake's initial-cache file mechanism. This feature allows you -to pass a file to CMake that provides variables to bootstrap the configuration -process. - -You can pass initial-cache files to cmake via the ``-C`` command line option. - -.. code-block:: bash +like Fortran, MPI, OpenMP, and CUDA. - cmake -C config_file.cmake +Example files +------------- -We call these initial-cache files ``host-config`` files since we typically create -a file for each platform or for specific hosts, if necessary. - -These files use standard CMake commands. CMake ``set()`` commands need to specify -``CACHE`` as follows: - -.. code-block:: cmake - - set(CMAKE_VARIABLE_NAME {VALUE} CACHE PATH "") +Files related to setting up the Bare Bones project: -Here is a snippet from a host-config file that specifies compiler details for -using gcc 4.9.3 on LLNL's surface cluster. +.. container:: toggle -.. literalinclude:: ../../host-configs/other/llnl-surface-chaos_5_x86_64_ib-gcc@4.9.3.cmake - :start-after: _blt_tutorial_surface_compiler_config_start - :end-before: _blt_tutorial_surface_compiler_config_end - :language: cmake + .. container:: label + ``CMakeLists.txt`` + .. literalinclude:: ./bare_bones/CMakeLists.txt + :language: cmake + :linenos: diff --git a/docs/tutorial/host_configs.rst b/docs/tutorial/host_configs.rst new file mode 100644 index 000000000..b88b07951 --- /dev/null +++ b/docs/tutorial/host_configs.rst @@ -0,0 +1,241 @@ +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details +.. # +.. # SPDX-License-Identifier: (BSD-3-Clause) + +.. _HostConfigs: + +Host-configs +============ + +To capture (and revision control) build options, third party library paths, etc., +we recommend using CMake's initial-cache file mechanism. This feature allows you +to pass a file to CMake that provides variables to bootstrap the configuration +process. + +You can pass initial-cache files to cmake via the ``-C`` command line option. + +.. code-block:: bash + + cmake -C config_file.cmake + + +We call these initial-cache files ``host-config`` files since we typically create +a file for each platform or for specific hosts, if necessary. + +These files use standard CMake commands. CMake ``set()`` commands need to specify +``CACHE`` as follows: + +.. code-block:: cmake + + set(CMAKE_VARIABLE_NAME {VALUE} CACHE PATH "") + +Here is a snippet from a host-config file that specifies compiler details for +using specific gcc (version 4.9.3 in this case) on the LLNL Pascal cluster. + +.. literalinclude:: ../../host-configs/llnl/toss_3_x86_64_ib/gcc@4.9.3_nvcc.cmake + :start-after: _blt_tutorial_compiler_config_start + :end-before: _blt_tutorial_compiler_config_end + :language: cmake + + +Building and Testing on Pascal +------------------------------ + +Since compute nodes on the Pascal cluster have CPUs and GPUs, here is how you +can use the host-config file to configure a build of the ``calc_pi`` project with +MPI and CUDA enabled on Pascal: + +.. code-block:: bash + + # create build dir + mkdir build + cd build + # configure using host-config + cmake -C ../../host-configs/llnl/toss_3_x86_64_ib/gcc@4.9.3_nvcc.cmake .. + +After building (``make``), you can run ``make test`` on a batch node (where the GPUs reside) +to run the unit tests that are using MPI and CUDA: + +.. code-block:: console + + bash-4.1$ salloc -A + bash-4.1$ make + bash-4.1$ make test + + Running tests... + Test project blt/docs/tutorial/calc_pi/build + Start 1: test_1 + 1/8 Test #1: test_1 ........................... Passed 0.01 sec + Start 2: test_2 + 2/8 Test #2: test_2 ........................... Passed 2.79 sec + Start 3: test_3 + 3/8 Test #3: test_3 ........................... Passed 0.54 sec + Start 4: blt_gtest_smoke + 4/8 Test #4: blt_gtest_smoke .................. Passed 0.01 sec + Start 5: blt_fruit_smoke + 5/8 Test #5: blt_fruit_smoke .................. Passed 0.01 sec + Start 6: blt_mpi_smoke + 6/8 Test #6: blt_mpi_smoke .................... Passed 2.82 sec + Start 7: blt_cuda_smoke + 7/8 Test #7: blt_cuda_smoke ................... Passed 0.48 sec + Start 8: blt_cuda_runtime_smoke + 8/8 Test #8: blt_cuda_runtime_smoke ........... Passed 0.11 sec + + 100% tests passed, 0 tests failed out of 8 + + Total Test time (real) = 6.80 sec + + +Building and Testing on Ray +--------------------------- + +Here is how you can use the host-config file to configure a build of the ``calc_pi`` project with MPI and CUDA +enabled on the LLNL BlueOS Ray cluster: + +.. code-block:: bash + + # create build dir + mkdir build + cd build + # configure using host-config + cmake -C ../../host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_xlf.cmake .. + +And here is how to build and test the code on Ray: + +.. code-block:: console + + bash-4.2$ lalloc 1 -G + bash-4.2$ make + bash-4.2$ make test + + Running tests... + Test project projects/blt/docs/tutorial/calc_pi/build + Start 1: test_1 + 1/7 Test #1: test_1 ........................... Passed 0.01 sec + Start 2: test_2 + 2/7 Test #2: test_2 ........................... Passed 1.24 sec + Start 3: test_3 + 3/7 Test #3: test_3 ........................... Passed 0.17 sec + Start 4: blt_gtest_smoke + 4/7 Test #4: blt_gtest_smoke .................. Passed 0.01 sec + Start 5: blt_mpi_smoke + 5/7 Test #5: blt_mpi_smoke .................... Passed 0.82 sec + Start 6: blt_cuda_smoke + 6/7 Test #6: blt_cuda_smoke ................... Passed 0.15 sec + Start 7: blt_cuda_runtime_smoke + 7/7 Test #7: blt_cuda_runtime_smoke ........... Passed 0.04 sec + + 100% tests passed, 0 tests failed out of 7 + + Total Test time (real) = 2.47 sec + + +Building and Testing on Summit +------------------------------- + +Here is how you can use the host-config file to configure a build of the ``calc_pi`` project with MPI and CUDA +enabled on the OLCF Summit cluster: + +.. code-block:: bash + + # load the cmake module + module load cmake + # create build dir + mkdir build + cd build + # configure using host-config + cmake -C ../../host-configs/olcf/summit/gcc@6.4.0_nvcc.cmake .. + + +And here is how to build and test the code on Summit: + +.. code-block:: console + + bash-4.2$ bsub -W 30 -nnodes 1 -P -Is /bin/bash + bash-4.2$ module load gcc cuda + bash-4.2$ make + bash-4.2$ make test + + Running tests... + Test project /projects/blt/docs/tutorial/calc_pi/build + Start 1: test_1 + 1/11 Test #1: test_1 ........................... Passed 0.00 sec + Start 2: test_2 + 2/11 Test #2: test_2 ........................... Passed 1.03 sec + Start 3: test_3 + 3/11 Test #3: test_3 ........................... Passed 0.21 sec + Start 4: blt_gtest_smoke + 4/11 Test #4: blt_gtest_smoke .................. Passed 0.00 sec + Start 5: blt_fruit_smoke + 5/11 Test #5: blt_fruit_smoke .................. Passed 0.00 sec + Start 6: blt_mpi_smoke + 6/11 Test #6: blt_mpi_smoke .................... Passed 0.76 sec + Start 7: blt_cuda_smoke + 7/11 Test #7: blt_cuda_smoke ................... Passed 0.22 sec + Start 8: blt_cuda_runtime_smoke + 8/11 Test #8: blt_cuda_runtime_smoke ........... Passed 0.07 sec + Start 9: blt_cuda_version_smoke + 9/11 Test #9: blt_cuda_version_smoke ........... Passed 0.06 sec + Start 10: blt_cuda_mpi_smoke + 10/11 Test #10: blt_cuda_mpi_smoke ............... Passed 0.80 sec + Start 11: blt_cuda_gtest_smoke + 11/11 Test #11: blt_cuda_gtest_smoke ............. Passed 0.21 sec + + 100% tests passed, 0 tests failed out of 11 + + Total Test time (real) = 3.39 sec + + +Example Host-configs +-------------------- + +Basic TOSS3 (for example: Quartz) host-config that has C, C++, and Fortran Compilers along with MPI support: + +.. container:: toggle + + .. container:: label + + ``gcc@8.3.1 host-config`` + + .. literalinclude:: ../../host-configs/llnl/toss_3_x86_64_ib/gcc@8.3.1.cmake + :language: cmake + :linenos: + +Here are the full example host-config files for LLNL's Pascal, Ray, and Quartz Clusters that uses +the default compilers on the system: + +.. container:: toggle + + .. container:: label + + ``gcc@4.9.3 host-config`` + + .. literalinclude:: ../../host-configs/llnl/toss_3_x86_64_ib/gcc@4.9.3_nvcc.cmake + :language: cmake + :linenos: + +More complicated BlueOS host-config that has C, C++, MPI, and CUDA support: + +.. container:: toggle + + .. container:: label + + ``clang@upstream C++17 host-config`` + + .. literalinclude:: ../../host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_c++17_no_separable.cmake + :language: cmake + :linenos: + +Here is a full example host-config file for an OSX laptop, using a set of dependencies built with Spack: + +.. container:: toggle + + .. container:: label + + ``OSX clang@7.3.0 host-config`` + + .. literalinclude:: ../../host-configs/darwin/elcapitan-x86_64/naples-clang@7.3.0.cmake + :language: cmake + :linenos: + diff --git a/docs/tutorial/importing_targets.rst b/docs/tutorial/importing_targets.rst new file mode 100644 index 000000000..73ce9c183 --- /dev/null +++ b/docs/tutorial/importing_targets.rst @@ -0,0 +1,32 @@ +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details +.. # +.. # SPDX-License-Identifier: (BSD-3-Clause) + +.. _ImportingTargets: + +Importing Targets +================= + +One key goal for BLT is to simplify the use of external dependencies and libraries when building +your project. To accomplish this, BLT provides a ``DEPENDS_ON`` option for the :ref:`blt_add_library` +and :ref:`blt_add_executable` macros that supports both your own projects CMake targets +and imported targets. We have logically broken this topic into two groups: + +:ref:`CommonHPCDependencies` + Dependencies such as MPI, CUDA, HIP, and OpenMP, are bundled and ready to use included + with BLT as regular named CMake targets. For example, just adding ``openmp`` to any ``DEPENDS_ON`` + will add the necessary OpenMP compiler and link flags to any target. + +:ref:`ThirdPartyLibraries` + These are external libraries that your project depend on, such as Lua. They are imported into your + project in different ways depending on the level of CMake support provided + by that project. BLT provides a macro, :ref:`blt_import_library`, which allows you to bundle all + necessary information under a single name. Some projects properly export their CMake targets and + only need to be imported via a call to ``include()``. + +.. toctree:: + :hidden: + + common_hpc_dependencies + third_party_libraries diff --git a/docs/tutorial/index.rst b/docs/tutorial/index.rst index 3ed60f49d..d4e0e4c3a 100644 --- a/docs/tutorial/index.rst +++ b/docs/tutorial/index.rst @@ -1,5 +1,5 @@ -.. # Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -.. # other BLT Project Developers. See the top-level COPYRIGHT file for details +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details .. # .. # SPDX-License-Identifier: (BSD-3-Clause) @@ -9,29 +9,50 @@ User Tutorial This tutorial provides instructions for: * Adding BLT to a CMake project - * Setting up *host-config* files to handle multiple platform configurations * Building, linking, and installing libraries and executables * Setting up unit tests with GTest + * Setting up *host-config* files to handle multiple platform configurations * Using external project dependencies + * Exporting your project's CMake targets for outside projects to use * Creating documentation with Sphinx and Doxygen -The tutorial provides several examples that calculate the value of :math:`\pi` +The two example CMake projects used are included in BLT's source tree at: + +* ``/cmake/docs/tutorial/bare_bones`` +* ``/cmake/docs/tutorial/calc_pi`` + +Here are direct links to the projects in BLT's GitHub repo: + +* https://github.com/LLNL/blt/tree/develop/docs/tutorial/bare_bones +* https://github.com/LLNL/blt/tree/develop/docs/tutorial/calc_pi + + +``bare_bones`` provides a minimum template for starting a new project and +``calc_pi`` provides several examples that calculate the value of :math:`\pi` by approximating the integral :math:`f(x) = \int_0^14/(1+x^2)` using numerical -integration. The code is adapted from: -https://www.mcs.anl.gov/research/projects/mpi/usingmpi/examples-usingmpi/simplempi/cpi_c.html. +integration. The code is adapted from ANL's `using MPI examples `_. + + +Most of the tutorial focuses on the BLT features used to create the complete +``calc_pi`` project. + -The tutorial requires a C++ compiler and CMake, we recommend using CMake 3.8.0 or newer. -Parts of the tutorial also require MPI, CUDA, Sphinx and Doxygen. +The tutorial requires a C++ compiler and CMake, we recommend using CMake 3.8.0 or newer. +Parts of the tutorial also require MPI, CUDA, Sphinx, and Doxygen. +We provide instructions to build and run these projects on several +LLNL HPC platforms and ORNL's Summit platform. See :ref:`HostConfigs`. .. toctree:: :maxdepth: 3 :caption: Tutorial Contents + :includehidden: - setup_blt - creating_execs_and_libs - using_flags - unit_testing - external_dependencies + getting_started + creating_targets + adding_tests + host_configs + importing_targets creating_documentation + advanced_topics recommendations diff --git a/docs/tutorial/object_libraries.rst b/docs/tutorial/object_libraries.rst new file mode 100644 index 000000000..dd1bac9be --- /dev/null +++ b/docs/tutorial/object_libraries.rst @@ -0,0 +1,58 @@ +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details +.. # +.. # SPDX-License-Identifier: (BSD-3-Clause) + +.. _ObjectLibraries: + +Object Libraries +================ + +BLT has simplified the use of CMake object libraries through the +:ref:`blt_add_library` macro. Object libraries are a collection of object files +that are not linked or archived into a library. They are used in other libraries +or executables through the ``DEPENDS_ON`` macro argument. This is generally +useful for combining smaller libraries into a larger library without +the linker removing unused symbols in the larger library. + +.. code-block:: cmake + + blt_add_library(NAME myObjectLibrary + SOURCES source1.cpp + HEADERS header1.cpp + OBJECT TRUE) + + blt_add_exectuble(NAME helloWorld + SOURCES main.cpp + DEPENDS_ON myObjectLibrary) + +.. note:: + Due to record keeping on BLT's part to make object libraries as easy to use + as possible, you need to define object libraries before you use them + if you need their inheritable information to be correct. + +If you are using separable CUDA compilation (relocatable device code) in your +object library, users of that library will be required to use NVCC to link their +executables - in general, only NVCC can perform the "device link" step. To remove +this restriction, you can enable the ``CUDA_RESOLVE_DEVICE_SYMBOLS`` property on +an object library: + +.. code-block:: cmake + + set_target_properties(myObjectLibrary PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON) + +To enable this device linking step for all libraries in your project (including object libraries), you +can set the ``CMAKE_CUDA_RESOLVE_DEVICE_SYMBOLS`` option to ``ON``. This defaults the +``CUDA_RESOLVE_DEVICE_SYMBOLS`` target property to ``ON`` for all targets created by BLT. + +You can read more about this property in the +`CMake documentation `_. + +.. note:: + These options only apply when an object library in your project is linked later + into a shared or static library, in which case a separate object file containing + device symbols is created and added to the "final" library. Object libraries + provided directly to users of your project will still require a device link step. + +The ``CUDA_RESOLVE_DEVICE_SYMBOLS`` property is also supported for static and shared libraries. +By default, it is enabled for shared libraries but disabled for static libraries. diff --git a/docs/tutorial/using_flags.rst b/docs/tutorial/portable_compiler_flags.rst similarity index 78% rename from docs/tutorial/using_flags.rst rename to docs/tutorial/portable_compiler_flags.rst index 787692603..0cfce2634 100644 --- a/docs/tutorial/using_flags.rst +++ b/docs/tutorial/portable_compiler_flags.rst @@ -1,13 +1,15 @@ -.. # Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -.. # other BLT Project Developers. See the top-level COPYRIGHT file for details +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details .. # .. # SPDX-License-Identifier: (BSD-3-Clause) -Portable compiler flags -========================= +.. _PortableCompilerFlags: + +Portable Compiler Flags +======================= To simplify the development of code that is portable across different architectures -and compilers, BLT provides the ``blt_append_custom_compiler_flag()`` macro, +and compilers, BLT provides the :ref:`blt_append_custom_compiler_flag` macro, which allows users to easily place a compiler dependent flag into a CMake variable. .. admonition:: blt_append_custom_compiler_flag @@ -39,7 +41,7 @@ Here is an example for setting the appropriate flag to treat warnings as errors: ) Since values for ``GNU``, ``CLANG`` and ``INTEL`` are not supplied, -they will get the default value (``-Werror``) +they will get the default value, ``-Werror``, which is supplied by the macro's ``DEFAULT`` argument. BLT also provides a simple macro to add compiler flags to a target. @@ -64,6 +66,6 @@ Here is another example to disable warnings about unknown OpenMP pragmas in the MSVC "/wd4068" ) -Note that GNU does not have a way to only disable warnings about openmp pragmas, -so one must disable warnings about all unknown pragmas on this compiler. - +.. note:: + GNU does not have a way to only disable warnings about OpenMP pragmas, + so you must disable warnings about all unknown pragmas on this compiler. diff --git a/docs/tutorial/recommendations.rst b/docs/tutorial/recommendations.rst index 6f55becdf..7e49f58f8 100644 --- a/docs/tutorial/recommendations.rst +++ b/docs/tutorial/recommendations.rst @@ -1,35 +1,37 @@ -.. # Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -.. # other BLT Project Developers. See the top-level COPYRIGHT file for details +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details .. # .. # SPDX-License-Identifier: (BSD-3-Clause) -.. _Recommendations: +.. _CMakeRecommendations: -CMake Recommendations -====================== +CMake Recommendations +===================== This section includes several recommendations for how to wield CMake. Some of them are embodied in BLT, others are broader suggestions for CMake bliss. -.. rubric:: Disable in-source builds +Disable In-source Builds +------------------------ *BLT Enforces This* - In-source builds clutter source code with temporary build files and prevent other out-of-source builds from being created. Disabling in-source builds avoids clutter and accidental checkins of temporary build files. -.. rubric:: Avoid using globs to identify source files + +Avoid using Globs to Identify Source Files +------------------------------------------ Globs are evaluated at CMake configure time - not build time. This means CMake will not detect new source files when they are added to the file system unless there are other changes that trigger CMake to reconfigure. -The CMake documentation also warns against this: -https://cmake.org/cmake/help/v3.10/command/file.html?highlight=glob#file +The CMake documentation also warns against `this `_. -.. rubric:: Use arguments instead of options in CMake Macros and Functions +Use Arguments instead of Options in CMake Macros and Functions +-------------------------------------------------------------- ``CMAKE_PARSE_ARGUMENTS`` allows Macros or Functions to support options. Options are enabled by passing them by name when calling a Macro or Function. Because of this, wrapping an existing Macro or Function in a way @@ -56,25 +58,30 @@ To simplify calling logic, we recommend using an argument instead of an option. my_function(arg1 arg2 arg3 ${arg4_value}) -.. rubric:: Prefer explicit paths to locate third-party dependencies +Prefer Explicit Paths to Locate Third-party Dependencies +-------------------------------------------------------- Require passing explicit paths (ex: ``ZZZ_DIR``) for third-party dependency locations. This avoids surprises with incompatible installs sprinkled in various system locations. If you are using off-the-shelf *FindZZZ* logic, also consider adding CMake checks to verify that *FindZZZ* logic actually found the dependencies at the location specified. -.. rubric:: Emit a configure error if an explicitly identified third-party dependency is not found or an incorrect version is found. -If an explicit path to a dependency is given (ex: ``ZZZ_DIR``) it should be valid or result in a CMake configure error. +Error at Configure Time for Third-party Dependency Problems +----------------------------------------------------------- + +Emit a configure error if an explicitly identified third-party dependency is not found or an incorrect +version is found. If an explicit path to a dependency is given (ex: ``ZZZ_DIR``) it should be valid or result in a CMake configure error. -In contrast, if you only issue a warning and automatically disable a feature when a third-party dependency is bad, -the warning often goes unnoticed and may not be caught until folks using your software are surprised. +In contrast, if you only issue a warning and automatically disable a feature when a third-party dependency +is bad, the warning often goes unnoticed and may not be caught until folks using your software are surprised. Emitting a configure error stops CMake and draws attention to the fact that something is wrong. Optional dependencies are still supported by including them only if an explicit path to the dependency is provided (ex: ``ZZZ_DIR``). -.. rubric:: Add headers as source files to targets +Add Headers as Source Files to Targets +-------------------------------------- *BLT Macros Support This* @@ -82,7 +89,8 @@ This ensures headers are tracked as dependencies and are included in the project created by CMake's IDE generators, like Xcode or Eclipse. -.. rubric:: Always support `make install` +Always Support `make install` +----------------------------- This allows CMake to do the right thing based on ``CMAKE_INSTALL_PREFIX``, and also helps support CPack create release packages. This is especially important for libraries. diff --git a/docs/tutorial/third_party_libraries.rst b/docs/tutorial/third_party_libraries.rst new file mode 100644 index 000000000..e9f5255d3 --- /dev/null +++ b/docs/tutorial/third_party_libraries.rst @@ -0,0 +1,151 @@ +.. # Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +.. # other BLT Project Developers. See the top-level LICENSE file for details +.. # +.. # SPDX-License-Identifier: (BSD-3-Clause) + +.. _ThirdPartyLibraries: + +Third Party Libraries +===================== + +Third party libraries come in three flavors based on the CMake support provided by +the project and the CMake community as a whole: no Cmake support, CMake's Find* modules, +and First Class project support. + +No CMake Support +~~~~~~~~~~~~~~~~ + +Some libraries have no support for easily importing their CMake targets into +external projects, either through properly exporting their targets themselves +or the CMake community has not written a Find module that eases this work. + +BLT provides a :ref:`blt_import_library` macro allows you to reuse all information needed +for an external dependency under a single name. This includes any include +directories, libraries, compile flags, link flags, defines, etc. You can also +hide any warnings created by their headers by setting the +``TREAT_INCLUDES_AS_SYSTEM`` argument. + +We will use Lua as an example of this because up until recently (CMake version 3.18), +there was no Find module. This provides us a great example on how to show two ways +of importing the same library's targets. + +The following example shows how to find a library, Lua this time, manually. By first, +searching for the include directories and then for the library itself. Finally it calls +:ref:`blt_import_library` to bundle that information under one easy to remember name, ``lua`` : + +.. code-block:: cmake + + # first Check for LUA_DIR + if (NOT EXISTS "${LUA_DIR}") + message(FATAL_ERROR "Given LUA_DIR does not exist: ${LUA_DIR}") + endif() + + if (NOT IS_DIRECTORY "${LUA_DIR}") + message(FATAL_ERROR "Given LUA_DIR is not a directory: ${LUA_DIR}") + endif() + + # Find includes directory + find_path( LUA_INCLUDE_DIR lua.hpp + PATHS ${LUA_DIR}/include/ + ${LUA_DIR}/include/lua + NO_DEFAULT_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_CMAKE_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + + # Find libraries + find_library( LUA_LIBRARY NAMES lua liblua + PATHS ${LUA_DIR}/lib + NO_DEFAULT_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_CMAKE_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + + + include(FindPackageHandleStandardArgs) + # handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE + # if all listed variables are TRUE + find_package_handle_standard_args(LUA DEFAULT_MSG + LUA_INCLUDE_DIR + LUA_LIBRARY ) + + if(NOT LUA_FOUND) + message(FATAL_ERROR "LUA_DIR is not a path to a valid Lua install") + endif() + + message(STATUS "Lua Includes: ${LUA_INCLUDE_DIR}") + message(STATUS "Lua Libraries: ${LUA_LIBRARY}") + + blt_import_library(NAME lua + TREAT_INCLUDES_AS_SYSTEM ON + DEFINES HAVE_LUA=1 + INCLUDES ${LUA_LIBRARY} + LIBRARIES ${LUA_INCLUDE_DIR} + EXPORTABLE ON) + +Then ``lua`` is available to be used in the ``DEPENDS_ON`` list in the following +:ref:`blt_add_executable` or :ref:`blt_add_library` calls, or in any CMake command that accepts a target. + +.. note:: + CMake targets created by :ref:`blt_import_library` are ``INTERFACE`` libraries that can be installed + and exported if the ``EXPORTABLE`` option is enabled. For example, if the ``calc_pi`` project depends on + Lua, it could export its ``lua`` target. To avoid introducing target name conflicts for users of the + ``calc_pi`` project who might also create a target called ``lua``, ``lua`` should be exported as + ``calc_pi\:\:lua`` . + +.. note:: + Because CMake targets are only accessible from within the directory they were defined (including + subdirectories), the ``include()`` command should be preferred to the ``add_subdirectory()`` command + for adding CMake files that create imported library targets needed in other directories. The ``GLOBAL`` + option to :ref:`blt_import_library` can also be used to manage visibility. + + +Cmake's Find Modules +~~~~~~~~~~~~~~~~~~~~ + +This time we will do exactly the same thing but using the new CMake provided ``FindLua.cmake`` module. +Instead of calling having to ensure correctness and calling ``find_path`` and ``find_library``, we +only have to call ``find_package`` and it handles this for us. Each Find module outputs differently +named variables so it is important to read the documentation on CMake's website. This is where +:ref:`blt_import_library` shines because you only have to figure those variables once then use the +new imported library's ``NAME`` in the rest of your project. + +.. code-block:: cmake + + # FindLua.cmake takes in LUA_DIR, which the directory where Lua was installed to + # and fills variables: LUA_FOUND, LUA_LIBRARIES, and LUA_INCLUDE_DIR + find_package(Lua NO_DEFAULT_PATH + PATHS ${LUA_DIR}) + + if (NOT LUA_FOUND) + MESSAGE(FATAL_ERROR "Could not find Lua in the provided LUA_DIR: ${LUA_DIR}") + endif() + + blt_import_library(NAME lua + TREAT_INCLUDES_AS_SYSTEM ON + DEFINES HAVE_LUA=1 + INCLUDES ${LUA_LIBRARIES} + LIBRARIES ${LUA_INCLUDE_DIR} + EXPORTABLE ON) + + +First Class Project Support +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Some projects provide what we call First Class support. They have gone through the effort of +properly exporting all necessary targets to use their project and +install the necessary configuration files inside of their install directory, usually something +like ``\lib\cmake\Config.cmake``. + +LLNL's `Axom project `_ exports all targets that can be easily +imported into your project with a single CMake function call: + +.. code-block:: cmake + + # use the provided PATH directory and create a cmake target named 'axom' + find_package(axom REQUIRED) + +You can then add the created CMake target, ``axom``, to any ``DEPENDS_ON`` list or use any other +regular CMake function to change it. diff --git a/host-configs/darwin/elcapitan-x86_64/naples-clang@7.3.0.cmake b/host-configs/darwin/elcapitan-x86_64/naples-clang@7.3.0.cmake index 995ecbfb0..61d07a4d1 100644 --- a/host-configs/darwin/elcapitan-x86_64/naples-clang@7.3.0.cmake +++ b/host-configs/darwin/elcapitan-x86_64/naples-clang@7.3.0.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) diff --git a/host-configs/llnl/bgqos_0/clang@4.0.0_xlf.cmake b/host-configs/llnl/bgqos_0/clang@4.0.0_xlf.cmake deleted file mode 100644 index 4d24224b1..000000000 --- a/host-configs/llnl/bgqos_0/clang@4.0.0_xlf.cmake +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details -# -# SPDX-License-Identifier: (BSD-3-Clause) - -#------------------------------------------------------------------------------ -# Example host-config file for clang C/C++ compiler -# paired with xlf Fortran compiler on LLNL's bgq machine -#------------------------------------------------------------------------------ - -set(CLANG_HOME "/collab/usr/gapps/opnsrc/gnu/dev/lnx-2.12-ppc/bgclang/r284961-stable") -set(CMAKE_C_COMPILER "${CLANG_HOME}/llnl/bin/mpiclang" CACHE PATH "") -set(CMAKE_CXX_COMPILER "${CLANG_HOME}/llnl/bin/mpiclang++11" CACHE PATH "") - -# Set Fortran compiler -set(ENABLE_FORTRAN ON CACHE BOOL "") -set(CMAKE_Fortran_COMPILER "/opt/ibmcmp/xlf/bg/14.1/bin/bgxlf2003" CACHE PATH "") - - -#------------------------------------------------------------------------------ -# Extra options and flags -#------------------------------------------------------------------------------ - -set(ENABLE_DOCS OFF CACHE BOOL "") -set(CMAKE_SKIP_RPATH TRUE CACHE BOOL "") - -# Use clang's libc++ instead of libstdc++ -set(BLT_CXX_FLAGS "-stdlib=libc++" CACHE STRING "") -set(gtest_defines "-DGTEST_HAS_CXXABI_H_=0" CACHE STRING "") - -# Converts C-style comments to Fortran style in preprocessed files -set(BLT_FORTRAN_FLAGS "-WF,-C!" CACHE STRING "") - - -#------------------------------------------------------------------------------ -# MPI Support -# Note: On BGQ, CMake uses the wrong linker flags when using FindMPI. -# Disable FindMPI to use LLNL wrapper scripts via CMake compiler variables. -#------------------------------------------------------------------------------ - -set(ENABLE_MPI ON CACHE BOOL "") -set(ENABLE_FIND_MPI OFF CACHE BOOL "") - -# Pass in an explicit path to help find mpif.h -set(MPI_Fortran_INCLUDE_PATH "/usr/local/tools/deg/drivers/V1R2M0/ppc64/comm/gcc/include" CACHE PATH "") - -set(MPIEXEC "/usr/bin/srun" CACHE PATH "") -set(MPIEXEC_NUMPROC_FLAG "-n" CACHE PATH "") - -# Ensures that tests will be wrapped with srun to run on the backend nodes -set(ENABLE_WRAP_ALL_TESTS_WITH_MPIEXEC TRUE CACHE BOOL "Run tests on backend nodes") diff --git a/host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_link_with_nvcc.cmake b/host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_link_with_nvcc.cmake index 13e109399..36c6634f6 100644 --- a/host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_link_with_nvcc.cmake +++ b/host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_link_with_nvcc.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) diff --git a/host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_c++17.cmake b/host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_c++17.cmake new file mode 100644 index 000000000..dd741836d --- /dev/null +++ b/host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_c++17.cmake @@ -0,0 +1,68 @@ +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details +# +# SPDX-License-Identifier: (BSD-3-Clause) + +#------------------------------------------------------------------------------ +# Example host-config file for the blue_os cluster at LLNL, specifically Lassen +#------------------------------------------------------------------------------ +# +# This file provides CMake with paths / details for: +# C/C++: Clang with GCC 8.3.1 toolchain +# Cuda +# MPI +# +#------------------------------------------------------------------------------ + +#--------------------------------------- +# Compilers +#--------------------------------------- + +set(_CLANG_VERSION "clang-upstream-2019.08.15") +set(_CLANG_DIR "/usr/tce/packages/clang/${_CLANG_VERSION}") +set(_GCC_DIR "/usr/tce/packages/gcc/gcc-8.3.1") + +set(CMAKE_C_COMPILER "${_CLANG_DIR}/bin/clang" CACHE PATH "") +set(CMAKE_CXX_COMPILER "${_CLANG_DIR}/bin/clang++" CACHE PATH "") + +set(BLT_CXX_STD "c++17" CACHE STRING "") + +set(CMAKE_C_FLAGS "--gcc-toolchain=${_GCC_DIR}" CACHE PATH "") +set(CMAKE_CXX_FLAGS "--gcc-toolchain=${_GCC_DIR}" CACHE PATH "") + +set(BLT_EXE_LINKER_FLAGS " -Wl,-rpath,${_GCC_DIR}/lib" CACHE PATH "Adds a missing libstdc++ rpath") + +#--------------------------------------- +# MPI +#--------------------------------------- +set(ENABLE_MPI ON CACHE BOOL "") + +set(_MPI_BASE_DIR "/usr/tce/packages/spectrum-mpi/spectrum-mpi-rolling-release-${_CLANG_VERSION}") + +set(MPI_C_COMPILER "${_MPI_BASE_DIR}/bin/mpicc" CACHE PATH "") +set(MPI_CXX_COMPILER "${_MPI_BASE_DIR}/bin/mpicxx" CACHE PATH "") + +#------------------------------------------------------------------------------ +# Cuda +#------------------------------------------------------------------------------ + +set(ENABLE_CUDA ON CACHE BOOL "") + +set(CUDA_TOOLKIT_ROOT_DIR "/usr/tce/packages/cuda/cuda-11.0.182" CACHE PATH "") + +set(CMAKE_CUDA_COMPILER "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc" CACHE PATH "") +set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}" CACHE PATH "") + +set(CMAKE_CUDA_ARCHITECTURES "70" CACHE STRING "") +set(_cuda_arch "sm_${CMAKE_CUDA_ARCHITECTURES}") +set(CMAKE_CUDA_FLAGS "-Xcompiler=--gcc-toolchain=${_GCC_DIR} -restrict -arch ${_cuda_arch} -std=c++17 --expt-extended-lambda -G" CACHE STRING "") + +set(CUDA_SEPARABLE_COMPILATION ON CACHE BOOL "" ) + +# nvcc does not like gtest's 'pthreads' flag +set(gtest_disable_pthreads ON CACHE BOOL "") +set(ENABLE_GTEST_DEATH_TESTS OFF CACHE BOOL "") + +# Very specific fix for working around CMake adding implicit link directories returned by the BlueOS +# compilers to link CUDA executables +set(BLT_CMAKE_IMPLICIT_LINK_DIRECTORIES_EXCLUDE "/usr/tce/packages/gcc/gcc-4.9.3/lib64/gcc/powerpc64le-unknown-linux-gnu/4.9.3;/usr/tce/packages/gcc/gcc-4.9.3/lib64" CACHE STRING "") diff --git a/host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_c++17_no_separable.cmake b/host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_c++17_no_separable.cmake new file mode 100644 index 000000000..2907ac1a4 --- /dev/null +++ b/host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_c++17_no_separable.cmake @@ -0,0 +1,66 @@ +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details +# +# SPDX-License-Identifier: (BSD-3-Clause) + +#------------------------------------------------------------------------------ +# Example host-config file for the blue_os cluster at LLNL +#------------------------------------------------------------------------------ +# +# This file provides CMake with paths / details for: +# C/C++: Clang with GCC 8.3.1 toolchain with C++17 support +# Cuda +# MPI +# +#------------------------------------------------------------------------------ + +#--------------------------------------- +# Compilers +#--------------------------------------- + +set(_CLANG_VERSION "clang-upstream-2019.08.15") +set(_CLANG_DIR "/usr/tce/packages/clang/${_CLANG_VERSION}") +set(_GCC_DIR "/usr/tce/packages/gcc/gcc-8.3.1") + +set(CMAKE_C_COMPILER "${_CLANG_DIR}/bin/clang" CACHE PATH "") +set(CMAKE_CXX_COMPILER "${_CLANG_DIR}/bin/clang++" CACHE PATH "") + +set(BLT_CXX_STD "c++17" CACHE STRING "") + +set(CMAKE_C_FLAGS "--gcc-toolchain=${_GCC_DIR}" CACHE PATH "") +set(CMAKE_CXX_FLAGS "--gcc-toolchain=${_GCC_DIR}" CACHE PATH "") + +set(BLT_EXE_LINKER_FLAGS " -Wl,-rpath,${_GCC_DIR}/lib" CACHE PATH "Adds a missing libstdc++ rpath") + +#--------------------------------------- +# MPI +#--------------------------------------- +set(ENABLE_MPI ON CACHE BOOL "") + +set(_MPI_BASE_DIR "/usr/tce/packages/spectrum-mpi/spectrum-mpi-rolling-release-${_CLANG_VERSION}") + +set(MPI_C_COMPILER "${_MPI_BASE_DIR}/bin/mpicc" CACHE PATH "") +set(MPI_CXX_COMPILER "${_MPI_BASE_DIR}/bin/mpicxx" CACHE PATH "") + +#------------------------------------------------------------------------------ +# Cuda +#------------------------------------------------------------------------------ + +set(ENABLE_CUDA ON CACHE BOOL "") + +set(CUDA_TOOLKIT_ROOT_DIR "/usr/tce/packages/cuda/cuda-11.0.182" CACHE PATH "") + +set(CMAKE_CUDA_COMPILER "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc" CACHE PATH "") +set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}" CACHE PATH "") + +set(CMAKE_CUDA_ARCHITECTURES "70" CACHE STRING "") +set(_cuda_arch "sm_${CMAKE_CUDA_ARCHITECTURES}") +set(CMAKE_CUDA_FLAGS "-Xcompiler=--gcc-toolchain=${_GCC_DIR} -restrict -arch ${_cuda_arch} -std=c++17 --expt-extended-lambda -G" CACHE STRING "") + +# nvcc does not like gtest's 'pthreads' flag +set(gtest_disable_pthreads ON CACHE BOOL "") +set(ENABLE_GTEST_DEATH_TESTS OFF CACHE BOOL "") + +# Very specific fix for working around CMake adding implicit link directories returned by the BlueOS +# compilers to link CUDA executables +set(BLT_CMAKE_IMPLICIT_LINK_DIRECTORIES_EXCLUDE "/usr/tce/packages/gcc/gcc-4.9.3/lib64/gcc/powerpc64le-unknown-linux-gnu/4.9.3;/usr/tce/packages/gcc/gcc-4.9.3/lib64" CACHE STRING "") diff --git a/host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_xlf.cmake b/host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_xlf.cmake index 478393d07..a4c8806cc 100644 --- a/host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_xlf.cmake +++ b/host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_xlf.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -60,18 +60,19 @@ set(BLT_FORTRAN_FLAGS "-WF,-C!" CACHE PATH "Converts C-style comments to Fortran #------------------------------------------------------------------------------ # CUDA support #------------------------------------------------------------------------------ - +#_blt_tutorial_useful_cuda_flags_start set(ENABLE_CUDA ON CACHE BOOL "") set(CUDA_TOOLKIT_ROOT_DIR "/usr/tce/packages/cuda/cuda-10.1.168" CACHE PATH "") set(CMAKE_CUDA_COMPILER "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc" CACHE PATH "") set(CMAKE_CUDA_HOST_COMPILER "${MPI_CXX_COMPILER}" CACHE PATH "") -set(_cuda_arch "sm_70") +set(CMAKE_CUDA_ARCHITECTURES "70" CACHE STRING "") +set(_cuda_arch "sm_${CMAKE_CUDA_ARCHITECTURES}") set(CMAKE_CUDA_FLAGS "-restrict -arch ${_cuda_arch} -std=c++11 --expt-extended-lambda -G" CACHE STRING "") set(CUDA_SEPARABLE_COMPILATION ON CACHE BOOL "" ) # nvcc does not like gtest's 'pthreads' flag set(gtest_disable_pthreads ON CACHE BOOL "") - +#_blt_tutorial_useful_cuda_flags_end diff --git a/host-configs/llnl/blueos_3_ppc64le_ib_p9/pgi@20.4_nvcc.cmake b/host-configs/llnl/blueos_3_ppc64le_ib_p9/pgi@20.4_nvcc.cmake new file mode 100644 index 000000000..1e4d7b741 --- /dev/null +++ b/host-configs/llnl/blueos_3_ppc64le_ib_p9/pgi@20.4_nvcc.cmake @@ -0,0 +1,25 @@ +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details +# +# SPDX-License-Identifier: (BSD-3-Clause) + +#------------------------------------------------------------------------------ +# Example host-config file for using PGI and CUDA +#------------------------------------------------------------------------------ +set (CMAKE_CXX_COMPILER "/usr/tce/packages/pgi/pgi-20.4/bin/pgc++" CACHE PATH "") +set (CMAKE_C_COMPILER "/usr/tce/packages/pgi/pgi-20.4/bin/pgcc" CACHE PATH "") + +set(ENABLE_FORTRAN OFF CACHE BOOL "") +set(ENABLE_MPI OFF CACHE BOOL "") +set(ENABLE_OPENMP OFF CACHE BOOL "") + +set(ENABLE_CUDA ON CACHE BOOL "") + +set(CUDA_TOOLKIT_ROOT_DIR "/usr/tce/packages/cuda/cuda-10.1.243" CACHE PATH "") +set(CMAKE_CUDA_COMPILER "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc" CACHE PATH "") +set(CMAKE_CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER} CACHE PATH "") + +set(CUDA_SEPARABLE_COMPILATION ON CACHE BOOL "" ) + +set (_cuda_arch "sm_70") +set (CMAKE_CUDA_FLAGS "-restrict -arch ${_cuda_arch} -std=c++11 --expt-extended-lambda -G" CACHE STRING "" ) diff --git a/host-configs/llnl/toss_3_x86_64_ib/clang@4.0.0-libcxx.cmake b/host-configs/llnl/toss_3_x86_64_ib/clang@4.0.0-libcxx.cmake index e34094a6c..0566d9298 100644 --- a/host-configs/llnl/toss_3_x86_64_ib/clang@4.0.0-libcxx.cmake +++ b/host-configs/llnl/toss_3_x86_64_ib/clang@4.0.0-libcxx.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) diff --git a/host-configs/llnl/toss_3_x86_64_ib/clang@6.0.0-static-analysis.cmake b/host-configs/llnl/toss_3_x86_64_ib/clang@6.0.0-static-analysis.cmake index 1e4e0164c..7f1556dfb 100644 --- a/host-configs/llnl/toss_3_x86_64_ib/clang@6.0.0-static-analysis.cmake +++ b/host-configs/llnl/toss_3_x86_64_ib/clang@6.0.0-static-analysis.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -42,6 +42,9 @@ set(gtest_defines "-DGTEST_HAS_CXXABI_H_=0" CACHE STRING "") set(ClangQuery_DIR ${CLANG_HOME}/bin) set(ENABLE_CLANGQUERY ON CACHE BOOL "") +set(ClangTidy_DIR ${CLANG_HOME}/bin) +set(ENABLE_CLANGTIDY ON CACHE BOOL "") + #------------------------------------------------------------------------------ # MPI Support #------------------------------------------------------------------------------ @@ -54,4 +57,3 @@ set(MPI_Fortran_COMPILER "${MPI_HOME}/bin/mpifort" CACHE PATH "") set(MPIEXEC "/usr/bin/srun" CACHE PATH "") set(MPIEXEC_NUMPROC_FLAG "-n" CACHE PATH "") - diff --git a/host-configs/llnl/toss_3_x86_64_ib/gcc@4.9.3_nvcc.cmake b/host-configs/llnl/toss_3_x86_64_ib/gcc@4.9.3_nvcc.cmake new file mode 100644 index 000000000..b837b547e --- /dev/null +++ b/host-configs/llnl/toss_3_x86_64_ib/gcc@4.9.3_nvcc.cmake @@ -0,0 +1,58 @@ +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details +# +# SPDX-License-Identifier: (BSD-3-Clause) + +#------------------------------------------------------------------------------ +# Example host-config file for the Pascal cluster at LLNL +#------------------------------------------------------------------------------ +# This file provides CMake with paths / details for: +# C,C++, & Fortran compilers + MPI & CUDA +#------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ +# gcc@4.9.3 compilers +#------------------------------------------------------------------------------ +# _blt_tutorial_compiler_config_start +set(GCC_HOME "/usr/tce") +set(CMAKE_C_COMPILER "${GCC_HOME}/bin/gcc" CACHE PATH "") +set(CMAKE_CXX_COMPILER "${GCC_HOME}/bin/g++" CACHE PATH "") + +# Fortran support +set(ENABLE_FORTRAN ON CACHE BOOL "") +set(CMAKE_Fortran_COMPILER "${GCC_HOME}/bin/gfortran" CACHE PATH "") +# _blt_tutorial_compiler_config_end + +#------------------------------------------------------------------------------ +# MPI Support +#------------------------------------------------------------------------------ +# _blt_tutorial_mpi_config_start +set(ENABLE_MPI ON CACHE BOOL "") + +set(MPI_HOME "/usr/tce/packages/mvapich2/mvapich2-2.3-gcc-4.9.3/") +set(MPI_C_COMPILER "${MPI_HOME}/bin/mpicc" CACHE PATH "") + +set(MPI_CXX_COMPILER "${MPI_HOME}/bin/mpicxx" CACHE PATH "") + +set(MPI_Fortran_COMPILER "${MPI_HOME}/bin/mpif90" CACHE PATH "") +# _blt_tutorial_mpi_config_end + +#------------------------------------------------------------------------------ +# CUDA support +#------------------------------------------------------------------------------ +# _blt_tutorial_cuda_config_start +set(ENABLE_CUDA ON CACHE BOOL "") + +set(CUDA_TOOLKIT_ROOT_DIR "/usr/tce/packages/cuda/cuda-10.1.168" CACHE PATH "") +set(CMAKE_CUDA_COMPILER "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc" CACHE PATH "") +set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}" CACHE PATH "") + +set(CMAKE_CUDA_ARCHITECTURES "70" CACHE STRING "") +set(_cuda_arch "sm_${CMAKE_CUDA_ARCHITECTURES}") +set(CMAKE_CUDA_FLAGS "-restrict -arch ${_cuda_arch} -std=c++11 --expt-extended-lambda -G" + CACHE STRING "") + +set(CUDA_SEPARABLE_COMPILATION ON CACHE BOOL "") + +# _blt_tutorial_cuda_config_end + diff --git a/host-configs/llnl/toss_3_x86_64_ib/gcc@4.9.3.cmake b/host-configs/llnl/toss_3_x86_64_ib/gcc@8.3.1.cmake similarity index 89% rename from host-configs/llnl/toss_3_x86_64_ib/gcc@4.9.3.cmake rename to host-configs/llnl/toss_3_x86_64_ib/gcc@8.3.1.cmake index 061a12928..d83451926 100644 --- a/host-configs/llnl/toss_3_x86_64_ib/gcc@4.9.3.cmake +++ b/host-configs/llnl/toss_3_x86_64_ib/gcc@8.3.1.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -13,10 +13,10 @@ #------------------------------------------------------------------------------ #------------------------------------------------------------------------------ -# gcc@4.9.3 compilers +# gcc@8.3.1 compilers #------------------------------------------------------------------------------ -set(GCC_VERSION "gcc-4.9.3") +set(GCC_VERSION "gcc-8.3.1") set(GCC_HOME "/usr/tce/packages/gcc/${GCC_VERSION}") # c compiler diff --git a/host-configs/llnl/toss_3_x86_64_ib/pgi@18.5.cmake b/host-configs/llnl/toss_3_x86_64_ib/pgi@20.1.cmake similarity index 83% rename from host-configs/llnl/toss_3_x86_64_ib/pgi@18.5.cmake rename to host-configs/llnl/toss_3_x86_64_ib/pgi@20.1.cmake index 336c3c11d..8b8ed6575 100644 --- a/host-configs/llnl/toss_3_x86_64_ib/pgi@18.5.cmake +++ b/host-configs/llnl/toss_3_x86_64_ib/pgi@20.1.cmake @@ -1,13 +1,13 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) #------------------------------------------------------------------------------ -# Example pgi@18.5 host-config for LLNL toss3 machines +# Example pgi@20.1 host-config for LLNL toss3 machines #------------------------------------------------------------------------------ -set(COMPILER_HOME "/usr/tce/packages/pgi/pgi-18.5") +set(COMPILER_HOME "/usr/tce/packages/pgi/pgi-20.1") # c compiler set(CMAKE_C_COMPILER "${COMPILER_HOME}/bin/pgcc" CACHE PATH "") @@ -34,7 +34,7 @@ set(ENABLE_OPENMP ON CACHE BOOL "") set(ENABLE_MPI ON CACHE BOOL "") -set(MPI_HOME "/usr/tce/packages/mvapich2/mvapich2-2.2-pgi-18.5") +set(MPI_HOME "/usr/tce/packages/mvapich2/mvapich2-2.3-pgi-20.1") set(MPI_C_COMPILER "${MPI_HOME}/bin/mpicc" CACHE PATH "") set(MPI_CXX_COMPILER "${MPI_HOME}/bin/mpicxx" CACHE PATH "") diff --git a/host-configs/llnl/windows/sqa-uno-msvc@15.cmake b/host-configs/llnl/windows/sqa-uno-msvc@15.cmake index efbafd339..95c84018b 100644 --- a/host-configs/llnl/windows/sqa-uno-msvc@15.cmake +++ b/host-configs/llnl/windows/sqa-uno-msvc@15.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) diff --git a/host-configs/olcf/summit/gcc@6.4.0_nvcc.cmake b/host-configs/olcf/summit/gcc@6.4.0_nvcc.cmake new file mode 100644 index 000000000..b31ede032 --- /dev/null +++ b/host-configs/olcf/summit/gcc@6.4.0_nvcc.cmake @@ -0,0 +1,68 @@ +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details +# +# SPDX-License-Identifier: (BSD-3-Clause) + +#------------------------------------------------------------------------------ +# Example host-config file for the Summit cluster at the OLCF +#------------------------------------------------------------------------------ +# This file provides CMake with paths / details for: +# C,C++, & Fortran compilers + MPI & CUDA +# +# As of 3/29/2021 - these settings match summit modules: +# gcc +# cuda +# +# We recommend loading these modules. +# +#------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ +# gcc@9.4.3 compilers +#------------------------------------------------------------------------------ +# _blt_tutorial_compiler_config_start +set(GCC_HOME "/sw/summit/gcc/6.4.0") +set(CMAKE_C_COMPILER "${GCC_HOME}/bin/gcc" CACHE PATH "") +set(CMAKE_CXX_COMPILER "${GCC_HOME}/bin/g++" CACHE PATH "") + +# Fortran support +set(ENABLE_FORTRAN ON CACHE BOOL "") +set(CMAKE_Fortran_COMPILER "${GCC_HOME}/bin/gfortran" CACHE PATH "") +# _blt_tutorial_compiler_config_end + +#------------------------------------------------------------------------------ +# MPI Support +#------------------------------------------------------------------------------ +# _blt_tutorial_mpi_config_start +set(ENABLE_MPI ON CACHE BOOL "") + +set(MPI_HOME "/autofs/nccs-svm1_sw/summit/.swci/1-compute/opt/spack/20180914/linux-rhel7-ppc64le/gcc-6.4.0/spectrum-mpi-10.3.1.2-20200121-awz2q5brde7wgdqqw4ugalrkukeub4eb") +set(MPI_C_COMPILER "${MPI_HOME}/bin/mpicc" CACHE PATH "") + +set(MPI_CXX_COMPILER "${MPI_HOME}/bin/mpicxx" CACHE PATH "") + +set(MPI_Fortran_COMPILER "${MPI_HOME}/bin/mpif90" CACHE PATH "") + +set(MPIEXEC_EXECUTABLE "/sw/summit/xalt/1.2.1/bin/jsrun" CACHE PATH "") + +# _blt_tutorial_mpi_config_end + +#------------------------------------------------------------------------------ +# CUDA support +#------------------------------------------------------------------------------ +# _blt_tutorial_cuda_config_start +set(ENABLE_CUDA ON CACHE BOOL "") + +set(CUDA_TOOLKIT_ROOT_DIR "/sw/summit/cuda/10.1.243/" CACHE PATH "") +set(CMAKE_CUDA_COMPILER "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc" CACHE PATH "") +set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}" CACHE PATH "") + +set(CMAKE_CUDA_ARCHITECTURES "70" CACHE STRING "") +set(_cuda_arch "sm_${CMAKE_CUDA_ARCHITECTURES}") +set(CMAKE_CUDA_FLAGS "-restrict -arch ${_cuda_arch} -std=c++11 --expt-extended-lambda -G" + CACHE STRING "") + +set(CUDA_SEPARABLE_COMPILATION ON CACHE BOOL "") + +# _blt_tutorial_cuda_config_end + diff --git a/host-configs/other/hcc.cmake b/host-configs/other/hcc.cmake index 15469bd24..8f3d08de3 100644 --- a/host-configs/other/hcc.cmake +++ b/host-configs/other/hcc.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -32,7 +32,11 @@ set(ENABLE_OPENMP OFF CACHE BOOL "") set(ROCM_ROOT_DIR "/opt/rocm" CACHE PATH "ROCm ROOT directory path") -set(ROCM_INCLUDE_PATH "${ROCM_ROOT_DIR}/hcc/include;${ROCM_ROOT_DIR}/include" CACHE PATH "") +if ( IS_DIRECTORY "${ROCM_ROOT_DIR}/hcc/include" ) # this path only exists on older rocm installs + set(ROCM_INCLUDE_PATH "${ROCM_ROOT_DIR}/hcc/include;${ROCM_ROOT_DIR}/include" CACHE PATH "") +else() + set(ROCM_INCLUDE_PATH "${ROCM_ROOT_DIR}/include" CACHE PATH "") +endif() set(ROCM_CXX_LIBRARIES "-L${ROCM_ROOT_DIR}/lib -lhc_am -lhip_hcc" CACHE STRING "") ########################################################### @@ -60,6 +64,7 @@ set(ROCM_CXX_LINK_FLAGS "${ROCM_CXX_LINK_FLAGS} ${ROCM_ARCH_FLAG} ${ROCM_CXX_LIB ########################################################### # set CMake cache variables ########################################################### +# if hcc does not exist, consider setting the compiler to "${ROCM_ROOT_DIR}/bin/hipcc" set(CMAKE_CXX_COMPILER "${ROCM_ROOT_DIR}/hcc/bin/hcc" CACHE FILEPATH "ROCm HCC compiler") # set(BLT_CXX_FLAGS "${ROCM_CXX_COMPILE_FLAGS}" CACHE STRING "HCC compiler flags") diff --git a/host-configs/other/hip.cmake b/host-configs/other/hip.cmake index 21d2537b5..b97dcaaa9 100644 --- a/host-configs/other/hip.cmake +++ b/host-configs/other/hip.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) diff --git a/host-configs/other/llnl-surface-chaos_5_x86_64_ib-gcc@4.9.3.cmake b/host-configs/other/llnl-surface-chaos_5_x86_64_ib-gcc@4.9.3.cmake deleted file mode 100644 index 0cb0a2623..000000000 --- a/host-configs/other/llnl-surface-chaos_5_x86_64_ib-gcc@4.9.3.cmake +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details -# -# SPDX-License-Identifier: (BSD-3-Clause) - -#------------------------------------------------------------------------------ -# Example host-config file for the surface cluster at LLNL -#------------------------------------------------------------------------------ -# -# This file provides CMake with paths / details for: -# C,C++, & Fortran compilers + MPI & CUDA -#------------------------------------------------------------------------------ - -#------------------------------------------------------------------------------ -# gcc@4.9.3 compilers -#------------------------------------------------------------------------------ -# _blt_tutorial_surface_compiler_config_start -set(CMAKE_C_COMPILER "/usr/apps/gnu/4.9.3/bin/gcc" CACHE PATH "") -set(CMAKE_CXX_COMPILER "/usr/apps/gnu/4.9.3/bin/g++" CACHE PATH "") - -# Fortran support -set(ENABLE_FORTRAN ON CACHE BOOL "") -set(CMAKE_Fortran_COMPILER "/usr/apps/gnu/4.9.3/bin/gfortran" CACHE PATH "") -# _blt_tutorial_surface_compiler_config_end - -#------------------------------------------------------------------------------ -# MPI Support -#------------------------------------------------------------------------------ -# _blt_tutorial_surface_mpi_config_start -set(ENABLE_MPI ON CACHE BOOL "") - -set(MPI_C_COMPILER "/usr/local/tools/mvapich2-gnu-2.0/bin/mpicc" CACHE PATH "") - -set(MPI_CXX_COMPILER "/usr/local/tools/mvapich2-gnu-2.0/bin/mpicc" CACHE PATH "") - -set(MPI_Fortran_COMPILER "/usr/local/tools/mvapich2-gnu-2.0/bin/mpif90" CACHE PATH "") -# _blt_tutorial_surface_mpi_config_end - -#------------------------------------------------------------------------------ -# CUDA support -#------------------------------------------------------------------------------ -# _blt_tutorial_surface_cuda_config_start -set(ENABLE_CUDA ON CACHE BOOL "") - -set(CUDA_TOOLKIT_ROOT_DIR "/opt/cudatoolkit-8.0" CACHE PATH "") -set(CMAKE_CUDA_COMPILER "/opt/cudatoolkit-8.0/bin/nvcc" CACHE PATH "") -set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}" CACHE PATH "") -set(CUDA_SEPARABLE_COMPILATION ON CACHE BOOL "") -# _blt_tutorial_surface_cuda_config_end - diff --git a/share/blt/logo/blt_logo_transparent.png b/share/blt/logo/blt_logo_transparent.png new file mode 100644 index 000000000..cdb04285e Binary files /dev/null and b/share/blt/logo/blt_logo_transparent.png differ diff --git a/tests/ctest-to-junit.xsl b/tests/ctest-to-junit.xsl new file mode 100644 index 000000000..b6a00b9ee --- /dev/null +++ b/tests/ctest-to-junit.xsl @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/internal/CMakeLists.txt b/tests/internal/CMakeLists.txt index 321e8362c..b090c57c5 100644 --- a/tests/internal/CMakeLists.txt +++ b/tests/internal/CMakeLists.txt @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -67,8 +67,12 @@ if(ENABLE_GTEST) # Header-only test #------------------------------------------------------ + blt_add_target_definitions(TO example + TARGET_DEFINITIONS BLT_EXAMPLE_LIB) + blt_add_library(NAME blt_header_only - HEADERS "src/HeaderOnly.hpp") + HEADERS "src/HeaderOnly.hpp" + DEPENDS_ON example) # This executable depends on the header-only library @@ -90,10 +94,6 @@ if(ENABLE_GTEST) set(_try_combine_static_libs OFF) endif() - if ("$ENV{SYS_TYPE}" STREQUAL "bgqos_0") - set(_try_combine_static_libs OFF) - endif() - if ( ${_try_combine_static_libs} ) add_subdirectory( src/combine_static_library_test ) endif () @@ -159,7 +159,7 @@ if(ENABLE_GTEST) #------------------------------------------------------ # CUDA tests #------------------------------------------------------ - if (ENABLE_CUDA) + if (ENABLE_CUDA AND CUDA_SEPARABLE_COMPILATION) add_subdirectory(src/test_cuda_device_call_from_kernel) endif() @@ -255,16 +255,20 @@ endif() message(STATUS "Exercising blt_print_target_properties macro on some targets and non-targets.") message(STATUS "") -foreach(_target gtest example t_example_smoke not-a-target blt_header_only mpi) +foreach(_target gtest example t_example_smoke not-a-target blt_header_only mpi cuda cuda_runtime) blt_print_target_properties(TARGET ${_target}) endforeach() add_subdirectory(src/object_library_test) -if(ENABLE_CLANGQUERY) +if(ENABLE_CLANGQUERY OR ENABLE_CLANGTIDY) add_subdirectory(src/static_analysis) endif() +if(ENABLE_HIP) + add_subdirectory(src/hip_defines_test) +endif() + #------------------------------------------------------------------------------ # Format the testing code using ClangFormat #------------------------------------------------------------------------------ @@ -274,6 +278,7 @@ if(CLANGFORMAT_FOUND) ../smoke/blt_cuda_mpi_smoke.cpp ../smoke/blt_cuda_openmp_smoke.cpp ../smoke/blt_cuda_runtime_smoke.cpp + ../smoke/blt_cuda_gtest_smoke.cpp ../smoke/blt_cuda_smoke.cpp ../smoke/blt_fruit_smoke.f90 ../smoke/blt_gbenchmark_smoke.cpp @@ -282,10 +287,12 @@ if(CLANGFORMAT_FOUND) ../smoke/blt_hcc_runtime_smoke.cpp ../smoke/blt_hcc_smoke.cpp ../smoke/blt_hip_runtime_smoke.cpp + ../smoke/blt_hip_gtest_smoke.cpp ../smoke/blt_hip_smoke.cpp ../smoke/blt_mpi_smoke.cpp ../smoke/blt_openmp_smoke.cpp ../smoke/fortran_driver.cpp + ../smoke/fortran_mpi_driver.cpp ) set(internal_tests_srcs @@ -325,8 +332,14 @@ if(CLANGFORMAT_FOUND) src/test_cuda_device_call_from_kernel/CudaTests.cpp src/test_cuda_device_call_from_kernel/Parent.cpp src/test_cuda_device_call_from_kernel/Parent.hpp + + src/hip_defines_test/foo.cpp + src/hip_defines_test/bar.cpp ) + # Specify the major version for astyle + set(BLT_REQUIRED_ASTYLE_VERSION "3") + blt_add_code_checks( PREFIX smoke_tests SOURCES ${smoke_tests_srcs} @@ -339,6 +352,56 @@ if(CLANGFORMAT_FOUND) endif() +if(YAPF_FOUND) + # Test case where a style target running yapf should do nothing, and + # a corresponding check target should return 0 + set(internal_conformant_python_srcs + src/test_yapf_conformant.py) + + blt_add_code_checks( + PREFIX yapf_conformant_tests + SOURCES ${internal_conformant_python_srcs} + YAPF_CFG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/yapf.cfg ) + + # Test case where a style target running yapf should reformat the source file, + # and a corresponding check target should return a nonzero code + # + # After styling, test_yapf_conformant.py and + # test_yapf_nonconformant.py should have the same contents + set(internal_nonconformant_python_srcs + src/test_yapf_nonconformant.py) + + blt_add_code_checks( + PREFIX yapf_nonconformant_tests + SOURCES ${internal_nonconformant_python_srcs} + YAPF_CFG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/yapf.cfg) +endif() # end if(YAPF_FOUND) + +if (CMAKEFORMAT_FOUND) + # Test case where a style target running cmake-format should do nothing, and + # a corresponding check target should return 0 + set(internal_conformant_cmake_srcs + src/test_cmake_format_conformant.cmake) + + blt_add_code_checks( + PREFIX cmake_format_conformant_tests + SOURCES ${internal_conformant_cmake_srcs} + CMAKEFORMAT_CFG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake-format-style.py ) + + # Test case where a style target running cmake-format should reformat the source file, + # and a corresponding check target should return a nonzero code + # + # After styling, cmake_format_conformant.cmake and + # cmake_format_nonconformant.cmake should have the same contents + set(internal_nonconformant_cmake_srcs + src/test_cmake_format_nonconformant.cmake) + + blt_add_code_checks( + PREFIX cmake_format_nonconformant_tests + SOURCES ${internal_nonconformant_cmake_srcs} + CMAKEFORMAT_CFG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake-format-style.py ) +endif() # end if(CMAKEFORMAT_FOUND) + # Check blt_add_test with a command that is not a target if(WIN32) configure_file(return_true_win32.in tests/return_true.bat COPYONLY) diff --git a/tests/internal/cmake_format_style.py b/tests/internal/cmake_format_style.py new file mode 100644 index 000000000..10fde7327 --- /dev/null +++ b/tests/internal/cmake_format_style.py @@ -0,0 +1,244 @@ +# This file was generated by running +# cmake-format --dump-config python + +# ---------------------------------- +# Options affecting listfile parsing +# ---------------------------------- +with section("parse"): + + # Specify structure for custom cmake functions + additional_commands = { 'foo': { 'flags': ['BAR', 'BAZ'], + 'kwargs': {'DEPENDS': '*', 'HEADERS': '*', 'SOURCES': '*'}}} + + # Override configurations per-command where available + override_spec = {} + + # Specify variable tags. + vartags = [] + + # Specify property tags. + proptags = [] + +# ----------------------------- +# Options affecting formatting. +# ----------------------------- +with section("format"): + + # Disable formatting entirely, making cmake-format a no-op + disable = False + + # How wide to allow formatted cmake files + line_width = 80 + + # How many spaces to tab for indent + tab_size = 2 + + # If true, lines are indented using tab characters (utf-8 0x09) instead of + # space characters (utf-8 0x20). In cases where the layout would + # require a fractional tab character, the behavior of the fractional + # indentation is governed by + use_tabchars = False + + # If is True, then the value of this variable indicates how + # fractional indentions are handled during whitespace replacement. If set to + # 'use-space', fractional indentation is left as spaces (utf-8 0x20). If set + # to `round-up` fractional indentation is replaced with a single tab character + # (utf-8 0x09) effectively shifting the column to the next tabstop + fractional_tab_policy = 'use-space' + + # If an argument group contains more than this many sub-groups (parg or kwarg + # groups) then force it to a vertical layout. + max_subgroups_hwrap = 2 + + # If a positional argument group contains more than this many arguments, then + # force it to a vertical layout. + max_pargs_hwrap = 6 + + # If a cmdline positional group consumes more than this many lines without + # nesting, then invalidate the layout (and nest) + max_rows_cmdline = 2 + + # If true, separate flow control names from their parentheses with a space + separate_ctrl_name_with_space = False + + # If true, separate function names from parentheses with a space + separate_fn_name_with_space = False + + # If a statement is wrapped to more than one line, than dangle the closing + # parenthesis on its own line. + dangle_parens = False + + # If the trailing parenthesis must be 'dangled' on its on line, then align it + # to this reference: `prefix`: the start of the statement, `prefix-indent`: + # the start of the statement, plus one indentation level, `child`: align to + # the column of the arguments + dangle_align = 'prefix' + + # If the statement spelling length (including space and parenthesis) is + # smaller than this amount, then force reject nested layouts. + min_prefix_chars = 4 + + # If the statement spelling length (including space and parenthesis) is larger + # than the tab width by more than this amount, then force reject un-nested + # layouts. + max_prefix_chars = 10 + + # If a candidate layout is wrapped horizontally but it exceeds this many + # lines, then reject the layout. + max_lines_hwrap = 2 + + # What style line endings to use in the output. + line_ending = 'unix' + + # Format command names consistently as 'lower' or 'upper' case + command_case = 'canonical' + + # Format keywords consistently as 'lower' or 'upper' case + keyword_case = 'unchanged' + + # A list of command names which should always be wrapped + always_wrap = [] + + # If true, the argument lists which are known to be sortable will be sorted + # lexicographicall + enable_sort = True + + # If true, the parsers may infer whether or not an argument list is sortable + # (without annotation). + autosort = False + + # By default, if cmake-format cannot successfully fit everything into the + # desired linewidth it will apply the last, most agressive attempt that it + # made. If this flag is True, however, cmake-format will print error, exit + # with non-zero status code, and write-out nothing + require_valid_layout = False + + # A dictionary mapping layout nodes to a list of wrap decisions. See the + # documentation for more information. + layout_passes = {} + +# ------------------------------------------------ +# Options affecting comment reflow and formatting. +# ------------------------------------------------ +with section("markup"): + + # What character to use for bulleted lists + bullet_char = '*' + + # What character to use as punctuation after numerals in an enumerated list + enum_char = '.' + + # If comment markup is enabled, don't reflow the first comment block in each + # listfile. Use this to preserve formatting of your copyright/license + # statements. + first_comment_is_literal = False + + # If comment markup is enabled, don't reflow any comment block which matches + # this (regex) pattern. Default is `None` (disabled). + literal_comment_pattern = None + + # Regular expression to match preformat fences in comments default= + # ``r'^\s*([`~]{3}[`~]*)(.*)$'`` + fence_pattern = '^\\s*([`~]{3}[`~]*)(.*)$' + + # Regular expression to match rulers in comments default= + # ``r'^\s*[^\w\s]{3}.*[^\w\s]{3}$'`` + ruler_pattern = '^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$' + + # If a comment line matches starts with this pattern then it is explicitly a + # trailing comment for the preceeding argument. Default is '#<' + explicit_trailing_pattern = '#<' + + # If a comment line starts with at least this many consecutive hash + # characters, then don't lstrip() them off. This allows for lazy hash rulers + # where the first hash char is not separated by space + hashruler_min_length = 10 + + # If true, then insert a space between the first hash char and remaining hash + # chars in a hash ruler, and normalize its length to fill the column + canonicalize_hashrulers = True + + # enable comment markup parsing and reflow + enable_markup = True + +# ---------------------------- +# Options affecting the linter +# ---------------------------- +with section("lint"): + + # a list of lint codes to disable + disabled_codes = [] + + # regular expression pattern describing valid function names + function_pattern = '[0-9a-z_]+' + + # regular expression pattern describing valid macro names + macro_pattern = '[0-9A-Z_]+' + + # regular expression pattern describing valid names for variables with global + # (cache) scope + global_var_pattern = '[A-Z][0-9A-Z_]+' + + # regular expression pattern describing valid names for variables with global + # scope (but internal semantic) + internal_var_pattern = '_[A-Z][0-9A-Z_]+' + + # regular expression pattern describing valid names for variables with local + # scope + local_var_pattern = '[a-z][a-z0-9_]+' + + # regular expression pattern describing valid names for privatedirectory + # variables + private_var_pattern = '_[0-9a-z_]+' + + # regular expression pattern describing valid names for public directory + # variables + public_var_pattern = '[A-Z][0-9A-Z_]+' + + # regular expression pattern describing valid names for function/macro + # arguments and loop variables. + argument_var_pattern = '[a-z][a-z0-9_]+' + + # regular expression pattern describing valid names for keywords used in + # functions or macros + keyword_pattern = '[A-Z][0-9A-Z_]+' + + # In the heuristic for C0201, how many conditionals to match within a loop in + # before considering the loop a parser. + max_conditionals_custom_parser = 2 + + # Require at least this many newlines between statements + min_statement_spacing = 1 + + # Require no more than this many newlines between statements + max_statement_spacing = 2 + max_returns = 6 + max_branches = 12 + max_arguments = 5 + max_localvars = 15 + max_statements = 50 + +# ------------------------------- +# Options affecting file encoding +# ------------------------------- +with section("encode"): + + # If true, emit the unicode byte-order mark (BOM) at the start of the file + emit_byteorder_mark = False + + # Specify the encoding of the input file. Defaults to utf-8 + input_encoding = 'utf-8' + + # Specify the encoding of the output file. Defaults to utf-8. Note that cmake + # only claims to support utf-8 so be careful when using anything else + output_encoding = 'utf-8' + +# ------------------------------------- +# Miscellaneous configurations options. +# ------------------------------------- +with section("misc"): + + # A dictionary containing any per-command configuration overrides. Currently + # only `command_case` is supported. + per_command = {} + diff --git a/tests/internal/src/Example.cpp b/tests/internal/src/Example.cpp index 0aa0b2070..380b3c1b2 100644 --- a/tests/internal/src/Example.cpp +++ b/tests/internal/src/Example.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/Example.hpp b/tests/internal/src/Example.hpp index d39936e64..6e7841c77 100644 --- a/tests/internal/src/Example.hpp +++ b/tests/internal/src/Example.hpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/Example_Exports.h b/tests/internal/src/Example_Exports.h index 6c5c9413c..feb1a62fa 100644 --- a/tests/internal/src/Example_Exports.h +++ b/tests/internal/src/Example_Exports.h @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/HeaderOnly.hpp b/tests/internal/src/HeaderOnly.hpp index d23209473..fa42fa1cb 100644 --- a/tests/internal/src/HeaderOnly.hpp +++ b/tests/internal/src/HeaderOnly.hpp @@ -1,17 +1,24 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) #ifndef BLT_HEADER_ONLY_HPP #define BLT_HEADER_ONLY_HPP +#include "Example.hpp" + +#ifndef BLT_EXAMPLE_LIB + #error Compile definitions were not propagated from "example" library +#endif + namespace blt { inline bool ReturnTrue() { - return true; + Example e; + return e.ReturnTrue(); } } // end of namespace blt diff --git a/tests/internal/src/combine_static_library_test/CMakeLists.txt b/tests/internal/src/combine_static_library_test/CMakeLists.txt index 8c097da3f..96faabbb5 100644 --- a/tests/internal/src/combine_static_library_test/CMakeLists.txt +++ b/tests/internal/src/combine_static_library_test/CMakeLists.txt @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/combine_static_library_test/Foo1.cpp b/tests/internal/src/combine_static_library_test/Foo1.cpp index 22b5e4df9..6bc0f3f58 100644 --- a/tests/internal/src/combine_static_library_test/Foo1.cpp +++ b/tests/internal/src/combine_static_library_test/Foo1.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/combine_static_library_test/Foo1.hpp b/tests/internal/src/combine_static_library_test/Foo1.hpp index a6763fdbf..439c733b5 100644 --- a/tests/internal/src/combine_static_library_test/Foo1.hpp +++ b/tests/internal/src/combine_static_library_test/Foo1.hpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/combine_static_library_test/Foo2.cpp b/tests/internal/src/combine_static_library_test/Foo2.cpp index 0075b7b67..9a8160408 100644 --- a/tests/internal/src/combine_static_library_test/Foo2.cpp +++ b/tests/internal/src/combine_static_library_test/Foo2.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/combine_static_library_test/Foo2.hpp b/tests/internal/src/combine_static_library_test/Foo2.hpp index d8a4b5199..984d71c80 100644 --- a/tests/internal/src/combine_static_library_test/Foo2.hpp +++ b/tests/internal/src/combine_static_library_test/Foo2.hpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/combine_static_library_test/Foo3.cpp b/tests/internal/src/combine_static_library_test/Foo3.cpp index b500b77da..ee5ba3be8 100644 --- a/tests/internal/src/combine_static_library_test/Foo3.cpp +++ b/tests/internal/src/combine_static_library_test/Foo3.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/combine_static_library_test/Foo3.hpp b/tests/internal/src/combine_static_library_test/Foo3.hpp index e4aa72a43..9ebdd48fc 100644 --- a/tests/internal/src/combine_static_library_test/Foo3.hpp +++ b/tests/internal/src/combine_static_library_test/Foo3.hpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/combine_static_library_test/blt_combine_static_libraries_shared_smoke.cpp b/tests/internal/src/combine_static_library_test/blt_combine_static_libraries_shared_smoke.cpp index 01149851b..4d3d28c43 100644 --- a/tests/internal/src/combine_static_library_test/blt_combine_static_libraries_shared_smoke.cpp +++ b/tests/internal/src/combine_static_library_test/blt_combine_static_libraries_shared_smoke.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/combine_static_library_test/blt_combine_static_libraries_static_smoke.cpp b/tests/internal/src/combine_static_library_test/blt_combine_static_libraries_static_smoke.cpp index 01149851b..4d3d28c43 100644 --- a/tests/internal/src/combine_static_library_test/blt_combine_static_libraries_static_smoke.cpp +++ b/tests/internal/src/combine_static_library_test/blt_combine_static_libraries_static_smoke.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/combine_static_library_test/main.cpp b/tests/internal/src/combine_static_library_test/main.cpp index 3f0b0ce35..0e57cea15 100644 --- a/tests/internal/src/combine_static_library_test/main.cpp +++ b/tests/internal/src/combine_static_library_test/main.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/hip_defines_test/CMakeLists.txt b/tests/internal/src/hip_defines_test/CMakeLists.txt new file mode 100644 index 000000000..c5f3d5b39 --- /dev/null +++ b/tests/internal/src/hip_defines_test/CMakeLists.txt @@ -0,0 +1,28 @@ +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details +# +# SPDX-License-Identifier: (BSD-3-Clause) + +############################################################################### +# +# Tests to make sure that definitions from one target do not propagate to another +# +############################################################################### + +blt_add_executable(NAME blt_hip_defines_test_foo + SOURCES foo.cpp + DEFINES FOO_ONLY + DEPENDS_ON hip) + +blt_add_executable(NAME blt_hip_defines_test_bar + SOURCES bar.cpp + DEFINES BAR_ONLY + DEPENDS_ON hip) + +blt_add_test( NAME blt_test_hip_defines_first + COMMAND blt_hip_defines_test_foo + ) + +blt_add_test( NAME blt_test_hip_defines_second + COMMAND blt_hip_defines_test_bar + ) diff --git a/tests/internal/src/hip_defines_test/bar.cpp b/tests/internal/src/hip_defines_test/bar.cpp new file mode 100644 index 000000000..487b91ee3 --- /dev/null +++ b/tests/internal/src/hip_defines_test/bar.cpp @@ -0,0 +1,13 @@ +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details +// +// SPDX-License-Identifier: (BSD-3-Clause) + +int main() +{ + #if !defined(FOO_ONLY) && defined(BAR_ONLY) + return 0; + #else + return 1; + #endif +} diff --git a/tests/internal/src/hip_defines_test/foo.cpp b/tests/internal/src/hip_defines_test/foo.cpp new file mode 100644 index 000000000..6db75427c --- /dev/null +++ b/tests/internal/src/hip_defines_test/foo.cpp @@ -0,0 +1,13 @@ +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details +// +// SPDX-License-Identifier: (BSD-3-Clause) + +int main() +{ + #if defined(FOO_ONLY) && !defined(BAR_ONLY) + return 0; + #else + return 1; + #endif +} diff --git a/tests/internal/src/object_library_test/CMakeLists.txt b/tests/internal/src/object_library_test/CMakeLists.txt index f370b1e22..a8aa578fb 100644 --- a/tests/internal/src/object_library_test/CMakeLists.txt +++ b/tests/internal/src/object_library_test/CMakeLists.txt @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/object_library_test/base_object.cpp b/tests/internal/src/object_library_test/base_object.cpp index 8db69bc10..bce52e83b 100644 --- a/tests/internal/src/object_library_test/base_object.cpp +++ b/tests/internal/src/object_library_test/base_object.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/object_library_test/base_object.hpp b/tests/internal/src/object_library_test/base_object.hpp index 472df43e1..e3d98d60c 100644 --- a/tests/internal/src/object_library_test/base_object.hpp +++ b/tests/internal/src/object_library_test/base_object.hpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/object_library_test/inherited_base/CMakeLists.txt b/tests/internal/src/object_library_test/inherited_base/CMakeLists.txt index c9add8f5b..e3b9aed82 100644 --- a/tests/internal/src/object_library_test/inherited_base/CMakeLists.txt +++ b/tests/internal/src/object_library_test/inherited_base/CMakeLists.txt @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/object_library_test/inherited_base/inherited_base.cpp b/tests/internal/src/object_library_test/inherited_base/inherited_base.cpp index cae6480fb..116c59cd5 100644 --- a/tests/internal/src/object_library_test/inherited_base/inherited_base.cpp +++ b/tests/internal/src/object_library_test/inherited_base/inherited_base.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/object_library_test/inherited_base/inherited_base.hpp b/tests/internal/src/object_library_test/inherited_base/inherited_base.hpp index 36f978ebd..cd0a06c51 100644 --- a/tests/internal/src/object_library_test/inherited_base/inherited_base.hpp +++ b/tests/internal/src/object_library_test/inherited_base/inherited_base.hpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/object_library_test/main.cpp b/tests/internal/src/object_library_test/main.cpp index dc0c31c65..3e27582a2 100644 --- a/tests/internal/src/object_library_test/main.cpp +++ b/tests/internal/src/object_library_test/main.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/object_library_test/object.cpp b/tests/internal/src/object_library_test/object.cpp index 0997719e8..76706da0c 100644 --- a/tests/internal/src/object_library_test/object.cpp +++ b/tests/internal/src/object_library_test/object.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/object_library_test/object.hpp b/tests/internal/src/object_library_test/object.hpp index b8dcaf497..b7aefda2b 100644 --- a/tests/internal/src/object_library_test/object.hpp +++ b/tests/internal/src/object_library_test/object.hpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/static_analysis/CMakeLists.txt b/tests/internal/src/static_analysis/CMakeLists.txt index fc457bb1b..7addf9616 100644 --- a/tests/internal/src/static_analysis/CMakeLists.txt +++ b/tests/internal/src/static_analysis/CMakeLists.txt @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -18,3 +18,9 @@ blt_add_code_checks(PREFIX all blt_add_clang_query_target(NAME filtered CHECKERS "if-stmt" SRC_FILES well_analyzed_source.cpp) +blt_add_executable( NAME subtle_error + SOURCES subtle_error_source.cpp +) +blt_add_clang_tidy_target(NAME check_for_subtle_error + CHECKS "clang-analyzer-*" + SRC_FILES subtle_error_source.cpp) diff --git a/tests/internal/src/static_analysis/subtle_error_source.cpp b/tests/internal/src/static_analysis/subtle_error_source.cpp new file mode 100644 index 000000000..4226cc473 --- /dev/null +++ b/tests/internal/src/static_analysis/subtle_error_source.cpp @@ -0,0 +1,25 @@ +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details +// +// SPDX-License-Identifier: (BSD-3-Clause) + +/** + * This file contains a subtle C++ error that results in a runtime crash. + * + * The "subtle_error" target ("make subtle_error") should behave incorrectly when run. + * + * The "check_for_subtle_error" target ("make check_for_subtle_error") + * will run the clang-tidy static analyzer and report the error via stdout. + * + * See https://clang.llvm.org/extra/clang-tidy/checks/list.html + * for the full list of available checks + */ + +#include + +int main() +{ + int array[1] = {5}; + int first_element = array[1]; + std::cout << first_element << "\n"; +} diff --git a/tests/internal/src/static_analysis/well_analyzed_source.cpp b/tests/internal/src/static_analysis/well_analyzed_source.cpp index ab7f6edd0..298b9c8c3 100644 --- a/tests/internal/src/static_analysis/well_analyzed_source.cpp +++ b/tests/internal/src/static_analysis/well_analyzed_source.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/t_example_compile_definitions.cpp b/tests/internal/src/t_example_compile_definitions.cpp index 3d0b185df..8f0f6fd03 100644 --- a/tests/internal/src/t_example_compile_definitions.cpp +++ b/tests/internal/src/t_example_compile_definitions.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/t_example_smoke.cpp b/tests/internal/src/t_example_smoke.cpp index caa2d17d9..a4c968646 100644 --- a/tests/internal/src/t_example_smoke.cpp +++ b/tests/internal/src/t_example_smoke.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/t_git_macros_smoke.cpp.in b/tests/internal/src/t_git_macros_smoke.cpp.in index 327c8141f..6612c79e5 100644 --- a/tests/internal/src/t_git_macros_smoke.cpp.in +++ b/tests/internal/src/t_git_macros_smoke.cpp.in @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/t_header_only_smoke.cpp b/tests/internal/src/t_header_only_smoke.cpp index 2aef8efc9..53cf39a23 100644 --- a/tests/internal/src/t_header_only_smoke.cpp +++ b/tests/internal/src/t_header_only_smoke.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/test_cmake_format_conformant.cmake b/tests/internal/src/test_cmake_format_conformant.cmake new file mode 100644 index 000000000..64ae0b1a5 --- /dev/null +++ b/tests/internal/src/test_cmake_format_conformant.cmake @@ -0,0 +1,55 @@ +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and other +# BLT Project Developers. See the top-level LICENSE file for details +# +# SPDX-License-Identifier: (BSD-3-Clause) +# ------------------------------------------------------------------------------ +# Example CMake file used to test cmake-format +# ------------------------------------------------------------------------------ +macro(cmake_format_example) + # Test for 80 column wrap + set(greek_letters + alpha + beta + gamme + delta + epsilon + zeta + eta + theta + iota + kappa + lambda + mu + nu + xi + omicron + pi + rho + sigma + tau + upsilon + phi + chi + psi + omega) + + # Test for reflowing multi-line command to single line + set(shopkeeper "the" "frogurt" "is" "also" "cursed") + + # Test that cmake-format doesn't break up a long string argument + set(bird_physics_quote + "A five ounce bird could not carry a one pound coconut.") + + # Indent conditionals + if(first_condition) + if(second_condition) + # Condense blank lines below comment to single line + + # Reflow a long comment into multiple lines because it's extremely long -- + # longer than the line length limit. + set(foo bar baz quux) + + # Reflow a mulitple line short comment to a single line + endif() + endif() +endmacro() diff --git a/tests/internal/src/test_cmake_format_nonconformant.cmake b/tests/internal/src/test_cmake_format_nonconformant.cmake new file mode 100644 index 000000000..29e86859c --- /dev/null +++ b/tests/internal/src/test_cmake_format_nonconformant.cmake @@ -0,0 +1,38 @@ +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and other +# BLT Project Developers. See the top-level LICENSE file for details +# +# SPDX-License-Identifier: (BSD-3-Clause) +# ------------------------------------------------------------------------------ +# Example CMake file used to test cmake-format +# ------------------------------------------------------------------------------ +macro(cmake_format_example) + # Test for 80 column wrap + set(greek_letters alpha beta gamme delta epsilon zeta eta theta iota kappa lambda mu nu xi omicron pi rho sigma tau upsilon phi chi psi omega) + + # Test for reflowing multi-line command to single line + set(shopkeeper + "the" + "frogurt" + "is" + "also" + "cursed") + + # Test that cmake-format doesn't break up a long string argument + set(bird_physics_quote "A five ounce bird could not carry a one pound coconut.") + + # Indent conditionals + if(first_condition) + if(second_condition) + # Condense blank lines below comment to single line + + + + # Reflow a long comment into multiple lines because it's extremely long -- longer than the line length limit. + set(foo bar baz quux) + + # Reflow a mulitple + # line short comment + # to a single line + endif() + endif() +endmacro() diff --git a/tests/internal/src/test_cuda_device_call_from_kernel/CMakeLists.txt b/tests/internal/src/test_cuda_device_call_from_kernel/CMakeLists.txt index 5e242f732..5cd0867e6 100644 --- a/tests/internal/src/test_cuda_device_call_from_kernel/CMakeLists.txt +++ b/tests/internal/src/test_cuda_device_call_from_kernel/CMakeLists.txt @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/test_cuda_device_call_from_kernel/Child.cpp b/tests/internal/src/test_cuda_device_call_from_kernel/Child.cpp index 03009801e..c81443afa 100644 --- a/tests/internal/src/test_cuda_device_call_from_kernel/Child.cpp +++ b/tests/internal/src/test_cuda_device_call_from_kernel/Child.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/test_cuda_device_call_from_kernel/Child.hpp b/tests/internal/src/test_cuda_device_call_from_kernel/Child.hpp index e148050bd..00f66f1c4 100644 --- a/tests/internal/src/test_cuda_device_call_from_kernel/Child.hpp +++ b/tests/internal/src/test_cuda_device_call_from_kernel/Child.hpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/test_cuda_device_call_from_kernel/CudaTests.cpp b/tests/internal/src/test_cuda_device_call_from_kernel/CudaTests.cpp index 2ee6aa53d..7680a2caf 100644 --- a/tests/internal/src/test_cuda_device_call_from_kernel/CudaTests.cpp +++ b/tests/internal/src/test_cuda_device_call_from_kernel/CudaTests.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/test_cuda_device_call_from_kernel/Parent.cpp b/tests/internal/src/test_cuda_device_call_from_kernel/Parent.cpp index 0ca76ce8a..a58532e12 100644 --- a/tests/internal/src/test_cuda_device_call_from_kernel/Parent.cpp +++ b/tests/internal/src/test_cuda_device_call_from_kernel/Parent.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/test_cuda_device_call_from_kernel/Parent.hpp b/tests/internal/src/test_cuda_device_call_from_kernel/Parent.hpp index eb10ee708..64ffe23f0 100644 --- a/tests/internal/src/test_cuda_device_call_from_kernel/Parent.hpp +++ b/tests/internal/src/test_cuda_device_call_from_kernel/Parent.hpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/test_cuda_mpi.cpp b/tests/internal/src/test_cuda_mpi.cpp index 975cc3439..8e288afe8 100644 --- a/tests/internal/src/test_cuda_mpi.cpp +++ b/tests/internal/src/test_cuda_mpi.cpp @@ -1,6 +1,6 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/internal/src/test_yapf_conformant.py b/tests/internal/src/test_yapf_conformant.py new file mode 100644 index 000000000..c90908f57 --- /dev/null +++ b/tests/internal/src/test_yapf_conformant.py @@ -0,0 +1,18 @@ +# Example from google/yapf repo +x = {'a': 37, 'b': 42, 'c': 927} + +y = 'hello ' 'world' +z = 'hello ' + 'world' +a = 'hello {}'.format('world') + + +class foo(object): + def f(self): + return 37 * -+2 + + def g(self, x, y=42): + return y + + +def f(a): + return 37 + -+a[42 - x:y**3] diff --git a/tests/internal/src/test_yapf_nonconformant.py b/tests/internal/src/test_yapf_nonconformant.py new file mode 100644 index 000000000..58a75e381 --- /dev/null +++ b/tests/internal/src/test_yapf_nonconformant.py @@ -0,0 +1,15 @@ +# Example from google/yapf repo +x = { 'a':37,'b':42, + +'c':927} + +y = 'hello ''world' +z = 'hello '+'world' +a = 'hello {}'.format('world') +class foo ( object ): + def f (self ): + return 37*-+2 + def g(self, x,y=42): + return y +def f ( a ) : + return 37+-+a[42-x : y**3] diff --git a/tests/internal/yapf.cfg b/tests/internal/yapf.cfg new file mode 100644 index 000000000..2631b0990 --- /dev/null +++ b/tests/internal/yapf.cfg @@ -0,0 +1,6 @@ +# Style settings example shown in +# https://github.com/google/yapf/blob/master/README.rst +[style] +based_on_style = pep8 +spaces_before_comment = 4 +split_before_logical_operator = true diff --git a/tests/smoke/CMakeLists.txt b/tests/smoke/CMakeLists.txt index 88449a1fa..8d3ef0d33 100644 --- a/tests/smoke/CMakeLists.txt +++ b/tests/smoke/CMakeLists.txt @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -21,6 +21,7 @@ if(ENABLE_GTEST) COMMAND blt_gtest_smoke) endif() + ################ # gmock test ################ @@ -65,6 +66,19 @@ if (ENABLE_FORTRAN AND ENABLE_FRUIT) COMMAND blt_fruit_smoke) endif() +############### +# fruit mpi test +############### +if (ENABLE_FORTRAN AND ENABLE_FRUIT AND ENABLE_MPI AND ENABLE_FRUIT_MPI) + blt_add_executable(NAME blt_fruit_mpi_smoke + SOURCES blt_fruit_mpi_smoke.f90 + OUTPUT_DIR ${TEST_OUTPUT_DIRECTORY} + DEPENDS_ON fruit_mpi + FOLDER blt/tests ) + + blt_add_test(NAME blt_fruit_mpi_smoke + COMMAND blt_fruit_mpi_smoke) +endif() ################ # OpenMP test @@ -123,6 +137,14 @@ if (ENABLE_CUDA) blt_add_test(NAME blt_cuda_runtime_smoke COMMAND blt_cuda_runtime_smoke) + blt_add_executable(NAME blt_cuda_version_smoke + SOURCES blt_cuda_version_smoke.cpp + OUTPUT_DIR ${TEST_OUTPUT_DIRECTORY} + DEPENDS_ON cuda_runtime + FOLDER blt/tests ) + + blt_add_test(NAME blt_cuda_version_smoke + COMMAND blt_cuda_version_smoke) if (ENABLE_OPENMP) blt_add_executable(NAME blt_cuda_openmp_smoke SOURCES blt_cuda_openmp_smoke.cpp @@ -144,6 +166,17 @@ if (ENABLE_CUDA) COMMAND blt_cuda_mpi_smoke NUM_MPI_TASKS 4) endif() + + if(ENABLE_GTEST) + blt_add_executable(NAME blt_cuda_gtest_smoke + SOURCES blt_cuda_gtest_smoke.cpp + OUTPUT_DIR ${TEST_OUTPUT_DIRECTORY} + DEPENDS_ON cuda gtest + FOLDER blt/tests ) + + blt_add_test(NAME blt_cuda_gtest_smoke + COMMAND blt_cuda_gtest_smoke) + endif() endif() ################ @@ -193,4 +226,15 @@ if (ENABLE_HIP) blt_add_test(NAME blt_hip_runtime_smoke COMMAND blt_hip_runtime_smoke) + if(ENABLE_GTEST) + blt_add_executable(NAME blt_hip_gtest_smoke + SOURCES blt_hip_gtest_smoke.cpp + OUTPUT_DIR ${TEST_OUTPUT_DIRECTORY} + DEPENDS_ON gtest hip + FOLDER blt/tests ) + + blt_add_test(NAME blt_hip_gtest_smoke + COMMAND blt_hip_gtest_smoke) + endif() + endif() diff --git a/tests/smoke/blt_cuda_gtest_smoke.cpp b/tests/smoke/blt_cuda_gtest_smoke.cpp new file mode 100644 index 000000000..098108e5e --- /dev/null +++ b/tests/smoke/blt_cuda_gtest_smoke.cpp @@ -0,0 +1,40 @@ +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details +// +// SPDX-License-Identifier: (BSD-3-Clause) + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Note: This is a CUDA Hello world example from NVIDIA: +// Obtained from here: https://developer.nvidia.com/cuda-education +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +//----------------------------------------------------------------------------- +// +// file: blt_cuda_smoke.cpp +// +//----------------------------------------------------------------------------- + +#include +#include + +#include "gtest/gtest.h" + +__device__ const char *STR = "HELLO WORLD!"; +const char STR_LENGTH = 12; + +__global__ void hello() +{ + printf("%c\n", STR[threadIdx.x % STR_LENGTH]); +} + +//------------------------------------------------------------------------------ +// Simple smoke test for gtest+CUDA +//------------------------------------------------------------------------------ +TEST(blt_cuda_gtest_smoke,basic_assert_example) +{ + int num_threads = STR_LENGTH; + int num_blocks = 1; + hello<<>>(); + cudaDeviceSynchronize(); + EXPECT_TRUE( true ); +} diff --git a/tests/smoke/blt_cuda_mpi_smoke.cpp b/tests/smoke/blt_cuda_mpi_smoke.cpp index d1f0ed0e4..ccccb562e 100644 --- a/tests/smoke/blt_cuda_mpi_smoke.cpp +++ b/tests/smoke/blt_cuda_mpi_smoke.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/smoke/blt_cuda_openmp_smoke.cpp b/tests/smoke/blt_cuda_openmp_smoke.cpp index d1532cb5e..2bfd5c2d5 100644 --- a/tests/smoke/blt_cuda_openmp_smoke.cpp +++ b/tests/smoke/blt_cuda_openmp_smoke.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/smoke/blt_cuda_runtime_smoke.cpp b/tests/smoke/blt_cuda_runtime_smoke.cpp index ccff05c56..9348594f4 100644 --- a/tests/smoke/blt_cuda_runtime_smoke.cpp +++ b/tests/smoke/blt_cuda_runtime_smoke.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/smoke/blt_cuda_smoke.cpp b/tests/smoke/blt_cuda_smoke.cpp index a2c3d4e75..a3f21c88e 100644 --- a/tests/smoke/blt_cuda_smoke.cpp +++ b/tests/smoke/blt_cuda_smoke.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/smoke/blt_cuda_version_smoke.cpp b/tests/smoke/blt_cuda_version_smoke.cpp new file mode 100644 index 000000000..97c43fa93 --- /dev/null +++ b/tests/smoke/blt_cuda_version_smoke.cpp @@ -0,0 +1,42 @@ +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details +// +// SPDX-License-Identifier: (BSD-3-Clause) + +//----------------------------------------------------------------------------- +// +// file: blt_cuda_version_smoke.cpp +// +//----------------------------------------------------------------------------- + +#include +#include "cuda_runtime_api.h" + + +int main() +{ + int driverVersion = 0; + int runtimeVersion = 0; + cudaError_t error_id; + + error_id = cudaDriverGetVersion(&driverVersion); + if (error_id != cudaSuccess) { + std::string msg = "cudaDriverGetVersion returned CUDA Error (" + std::to_string(error_id) + + "): " + cudaGetErrorString(error_id) + "\n"; + std::cerr << msg; + return 1; + } + std::cout << "CUDA driver version: " << driverVersion << std::endl; + + error_id = cudaRuntimeGetVersion(&runtimeVersion); + if (error_id != cudaSuccess) { + std::string msg = "cudaDriverGetVersion returned CUDA Error (" + std::to_string(error_id) + + "): " + cudaGetErrorString(error_id) + "\n"; + std::cerr << msg; + return 2; + } + std::cout << "CUDA runtime version: " << runtimeVersion << std::endl; + + return 0; +} + diff --git a/tests/smoke/blt_fruit_mpi_smoke.f90 b/tests/smoke/blt_fruit_mpi_smoke.f90 new file mode 100644 index 000000000..160596205 --- /dev/null +++ b/tests/smoke/blt_fruit_mpi_smoke.f90 @@ -0,0 +1,73 @@ +! Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +! other BLT Project Developers. See the top-level LICENSE file for details +! +! SPDX-License-Identifier: (BSD-3-Clause) + +!------------------------------------------------------------------------------ +! +! blt_fruit_smoke.f90 +! +!------------------------------------------------------------------------------ +module fruit_mpi_smoke + use iso_c_binding + use fruit + use mpi + use fruit_mpi + implicit none + +contains +!------------------------------------------------------------------------------ + + subroutine simple_mpi_test(comm) + integer, intent(in) :: comm + integer :: comm_size, comm_rank + integer :: mpi_err_stat + integer, parameter :: first_rank = 0 + + call mpi_comm_size(comm, comm_size, mpi_err_stat) + call mpi_comm_rank(comm, comm_rank, mpi_err_stat) + + call assert_true(comm_rank .ge. first_rank, & + "MPI comm rank is negative; something strange is happening") + call assert_true(comm_rank .lt. comm_size, & + "MPI comm rank is greater than or equal to comm size") + end subroutine simple_mpi_test + + +!---------------------------------------------------------------------- +end module fruit_mpi_smoke +!---------------------------------------------------------------------- + +program fortran_mpi_test + use fruit + use mpi + use fruit_mpi + use fruit_mpi_smoke + implicit none + logical :: ok_on_rank, ok_on_comm + + integer :: mpi_err_stat + integer :: comm_size, comm_rank + integer, parameter :: comm = MPI_COMM_WORLD + + call mpi_init(mpi_err_stat) + call mpi_comm_size(comm, comm_size, mpi_err_stat) + call mpi_comm_rank(comm, comm_rank, mpi_err_stat) + + call init_fruit +!---------- +! Our tests + call simple_mpi_test(comm) +!---------- + + call fruit_summary_mpi(comm_size, comm_rank) + call is_all_successful(ok_on_rank) + call mpi_allreduce(ok_on_rank, ok_on_comm, 1, MPI_LOGICAL, MPI_LAND, comm, mpi_err_stat) + + call fruit_finalize_mpi(comm_size, comm_rank) + call mpi_finalize(mpi_err_stat) + + if (.not. ok_on_comm) then + call exit(1) + endif +end program fortran_mpi_test diff --git a/tests/smoke/blt_fruit_smoke.f90 b/tests/smoke/blt_fruit_smoke.f90 index ad3b25c69..88dad321d 100644 --- a/tests/smoke/blt_fruit_smoke.f90 +++ b/tests/smoke/blt_fruit_smoke.f90 @@ -1,5 +1,5 @@ -! Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -! other BLT Project Developers. See the top-level COPYRIGHT file for details +! Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +! other BLT Project Developers. See the top-level LICENSE file for details ! ! SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/smoke/blt_gbenchmark_smoke.cpp b/tests/smoke/blt_gbenchmark_smoke.cpp index 357d99654..bbc0176a9 100644 --- a/tests/smoke/blt_gbenchmark_smoke.cpp +++ b/tests/smoke/blt_gbenchmark_smoke.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/smoke/blt_gmock_smoke.cpp b/tests/smoke/blt_gmock_smoke.cpp index c7fbc1320..d565a1949 100644 --- a/tests/smoke/blt_gmock_smoke.cpp +++ b/tests/smoke/blt_gmock_smoke.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/smoke/blt_gtest_smoke.cpp b/tests/smoke/blt_gtest_smoke.cpp index 6047be56b..4511d059a 100644 --- a/tests/smoke/blt_gtest_smoke.cpp +++ b/tests/smoke/blt_gtest_smoke.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/smoke/blt_hcc_runtime_smoke.cpp b/tests/smoke/blt_hcc_runtime_smoke.cpp index b45a08f34..b152acea8 100644 --- a/tests/smoke/blt_hcc_runtime_smoke.cpp +++ b/tests/smoke/blt_hcc_runtime_smoke.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/smoke/blt_hcc_smoke.cpp b/tests/smoke/blt_hcc_smoke.cpp index 48c2ceb08..55bd6abd9 100644 --- a/tests/smoke/blt_hcc_smoke.cpp +++ b/tests/smoke/blt_hcc_smoke.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/smoke/blt_hip_gtest_smoke.cpp b/tests/smoke/blt_hip_gtest_smoke.cpp new file mode 100644 index 000000000..018935643 --- /dev/null +++ b/tests/smoke/blt_hip_gtest_smoke.cpp @@ -0,0 +1,35 @@ +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details +// +// SPDX-License-Identifier: (BSD-3-Clause) + +//----------------------------------------------------------------------------- +// +// file: blt_hip_smoke.cpp +// +//----------------------------------------------------------------------------- + +#include +#include +#include "gtest/gtest.h" +#include "hip/hip_runtime.h" + +__device__ const char STR[] = "HELLO WORLD!"; +const char STR_LENGTH = 12; + +__global__ void hello() +{ + printf("%c\n", STR[threadIdx.x % STR_LENGTH]); +} + +//------------------------------------------------------------------------------ +// Simple smoke test for gtest+HIP +//------------------------------------------------------------------------------ +TEST(blt_hip_gtest_smoke,basic_assert_example) +{ + int num_threads = STR_LENGTH; + int num_blocks = 1; + hipLaunchKernelGGL((hello), dim3(num_blocks), dim3(num_threads),0,0); + hipDeviceSynchronize(); + EXPECT_TRUE( true ); +} diff --git a/tests/smoke/blt_hip_runtime_smoke.cpp b/tests/smoke/blt_hip_runtime_smoke.cpp index e908f1f0b..09af2915f 100644 --- a/tests/smoke/blt_hip_runtime_smoke.cpp +++ b/tests/smoke/blt_hip_runtime_smoke.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/smoke/blt_hip_smoke.cpp b/tests/smoke/blt_hip_smoke.cpp index 702ff2b2d..7138476ed 100644 --- a/tests/smoke/blt_hip_smoke.cpp +++ b/tests/smoke/blt_hip_smoke.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/smoke/blt_mpi_smoke.cpp b/tests/smoke/blt_mpi_smoke.cpp index 967ed1f88..79fa2389c 100644 --- a/tests/smoke/blt_mpi_smoke.cpp +++ b/tests/smoke/blt_mpi_smoke.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/smoke/blt_openmp_smoke.cpp b/tests/smoke/blt_openmp_smoke.cpp index 74a5f0d68..cd3743853 100644 --- a/tests/smoke/blt_openmp_smoke.cpp +++ b/tests/smoke/blt_openmp_smoke.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/smoke/fortran_driver.cpp b/tests/smoke/fortran_driver.cpp index 489009785..c2c015738 100644 --- a/tests/smoke/fortran_driver.cpp +++ b/tests/smoke/fortran_driver.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -// other BLT Project Developers. See the top-level COPYRIGHT file for details +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details // // SPDX-License-Identifier: (BSD-3-Clause) diff --git a/tests/smoke/fortran_mpi_driver.cpp b/tests/smoke/fortran_mpi_driver.cpp new file mode 100644 index 000000000..d327d072e --- /dev/null +++ b/tests/smoke/fortran_mpi_driver.cpp @@ -0,0 +1,23 @@ +// Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +// other BLT Project Developers. See the top-level LICENSE file for details +// +// SPDX-License-Identifier: (BSD-3-Clause) + +//---------------------------------------------------------------------- + +/* + fortran_mpi_test manages MPI_Init & MPI_Finalize. Do not put MPI + calls in this driver file -- put these calls in fortran_mpi_test, + which should be defined in blt_fruit_mpi_test.f90. + */ +extern "C" int fortran_mpi_test(); + +int main() +{ + int result = 0; + + // finalized when exiting main scope + result = fortran_mpi_test(); + + return result; +} diff --git a/thirdparty_builtin/CMakeLists.txt b/thirdparty_builtin/CMakeLists.txt index 125874287..a222f8d91 100644 --- a/thirdparty_builtin/CMakeLists.txt +++ b/thirdparty_builtin/CMakeLists.txt @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and -# other BLT Project Developers. See the top-level COPYRIGHT file for details +# Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details # # SPDX-License-Identifier: (BSD-3-Clause) @@ -82,7 +82,7 @@ if(ENABLE_TESTS) set (INSTALL_GMOCK OFF CACHE BOOL "") set (INSTALL_GTEST OFF CACHE BOOL "") - + # Enable builtin google test add_subdirectory(googletest-master-2020-01-07 ${BLT_BUILD_DIR}/thirdparty_builtin/googletest-master-2020-01-07) @@ -99,7 +99,7 @@ if(ENABLE_TESTS) DEFINES ${gtest_defines} ${gtest_export_defines} TREAT_INCLUDES_AS_SYSTEM ON ) - + blt_add_target_definitions(TO gtest TARGET_DEFINITIONS ${gtest_defines}) list(APPEND _blt_tpl_targets gtest gtest_main) @@ -119,10 +119,14 @@ if(ENABLE_TESTS) # Enable Fruit (FortRan UnIT testing) support if (ENABLE_FORTRAN) message(STATUS "Fruit Support is ${ENABLE_FRUIT}") + message(STATUS "Fruit MPI Support is ${ENABLE_FRUIT_MPI}") if(ENABLE_FRUIT) add_subdirectory(fruit-3.4.1 ${BLT_BUILD_DIR}/thirdparty_builtin/fruit-3.4.1) - list(APPEND _blt_tpl_targets fruit) + list(APPEND _blt_tpl_targets fruit) + if(ENABLE_MPI AND ENABLE_FRUIT_MPI) + list(APPEND _blt_tpl_targets fruit_mpi) + endif() endif() endif() @@ -168,5 +172,3 @@ if(ENABLE_FOLDERS) blt_set_target_folder(TARGET ${tpl} FOLDER blt/thirdparty) endforeach() endif() - - diff --git a/thirdparty_builtin/fruit-3.4.1/CMakeLists.txt b/thirdparty_builtin/fruit-3.4.1/CMakeLists.txt index 6d06a9f99..88dd9b67a 100644 --- a/thirdparty_builtin/fruit-3.4.1/CMakeLists.txt +++ b/thirdparty_builtin/fruit-3.4.1/CMakeLists.txt @@ -15,3 +15,17 @@ blt_register_library( NAME fruit INCLUDES ${CMAKE_Fortran_MODULE_DIRECTORY} LIBRARIES fruit ) + +if(ENABLE_FRUIT_MPI) + blt_add_library( + NAME fruit_mpi + SOURCES fruit_mpi.f90 + DEPENDS_ON fruit MPI::MPI_Fortran + ) + blt_register_library( NAME fruit_mpi + DEPENDS_ON fruit MPI::MPI_Fortran + FORTRAN_MODULES ${CMAKE_Fortran_MODULE_DIRECTORY} + INCLUDES ${CMAKE_Fortran_MODULE_DIRECTORY} + LIBRARIES fruit_mpi + ) +endif() diff --git a/thirdparty_builtin/fruit-3.4.1/fruit_mpi.f90 b/thirdparty_builtin/fruit-3.4.1/fruit_mpi.f90 new file mode 100644 index 000000000..9cd297a3e --- /dev/null +++ b/thirdparty_builtin/fruit-3.4.1/fruit_mpi.f90 @@ -0,0 +1,261 @@ +module fruit_mpi + use fruit + use mpi + implicit none + private + + integer, parameter :: XML_OPEN = 20 + integer, parameter :: XML_WORK = 21 + character(len = *), parameter :: xml_filename = "result.xml" + integer, parameter :: NUMBER_LENGTH = 10 + integer, parameter :: FN_LENGTH = 50 + + public :: fruit_init_mpi_xml + interface fruit_init_mpi_xml + module procedure fruit_init_mpi_xml_ + end interface + + public :: fruit_finalize_mpi + interface fruit_finalize_mpi + module procedure fruit_finalize_mpi_ + end interface + + public :: fruit_summary_mpi + interface fruit_summary_mpi + module procedure fruit_summary_mpi_ + end interface + + public :: fruit_summary_mpi_xml + interface fruit_summary_mpi_xml + module procedure fruit_summary_mpi_xml_ + end interface +contains + subroutine fruit_init_mpi_xml_(rank) + integer, intent(in) :: rank + character(len = FN_LENGTH) :: xml_filename_work + + write(xml_filename_work, '("result_tmp_", i5.5, ".xml")') rank + call set_xml_filename_work(xml_filename_work) + + call init_fruit_xml(rank) + end subroutine fruit_init_mpi_xml_ + + subroutine fruit_finalize_mpi_(size, rank) + integer, intent(in) :: size, rank + if (size < 0) print *, "size negative" + if (rank < 0) print *, "rank negative" + call fruit_finalize + end subroutine fruit_finalize_mpi_ + + subroutine fruit_summary_mpi_(size, rank) + integer, intent(in) :: size, rank + integer :: fail_assert_sum + integer :: succ_assert_sum + integer :: fail_case_sum + integer :: succ_case_sum + + integer :: fail_assert + integer :: succ_assert + integer :: fail_case + integer :: succ_case + + integer :: message_index + integer :: num_msgs + integer :: num_msgs_sum + integer, allocatable :: num_msgs_rank(:) + + integer :: ierr + integer :: i + integer :: imsg + integer :: status(MPI_STATUS_SIZE) + + integer, parameter :: MSG_LENGTH_HERE = 256 + character(len = MSG_LENGTH_HERE), allocatable :: msgs(:) + character(len = MSG_LENGTH_HERE), allocatable :: msgs_all(:) + + call get_assert_and_case_count(& + & fail_assert, succ_assert, & + & fail_case, succ_case) + + call get_message_index(message_index) + num_msgs = message_index - 1 + allocate(msgs(num_msgs)) + call get_message_array(msgs) + + allocate(num_msgs_rank(size)) + call MPI_Allgather(& + & num_msgs, 1, MPI_INTEGER, & + & num_msgs_rank, 1, MPI_INTEGER, MPI_COMM_WORLD, ierr) + + num_msgs_sum = sum(num_msgs_rank(:)) + allocate(msgs_all(num_msgs_sum)) + + ! array msgs_all: + ! + ! | msgs(:) of rank 0 | msgs(:) of rank 1 | msgs(:) of rank 2 | + ! | | | | + ! | num_msgs_rank(1) | num_msgs_rank(2) | num_msgs_rank(3) | + ! | | | | + ! | | | | + ! A A A + ! | | | + ! sum(num_msgs_rank(1:1))+1 | num_msgs_sum + ! sum(num_msgs_rank(1:2))+1 + + if (rank == 0) then + msgs_all(1:num_msgs) = msgs(1:num_msgs) + do i = 1, size - 1 + imsg = sum(num_msgs_rank(1:i)) + 1 + call MPI_RECV(& + & msgs_all(imsg), & + & num_msgs_rank(i + 1) * MSG_LENGTH_HERE, MPI_CHARACTER, & + & i, 7, MPI_COMM_WORLD, status, ierr) + enddo + else + call MPI_Send(& + & msgs, & + & num_msgs * MSG_LENGTH_HERE , MPI_CHARACTER, & + & 0, 7, MPI_COMM_WORLD, ierr) + endif + + call MPI_REDUCE(& + & fail_assert , & + & fail_assert_sum, 1, MPI_INTEGER, MPI_SUM, 0, MPI_COMM_WORLD, ierr) + + call MPI_REDUCE(& + & succ_assert , & + & succ_assert_sum, 1, MPI_INTEGER, MPI_SUM, 0, MPI_COMM_WORLD, ierr) + + call MPI_REDUCE(& + & fail_case , & + & fail_case_sum, 1, MPI_INTEGER, MPI_SUM, 0, MPI_COMM_WORLD, ierr) + + call MPI_REDUCE(& + & succ_case , & + & succ_case_sum, 1, MPI_INTEGER, MPI_SUM, 0, MPI_COMM_WORLD, ierr) + + if (rank == 0) then + write (*,*) + write (*,*) + write (*,*) ' Start of FRUIT summary: ' + write (*,*) + + if (fail_assert_sum > 0) then + write (*,*) 'Some tests failed!' + else + write (*,*) 'SUCCESSFUL!' + end if + + write (*,*) + write (*,*) ' -- Failed assertion messages:' + + do i = 1, num_msgs_sum + write (*, "(A)") ' '//trim(msgs_all(i)) + end do + + write (*, *) ' -- end of failed assertion messages.' + write (*, *) + + if (succ_assert_sum + fail_assert_sum /= 0) then + call fruit_summary_table(& + & succ_assert_sum, fail_assert_sum, & + & succ_case_sum , fail_case_sum & + &) + endif + write(*, *) ' -- end of FRUIT summary' + endif + end subroutine fruit_summary_mpi_ + + subroutine fruit_summary_mpi_xml_(size, rank) + integer, intent(in) :: size, rank + + character(len = 1000) :: whole_line + character(len = 100) :: full_count + character(len = 100) :: fail_count + character(len = FN_LENGTH) :: xml_filename_work + character(len = FN_LENGTH), allocatable :: xml_filename_work_all(:) + + integer :: fail_assert , succ_assert , fail_case , succ_case + integer :: fail_assert_sum, succ_assert_sum, fail_case_sum , succ_case_sum + integer :: i + integer :: status(MPI_STATUS_SIZE) + integer :: ierr + + call get_xml_filename_work(xml_filename_work) + + allocate(xml_filename_work_all(size)) + + if (rank /= 0) then + call MPI_Send( xml_filename_work, & + & FN_LENGTH, MPI_CHARACTER, 0, 8, MPI_COMM_WORLD, ierr) + endif + if (rank == 0) then + xml_filename_work_all(1) = xml_filename_work + + do i = 1+1, size + call MPI_RECV(xml_filename_work_all(i), & + & FN_LENGTH, MPI_CHARACTER, i - 1, 8, MPI_COMM_WORLD, status, ierr) + enddo + endif + + call get_assert_and_case_count(& + & fail_assert, succ_assert, & + & fail_case, succ_case) + + call MPI_REDUCE(& + & fail_assert , & + & fail_assert_sum, 1, MPI_INTEGER, MPI_SUM, 0, MPI_COMM_WORLD, ierr) + + call MPI_REDUCE(& + & succ_assert , & + & succ_assert_sum, 1, MPI_INTEGER, MPI_SUM, 0, MPI_COMM_WORLD, ierr) + + call MPI_REDUCE(& + & fail_case , & + & fail_case_sum, 1, MPI_INTEGER, MPI_SUM, 0, MPI_COMM_WORLD, ierr) + + call MPI_REDUCE(& + & succ_case , & + & succ_case_sum, 1, MPI_INTEGER, MPI_SUM, 0, MPI_COMM_WORLD, ierr) + + full_count = int_to_str(succ_case_sum + fail_case_sum) + fail_count = int_to_str( fail_case_sum) + + if (rank == 0) then + open (XML_OPEN, file = xml_filename, action ="write", status = "replace") + write(XML_OPEN, '("")') + write(XML_OPEN, '("")') + write(XML_OPEN, '(" ")') + + do i = 1, size + open (XML_WORK, FILE = xml_filename_work_all(i)) + do + read(XML_WORK, '(a)', end = 999) whole_line + write(XML_OPEN, '(a)') trim(whole_line) + enddo + 999 continue + close(XML_WORK) + enddo + + write(XML_OPEN, '(" ")') + write(XML_OPEN, '("")') + close(XML_OPEN) + endif + if (size < 0) print *, "size < 0" + end subroutine fruit_summary_mpi_xml_ + + function int_to_str(i) + integer, intent(in) :: i + character(LEN = NUMBER_LENGTH) :: int_to_str + + write(int_to_str, '(i10)') i + int_to_str = adjustl(int_to_str) + end function int_to_str +end module fruit_mpi diff --git a/thirdparty_builtin/googletest-master-2020-01-07/googlemock/CMakeLists.txt b/thirdparty_builtin/googletest-master-2020-01-07/googlemock/CMakeLists.txt index d32b70b5b..17ca62f5a 100644 --- a/thirdparty_builtin/googletest-master-2020-01-07/googlemock/CMakeLists.txt +++ b/thirdparty_builtin/googletest-master-2020-01-07/googlemock/CMakeLists.txt @@ -107,10 +107,10 @@ endif() # to the targets for when we are part of a parent build (ie being pulled # in via add_subdirectory() rather than being a standalone build). if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") - target_include_directories(gmock SYSTEM INTERFACE + target_include_directories(gmock INTERFACE "$" "$/${CMAKE_INSTALL_INCLUDEDIR}>") - target_include_directories(gmock_main SYSTEM INTERFACE + target_include_directories(gmock_main INTERFACE "$" "$/${CMAKE_INSTALL_INCLUDEDIR}>") endif() diff --git a/thirdparty_builtin/googletest-master-2020-01-07/googletest/CMakeLists.txt b/thirdparty_builtin/googletest-master-2020-01-07/googletest/CMakeLists.txt index 4fd7b5262..ae080855c 100644 --- a/thirdparty_builtin/googletest-master-2020-01-07/googletest/CMakeLists.txt +++ b/thirdparty_builtin/googletest-master-2020-01-07/googletest/CMakeLists.txt @@ -131,10 +131,10 @@ cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc) # to the targets for when we are part of a parent build (ie being pulled # in via add_subdirectory() rather than being a standalone build). if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") - target_include_directories(gtest SYSTEM INTERFACE + target_include_directories(gtest INTERFACE "$" "$/${CMAKE_INSTALL_INCLUDEDIR}>") - target_include_directories(gtest_main SYSTEM INTERFACE + target_include_directories(gtest_main INTERFACE "$" "$/${CMAKE_INSTALL_INCLUDEDIR}>") endif() diff --git a/thirdparty_builtin/patches/gtest-2020-08-25-turn-off-exported-includes.patch b/thirdparty_builtin/patches/gtest-2020-08-25-turn-off-exported-includes.patch new file mode 100644 index 000000000..476161011 --- /dev/null +++ b/thirdparty_builtin/patches/gtest-2020-08-25-turn-off-exported-includes.patch @@ -0,0 +1,54 @@ +diff --git a/thirdparty_builtin/googletest-master-2020-01-07/googlemock/CMakeLists.txt b/thirdparty_builtin/googletest-master-2020-01-07/googlemock/CMakeLists.txt +index d32b70b..3409d30 100644 +--- a/thirdparty_builtin/googletest-master-2020-01-07/googlemock/CMakeLists.txt ++++ b/thirdparty_builtin/googletest-master-2020-01-07/googlemock/CMakeLists.txt +@@ -106,14 +106,14 @@ endif() + # If the CMake version supports it, attach header directory information + # to the targets for when we are part of a parent build (ie being pulled + # in via add_subdirectory() rather than being a standalone build). +-if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") +- target_include_directories(gmock SYSTEM INTERFACE +- "$" +- "$/${CMAKE_INSTALL_INCLUDEDIR}>") +- target_include_directories(gmock_main SYSTEM INTERFACE +- "$" +- "$/${CMAKE_INSTALL_INCLUDEDIR}>") +-endif() ++#if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") ++# target_include_directories(gmock SYSTEM INTERFACE ++# "$" ++# "$/${CMAKE_INSTALL_INCLUDEDIR}>") ++# target_include_directories(gmock_main SYSTEM INTERFACE ++# "$" ++# "$/${CMAKE_INSTALL_INCLUDEDIR}>") ++#endif() + + ######################################################################## + # +diff --git a/thirdparty_builtin/googletest-master-2020-01-07/googletest/CMakeLists.txt b/thirdparty_builtin/googletest-master-2020-01-07/googletest/CMakeLists.txt +index 4fd7b52..b67c13a 100644 +--- a/thirdparty_builtin/googletest-master-2020-01-07/googletest/CMakeLists.txt ++++ b/thirdparty_builtin/googletest-master-2020-01-07/googletest/CMakeLists.txt +@@ -130,14 +130,14 @@ cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc) + # If the CMake version supports it, attach header directory information + # to the targets for when we are part of a parent build (ie being pulled + # in via add_subdirectory() rather than being a standalone build). +-if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") +- target_include_directories(gtest SYSTEM INTERFACE +- "$" +- "$/${CMAKE_INSTALL_INCLUDEDIR}>") +- target_include_directories(gtest_main SYSTEM INTERFACE +- "$" +- "$/${CMAKE_INSTALL_INCLUDEDIR}>") +-endif() ++#if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") ++# target_include_directories(gtest SYSTEM INTERFACE ++# "$" ++# "$/${CMAKE_INSTALL_INCLUDEDIR}>") ++# target_include_directories(gtest_main SYSTEM INTERFACE ++# "$" ++# "$/${CMAKE_INSTALL_INCLUDEDIR}>") ++#endif() + target_link_libraries(gtest_main PUBLIC gtest) + + ######################################################################## diff --git a/thirdparty_builtin/patches/gtest-2020-10-07-interface-includes.patch b/thirdparty_builtin/patches/gtest-2020-10-07-interface-includes.patch new file mode 100644 index 000000000..1c8cd2918 --- /dev/null +++ b/thirdparty_builtin/patches/gtest-2020-10-07-interface-includes.patch @@ -0,0 +1,34 @@ +diff --git a/thirdparty_builtin/googletest-master-2020-01-07/googlemock/CMakeLists.txt b/thirdparty_builtin/googletest-master-2020-01-07/googlemock/CMakeLists.txt +index 17ca62f..d32b70b 100644 +--- a/thirdparty_builtin/googletest-master-2020-01-07/googlemock/CMakeLists.txt ++++ b/thirdparty_builtin/googletest-master-2020-01-07/googlemock/CMakeLists.txt +@@ -107,10 +107,10 @@ endif() + # to the targets for when we are part of a parent build (ie being pulled + # in via add_subdirectory() rather than being a standalone build). + if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") +- target_include_directories(gmock INTERFACE ++ target_include_directories(gmock SYSTEM INTERFACE + "$" + "$/${CMAKE_INSTALL_INCLUDEDIR}>") +- target_include_directories(gmock_main INTERFACE ++ target_include_directories(gmock_main SYSTEM INTERFACE + "$" + "$/${CMAKE_INSTALL_INCLUDEDIR}>") + endif() +diff --git a/thirdparty_builtin/googletest-master-2020-01-07/googletest/CMakeLists.txt b/thirdparty_builtin/googletest-master-2020-01-07/googletest/CMakeLists.txt +index ae08085..4fd7b52 100644 +--- a/thirdparty_builtin/googletest-master-2020-01-07/googletest/CMakeLists.txt ++++ b/thirdparty_builtin/googletest-master-2020-01-07/googletest/CMakeLists.txt +@@ -131,10 +131,10 @@ cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc) + # to the targets for when we are part of a parent build (ie being pulled + # in via add_subdirectory() rather than being a standalone build). + if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") +- target_include_directories(gtest INTERFACE ++ target_include_directories(gtest SYSTEM INTERFACE + "$" + "$/${CMAKE_INSTALL_INCLUDEDIR}>") +- target_include_directories(gtest_main INTERFACE ++ target_include_directories(gtest_main SYSTEM INTERFACE + "$" + "$/${CMAKE_INSTALL_INCLUDEDIR}>") + endif()