From 26dcb621d7622fffff1f53d29d74fc184128ed95 Mon Sep 17 00:00:00 2001 From: Chris White Date: Thu, 16 Jan 2020 10:25:42 -0800 Subject: [PATCH 01/40] Fix tests defaulting to c++11, Fix warning that would have never triggered --- docs/tutorial/blank_project/CMakeLists.txt | 10 ++++++++++ docs/tutorial/calc_pi/CMakeLists.txt | 7 ++++++- tests/internal/CMakeLists.txt | 4 ++++ thirdparty_builtin/CMakeLists.txt | 16 ++++++++-------- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/docs/tutorial/blank_project/CMakeLists.txt b/docs/tutorial/blank_project/CMakeLists.txt index 5cb199f71..9631f6808 100644 --- a/docs/tutorial/blank_project/CMakeLists.txt +++ b/docs/tutorial/blank_project/CMakeLists.txt @@ -5,6 +5,11 @@ cmake_minimum_required(VERSION 3.8) project( blank ) +# Note: This is specific to running our tests and shouldn't be exported to documentation +if(NOT BLT_SOURCE_DIR) + set(BLT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../..") +endif() + #------------------------------------------------------------------------------ # Setup BLT #------------------------------------------------------------------------------ @@ -28,5 +33,10 @@ else() endif() endif() +# Default to C++11 if not set so GTest/GMock can build +if (NOT BLT_CXX_STD) + set(BLT_CXX_STD "c++11" CACHE STRING "") +endif() + include(${BLT_SOURCE_DIR}/SetupBLT.cmake) # _blt_tutorial_include_blt_end diff --git a/docs/tutorial/calc_pi/CMakeLists.txt b/docs/tutorial/calc_pi/CMakeLists.txt index 6ac7a8563..5fa6f4a39 100644 --- a/docs/tutorial/calc_pi/CMakeLists.txt +++ b/docs/tutorial/calc_pi/CMakeLists.txt @@ -11,7 +11,12 @@ project( pi_playground ) #------------------------------------------------------------------------------ # 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 "${CMAKE_CURRENT_SOURCE_DIR}/../../..") +endif() + +# Default to C++11 if not set so GTest/GMock can build +if (NOT BLT_CXX_STD) + set(BLT_CXX_STD "c++11" CACHE STRING "") endif() include(${BLT_SOURCE_DIR}/SetupBLT.cmake) diff --git a/tests/internal/CMakeLists.txt b/tests/internal/CMakeLists.txt index 517091c26..4200bfda2 100644 --- a/tests/internal/CMakeLists.txt +++ b/tests/internal/CMakeLists.txt @@ -19,6 +19,10 @@ if(NOT BLT_SOURCE_DIR) set(BLT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../..") endif() +if (NOT BLT_CXX_STD) + set(BLT_CXX_STD "c++11" CACHE STRING "") +endif() + include(${BLT_SOURCE_DIR}/SetupBLT.cmake) #------------------------------------------------------------------------------ diff --git a/thirdparty_builtin/CMakeLists.txt b/thirdparty_builtin/CMakeLists.txt index c49c12485..751e8729c 100644 --- a/thirdparty_builtin/CMakeLists.txt +++ b/thirdparty_builtin/CMakeLists.txt @@ -5,6 +5,14 @@ set(_blt_tpl_targets) # tracks names of enabled tpl targets +if(ENABLE_GBENCHMARK OR ENABLE_GTEST OR ENABLE_GMOCK) + if("${CMAKE_CXX_STANDARD}" STREQUAL "" OR + "${CMAKE_CXX_STANDARD}" LESS 11) + message(WARNING "GoogleTest, GoogleMock, and GoogleBenchmark require greater than C++11. " + "Set BLT_CXX_STD to 'c++11' or higher before loading BLT.") + endif() +endif() + if(ENABLE_TESTS) include(CTest) @@ -60,10 +68,6 @@ if(ENABLE_TESTS) if(ENABLE_GTEST) - if(CMAKE_CXX_STANDARD LESS 11) - message(WARNING "C++11 is required to compile gtest or gmock.") - endif() - # # gtest 1.8 emits many warnings related to dll-interface # issues on windows, so we add flags to work around these @@ -136,10 +140,6 @@ if(ENABLE_BENCHMARKS) message(FATAL_ERROR "Google Benchmark cannot be built when BUILD_SHARED_LIBS=ON or on Windows") endif() - if(CMAKE_CXX_STANDARD LESS 11) - message(WARNING "C++11 is required to compile gbenchmark.") - endif() - set(BENCHMARK_ENABLE_TESTING OFF CACHE "" BOOL) add_subdirectory(benchmark-1.5.0 ${BLT_BUILD_DIR}/thirdparty_builtin/benchmark-1.5.0) From c3957bb4269ff0b9adb1b682b7c49c935fd8a01f Mon Sep 17 00:00:00 2001 From: Chris White Date: Thu, 16 Jan 2020 17:17:32 -0800 Subject: [PATCH 02/40] Fix very wrong wording --- thirdparty_builtin/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thirdparty_builtin/CMakeLists.txt b/thirdparty_builtin/CMakeLists.txt index 751e8729c..125874287 100644 --- a/thirdparty_builtin/CMakeLists.txt +++ b/thirdparty_builtin/CMakeLists.txt @@ -8,7 +8,7 @@ set(_blt_tpl_targets) # tracks names of enabled tpl targets if(ENABLE_GBENCHMARK OR ENABLE_GTEST OR ENABLE_GMOCK) if("${CMAKE_CXX_STANDARD}" STREQUAL "" OR "${CMAKE_CXX_STANDARD}" LESS 11) - message(WARNING "GoogleTest, GoogleMock, and GoogleBenchmark require greater than C++11. " + message(WARNING "GoogleTest, GoogleMock, and GoogleBenchmark require C++11 or later. " "Set BLT_CXX_STD to 'c++11' or higher before loading BLT.") endif() endif() From 85a36470054426f39cfebaea4f662c7048600ade Mon Sep 17 00:00:00 2001 From: Chris White Date: Fri, 17 Jan 2020 17:35:19 -0800 Subject: [PATCH 03/40] Update blt_add_library docs --- cmake/BLTMacros.cmake | 2 +- docs/api/target.rst | 106 ++++++++++++++++++++++++++++-------------- 2 files changed, 72 insertions(+), 36 deletions(-) diff --git a/cmake/BLTMacros.cmake b/cmake/BLTMacros.cmake index b040162ac..0192d9310 100644 --- a/cmake/BLTMacros.cmake +++ b/cmake/BLTMacros.cmake @@ -355,7 +355,7 @@ endmacro(blt_register_library) macro(blt_add_library) set(options) - set(singleValueArgs NAME OUTPUT_NAME OUTPUT_DIR HEADERS_OUTPUT_SUBDIR SHARED OBJECT CLEAR_PREFIX FOLDER) + set(singleValueArgs NAME OUTPUT_NAME OUTPUT_DIR SHARED OBJECT CLEAR_PREFIX FOLDER) set(multiValueArgs SOURCES HEADERS INCLUDES DEFINES DEPENDS_ON) # parse the arguments diff --git a/docs/api/target.rst b/docs/api/target.rst index cb0eb517c..6969590fa 100644 --- a/docs/api/target.rst +++ b/docs/api/target.rst @@ -118,52 +118,88 @@ blt_add_library CLEAR_PREFIX [TRUE | FALSE] FOLDER [name]) -Adds a library target, called , to be built from the given sources. +Adds a library target to your project. -This macro uses the BUILD_SHARED_LIBS, which is defaulted to OFF, to determine -whether the library will be build as shared or static. The optional boolean -SHARED argument can be used to override this choice. +NAME + Name of the created CMake target -The OBJECT argument creates a CMake object library. Basically it is a collection -of compiled source files that are not archived or linked. Unlike regular CMake -object libraries you do not have to use the $> syntax, -you can just use . +SOURCES + List of all sources to be added -Note: Object libraries do not follow CMake's transitivity rules until 3.12. -BLT will add the various information provided in this macro and its -dependencies in the order you provide them to help. +HEADERS + List of all headers to be added -The INCLUDES argument allows you to define what include directories are -needed by any target that is dependent on this library. These will -be inherited by CMake's target dependency rules. +INCLUDES + List of include directories both used by this target and inherited by dependent + targets -The DEFINES argument allows you to add needed compiler definitions that are -needed by any target that is dependent on this library. These will -be inherited by CMake's target dependency rules. +DEFINES + List of compiler defines both used by this target and inherited by dependent + targets -If given a DEPENDS_ON argument, it will add the necessary includes and -libraries if they are already registered with blt_register_library. If -not it will add them as a CMake target dependency. +DEPENDS_ON + List of CMake targets and BLT registered libraries that this library + depends on -In addition, this macro will add the associated dependencies to the given -library target. Specifically, it will add the dependency for the CMake target -and for copying the headers for that target as well. +OUTPUT_NAME + Override built file name of library (defaults to ) -The OUTPUT_DIR is used to control the build output directory of this -library. This is used to overwrite the default lib directory. -OUTPUT_NAME is the name of the output file; the default is NAME. +OUTPUT_DIR + Directory that this target will built to -It's useful when multiple libraries with the same name need to be created -by different targets. NAME is the target name, OUTPUT_NAME is the library name. -CLEAR_PREFIX allows you to remove the automatically appended "lib" prefix -from your built library. The created library will be foo.a instead of libfoo.a. -FOLDER is an optional keyword to organize the target into a folder in an IDE. +SHARED + 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) + +FOLDER + Name of the IDE folder to ease organization -This is available when ENABLE_FOLDERS is ON and when the cmake generator -supports this feature and will otherwise be ignored. +This macro supports three types of libraries automatically: normal, header-only, +or object. -Note: Do not use with header-only (INTERFACE) libraries, as this will generate -a CMake configuration error. +Normal libraries are libraries that have sources that are compiled and linked into a single +library and have headers that go along with them (unless it's a Fortran library). + +Header-only libraries are useful when you do not the library separately compiled or +are using C++ templates that require the library's user to instatiate them. To create +a header-only library (CMake calls them INTERFACE libraries), simply +list all headers under the HEADER argument and do not specify SOURCES. + +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. + +.. 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. + +This macro uses the BUILD_SHARED_LIBS, which is defaulted to OFF, to determine +whether the library will be build as shared or static. The optional boolean +SHARED argument can be used to override this choice. + +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). + +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. + +.. 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_test: From 3597fb468f2a9eb60a1939810ad1a721569be057 Mon Sep 17 00:00:00 2001 From: Chris White Date: Tue, 21 Jan 2020 14:45:38 -0800 Subject: [PATCH 04/40] Address bad grammar --- docs/api/target.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/api/target.rst b/docs/api/target.rst index 6969590fa..b4af96ec5 100644 --- a/docs/api/target.rst +++ b/docs/api/target.rst @@ -165,16 +165,16 @@ or object. Normal libraries are libraries that have sources that are compiled and linked into a single library and have headers that go along with them (unless it's a Fortran library). -Header-only libraries are useful when you do not the library separately compiled or -are using C++ templates that require the library's user to instatiate them. To create -a header-only library (CMake calls them INTERFACE libraries), simply -list all headers under the HEADER argument and do not specify SOURCES. +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). 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 +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. .. note:: @@ -183,7 +183,7 @@ use with BLT macros. Unless you have a good reason don't use Object l adds the INTERFACE target properties to get around this. This macro uses the BUILD_SHARED_LIBS, which is defaulted to OFF, to determine -whether the library will be build as shared or static. The optional boolean +whether the library will be built as shared or static. The optional boolean SHARED argument can be used to override this choice. If given a DEPENDS_ON argument, this macro will inherit the necessary information From 5ffb40befe6548b7ad57221b7ef1ef023b5738be Mon Sep 17 00:00:00 2001 From: George Zagaris Date: Tue, 25 Feb 2020 10:29:26 -0800 Subject: [PATCH 05/40] ENH: add blt_assert_exists utility macro --- cmake/BLTMacros.cmake | 32 ++++++++++++++++++++++++++++++++ docs/api/utility.rst | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/cmake/BLTMacros.cmake b/cmake/BLTMacros.cmake index 0192d9310..065dae636 100644 --- a/cmake/BLTMacros.cmake +++ b/cmake/BLTMacros.cmake @@ -5,6 +5,38 @@ include(${BLT_ROOT_DIR}/cmake/BLTPrivateMacros.cmake) +##------------------------------------------------------------------------------ +## blt_assert_exists( [DIRECTORY ] +## [TARGET ] +## [FILE ] ) +## +## Throws a FATAL_ERROR message if the specified directory, file, or target does +## not exist. +##------------------------------------------------------------------------------ +macro(blt_assert_exists) + + set(options) + set(singleValueArgs DIRECTORY TARGET FILE EXECUTABLE ) + set(multiValueArgs) + + # parse macro arguments + cmake_parse_arguments(arg + "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN} ) + + if (DEFINED arg_DIRECTORY AND NOT IS_DIRECTORY ${arg_DIRECTORY}) + message(FATAL_ERROR "directory [${arg_DIRECTORY}] does not exist!") + endif() + + if (DEFINED arg_FILE AND NOT EXISTS ${arg_FILE}) + message(FATAL_ERROR "file [${arg_FILE}] does not exists!") + endif() + + if (DEFINED arg_TARGET AND NOT TARGET ${arg_TARGET}) + message(FATAL_ERROR "target [${arg_TARGET}] not found!" ) + endif() + +endmacro(blt_assert_exists) + ##------------------------------------------------------------------------------ ## blt_list_append( TO ELEMENTS [ ...] IF ) ## diff --git a/docs/api/utility.rst b/docs/api/utility.rst index f462e00d7..3b35fdf73 100644 --- a/docs/api/utility.rst +++ b/docs/api/utility.rst @@ -7,6 +7,42 @@ Utility Macros ============== +blt_assert_exists +^^^^^^^^^^^^^^^^^^ + +.. code-block:: cmake + + blt_assert_exists( + [DIRECTORY ] + [FILE ] + [TARGET ) + +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. + +.. code-block:: cmake + :caption: **Example** + :linenos: + + ## check if the directory 'blt' exists in the project + blt_assert_exists( DIRECTORY ${PROJECT_SOURCE_DIR}/cmake/blt ) + + ## check if the file 'SetupBLT.cmake' file exists + blt_assert_exists( FILE ${PROJECT_SOURCE_DIR}/cmake/blt/SetupBLT.cmake ) + + ## checks can also be bundled in one call + blt_assert_exists( DIRECTORY ${PROJECT_SOURCE_DIR}/cmake/blt + FILE ${PROJECT_SOURCE_DIR}/cmake/blt/SetupBLT.cmake ) + + ## check if a CMake target for a library or executable exists + blt_assert_exists( TARGET foo ) + + blt_append_custom_compiler_flag ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From dc8fa59d99bcf16f085d9fc9433a467ea898a479 Mon Sep 17 00:00:00 2001 From: George Zagaris Date: Wed, 26 Feb 2020 15:17:01 -0800 Subject: [PATCH 06/40] DOC: update release notes Document addtion of blt_assert_exists() macro in release notes. --- RELEASE-NOTES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 3dd782792..7c67de0f6 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -12,6 +12,7 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/ ## [Version 0.3.0] - Release date 2020-01-08 ### Added +- Added blt_assert_exists() utility macro. - Sets CMake policy CMP0074 to NEW, when available. - Added simpler Clang+XLF+Cuda host-config for LLNL's blueos - API Docs that are public! From 1ba1cfe023418649967cd88182263dbfb6500cd5 Mon Sep 17 00:00:00 2001 From: George Zagaris Date: Wed, 26 Feb 2020 17:46:56 -0800 Subject: [PATCH 07/40] DOC: place documentation in correct section Put comment regarding the blt_assert_exists() macro in the Unreleased section. --- RELEASE-NOTES.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 7c67de0f6..140cab124 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -9,10 +9,12 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/ ## [Unreleased] - Release date yyyy-mm-dd +### Added +- Added blt_assert_exists() utility macro. + ## [Version 0.3.0] - Release date 2020-01-08 ### Added -- Added blt_assert_exists() utility macro. - Sets CMake policy CMP0074 to NEW, when available. - Added simpler Clang+XLF+Cuda host-config for LLNL's blueos - API Docs that are public! From 3600b4774d0a8f404562f4779af03def05bb3e4b Mon Sep 17 00:00:00 2001 From: George Zagaris Date: Wed, 26 Feb 2020 18:11:32 -0800 Subject: [PATCH 08/40] ENH: allow multi-value args in blt_asset_exists() --- cmake/BLTMacros.cmake | 38 +++++++++++++++++++++++++------------- docs/api/utility.rst | 18 +++++++++--------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/cmake/BLTMacros.cmake b/cmake/BLTMacros.cmake index 065dae636..bceec7d0d 100644 --- a/cmake/BLTMacros.cmake +++ b/cmake/BLTMacros.cmake @@ -6,33 +6,45 @@ include(${BLT_ROOT_DIR}/cmake/BLTPrivateMacros.cmake) ##------------------------------------------------------------------------------ -## blt_assert_exists( [DIRECTORY ] -## [TARGET ] -## [FILE ] ) +## blt_assert_exists( [DIRECTORIES [ ...] ] +## [TARGETS [ ...] ] +## [FILES ...] ) ## -## Throws a FATAL_ERROR message if the specified directory, file, or target does -## not exist. +## Throws a FATAL_ERROR message if any of the specified directories, files, or +## targets do not exist. ##------------------------------------------------------------------------------ macro(blt_assert_exists) set(options) - set(singleValueArgs DIRECTORY TARGET FILE EXECUTABLE ) - set(multiValueArgs) + set(singleValueArgs) + set(multiValueArgs DIRECTORIES TARGETS FILES) # parse macro arguments cmake_parse_arguments(arg "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN} ) - if (DEFINED arg_DIRECTORY AND NOT IS_DIRECTORY ${arg_DIRECTORY}) - message(FATAL_ERROR "directory [${arg_DIRECTORY}] does not exist!") + if (DEFINED arg_DIRECTORIES) + foreach (_dir ${arg_DIRECTORIES}) + if (NOT IS_DIRECTORY ${_dir}) + message(FATAL_ERROR "directory [${_dir}] does not exist!") + endif() + endforeach() endif() - if (DEFINED arg_FILE AND NOT EXISTS ${arg_FILE}) - message(FATAL_ERROR "file [${arg_FILE}] does not exists!") + if (DEFINED arg_FILES) + foreach (_file ${arg_FILES}) + if (NOT EXISTS ${_file}) + message(FATAL_ERROR "file [${_file}] does not exist!") + endif() + endforeach() endif() - if (DEFINED arg_TARGET AND NOT TARGET ${arg_TARGET}) - message(FATAL_ERROR "target [${arg_TARGET}] not found!" ) + if (DEFINED arg_TARGETS) + foreach (_target ${arg_TARGETS}) + if (NOT TARGET ${_target}) + message(FATAL_ERROR "target [${_target}] does not exist!") + endif() + endforeach() endif() endmacro(blt_assert_exists) diff --git a/docs/api/utility.rst b/docs/api/utility.rst index 3b35fdf73..9e826ec14 100644 --- a/docs/api/utility.rst +++ b/docs/api/utility.rst @@ -13,9 +13,9 @@ blt_assert_exists .. code-block:: cmake blt_assert_exists( - [DIRECTORY ] - [FILE ] - [TARGET ) + [DIRECTORIES [ ...] ] + [FILES [ ...] ] + [TARGETS [ ...] ] ) Checks if the specified directory, file and/or cmake target exists and throws an error message. @@ -30,17 +30,17 @@ an error message. :linenos: ## check if the directory 'blt' exists in the project - blt_assert_exists( DIRECTORY ${PROJECT_SOURCE_DIR}/cmake/blt ) + blt_assert_exists( DIRECTORIES ${PROJECT_SOURCE_DIR}/cmake/blt ) ## check if the file 'SetupBLT.cmake' file exists - blt_assert_exists( FILE ${PROJECT_SOURCE_DIR}/cmake/blt/SetupBLT.cmake ) + blt_assert_exists( FILES ${PROJECT_SOURCE_DIR}/cmake/blt/SetupBLT.cmake ) ## checks can also be bundled in one call - blt_assert_exists( DIRECTORY ${PROJECT_SOURCE_DIR}/cmake/blt - FILE ${PROJECT_SOURCE_DIR}/cmake/blt/SetupBLT.cmake ) + blt_assert_exists( DIRECTORIES ${PROJECT_SOURCE_DIR}/cmake/blt + FILES ${PROJECT_SOURCE_DIR}/cmake/blt/SetupBLT.cmake ) - ## check if a CMake target for a library or executable exists - blt_assert_exists( TARGET foo ) + ## check if the CMake targets `foo` and `bar` exist + blt_assert_exists( TARGETS foo bar ) blt_append_custom_compiler_flag From 040f081274357cd0fa1d80a3398e2f6af5a411f5 Mon Sep 17 00:00:00 2001 From: George Zagaris Date: Sat, 29 Feb 2020 10:58:27 -0800 Subject: [PATCH 09/40] DOC: fix heading in blt_assert_exists docs --- docs/api/utility.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/utility.rst b/docs/api/utility.rst index 9e826ec14..f9eb6e977 100644 --- a/docs/api/utility.rst +++ b/docs/api/utility.rst @@ -8,7 +8,7 @@ Utility Macros blt_assert_exists -^^^^^^^^^^^^^^^^^^ +~~~~~~~~~~~~~~~~~~~ .. code-block:: cmake From 11b97ed38bd1c801a0fcdf94a75cd1fb681c7492 Mon Sep 17 00:00:00 2001 From: Chris White Date: Wed, 11 Mar 2020 14:30:05 -0700 Subject: [PATCH 10/40] Remove googletest adding -Werror --- .../googletest/cmake/internal_utils.cmake | 4 ++-- .../gtest-2020-03-11-remove-werror.patch | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 thirdparty_builtin/patches/gtest-2020-03-11-remove-werror.patch diff --git a/thirdparty_builtin/googletest-master-2020-01-07/googletest/cmake/internal_utils.cmake b/thirdparty_builtin/googletest-master-2020-01-07/googletest/cmake/internal_utils.cmake index 2f70f0b08..36cbecb16 100644 --- a/thirdparty_builtin/googletest-master-2020-01-07/googletest/cmake/internal_utils.cmake +++ b/thirdparty_builtin/googletest-master-2020-01-07/googletest/cmake/internal_utils.cmake @@ -82,13 +82,13 @@ macro(config_compiler_and_linker) # http://stackoverflow.com/questions/3232669 explains the issue. set(cxx_base_flags "${cxx_base_flags} -wd4702") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(cxx_base_flags "-Wall -Wshadow -Werror -Wconversion") + set(cxx_base_flags "-Wall -Wshadow -Wconversion") set(cxx_exception_flags "-fexceptions") set(cxx_no_exception_flags "-fno-exceptions") set(cxx_strict_flags "-W -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wunused-parameter -Wcast-align -Wchar-subscripts -Winline -Wredundant-decls") set(cxx_no_rtti_flags "-fno-rtti") elseif (CMAKE_COMPILER_IS_GNUCXX) - set(cxx_base_flags "-Wall -Wshadow -Werror") + set(cxx_base_flags "-Wall -Wshadow") if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0) set(cxx_base_flags "${cxx_base_flags} -Wno-error=dangling-else") endif() diff --git a/thirdparty_builtin/patches/gtest-2020-03-11-remove-werror.patch b/thirdparty_builtin/patches/gtest-2020-03-11-remove-werror.patch new file mode 100644 index 000000000..be096c929 --- /dev/null +++ b/thirdparty_builtin/patches/gtest-2020-03-11-remove-werror.patch @@ -0,0 +1,20 @@ +diff --git a/thirdparty_builtin/googletest-master-2020-01-07/googletest/cmake/internal_utils.cmake b/thirdparty_builtin/googletest-master-2020-01-07/googletest/cmake/internal_utils.cmake +index 2f70f0b..36cbecb 100644 +--- a/thirdparty_builtin/googletest-master-2020-01-07/googletest/cmake/internal_utils.cmake ++++ b/thirdparty_builtin/googletest-master-2020-01-07/googletest/cmake/internal_utils.cmake +@@ -82,13 +82,13 @@ macro(config_compiler_and_linker) + # http://stackoverflow.com/questions/3232669 explains the issue. + set(cxx_base_flags "${cxx_base_flags} -wd4702") + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +- set(cxx_base_flags "-Wall -Wshadow -Werror -Wconversion") ++ set(cxx_base_flags "-Wall -Wshadow -Wconversion") + set(cxx_exception_flags "-fexceptions") + set(cxx_no_exception_flags "-fno-exceptions") + set(cxx_strict_flags "-W -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wunused-parameter -Wcast-align -Wchar-subscripts -Winline -Wredundant-decls") + set(cxx_no_rtti_flags "-fno-rtti") + elseif (CMAKE_COMPILER_IS_GNUCXX) +- set(cxx_base_flags "-Wall -Wshadow -Werror") ++ set(cxx_base_flags "-Wall -Wshadow") + if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0) + set(cxx_base_flags "${cxx_base_flags} -Wno-error=dangling-else") + endif() From 71cd724c61cd455a2d070348cbd9213fe81cb666 Mon Sep 17 00:00:00 2001 From: Chris White Date: Wed, 11 Mar 2020 15:53:53 -0700 Subject: [PATCH 11/40] Remove -Werror from Google Benchmark --- thirdparty_builtin/benchmark-1.5.0/CMakeLists.txt | 3 --- .../gbenchmark-2020-03-11-remove-werror.patch | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 thirdparty_builtin/patches/gbenchmark-2020-03-11-remove-werror.patch diff --git a/thirdparty_builtin/benchmark-1.5.0/CMakeLists.txt b/thirdparty_builtin/benchmark-1.5.0/CMakeLists.txt index d115ede39..c24d29fef 100644 --- a/thirdparty_builtin/benchmark-1.5.0/CMakeLists.txt +++ b/thirdparty_builtin/benchmark-1.5.0/CMakeLists.txt @@ -137,9 +137,6 @@ else() add_cxx_compiler_flag(-Wall) add_cxx_compiler_flag(-Wextra) add_cxx_compiler_flag(-Wshadow) - add_cxx_compiler_flag(-Werror RELEASE) - add_cxx_compiler_flag(-Werror RELWITHDEBINFO) - add_cxx_compiler_flag(-Werror MINSIZEREL) add_cxx_compiler_flag(-pedantic) add_cxx_compiler_flag(-pedantic-errors) add_cxx_compiler_flag(-Wshorten-64-to-32) diff --git a/thirdparty_builtin/patches/gbenchmark-2020-03-11-remove-werror.patch b/thirdparty_builtin/patches/gbenchmark-2020-03-11-remove-werror.patch new file mode 100644 index 000000000..ec50b484a --- /dev/null +++ b/thirdparty_builtin/patches/gbenchmark-2020-03-11-remove-werror.patch @@ -0,0 +1,14 @@ +diff --git a/thirdparty_builtin/benchmark-1.5.0/CMakeLists.txt b/thirdparty_builtin/benchmark-1.5.0/CMakeLists.txt +index d115ede..c24d29f 100644 +--- a/thirdparty_builtin/benchmark-1.5.0/CMakeLists.txt ++++ b/thirdparty_builtin/benchmark-1.5.0/CMakeLists.txt +@@ -137,9 +137,6 @@ else() + add_cxx_compiler_flag(-Wall) + add_cxx_compiler_flag(-Wextra) + add_cxx_compiler_flag(-Wshadow) +- add_cxx_compiler_flag(-Werror RELEASE) +- add_cxx_compiler_flag(-Werror RELWITHDEBINFO) +- add_cxx_compiler_flag(-Werror MINSIZEREL) + add_cxx_compiler_flag(-pedantic) + add_cxx_compiler_flag(-pedantic-errors) + add_cxx_compiler_flag(-Wshorten-64-to-32) From e080df3471f325e8f26b19c8371ad61b58c4c34b Mon Sep 17 00:00:00 2001 From: Chris White Date: Wed, 18 Mar 2020 16:43:01 -0700 Subject: [PATCH 12/40] Add clang-format support --- cmake/BLTOptions.cmake | 17 +- cmake/SetupCodeChecks.cmake | 323 ++++++++++++++++--------- cmake/thirdparty/SetupThirdParty.cmake | 9 +- 3 files changed, 231 insertions(+), 118 deletions(-) diff --git a/cmake/BLTOptions.cmake b/cmake/BLTOptions.cmake index 35fded947..465059153 100644 --- a/cmake/BLTOptions.cmake +++ b/cmake/BLTOptions.cmake @@ -20,15 +20,22 @@ option(ENABLE_COVERAGE "Enables code coverage support" OFF) #------------------------------------------------------------------------------ # TPL Executable Options #------------------------------------------------------------------------------ -option(ENABLE_CLANGQUERY "Enables Clang-query support" ON) -option(ENABLE_CPPCHECK "Enables Cppcheck support" ON) -option(ENABLE_DOXYGEN "Enables Doxygen support" ON) option(ENABLE_GIT "Enables Git support" ON) + +# Documentation +option(ENABLE_DOXYGEN "Enables Doxygen support" ON) option(ENABLE_SPHINX "Enables Sphinx support" ON) -option(ENABLE_UNCRUSTIFY "Enables Uncrustify support" ON) -option(ENABLE_ASTYLE "Enables AStyle support" ON) + +# Quality +option(ENABLE_CLANGQUERY "Enables Clang-query support" ON) +option(ENABLE_CPPCHECK "Enables Cppcheck support" ON) option(ENABLE_VALGRIND "Enables Valgrind support" ON) +# Style +option(ENABLE_ASTYLE "Enables AStyle support" ON) +option(ENABLE_CLANGFORMAT "Enables ClangFormat support" ON) +option(ENABLE_UNCRUSTIFY "Enables Uncrustify support" ON) + #------------------------------------------------------------------------------ # Build Options #------------------------------------------------------------------------------ diff --git a/cmake/SetupCodeChecks.cmake b/cmake/SetupCodeChecks.cmake index 68f4ce870..b8fc58b8e 100644 --- a/cmake/SetupCodeChecks.cmake +++ b/cmake/SetupCodeChecks.cmake @@ -9,16 +9,6 @@ add_custom_target(${BLT_CODE_CHECK_TARGET_NAME}) add_custom_target(${BLT_CODE_STYLE_TARGET_NAME}) -if(UNCRUSTIFY_FOUND) - # targets for verifying formatting - add_custom_target(uncrustify_check) - add_dependencies(${BLT_CODE_CHECK_TARGET_NAME} uncrustify_check) - - # targets for modifying formatting - add_custom_target(uncrustify_style) - add_dependencies(${BLT_CODE_STYLE_TARGET_NAME} uncrustify_style) -endif() - if(ASTYLE_FOUND) # targets for verifying formatting add_custom_target(astyle_check) @@ -29,6 +19,26 @@ if(ASTYLE_FOUND) add_dependencies(${BLT_CODE_STYLE_TARGET_NAME} astyle_style) endif() +if(CLANGFORMAT_FOUND) + # targets for verifying formatting + add_custom_target(clangformat_check) + add_dependencies(${BLT_CODE_CHECK_TARGET_NAME} clangformat_check) + + # targets for modifying formatting + add_custom_target(clangformat_style) + add_dependencies(${BLT_CODE_STYLE_TARGET_NAME} clangformat_style) +endif() + +if(UNCRUSTIFY_FOUND) + # targets for verifying formatting + add_custom_target(uncrustify_check) + add_dependencies(${BLT_CODE_CHECK_TARGET_NAME} uncrustify_check) + + # targets for modifying formatting + add_custom_target(uncrustify_style) + add_dependencies(${BLT_CODE_STYLE_TARGET_NAME} uncrustify_style) +endif() + if(CPPCHECK_FOUND) add_custom_target(cppcheck_check) add_dependencies(${BLT_CODE_CHECK_TARGET_NAME} cppcheck_check) @@ -47,8 +57,8 @@ endif() # Code check targets should only be run on demand foreach(target - check uncrustify_check astyle_check cppcheck_check - style uncrustify_style astyle_style + check uncrustify_check astyle_check clangformat_check cppcheck_check + style uncrustify_style astyle_style clangformat_style clang_query_check interactive_clang_query_check) if(TARGET ${target}) set_property(TARGET ${target} PROPERTY EXCLUDE_FROM_ALL TRUE) @@ -116,24 +126,6 @@ macro(blt_add_code_checks) # Add code checks set(_error_msg "blt_add_code_checks tried to create an already existing target with given PREFIX: ${arg_PREFIX}. ") - if (UNCRUSTIFY_FOUND AND DEFINED arg_UNCRUSTIFY_CFG_FILE) - set(_check_target_name ${arg_PREFIX}_uncrustify_check) - blt_error_if_target_exists(${_check_target_name} ${_error_msg}) - set(_style_target_name ${arg_PREFIX}_uncrustify_style) - blt_error_if_target_exists(${_style_target_name} ${_error_msg}) - - blt_add_uncrustify_target( NAME ${_check_target_name} - MODIFY_FILES FALSE - CFG_FILE ${arg_UNCRUSTIFY_CFG_FILE} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - SRC_FILES ${_c_sources} ) - - blt_add_uncrustify_target( NAME ${_style_target_name} - MODIFY_FILES TRUE - CFG_FILE ${arg_UNCRUSTIFY_CFG_FILE} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - SRC_FILES ${_c_sources} ) - endif() if (ASTYLE_FOUND AND DEFINED arg_ASTYLE_CFG_FILE) set(_check_target_name ${arg_PREFIX}_astyle_check) @@ -154,6 +146,44 @@ macro(blt_add_code_checks) SRC_FILES ${_c_sources} ) endif() + if (CLANGFORMAT_FOUND AND DEFINED arg_CLANGFORMAT_CFG_FILE) + set(_check_target_name ${arg_PREFIX}_clangformat_check) + blt_error_if_target_exists(${_check_target_name} ${_error_msg}) + set(_style_target_name ${arg_PREFIX}_clangformat_style) + blt_error_if_target_exists(${_style_target_name} ${_error_msg}) + + blt_add_clangformat_target( NAME ${_check_target_name} + MODIFY_FILES FALSE + CFG_FILE ${arg_CLANGFORMAT_CFG_FILE} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + SRC_FILES ${_c_sources} ) + + blt_add_clangformat_target( NAME ${_style_target_name} + MODIFY_FILES TRUE + CFG_FILE ${arg_CLANGFORMAT_CFG_FILE} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + SRC_FILES ${_c_sources} ) + endif() + + if (UNCRUSTIFY_FOUND AND DEFINED arg_UNCRUSTIFY_CFG_FILE) + set(_check_target_name ${arg_PREFIX}_uncrustify_check) + blt_error_if_target_exists(${_check_target_name} ${_error_msg}) + set(_style_target_name ${arg_PREFIX}_uncrustify_style) + blt_error_if_target_exists(${_style_target_name} ${_error_msg}) + + blt_add_uncrustify_target( NAME ${_check_target_name} + MODIFY_FILES FALSE + CFG_FILE ${arg_UNCRUSTIFY_CFG_FILE} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + SRC_FILES ${_c_sources} ) + + blt_add_uncrustify_target( NAME ${_style_target_name} + MODIFY_FILES TRUE + CFG_FILE ${arg_UNCRUSTIFY_CFG_FILE} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + SRC_FILES ${_c_sources} ) + endif() + if (CPPCHECK_FOUND) set(_cppcheck_target_name ${arg_PREFIX}_cppcheck_check) blt_error_if_target_exists(${_cppcheck_target_name} ${_error_msg}) @@ -299,19 +329,19 @@ endmacro(blt_add_cppcheck_target) ##------------------------------------------------------------------------------ -## blt_add_uncrustify_target( NAME -## MODIFY_FILES [TRUE | FALSE (default)] -## CFG_FILE -## PREPEND_FLAGS -## APPEND_FLAGS -## COMMENT -## WORKING_DIRECTORY -## SRC_FILES [FILE1 [FILE2 ...]] ) +## blt_add_astyle_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 uncrustify over the given SRC_FILES. +## Creates a new target with the given NAME for running astyle over the given SRC_FILES. ##------------------------------------------------------------------------------ -macro(blt_add_uncrustify_target) - +macro(blt_add_astyle_target) + ## parse the arguments to the macro set(options) set(singleValueArgs NAME MODIFY_FILES CFG_FILE COMMENT WORKING_DIRECTORY) @@ -322,15 +352,15 @@ macro(blt_add_uncrustify_target) # Check/Set required parameters if(NOT DEFINED arg_NAME) - message(FATAL_ERROR "blt_add_uncrustify_target requires a NAME parameter") + message(FATAL_ERROR "blt_add_astyle_target requires a NAME parameter") endif() if(NOT DEFINED arg_CFG_FILE) - message(FATAL_ERROR "blt_add_uncrustify_target requires a CFG_FILE parameter") + message(FATAL_ERROR "blt_add_astyle_target requires a CFG_FILE parameter") endif() if(NOT DEFINED arg_SRC_FILES) - message(FATAL_ERROR "blt_add_uncrustify_target requires a SRC_FILES parameter") + message(FATAL_ERROR "blt_add_astyle_target requires a SRC_FILES parameter") endif() if(NOT DEFINED arg_MODIFY_FILES) @@ -346,61 +376,71 @@ macro(blt_add_uncrustify_target) set(_generate_target TRUE) if(${arg_MODIFY_FILES}) - set(MODIFY_FILES_FLAG --replace;--no-backup) + set(MODIFY_FILES_FLAG --suffix=none) else() - set(MODIFY_FILES_FLAG "--check") + set(MODIFY_FILES_FLAG --dry-run) - # Check the version -- output is of the form "uncrustify X.Y.Z" + # Check the version -- output is of the form "Artistic Style Version X.Y.Z" execute_process( - COMMAND ${UNCRUSTIFY_EXECUTABLE} --version + COMMAND ${ASTYLE_EXECUTABLE} --version OUTPUT_VARIABLE _version_str + ERROR_VARIABLE _version_str OUTPUT_STRIP_TRAILING_WHITESPACE ) - string(REGEX MATCH "([0-9]+(\\.)?)+(_[a-zA-Z])?" _uncrustify_version ${_version_str}) - + string(REGEX MATCH "([0-9]+(\\.)?)+$" _astyle_version ${_version_str}) + # Skip 'check' target if version is not high enough - if(_uncrustify_version VERSION_LESS 0.61) + if(_astyle_version VERSION_LESS 2.05) set(_generate_target FALSE) - message(WARNING "blt_add_uncrustify_target requires uncrustify v0.61 or greater " + message(WARNING "blt_add_astyle_target requires AStyle v2.05 or greater " " for style check targets. " - " Current uncrustify executable: '${UNCRUSTIFY_EXECUTABLE}' " - " Current uncrustify version is: ${_uncrustify_version}." ) - endif() + " Current AStyle executable: '${ASTYLE_EXECUTABLE}' " + " Current AStyle version is: ${_astyle_version}." ) + endif() endif() if(_generate_target) - add_custom_target(${arg_NAME} - COMMAND ${UNCRUSTIFY_EXECUTABLE} ${arg_PREPEND_FLAGS} - -c ${arg_CFG_FILE} ${MODIFY_FILES_FLAG} ${arg_SRC_FILES} ${arg_APPEND_FLAGS} - WORKING_DIRECTORY ${_wd} - COMMENT "${arg_COMMENT}Running uncrustify source code formatting checks.") - - # hook our new target into the proper dependency chain + + # AStyle doesn't report failure when there are files that require formatting. + # Fix this with a wrapper script that parses the output. + set(wrapped_astyle_script ${CMAKE_CURRENT_BINARY_DIR}/WrapAstyle_${arg_NAME}.cmake) + + configure_file( + ${BLT_ROOT_DIR}/cmake/WrapAstyle.cmake.in + ${wrapped_astyle_script} + @ONLY ) + + add_custom_target( + ${arg_NAME} + COMMAND ${CMAKE_COMMAND} -P ${wrapped_astyle_script} + WORKING_DIRECTORY ${_wd} + COMMENT "${arg_COMMENT}Running AStyle source code formatting checks.") + + # Hook our new target into the proper dependency chain if(${arg_MODIFY_FILES}) - add_dependencies(uncrustify_style ${arg_NAME}) + add_dependencies(astyle_style ${arg_NAME}) else() - add_dependencies(uncrustify_check ${arg_NAME}) + add_dependencies(astyle_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_uncrustify_target) +endmacro(blt_add_astyle_target) ##------------------------------------------------------------------------------ -## blt_add_astyle_target( NAME -## MODIFY_FILES [TRUE | FALSE (default)] -## CFG_FILE -## PREPEND_FLAGS -## APPEND_FLAGS -## COMMENT -## WORKING_DIRECTORY -## SRC_FILES [FILE1 [FILE2 ...]] ) +## blt_add_clangformat_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 astyle over the given SRC_FILES. +## Creates a new target with the given NAME for running clang-format over the given SRC_FILES. ##------------------------------------------------------------------------------ -macro(blt_add_astyle_target) +macro(blt_add_clangformat_target) ## parse the arguments to the macro set(options) @@ -412,15 +452,15 @@ macro(blt_add_astyle_target) # Check/Set required parameters if(NOT DEFINED arg_NAME) - message(FATAL_ERROR "blt_add_astyle_target requires a NAME parameter") + message(FATAL_ERROR "blt_add_clangformat_target requires a NAME parameter") endif() if(NOT DEFINED arg_CFG_FILE) - message(FATAL_ERROR "blt_add_astyle_target requires a CFG_FILE parameter") + message(FATAL_ERROR "blt_add_clangformat_target requires a CFG_FILE parameter") endif() if(NOT DEFINED arg_SRC_FILES) - message(FATAL_ERROR "blt_add_astyle_target requires a SRC_FILES parameter") + message(FATAL_ERROR "blt_add_clangformat_target requires a SRC_FILES parameter") endif() if(NOT DEFINED arg_MODIFY_FILES) @@ -436,54 +476,117 @@ macro(blt_add_astyle_target) set(_generate_target TRUE) if(${arg_MODIFY_FILES}) - set(MODIFY_FILES_FLAG --suffix=none) + set(MODIFY_FILES_FLAG -i) else() set(MODIFY_FILES_FLAG --dry-run) + endif() - # Check the version -- output is of the form "Artistic Style Version X.Y.Z" + if(_generate_target) + add_custom_target(${arg_NAME} + COMMAND ${CLANGFORMAT_EXECUTABLE} ${arg_PREPEND_FLAGS} + -style ${arg_CFG_FILE} ${MODIFY_FILES_FLAG} ${arg_SRC_FILES} ${arg_APPEND_FLAGS} + WORKING_DIRECTORY ${_wd} + COMMENT "${arg_COMMENT}Running clang-format source code formatting checks.") + + # Hook our new target into the proper dependency chain + if(${arg_MODIFY_FILES}) + add_dependencies(clangformat_style ${arg_NAME}) + else() + add_dependencies(clangformat_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_clangformat_target) + +##------------------------------------------------------------------------------ +## blt_add_uncrustify_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 uncrustify over the given SRC_FILES. +##------------------------------------------------------------------------------ +macro(blt_add_uncrustify_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_uncrustify_target requires a NAME parameter") + endif() + + if(NOT DEFINED arg_CFG_FILE) + message(FATAL_ERROR "blt_add_uncrustify_target requires a CFG_FILE parameter") + endif() + + if(NOT DEFINED arg_SRC_FILES) + message(FATAL_ERROR "blt_add_uncrustify_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) + + 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 ${ASTYLE_EXECUTABLE} --version + COMMAND ${UNCRUSTIFY_EXECUTABLE} --version OUTPUT_VARIABLE _version_str - ERROR_VARIABLE _version_str OUTPUT_STRIP_TRAILING_WHITESPACE ) - string(REGEX MATCH "([0-9]+(\\.)?)+$" _astyle_version ${_version_str}) - + string(REGEX MATCH "([0-9]+(\\.)?)+(_[a-zA-Z])?" _uncrustify_version ${_version_str}) + # Skip 'check' target if version is not high enough - if(_astyle_version VERSION_LESS 2.05) + if(_uncrustify_version VERSION_LESS 0.61) set(_generate_target FALSE) - message(WARNING "blt_add_astyle_target requires AStyle v2.05 or greater " + message(WARNING "blt_add_uncrustify_target requires uncrustify v0.61 or greater " " for style check targets. " - " Current AStyle executable: '${ASTYLE_EXECUTABLE}' " - " Current AStyle version is: ${_astyle_version}." ) - endif() + " Current uncrustify executable: '${UNCRUSTIFY_EXECUTABLE}' " + " Current uncrustify version is: ${_uncrustify_version}." ) + endif() endif() if(_generate_target) - - # AStyle doesn't report failure when there are files that require formatting. - # Fix this with a wrapper script that parses the output. - set(wrapped_astyle_script ${CMAKE_CURRENT_BINARY_DIR}/WrapAstyle_${arg_NAME}.cmake) - - configure_file( - ${BLT_ROOT_DIR}/cmake/WrapAstyle.cmake.in - ${wrapped_astyle_script} - @ONLY ) - - add_custom_target( - ${arg_NAME} - COMMAND ${CMAKE_COMMAND} -P ${wrapped_astyle_script} - WORKING_DIRECTORY ${_wd} - COMMENT "${arg_COMMENT}Running AStyle source code formatting checks.") - - # Hook our new target into the proper dependency chain + add_custom_target(${arg_NAME} + COMMAND ${UNCRUSTIFY_EXECUTABLE} ${arg_PREPEND_FLAGS} + -c ${arg_CFG_FILE} ${MODIFY_FILES_FLAG} ${arg_SRC_FILES} ${arg_APPEND_FLAGS} + WORKING_DIRECTORY ${_wd} + COMMENT "${arg_COMMENT}Running uncrustify source code formatting checks.") + + # hook our new target into the proper dependency chain if(${arg_MODIFY_FILES}) - add_dependencies(astyle_style ${arg_NAME}) + add_dependencies(uncrustify_style ${arg_NAME}) else() - add_dependencies(astyle_check ${arg_NAME}) + add_dependencies(uncrustify_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_astyle_target) + +endmacro(blt_add_uncrustify_target) diff --git a/cmake/thirdparty/SetupThirdParty.cmake b/cmake/thirdparty/SetupThirdParty.cmake index 34fe5b9a0..ffc92ad3e 100644 --- a/cmake/thirdparty/SetupThirdParty.cmake +++ b/cmake/thirdparty/SetupThirdParty.cmake @@ -86,12 +86,15 @@ blt_find_executable(NAME Valgrind #------------------------------------ # linting #------------------------------------ -blt_find_executable(NAME Uncrustify - EXECUTABLES uncrustify) - blt_find_executable(NAME AStyle EXECUTABLES astyle) +blt_find_executable(NAME ClangFormat + EXECUTABLES clang-format) + +blt_find_executable(NAME Uncrustify + EXECUTABLES uncrustify) + #------------------------------------ # Static analysis via Cppcheck From a44fc0987b3c7a0dafd5c137f40070a157601eab Mon Sep 17 00:00:00 2001 From: Chris White Date: Wed, 18 Mar 2020 17:04:45 -0700 Subject: [PATCH 13/40] Add docs for ClangFormat, Unify ClangFormat name --- cmake/SetupCodeChecks.cmake | 23 ++--- docs/api/code_check.rst | 164 ++++++++++++++++++++++++------------ 2 files changed, 124 insertions(+), 63 deletions(-) diff --git a/cmake/SetupCodeChecks.cmake b/cmake/SetupCodeChecks.cmake index b8fc58b8e..39c8c4283 100644 --- a/cmake/SetupCodeChecks.cmake +++ b/cmake/SetupCodeChecks.cmake @@ -68,11 +68,12 @@ endforeach() ##------------------------------------------------------------------------------ -## blt_add_code_checks( PREFIX -## SOURCES [source1 [source2 ...]] -## UNCRUSTIFY_CFG_FILE -## ASTYLE_CFG_FILE -## CPPCHECK_FLAGS ) +## blt_add_code_checks( PREFIX +## SOURCES [source1 [source2 ...]] +## ASTYLE_CFG_FILE +## CLANGFORMAT_CFG_FILE +## UNCRUSTIFY_CFG_FILE +## CPPCHECK_FLAGS ) ## ## This macro adds all enabled code check targets for the given SOURCES. It ## filters checks based on file extensions. @@ -81,7 +82,7 @@ endforeach() macro(blt_add_code_checks) set(options ) - set(singleValueArgs PREFIX UNCRUSTIFY_CFG_FILE ASTYLE_CFG_FILE) + set(singleValueArgs PREFIX ASTYLE_CFG_FILE CLANGFORMAT_CFG_FILE UNCRUSTIFY_CFG_FILE) set(multiValueArgs SOURCES CPPCHECK_FLAGS) cmake_parse_arguments(arg @@ -431,14 +432,14 @@ endmacro(blt_add_astyle_target) ##------------------------------------------------------------------------------ ## blt_add_clangformat_target( NAME ## MODIFY_FILES [TRUE | FALSE (default)] -## CFG_FILE -## PREPEND_FLAGS -## APPEND_FLAGS +## CFG_FILE +## PREPEND_FLAGS +## APPEND_FLAGS ## COMMENT ## WORKING_DIRECTORY ## SRC_FILES [FILE1 [FILE2 ...]] ) ## -## Creates a new target with the given NAME for running clang-format over the given SRC_FILES. +## Creates a new target with the given NAME for running ClangFormat over the given SRC_FILES. ##------------------------------------------------------------------------------ macro(blt_add_clangformat_target) @@ -486,7 +487,7 @@ macro(blt_add_clangformat_target) COMMAND ${CLANGFORMAT_EXECUTABLE} ${arg_PREPEND_FLAGS} -style ${arg_CFG_FILE} ${MODIFY_FILES_FLAG} ${arg_SRC_FILES} ${arg_APPEND_FLAGS} WORKING_DIRECTORY ${_wd} - COMMENT "${arg_COMMENT}Running clang-format source code formatting checks.") + COMMENT "${arg_COMMENT}Running ClangFormat source code formatting checks.") # Hook our new target into the proper dependency chain if(${arg_MODIFY_FILES}) diff --git a/docs/api/code_check.rst b/docs/api/code_check.rst index b9b1cddf4..7f674fcf2 100644 --- a/docs/api/code_check.rst +++ b/docs/api/code_check.rst @@ -11,11 +11,12 @@ blt_add_code_checks .. code-block:: cmake - blt_add_code_checks( PREFIX - SOURCES [source1 [source2 ...]] - UNCRUSTIFY_CFG_FILE - ASTYLE_CFG_FILE - CPPCHECK_FLAGS ) + blt_add_code_checks( PREFIX + SOURCES [source1 [source2 ...]] + ASTYLE_CFG_FILE + CLANGFORMAT_CFG_FILE + UNCRUSTIFY_CFG_FILE + CPPCHECK_FLAGS ) This macro adds all enabled code check targets for the given SOURCES. @@ -26,12 +27,15 @@ PREFIX SOURCES Source list that the code checks will be ran on -UNCRUSTIFY_CFG_FILE - Path to Uncrustify config file - ASTYLE_CFG_FILE Path to AStyle config file +CLANGFORMAT_CFG_FILE + Path to ClangFormat config file + +UNCRUSTIFY_CFG_FILE + Path to Uncrustify config file + CPPCHECK_FLAGS List of flags added to Cppcheck @@ -39,23 +43,29 @@ Sources are filtered based on file extensions for use in these code checks. If 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. -This macro supports code formatting with either Uncrustify or AStyle (but not both at the same time) -only if the following requirements are met: +This macro supports 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 + +- ClangFormat + + * 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 -- AStyle - - * ASTYLE_CFG_FILE is given - * ASTYLE_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 -`__`. +`__`. This macro supports the following static analysis tools with their requirements: @@ -152,21 +162,22 @@ SRC_FILES Cppcheck is a static analysis tool for C/C++ code. More information about Cppcheck can be found `here `_. -blt_add_uncrustify_target -~~~~~~~~~~~~~~~~~~~~~~~~~ + +blt_add_astyle_target +~~~~~~~~~~~~~~~~~~~~~ .. code-block:: cmake - blt_add_uncrustify_target( NAME - MODIFY_FILES [TRUE | FALSE (default)] - CFG_FILE - PREPEND_FLAGS - APPEND_FLAGS - COMMENT - WORKING_DIRECTORY - SRC_FILES [source1 [source2 ...]] ) + blt_add_astyle_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 Uncrustify +Creates a new build target for running AStyle NAME Name of created build target @@ -175,49 +186,49 @@ MODIFY_FILES Modify the files in place. Defaults to FALSE. CFG_FILE - Path to Uncrustify config file + Path to AStyle config file PREPEND_FLAGS - Additional flags added to the front of the Uncrustify flags + Additional flags added to the front of the AStyle flags APPEND_FLAGS - Additional flags added to the end of the Uncrustify flags + Additional flags added to the end of the AStyle flags COMMENT Comment prepended to the build target output WORKING_DIRECTORY - Directory in which the Uncrustify command is run. Defaults to where macro is called. + Directory in which the AStyle command is run. Defaults to where macro is called. SRC_FILES - Source list that Uncrustify will be ran on + Source list that AStyle will be ran on -Uncrustify is a Source Code Beautifier for C/C++ code. More information about -Uncrustify can be found `here `_. +AStyle is a Source Code Beautifier for C/C++ code. More information about +AStyle 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. .. Note:: - Setting MODIFY_FILES to FALSE is only supported in Uncrustify v0.61 or greater. + Setting MODIFY_FILES to FALSE is only supported in AStyle v2.05 or greater. -blt_add_astyle_target +blt_add_clangformat_target ~~~~~~~~~~~~~~~~~~~~~ .. code-block:: cmake - blt_add_astyle_target( NAME - MODIFY_FILES [TRUE | FALSE (default)] - CFG_FILE - PREPEND_FLAGS - APPEND_FLAGS - COMMENT - WORKING_DIRECTORY - SRC_FILES [FILE1 [FILE2 ...]] ) + blt_add_clangformat_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 AStyle +Creates a new build target for running ClangFormat NAME Name of created build target @@ -226,29 +237,78 @@ MODIFY_FILES Modify the files in place. Defaults to FALSE. CFG_FILE - Path to AStyle config file + Path to ClangFormat config file PREPEND_FLAGS - Additional flags added to the front of the AStyle flags + Additional flags added to the front of the ClangFormat flags APPEND_FLAGS - Additional flags added to the end of the AStyle flags + Additional flags added to the end of the ClangFormat flags COMMENT Comment prepended to the build target output WORKING_DIRECTORY - Directory in which the AStyle command is run. Defaults to where macro is called. + Directory in which the ClangFormat command is run. Defaults to where macro is called. SRC_FILES - Source list that AStyle will be ran on + Source list that ClangFormat will be ran on -AStyle is a Source Code Beautifier for C/C++ code. More information about -AStyle can be found `here `_. +ClangFormat is a Source Code Beautifier for C/C++ code. More information about +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 +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_uncrustify_target +~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: cmake + + blt_add_uncrustify_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 Uncrustify + +NAME + Name of created build target + +MODIFY_FILES + Modify the files in place. Defaults to FALSE. + +CFG_FILE + Path to Uncrustify config file + +PREPEND_FLAGS + Additional flags added to the front of the Uncrustify flags + +APPEND_FLAGS + Additional flags added to the end of the Uncrustify flags + +COMMENT + Comment prepended to the build target output + +WORKING_DIRECTORY + Directory in which the Uncrustify command is run. Defaults to where macro is called. + +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 `_. 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 AStyle v2.05 or greater. + Setting MODIFY_FILES to FALSE is only supported in Uncrustify v0.61 or greater. From 4cd8bd4a9e72e80cce02e6eadb0769a38409621f Mon Sep 17 00:00:00 2001 From: Chris White Date: Wed, 18 Mar 2020 18:52:42 -0700 Subject: [PATCH 14/40] Fix clangcheck_style, Fix more documentation --- CONTRIBUTING.md | 5 +++-- README.md | 18 ++++++++++++------ cmake/SetupCodeChecks.cmake | 28 ++++++++++++++++++---------- docs/api/code_check.rst | 12 ++++++++++++ tests/internal/CMakeLists.txt | 21 +++++++++++++-------- 5 files changed, 58 insertions(+), 26 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5547c7d7c..f170fe08e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,8 @@ Any questions can be sent to blt-dev@llnl.gov. # Attribution We want everyone to feel they are getting the proper attribution for their -contributions. Here are some suggestions on how to get that: +contributions. Github automatically tracks contribution but if you do not feel +that is adequate. Here are some suggestions we recommend: * New files: add your name and a date to the top of the file * New functions or macros: add your name to the comment above it @@ -34,5 +35,5 @@ For example: * Matt Larsen * Martin McFadden, LLNL * Mark Miller, LLNL -* David Poliakoff, LLNL +* David Poliakoff, Sandia National Laboratories diff --git a/README.md b/README.md index a329910c3..2180790a6 100644 --- a/README.md +++ b/README.md @@ -29,13 +29,15 @@ operating systems and technologies: [FRUIT](https://sourceforge.net/projects/fortranxunit), [gbenchmark](https://github.com/google/benchmark) * Documentation: - [Doxygen](http://www.doxygen.nl/), + [Doxygen](http://www.doxygen.nl/), [Sphinx](http://www.sphinx-doc.org) - * Code style and health: - [Uncrustify](http://uncrustify.sourceforge.net), - [AStyle](http://astyle.sourceforge.net), - [Cppcheck](http://cppcheck.sourceforge.net), - [clang-query](http://clang.llvm.org/docs/LibASTMatchers.html) + * Code style: + [AStyle](http://astyle.sourceforge.net), + [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html), + [Uncrustify](http://uncrustify.sourceforge.net) + * Code quality + [clang-query](http://clang.llvm.org/docs/LibASTMatchers.html), + [Cppcheck](http://cppcheck.sourceforge.net) Getting started @@ -132,3 +134,7 @@ PackageLicenseDeclared: BSD-3-Clause PackageName: gtest PackageHomePage: https://github.com/google/googletest PackageLicenseDeclared: BSD-3-Clause + +PackageName: run-clang-format +PackageHomePage: https://github.com/Sarcasm/run-clang-format +PackageLicenseDeclared: MIT diff --git a/cmake/SetupCodeChecks.cmake b/cmake/SetupCodeChecks.cmake index 39c8c4283..4e47c4dc7 100644 --- a/cmake/SetupCodeChecks.cmake +++ b/cmake/SetupCodeChecks.cmake @@ -476,18 +476,26 @@ macro(blt_add_clangformat_target) set(_generate_target TRUE) - if(${arg_MODIFY_FILES}) - set(MODIFY_FILES_FLAG -i) - else() - set(MODIFY_FILES_FLAG --dry-run) - endif() + # 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(_generate_target) - add_custom_target(${arg_NAME} - COMMAND ${CLANGFORMAT_EXECUTABLE} ${arg_PREPEND_FLAGS} - -style ${arg_CFG_FILE} ${MODIFY_FILES_FLAG} ${arg_SRC_FILES} ${arg_APPEND_FLAGS} - WORKING_DIRECTORY ${_wd} - COMMENT "${arg_COMMENT}Running ClangFormat source code formatting checks.") + # 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}) + add_custom_target(${arg_NAME} + COMMAND ${CLANGFORMAT_EXECUTABLE} ${arg_PREPEND_FLAGS} + --style=file -i ${arg_SRC_FILES} ${arg_APPEND_FLAGS} + WORKING_DIRECTORY ${_wd} + COMMENT "${arg_COMMENT}Running ClangFormat source code formatting checks.") + else() + set(_run_clangformat "${BLT_ROOT_DIR}/cmake/run-clang-format.py" --clang-format-executable ${CLANGFORMAT_EXECUTABLE}) + add_custom_target(${arg_NAME} + COMMAND ${_run_clangformat} -j1 ${arg_SRC_FILES} + WORKING_DIRECTORY ${_wd} + COMMENT "${arg_COMMENT}Running ClangFormat source code formatting checks.") + + endif() # Hook our new target into the proper dependency chain if(${arg_MODIFY_FILES}) diff --git a/docs/api/code_check.rst b/docs/api/code_check.rst index 7f674fcf2..cb2db22e0 100644 --- a/docs/api/code_check.rst +++ b/docs/api/code_check.rst @@ -61,6 +61,9 @@ This macro supports code formatting with either AStyle, ClangFormat, or Uncrusti * 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 @@ -262,6 +265,15 @@ target to the parent `style` build target. Otherwise the files are not modified 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. + +.. 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. blt_add_uncrustify_target ~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/internal/CMakeLists.txt b/tests/internal/CMakeLists.txt index 4200bfda2..564abef57 100644 --- a/tests/internal/CMakeLists.txt +++ b/tests/internal/CMakeLists.txt @@ -266,9 +266,9 @@ if(ENABLE_CLANGQUERY) endif() #------------------------------------------------------------------------------ -# Format the testing code using AStyle +# Format the testing code using ClangFormat #------------------------------------------------------------------------------ -if(ASTYLE_FOUND) +if(CLANGFORMAT_FOUND) set(smoke_tests_srcs ../smoke/blt_cuda_mpi_smoke.cpp @@ -327,15 +327,20 @@ if(ASTYLE_FOUND) src/test_cuda_device_call_from_kernel/Parent.hpp ) + set(_cfg_file "${BLT_ROOT_DIR}/thirdparty_builtin/benchmark-1.5.0/.clang-format") + if(NOT EXISTS "${_cfg_file}") + message(FATAL_ERROR "Could not find ClangFormat style file: ${_cfg_file}") + endif() + blt_add_code_checks( - PREFIX smoke_tests - SOURCES ${smoke_tests_srcs} - ASTYLE_CFG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/astyle.cfg ) + PREFIX smoke_tests + SOURCES ${smoke_tests_srcs} + CLANGFORMAT_CFG_FILE ${_cfg_file} ) blt_add_code_checks( - PREFIX internal_tests - SOURCES ${internal_tests_srcs} - ASTYLE_CFG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/astyle.cfg ) + PREFIX internal_tests + SOURCES ${internal_tests_srcs} + CLANGFORMAT_CFG_FILE ${_cfg_file} ) endif() From 84befc81626596d9c88322929a58ba5d32f7a773 Mon Sep 17 00:00:00 2001 From: Kenny Weiss Date: Wed, 18 Mar 2020 21:14:53 -0700 Subject: [PATCH 15/40] Updates to CONTRIBUTING.md Clarifies BLT's attribution policy for contributors. --- CONTRIBUTING.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f170fe08e..e22322ab7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,12 +9,9 @@ Any questions can be sent to blt-dev@llnl.gov. # Attribution -We want everyone to feel they are getting the proper attribution for their -contributions. Github automatically tracks contribution but if you do not feel -that is adequate. Here are some suggestions we recommend: +The BLT project uses git's commit history to track contributions from individual developers. -* New files: add your name and a date to the top of the file -* New functions or macros: add your name to the comment above it +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. For example: @@ -32,7 +29,7 @@ For example: * Chip Freitag, AMD, Inc. * Elsa Gonsiorowski, LLNL * Burl Hall, LLNL -* Matt Larsen +* Matt Larsen, LLNL * Martin McFadden, LLNL * Mark Miller, LLNL * David Poliakoff, Sandia National Laboratories From e558f63a79f52592c1968b65be9528dba5c6a313 Mon Sep 17 00:00:00 2001 From: Kenny Weiss Date: Wed, 18 Mar 2020 21:31:57 -0700 Subject: [PATCH 16/40] Updates README.md Adds a link to CONTRIBUTING.md to README.md --- README.md | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 2180790a6..f99bfc43b 100644 --- a/README.md +++ b/README.md @@ -61,17 +61,21 @@ Authors Developers include: - * Chris White (white238@llnl.gov) - * Kenneth Weiss (kweiss@llnl.gov) - * Cyrus Harrison (harrison37@llnl.gov) - * George Zagaris (zagaris2@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) - -Please see the [BLT Contributors Page](https://github.com/LLNL/BLT/graphs/contributors) for the full list of project contributors. + * 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 + +Please see our [contributing guide](https://github.com/LLNL/blt/blob/develop/CONTRIBUTING.md) +for details about how to contribute to the project. + +The full list of project contributors can be found on the +[BLT Contributors Page](https://github.com/LLNL/BLT/graphs/contributors). Open-Source Projects using BLT ------------------------------ From e172d11b9e1c1a774ed674162a8f03f553642f26 Mon Sep 17 00:00:00 2001 From: Kenny Weiss Date: Wed, 18 Mar 2020 21:38:06 -0700 Subject: [PATCH 17/40] Updates CONTRIBUTING.md Removes line that is no longer relevant. --- CONTRIBUTING.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e22322ab7..158ca92e7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,12 +13,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. -For example: - -``` -# Author: John Doe @ Some Company, Inc. -``` - # Contributors (In Alphabetical Order) * Izaak Beekman From 450f0d27e78764e4b54daa1de68f855a5c9f7621 Mon Sep 17 00:00:00 2001 From: Chris White Date: Thu, 19 Mar 2020 13:38:33 -0700 Subject: [PATCH 18/40] Add missing run-clang-format --- cmake/run-clang-format.py | 406 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 406 insertions(+) create mode 100755 cmake/run-clang-format.py diff --git a/cmake/run-clang-format.py b/cmake/run-clang-format.py new file mode 100755 index 000000000..ef3fa0f47 --- /dev/null +++ b/cmake/run-clang-format.py @@ -0,0 +1,406 @@ +#!/usr/bin/env python + +from __future__ import print_function, unicode_literals + +"""MIT License + +Copyright (c) 2017 Guillaume Papin + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +""" + +"""A wrapper script around clang-format, suitable for linting multiple files +and to use for continuous integration. + +This is an alternative API for the clang-format command line. +It runs over multiple files and directories in parallel. +A diff output is produced and a sensible exit code is returned. + +""" + +import argparse +import codecs +import difflib +import fnmatch +import io +import errno +import multiprocessing +import os +import signal +import subprocess +import sys +import traceback + +from functools import partial + +try: + from subprocess import DEVNULL # py3k +except ImportError: + DEVNULL = open(os.devnull, "wb") + + +DEFAULT_EXTENSIONS = 'c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx' +DEFAULT_CLANG_FORMAT_IGNORE = '.clang-format-ignore' + + +class ExitStatus: + SUCCESS = 0 + DIFF = 1 + TROUBLE = 2 + +def excludes_from_file(ignore_file): + excludes = [] + try: + with io.open(ignore_file, 'r', encoding='utf-8') as f: + for line in f: + if line.startswith('#'): + # ignore comments + continue + pattern = line.rstrip() + if not pattern: + # allow empty lines + continue + excludes.append(pattern) + except EnvironmentError as e: + if e.errno != errno.ENOENT: + raise + return excludes; + +def list_files(files, recursive=False, extensions=None, exclude=None): + if extensions is None: + extensions = [] + if exclude is None: + exclude = [] + + out = [] + for file in files: + if recursive and os.path.isdir(file): + for dirpath, dnames, fnames in os.walk(file): + fpaths = [os.path.join(dirpath, fname) for fname in fnames] + for pattern in exclude: + # os.walk() supports trimming down the dnames list + # by modifying it in-place, + # to avoid unnecessary directory listings. + dnames[:] = [ + x for x in dnames + if + not fnmatch.fnmatch(os.path.join(dirpath, x), pattern) + ] + fpaths = [ + x for x in fpaths if not fnmatch.fnmatch(x, pattern) + ] + for f in fpaths: + ext = os.path.splitext(f)[1][1:] + if ext in extensions: + out.append(f) + else: + out.append(file) + return out + + +def make_diff(file, original, reformatted): + return list( + difflib.unified_diff( + original, + reformatted, + fromfile='{}\t(original)'.format(file), + tofile='{}\t(reformatted)'.format(file), + n=3)) + + +class DiffError(Exception): + def __init__(self, message, errs=None): + super(DiffError, self).__init__(message) + self.errs = errs or [] + + +class UnexpectedError(Exception): + def __init__(self, message, exc=None): + super(UnexpectedError, self).__init__(message) + self.formatted_traceback = traceback.format_exc() + self.exc = exc + + +def run_clang_format_diff_wrapper(args, file): + try: + ret = run_clang_format_diff(args, file) + return ret + except DiffError: + raise + except Exception as e: + raise UnexpectedError('{}: {}: {}'.format(file, e.__class__.__name__, + e), e) + + +def run_clang_format_diff(args, file): + try: + with io.open(file, 'r', encoding='utf-8') as f: + original = f.readlines() + except IOError as exc: + raise DiffError(str(exc)) + +# BLT CHANGE TO ADD FORMAT FILE + invocation = [args.clang_format_executable, "-style=file", file] +# END BLT CHANGES + + # Use of utf-8 to decode the process output. + # + # Hopefully, this is the correct thing to do. + # + # It's done due to the following assumptions (which may be incorrect): + # - clang-format will returns the bytes read from the files as-is, + # without conversion, and it is already assumed that the files use utf-8. + # - if the diagnostics were internationalized, they would use utf-8: + # > Adding Translations to Clang + # > + # > Not possible yet! + # > Diagnostic strings should be written in UTF-8, + # > the client can translate to the relevant code page if needed. + # > Each translation completely replaces the format string + # > for the diagnostic. + # > -- http://clang.llvm.org/docs/InternalsManual.html#internals-diag-translation + # + # It's not pretty, due to Python 2 & 3 compatibility. + encoding_py3 = {} + if sys.version_info[0] >= 3: + encoding_py3['encoding'] = 'utf-8' + + try: + proc = subprocess.Popen( + invocation, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + **encoding_py3) + except OSError as exc: + raise DiffError( + "Command '{}' failed to start: {}".format( + subprocess.list2cmdline(invocation), exc + ) + ) + proc_stdout = proc.stdout + proc_stderr = proc.stderr + if sys.version_info[0] < 3: + # make the pipes compatible with Python 3, + # reading lines should output unicode + encoding = 'utf-8' + proc_stdout = codecs.getreader(encoding)(proc_stdout) + proc_stderr = codecs.getreader(encoding)(proc_stderr) + # hopefully the stderr pipe won't get full and block the process + outs = list(proc_stdout.readlines()) + errs = list(proc_stderr.readlines()) + proc.wait() + if proc.returncode: + raise DiffError( + "Command '{}' returned non-zero exit status {}".format( + subprocess.list2cmdline(invocation), proc.returncode + ), + errs, + ) + return make_diff(file, original, outs), errs + + +def bold_red(s): + return '\x1b[1m\x1b[31m' + s + '\x1b[0m' + + +def colorize(diff_lines): + def bold(s): + return '\x1b[1m' + s + '\x1b[0m' + + def cyan(s): + return '\x1b[36m' + s + '\x1b[0m' + + def green(s): + return '\x1b[32m' + s + '\x1b[0m' + + def red(s): + return '\x1b[31m' + s + '\x1b[0m' + + for line in diff_lines: + if line[:4] in ['--- ', '+++ ']: + yield bold(line) + elif line.startswith('@@ '): + yield cyan(line) + elif line.startswith('+'): + yield green(line) + elif line.startswith('-'): + yield red(line) + else: + yield line + + +def print_diff(diff_lines, use_color): + if use_color: + diff_lines = colorize(diff_lines) + if sys.version_info[0] < 3: + sys.stdout.writelines((l.encode('utf-8') for l in diff_lines)) + else: + sys.stdout.writelines(diff_lines) + + +def print_trouble(prog, message, use_colors): + error_text = 'error:' + if use_colors: + error_text = bold_red(error_text) + print("{}: {} {}".format(prog, error_text, message), file=sys.stderr) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + '--clang-format-executable', + metavar='EXECUTABLE', + help='path to the clang-format executable', + default='clang-format') + parser.add_argument( + '--extensions', + help='comma separated list of file extensions (default: {})'.format( + DEFAULT_EXTENSIONS), + default=DEFAULT_EXTENSIONS) + parser.add_argument( + '-r', + '--recursive', + action='store_true', + help='run recursively over directories') + parser.add_argument('files', metavar='file', nargs='+') + parser.add_argument( + '-q', + '--quiet', + action='store_true', + help="disable output, useful for the exit code") + parser.add_argument( + '-j', + metavar='N', + type=int, + default=0, + help='run N clang-format jobs in parallel' + ' (default number of cpus + 1)') + parser.add_argument( + '--color', + default='auto', + choices=['auto', 'always', 'never'], + help='show colored diff (default: auto)') + parser.add_argument( + '-e', + '--exclude', + metavar='PATTERN', + action='append', + default=[], + help='exclude paths matching the given glob-like pattern(s)' + ' from recursive search') + + args = parser.parse_args() + + # use default signal handling, like diff return SIGINT value on ^C + # https://bugs.python.org/issue14229#msg156446 + signal.signal(signal.SIGINT, signal.SIG_DFL) + try: + signal.SIGPIPE + except AttributeError: + # compatibility, SIGPIPE does not exist on Windows + pass + else: + signal.signal(signal.SIGPIPE, signal.SIG_DFL) + + colored_stdout = False + colored_stderr = False + if args.color == 'always': + colored_stdout = True + colored_stderr = True + elif args.color == 'auto': + colored_stdout = sys.stdout.isatty() + colored_stderr = sys.stderr.isatty() + + version_invocation = [args.clang_format_executable, str("--version")] + try: + subprocess.check_call(version_invocation, stdout=DEVNULL) + except subprocess.CalledProcessError as e: + print_trouble(parser.prog, str(e), use_colors=colored_stderr) + return ExitStatus.TROUBLE + except OSError as e: + print_trouble( + parser.prog, + "Command '{}' failed to start: {}".format( + subprocess.list2cmdline(version_invocation), e + ), + use_colors=colored_stderr, + ) + return ExitStatus.TROUBLE + + retcode = ExitStatus.SUCCESS + + excludes = excludes_from_file(DEFAULT_CLANG_FORMAT_IGNORE) + excludes.extend(args.exclude) + + files = list_files( + args.files, + recursive=args.recursive, + exclude=excludes, + extensions=args.extensions.split(',')) + + if not files: + return + + njobs = args.j + if njobs == 0: + njobs = multiprocessing.cpu_count() + 1 + njobs = min(len(files), njobs) + + if njobs == 1: + # execute directly instead of in a pool, + # less overhead, simpler stacktraces + it = (run_clang_format_diff_wrapper(args, file) for file in files) + pool = None + else: + pool = multiprocessing.Pool(njobs) + it = pool.imap_unordered( + partial(run_clang_format_diff_wrapper, args), files) + while True: + try: + outs, errs = next(it) + except StopIteration: + break + except DiffError as e: + print_trouble(parser.prog, str(e), use_colors=colored_stderr) + retcode = ExitStatus.TROUBLE + sys.stderr.writelines(e.errs) + except UnexpectedError as e: + print_trouble(parser.prog, str(e), use_colors=colored_stderr) + sys.stderr.write(e.formatted_traceback) + retcode = ExitStatus.TROUBLE + # stop at the first unexpected error, + # something could be very wrong, + # don't process all files unnecessarily + if pool: + pool.terminate() + break + else: + sys.stderr.writelines(errs) + if outs == []: + continue + if not args.quiet: + print_diff(outs, use_color=colored_stdout) + if retcode == ExitStatus.SUCCESS: + retcode = ExitStatus.DIFF + return retcode + + +if __name__ == '__main__': + sys.exit(main()) From 96f0871d444f39ebbbbd9e8ed2d80339c3bb77e4 Mon Sep 17 00:00:00 2001 From: Chris White Date: Thu, 19 Mar 2020 14:04:13 -0700 Subject: [PATCH 19/40] Clarify documentation --- docs/api/code_check.rst | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/api/code_check.rst b/docs/api/code_check.rst index cb2db22e0..a59f911e1 100644 --- a/docs/api/code_check.rst +++ b/docs/api/code_check.rst @@ -39,6 +39,10 @@ UNCRUSTIFY_CFG_FILE CPPCHECK_FLAGS List of flags added to Cppcheck +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 +functionality you will need to call the individual code check macros yourself. + 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. @@ -268,12 +272,16 @@ 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. + 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}")`. .. 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. + 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 ~~~~~~~~~~~~~~~~~~~~~~~~~ From c93199be99d161deef85ab3f728c995a1bcc9797 Mon Sep 17 00:00:00 2001 From: Chris White Date: Thu, 19 Mar 2020 14:28:27 -0700 Subject: [PATCH 20/40] Revert back to astyle for code styling internal files --- tests/internal/CMakeLists.txt | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/tests/internal/CMakeLists.txt b/tests/internal/CMakeLists.txt index 564abef57..cc1ba1dc9 100644 --- a/tests/internal/CMakeLists.txt +++ b/tests/internal/CMakeLists.txt @@ -327,20 +327,14 @@ if(CLANGFORMAT_FOUND) src/test_cuda_device_call_from_kernel/Parent.hpp ) - set(_cfg_file "${BLT_ROOT_DIR}/thirdparty_builtin/benchmark-1.5.0/.clang-format") - if(NOT EXISTS "${_cfg_file}") - message(FATAL_ERROR "Could not find ClangFormat style file: ${_cfg_file}") - endif() - blt_add_code_checks( - PREFIX smoke_tests - SOURCES ${smoke_tests_srcs} - CLANGFORMAT_CFG_FILE ${_cfg_file} ) + PREFIX smoke_tests + SOURCES ${smoke_tests_srcs} + ASTYLE_CFG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/astyle.cfg ) blt_add_code_checks( - PREFIX internal_tests - SOURCES ${internal_tests_srcs} - CLANGFORMAT_CFG_FILE ${_cfg_file} ) - + PREFIX internal_tests + SOURCES ${internal_tests_srcs} + ASTYLE_CFG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/astyle.cfg ) endif() From 7a976d8fac305e3215dd79aa8f070aa368efc31c Mon Sep 17 00:00:00 2001 From: Chris White Date: Thu, 19 Mar 2020 15:25:42 -0700 Subject: [PATCH 21/40] Update RELEASE-NOTES.md --- RELEASE-NOTES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 140cab124..cb63eec0b 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -31,6 +31,8 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/ - Added support for Cray compilers in blt_append_custom_compiler_flag. - Added ability to add flags to the cppcheck command line through blt_add_code_checks() - Added ability for blt_add_test() to set required number of OpenMP threads via new option NUM_OMP_THREADS. +- Added ClangFormat as an option for code styling. This has some caveats that are noted here: + https://llnl-blt.readthedocs.io/en/develop/api/code_check.html ### Changed - Restructured the host-config directory by site and platform. From 10fc1bfad0f3efb61a14614f45485284102c86bc Mon Sep 17 00:00:00 2001 From: Chris White Date: Thu, 19 Mar 2020 16:22:21 -0700 Subject: [PATCH 22/40] Fix docs slightly --- docs/api/code_check.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/api/code_check.rst b/docs/api/code_check.rst index a59f911e1..01b023648 100644 --- a/docs/api/code_check.rst +++ b/docs/api/code_check.rst @@ -43,6 +43,11 @@ The purpose of this macro is to enable all code checks in the default manner. I 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:: + We recommend guarding your code checks against someone directly including your CMake project + in theirs. 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. @@ -217,6 +222,7 @@ When MODIFY_FILES is set to TRUE, modifies the files in place and adds the creat 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 AStyle v2.05 or greater. From 94d46135057b243af2be060dfbeb0c8d4584a45f Mon Sep 17 00:00:00 2001 From: Chris White Date: Thu, 19 Mar 2020 16:34:18 -0700 Subject: [PATCH 23/40] Fix wording. --- docs/api/code_check.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/api/code_check.rst b/docs/api/code_check.rst index 01b023648..dc9e8867f 100644 --- a/docs/api/code_check.rst +++ b/docs/api/code_check.rst @@ -44,8 +44,9 @@ all code checks from the working directory `CMAKE_BINARY_DIR`. If you need more functionality you will need to call the individual code check macros yourself. .. note:: - We recommend guarding your code checks against someone directly including your CMake project - in theirs. The following check `if ("${PROJECT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")` + 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}")` 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 From a164c967bef9bac9afed72cd1f531352fc7fe7ec Mon Sep 17 00:00:00 2001 From: Chris White Date: Tue, 14 Apr 2020 18:52:16 -0700 Subject: [PATCH 24/40] Remove travis/appveyor, add azure --- .travis.yml | 225 -------------------------------------------- README.md | 4 +- appveyor.yml | 156 ------------------------------ azure-pipelines.yml | 100 ++++++++++++++++++++ 4 files changed, 102 insertions(+), 383 deletions(-) delete mode 100644 .travis.yml delete mode 100644 appveyor.yml create mode 100644 azure-pipelines.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 20f8d2789..000000000 --- a/.travis.yml +++ /dev/null @@ -1,225 +0,0 @@ -############################################################################### -# Copyright (c) 2017, Lawrence Livermore National Security, LLC. -# -# Produced at the Lawrence Livermore National Laboratory -# -# LLNL-CODE-725085 -# -# All rights reserved. -# -# This file is part of BLT. -# -# For additional details, please also read BLT/LICENSE. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, -# this list of conditions and the disclaimer below. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the disclaimer (as noted below) in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the name of the LLNS/LLNL nor the names of its contributors may -# be used to endorse or promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, -# LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY -# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################### - -sudo: false - -language: cpp -compiler: - - gcc -env: - global: - # we need to know the root dir for our 3rd party lib installs - - TRAVIS_HOME=`pwd`/.. - - TRAVIS_TPLS_DIR=${TRAVIS_HOME}/tpls - matrix: - # gcc w/ cmake 3.8.0, gmock off - - CMAKE_MAJOR=3.8 - CMAKE_MINOR=0 - BLT_CC=gcc-4.9 - BLT_CXX=g++-4.9 - BLT_FC=gfortran-4.9 - BLT_FORTRAN=ON - BLT_OPENMP=ON - BLT_GTEST=ON - BLT_FRUIT=ON - BLT_GMOCK=OFF - # gcc w/ cmake 3.8.0, all on - - CMAKE_MAJOR=3.8 - CMAKE_MINOR=0 - BLT_CC=gcc-4.9 - BLT_CXX=g++-4.9 - BLT_FC=gfortran-4.9 - BLT_FORTRAN=ON - BLT_OPENMP=ON - BLT_GTEST=ON - BLT_FRUIT=ON - BLT_GMOCK=ON - # gcc w/ cmake 3.8.0, gtest and fruit off - - CMAKE_MAJOR=3.8 - CMAKE_MINOR=0 - BLT_CC=gcc-4.9 - BLT_CXX=g++-4.9 - BLT_FC=gfortran-4.9 - BLT_FORTRAN=ON - BLT_GTEST=OFF - BLT_FRUIT=OFF - # gcc w/ cmake 3.9.6, all on - - CMAKE_MAJOR=3.9 - CMAKE_MINOR=6 - BLT_CC=gcc-4.9 - BLT_CXX=g++-4.9 - BLT_FC=gfortran-4.9 - BLT_FORTRAN=ON - BLT_OPENMP=ON - BLT_GTEST=ON - BLT_FRUIT=ON - BLT_GMOCK=ON - # gcc w/ cmake 3.11.4, all on - - CMAKE_MAJOR=3.11 - CMAKE_MINOR=4 - BLT_CC=gcc-4.9 - BLT_CXX=g++-4.9 - BLT_FC=gfortran-4.9 - BLT_FORTRAN=ON - BLT_OPENMP=ON - BLT_GTEST=ON - BLT_FRUIT=ON - BLT_GMOCK=ON -addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - gcc-4.9 - - g++-4.9 - - gfortran-4.9 - - mpich - - libmpich-dev -before_install: - # workaround apt related for error: - # Err:6 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu trusty InRelease - # The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 1E9377A2BA9EF27F - - sudo apt update -o Acquire::Retries=100 -o Acquire::http::Timeout="60" -o Acquire::AllowInsecureRepositories=true -o Acquire::AllowDowngradeToInsecureRepositories=true - - # download the ver of cmake we want to test - - wget --no-check-certificate http://www.cmake.org/files/v${CMAKE_MAJOR}/cmake-${CMAKE_MAJOR}.${CMAKE_MINOR}-Linux-x86_64.sh -install: - # install cmake - - mkdir -p ${TRAVIS_TPLS_DIR}/cmake/ - - sh cmake-${CMAKE_MAJOR}.${CMAKE_MINOR}-Linux-x86_64.sh --skip-license --prefix=${TRAVIS_TPLS_DIR}/cmake/ - - export PATH=${TRAVIS_TPLS_DIR}/cmake/bin:$PATH -script: - # set git user info - - git config --global user.email "blt-dev@llnl.gov" - - git config --global user.name "BLT Robot" - - BLT_SOURCE_DIR=${TRAVIS_BUILD_DIR} - - cmake --version - - cd $TRAVIS_BUILD_DIR/.. - # copy our internal testing project - - cp -r blt/tests/internal blt-test - # create a git repo for blt-test to test the git macros - - cd blt-test - - git init - - git add -A - - git commit -a -m "Initial Commit" - - git checkout -b test-branch - - git tag test-tag - - cd .. - # create an out-of-source build dir and an install dir - - mkdir travis-debug-build - - mkdir travis-debug-install - # sanity check - - ls - - ls blt-test - # change into build dir - - cd travis-debug-build - # point to blt - - CMAKE_OPTS="-DBLT_SOURCE_DIR=${BLT_SOURCE_DIR}" - # build type and install loc - - CMAKE_OPTS="${CMAKE_OPTS} -DCMAKE_BUILD_TYPE=Debug" - - CMAKE_OPTS="${CMAKE_OPTS} -DCMAKE_INSTALL_PREFIX=../travis-debug-install" - # c & c++ compilers - - CMAKE_OPTS="${CMAKE_OPTS} -DCMAKE_C_COMPILER=${BLT_CC}" - - CMAKE_OPTS="${CMAKE_OPTS} -DCMAKE_CXX_COMPILER=${BLT_CXX}" - - CMAKE_OPTS="${CMAKE_OPTS} -DBLT_CXX_STD:STRING=c++11" - # gtest support - - CMAKE_OPTS="${CMAKE_OPTS} -DENABLE_GTEST=${BLT_GTEST}" - # gmock support - - CMAKE_OPTS="${CMAKE_OPTS} -DENABLE_GMOCK=${BLT_GMOCK}" - # fruit support - - CMAKE_OPTS="${CMAKE_OPTS} -DENABLE_FRUIT=${BLT_FRUIT}" - # benchmarking - - CMAKE_OPTS="${CMAKE_OPTS} -DENABLE_BENCHMARKS=ON" - # enable fortran support - - CMAKE_OPTS="${CMAKE_OPTS} -DENABLE_FORTRAN=${BLT_FORTRAN}" - - CMAKE_OPTS="${CMAKE_OPTS} -DCMAKE_Fortran_COMPILER=${BLT_FC}" - # openmp support - - CMAKE_OPTS="${CMAKE_OPTS} -DENABLE_OPENMP=${BLT_OPENMP}" - # mpi support - - CMAKE_OPTS="${CMAKE_OPTS} -DENABLE_MPI=ON" - - CMAKE_OPTS="${CMAKE_OPTS} -DMPI_C_COMPILER=mpicc" - - CMAKE_OPTS="${CMAKE_OPTS} -DMPI_CXX_COMPILER=mpicc" - - CMAKE_OPTS="${CMAKE_OPTS} -DMPI_Fortran_COMPILER=mpif90" - # test git macros - - CMAKE_OPTS="${CMAKE_OPTS} -DTEST_GIT_MACROS=ON" - # configure with cmake - - cmake ${CMAKE_OPTS} ../blt-test - # build, link, and test - - make - - env CTEST_OUTPUT_ON_FAILURE=1 make test - - make install - ######################################################### - ######################################################### - # tutorial tests - ######################################################### - ######################################################### - # override prev gtest setting, these projects req gtest - - CMAKE_OPTS="${CMAKE_OPTS} -DENABLE_GTEST=ON" - ######################################################### - # test docs/tutorial/blank_project - ######################################################### - - cd ${TRAVIS_BUILD_DIR} - - mkdir -p test-tutorial/blank_project - - cd test-tutorial/blank_project - - cmake ${CMAKE_OPTS} ${BLT_SOURCE_DIR}/docs/tutorial/blank_project - - make - - env CTEST_OUTPUT_ON_FAILURE=1 make test - - make install - ######################################################### - # test docs/tutorial/calc_pi - ######################################################### - - cd ${TRAVIS_BUILD_DIR} - - mkdir -p test-tutorial/calc_pi - - cd test-tutorial/calc_pi - - cmake ${CMAKE_OPTS} ${BLT_SOURCE_DIR}/docs/tutorial/calc_pi - - make - - env CTEST_OUTPUT_ON_FAILURE=1 make test - - make install - - - -notifications: - email: - recipients: - - cyrush@llnl.gov - on_success: always - on_failure: always diff --git a/README.md b/README.md index f99bfc43b..459c02eab 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # BLT -[![Build Status](https://travis-ci.org/LLNL/blt.svg)](https://travis-ci.org/LLNL/blt) -[![Build Status](https://ci.appveyor.com/api/projects/status/fuaftu9mvp0y488j/branch/master?svg=true)](https://ci.appveyor.com/project/cyrush/blt/branch/master) +[![Build +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 diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 035f49af6..000000000 --- a/appveyor.yml +++ /dev/null @@ -1,156 +0,0 @@ -environment: - matrix: - - CMAKE_GENERATOR: "Visual Studio 14 2015" - CONFIG: Release - BUILD_SHARED_LIBS: ON - ENABLE_GMOCK: OFF - ENABLE_BENCHMARKS: OFF - ENABLE_MPI: OFF - MPI_HOME: "C:/Program Files (x86)/Microsoft SDKs/MPI" - - CMAKE_GENERATOR: "Visual Studio 14 2015" - CONFIG: Release - BUILD_SHARED_LIBS: OFF - ENABLE_GMOCK: ON - ENABLE_BENCHMARKS: ON - ENABLE_MPI: OFF - MPI_HOME: "C:/Program Files (x86)/Microsoft SDKs/MPI" - - CMAKE_GENERATOR: "Visual Studio 14 2015" - CONFIG: Release - BUILD_SHARED_LIBS: OFF - ENABLE_GMOCK: OFF - ENABLE_BENCHMARKS: OFF - ENABLE_MPI: ON - MPI_HOME: "C:/Program Files (x86)/Microsoft SDKs/MPI" - -init: - # line endings magic - - git config --global core.autocrlf input - # set git user info - - git config --global user.email "bltdev@llnl.gov" - - git config --global user.name "BLT Robot" - -install: - # Install MS-MPI - - ps: Start-FileDownload 'https://download.microsoft.com/download/B/2/E/B2EB83FE-98C2-4156-834A-E1711E6884FB/MSMpiSetup.exe' - - MSMpiSetup.exe -unattend - - set PATH=C:\Program Files\Microsoft MPI\Bin;%PATH% - - # Install MS-MPI SDK - - ps: Start-FileDownload 'https://download.microsoft.com/download/B/2/E/B2EB83FE-98C2-4156-834A-E1711E6884FB/msmpisdk.msi' - - msmpisdk.msi /passive - - # Install CMake 3.9 - ############################################################################ - #- ps: Start-FileDownload 'https://cmake.org/files/v3.9/cmake-3.9.6-win64-x64.msi' - #- ps: Start-FileDownload 'http://portal.nersc.gov/project/visit/cmake/cmake-3.9.6-win64-x64.msi' - #- cmake-3.9.6-win64-x64.msi /passive - #- set PATH=C:\Program Files\CMake\bin;%PATH% - - cmake --version - -before_build: - # remove some noisy warnings from Xamarin - - del "C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets" - # copy blt into blt-test and setup to build there - - ps: cd .. - - mkdir build - - cp -r blt\tests\internal blt-test - # create a git repo for blt-test to test the git macros - - cd blt-test - - git init - - git add -A - - git commit -a -m "Initial Commit" - - git checkout -b test-branch - - git tag test-tag - - cd ..\build - -build_script: - ######################################################### - ######################################################### - # blt-test - ######################################################### - ######################################################### - # configure - - echo Running cmake ... - - cmake -G "%CMAKE_GENERATOR%" ^ - -D BLT_SOURCE_DIR:PATH="c:\projects\blt" ^ - -D BUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% ^ - -D ENABLE_GMOCK=%ENABLE_GMOCK% ^ - -D ENABLE_BENCHMARKS=%ENABLE_BENCHMARKS% ^ - -D ENABLE_OPENMP=ON ^ - -D BLT_CXX_STD:STRING=c++11 ^ - -D ENABLE_MPI=%ENABLE_MPI% ^ - -D MPI_C_INCLUDE_PATH:PATH="%MPI_HOME%/Include" ^ - -D MPI_C_LIBRARIES:PATH="%MPI_HOME%/Lib/x86/msmpi.lib" ^ - -D MPI_CXX_INCLUDE_PATH:PATH="%MPI_HOME%/Include" ^ - -D MPI_CXX_LIBRARIES:PATH="%MPI_HOME%/Lib/x86/msmpi.lib" ^ - -D TEST_GIT_MACROS=ON ^ - ..\blt-test - - cd .. - #build - - echo Building blt-test ... - - cmake --build build --config %CONFIG% - # run our tests - - cmake -E env CTEST_OUTPUT_ON_FAILURE=1 cmake --build build --config %CONFIG% --target RUN_TESTS - - cd .. - ######################################################### - ######################################################### - # tutorial tests - ######################################################### - ######################################################### - ######################################################### - # test docs/tutorial/blank_project - ######################################################### - - mkdir build-tutorial_blank_project - - cd build-tutorial_blank_project - - echo Running cmake ... - - cmake -G "%CMAKE_GENERATOR%" ^ - -D BLT_SOURCE_DIR:PATH="c:\projects\blt" ^ - -D BUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% ^ - -D ENABLE_GMOCK=%ENABLE_GMOCK% ^ - -D ENABLE_BENCHMARKS=%ENABLE_BENCHMARKS% ^ - -D ENABLE_OPENMP=ON ^ - -D ENABLE_MPI=%ENABLE_MPI% ^ - -D MPI_C_INCLUDE_PATH:PATH="%MPI_HOME%/Include" ^ - -D MPI_C_LIBRARIES:PATH="%MPI_HOME%/Lib/x86/msmpi.lib" ^ - -D MPI_CXX_INCLUDE_PATH:PATH="%MPI_HOME%/Include" ^ - -D MPI_CXX_LIBRARIES:PATH="%MPI_HOME%/Lib/x86/msmpi.lib" ^ - c:\projects\blt\docs\tutorial\blank_project - - cd .. - #build - - echo Building Tutorial Blank Project ... - - cmake --build build-tutorial_blank_project --config %CONFIG% - # run our tests - - cmake -E env CTEST_OUTPUT_ON_FAILURE=1 cmake --build build-tutorial_blank_project --config %CONFIG% --target RUN_TESTS - - cd .. - ######################################################### - # test docs/tutorial/calc_pi - ######################################################### - - mkdir build-tutorial_calc_pi - - cd build-tutorial_calc_pi - - cmake -G "%CMAKE_GENERATOR%" ^ - -D BLT_SOURCE_DIR:PATH="c:\projects\blt" ^ - -D BUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% ^ - -D ENABLE_GMOCK=%ENABLE_GMOCK% ^ - -D ENABLE_BENCHMARKS=%ENABLE_BENCHMARKS% ^ - -D ENABLE_OPENMP=ON ^ - -D ENABLE_MPI=%ENABLE_MPI% ^ - -D MPI_C_INCLUDE_PATH:PATH="%MPI_HOME%/Include" ^ - -D MPI_C_LIBRARIES:PATH="%MPI_HOME%/Lib/x86/msmpi.lib" ^ - -D MPI_CXX_INCLUDE_PATH:PATH="%MPI_HOME%/Include" ^ - -D MPI_CXX_LIBRARIES:PATH="%MPI_HOME%/Lib/x86/msmpi.lib" ^ - c:\projects\blt\docs\tutorial\calc_pi - - cd .. - #build - - echo Building Tutorial Calc Pi ... - - cmake --build build-tutorial_calc_pi --config %CONFIG% - # run our tests - - cmake -E env CTEST_OUTPUT_ON_FAILURE=1 cmake --build build-tutorial_calc_pi --config %CONFIG% --target RUN_TESTS - - cd .. - -on_failure: - - ps: | - Write-Output "CMakeOutput.log" - cat c:\projects\build\CMakeFiles\CMakeOutput.log - Write-Output "CMakeError.log" - cat c:\projects\build\CMakeFiles\CMakeError.log - diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 000000000..5e826556f --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,100 @@ +# 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) + +variables: + DOCKER_FLAGS: "--user='root' -v `pwd`:/blt -w /blt/build $(Compiler_ImageName)" + +strategy: + matrix: + linux_gcc7: + VM_ImageName: 'ubuntu-16.04' + Compiler_ImageName: 'axom/tpls:gcc-7' + C_COMPILER: '/usr/bin/gcc' + CXX_COMPILER: '/usr/bin/g++' + MPI_DIR: '/home/axom/axom_tpls/gcc-7.3.0/mpich-3.2.1' + MPI_FLAGS: '-DENABLE_MPI=ON -DMPI_C_COMPILER=$(MPI_DIR)/bin/mpicc -DMPI_CXX_COMPILER=$(MPI_DIR)/bin/mpicxx -DMPIEXEC=$(MPI_DIR)/bin/mpiexec -DMPIEXEC_NUMPROC_FLAG=-n' + CMAKE_FLAGS: '-DCMAKE_C_COMPILER=$(C_COMPILER) -DCMAKE_CXX_COMPILER=$(CXX_COMPILER) -DENABLE_GTEST_DEATH_TESTS=OFF $(MPI_FLAGS) -DENABLE_OPENMP=ON' + TEST_TARGET: 'linux_gcc7' + linux_gcc8: + VM_ImageName: 'ubuntu-16.04' + Compiler_ImageName: 'axom/tpls:gcc-8' + C_COMPILER: '/usr/bin/gcc' + CXX_COMPILER: '/usr/bin/g++' + MPI_DIR: '/home/axom/axom_tpls/gcc-8.1.0/mpich-3.2.1' + MPI_FLAGS: '-DENABLE_MPI=ON -DMPI_C_COMPILER=$(MPI_DIR)/bin/mpicc -DMPI_CXX_COMPILER=$(MPI_DIR)/bin/mpicxx -DMPIEXEC=$(MPI_DIR)/bin/mpiexec -DMPIEXEC_NUMPROC_FLAG=-n' + CMAKE_FLAGS: '-DCMAKE_C_COMPILER=$(C_COMPILER) -DCMAKE_CXX_COMPILER=$(CXX_COMPILER) -DENABLE_GTEST_DEATH_TESTS=OFF $(MPI_FLAGS) -DENABLE_OPENMP=ON' + TEST_TARGET: 'linux_gcc8' + linux_clang4: + VM_ImageName: 'ubuntu-16.04' + Compiler_ImageName: 'axom/tpls:clang-4' + C_COMPILER: '/usr/bin/clang' + CXX_COMPILER: '/usr/bin/clang++' + MPI_DIR: '/home/axom/axom_tpls/clang-4.0.0/mpich-3.0.4' + MPI_FLAGS: '-DENABLE_MPI=ON -DMPI_C_COMPILER=$(MPI_DIR)/bin/mpicc -DMPI_CXX_COMPILER=$(MPI_DIR)/bin/mpicxx -DMPIEXEC=$(MPI_DIR)/bin/mpiexec -DMPIEXEC_NUMPROC_FLAG=-n' + CMAKE_FLAGS: '-DCMAKE_C_COMPILER=$(C_COMPILER) -DCMAKE_CXX_COMPILER=$(CXX_COMPILER) -DENABLE_GTEST_DEATH_TESTS=OFF $(MPI_FLAGS) -DENABLE_OPENMP=ON' + TEST_TARGET: 'linux_clang4' + linux_clang6: + VM_ImageName: 'ubuntu-16.04' + Compiler_ImageName: 'axom/tpls:clang-6' + C_COMPILER: '/usr/bin/clang' + CXX_COMPILER: '/usr/bin/clang++' + MPI_DIR: '/home/axom/axom_tpls/clang-6.0.0/mpich-3.0.4' + MPI_FLAGS: '-DENABLE_MPI=ON -DMPI_C_COMPILER=$(MPI_DIR)/bin/mpicc -DMPI_CXX_COMPILER=$(MPI_DIR)/bin/mpicxx -DMPIEXEC=$(MPI_DIR)/bin/mpiexec -DMPIEXEC_NUMPROC_FLAG=-n' + CMAKE_FLAGS: '-DCMAKE_C_COMPILER=$(C_COMPILER) -DCMAKE_CXX_COMPILER=$(CXX_COMPILER) -DENABLE_GTEST_DEATH_TESTS=OFF $(MPI_FLAGS) -DENABLE_OPENMP=ON' + TEST_TARGET: 'linux_clang6' + osx_gcc: + VM_ImageName: 'macos-10.14' + CMAKE_FLAGS: '' + TEST_TARGET: 'osx_gcc' + windows: + VM_ImageName: 'windows-2019' + CMAKE_FLAGS: '' + TEST_TARGET: 'win_vs' + +pool: + vmImage: $(VM_ImageName) + +steps: +# All +- checkout: self + clean: true + +# OSX and Windows +- task: CMake@1 + inputs: + workingDir: 'build' + cmakeArgs: '$(CMAKE_FLAGS) ../tests/internal' + condition: or( eq( variables['Agent.OS'], 'Windows_NT'), eq( variables['Agent.OS'], 'Darwin')) +- script: | + cmake --build build --config Release + displayName: 'OSX/Windows Build' + condition: or( eq( variables['Agent.OS'], 'Windows_NT'), eq( variables['Agent.OS'], 'Darwin')) +- script: | + cd build + ctest -C Release -T Test --output-on-failure -V + displayName: 'OSX/Windows Test' + condition: or( eq( variables['Agent.OS'], 'Windows_NT'), eq( variables['Agent.OS'], 'Darwin')) + +# Linux +- script: | + docker run $(DOCKER_FLAGS) cmake $(CMAKE_FLAGS) ../tests/internal + condition: eq( variables['Agent.OS'], 'Linux') + displayName: 'Linux CMake' +- script: | + docker run $(DOCKER_FLAGS) make -j2 + condition: eq( variables['Agent.OS'], 'Linux') + displayName: 'Linux Build' +- script: | + docker run $(DOCKER_FLAGS) ctest -T Test --output-on-failure -V + condition: eq( variables['Agent.OS'], 'Linux') + displayName: 'Linux Test' + +# All +- task: PublishTestResults@2 + inputs: + testResultsFormat: 'cTest' + testResultsFiles: 'build/Testing/*/Test.xml' + testRunTitle: '$(TEST_TARGET) Tests' + failTaskOnFailedTests: true From 5f1316c669c3a9a15a94ecab6f243d85cbccedbb Mon Sep 17 00:00:00 2001 From: Chris White Date: Tue, 14 Apr 2020 18:52:50 -0700 Subject: [PATCH 25/40] Update docs --- docs/api/target.rst | 52 +++++++++++++++++++++++++---------- tests/internal/CMakeLists.txt | 3 ++ 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/docs/api/target.rst b/docs/api/target.rst index b4af96ec5..075fcfad8 100644 --- a/docs/api/target.rst +++ b/docs/api/target.rst @@ -75,27 +75,46 @@ blt_add_executable OUTPUT_DIR [dir] FOLDER [name]) -Adds an executable target, called , to be built from the given sources. +Adds an executable target to the project. -The INCLUDES argument allows you to define what include directories are -needed to compile this executable. +NAME + Name of the created CMake target -The DEFINES argument allows you to add needed compiler definitions that are -needed to compile this executable. +SOURCES + List of all sources to be added -If given a DEPENDS_ON argument, it will add the necessary includes and -libraries if they are already registered with blt_register_library. If -not it will add them as a cmake target dependency. +INCLUDES + List of include directories both used by this target and inherited by dependent + targets -The OUTPUT_DIR is used to control the build output directory of this -executable. This is used to overwrite the default bin directory. +DEFINES + List of compiler defines both used by this target and inherited by dependent + targets -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 ) -FOLDER is an optional keyword to organize the target into a folder in an IDE. +DEPENDS_ON + List of CMake targets and BLT registered libraries that this target + depends on + +OUTPUT_DIR + Directory that this target will built to, defaults to bin + +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 +macro creates a true CMake target that can be altered by other CMake commands +like normal, such as `set_target_property()`. + +.. 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 ) + +.. 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. -This is available when ENABLE_FOLDERS is ON and when using a cmake generator -that supports this feature and will otherwise be ignored. .. _blt_add_library: @@ -159,6 +178,9 @@ CLEAR_PREFIX 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()`. + This macro supports three types of libraries automatically: normal, header-only, or object. diff --git a/tests/internal/CMakeLists.txt b/tests/internal/CMakeLists.txt index cc1ba1dc9..0779b0b9a 100644 --- a/tests/internal/CMakeLists.txt +++ b/tests/internal/CMakeLists.txt @@ -338,3 +338,6 @@ if(CLANGFORMAT_FOUND) ASTYLE_CFG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/astyle.cfg ) endif() + +# Add tutorials +add_subdirectory(../../docs/tutorial/calc_pi calc_pi) From 5c0fc35aeeb016b38e8d4b6b973554940f3e7eee Mon Sep 17 00:00:00 2001 From: Chris White Date: Tue, 21 Apr 2020 11:42:15 -0700 Subject: [PATCH 26/40] Fix duplicate MPI link flag --- RELEASE-NOTES.md | 1 + cmake/thirdparty/SetupMPI.cmake | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index cb63eec0b..b643fbcd9 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -41,6 +41,7 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/ ### Fixed - Fixed some warnings in CMake 3.14+ +- Duplication of MPI link flags in CMake 3.14+ when Fortran was enabled. ## [Version 0.2.5] - Release date 2019-06-13 diff --git a/cmake/thirdparty/SetupMPI.cmake b/cmake/thirdparty/SetupMPI.cmake index 9c475fdfd..577b4c4b6 100644 --- a/cmake/thirdparty/SetupMPI.cmake +++ b/cmake/thirdparty/SetupMPI.cmake @@ -84,8 +84,9 @@ if (ENABLE_FIND_MPI) list(APPEND _mpi_link_flags ${MPI_CXX_LINK_FLAGS}) endif() if (ENABLE_FORTRAN) - if (NOT "${MPI_C_LINK_FLAGS}" STREQUAL "${MPI_Fortran_LINK_FLAGS}") - list(APPEND _mpi_link_flags ${MPI_CXX_LINK_FLAGS}) + if ((NOT "${MPI_C_LINK_FLAGS}" STREQUAL "${MPI_Fortran_LINK_FLAGS}") AND + (NOT "${MPI_CXX_LINK_FLAGS}" STREQUAL "${MPI_Fortran_LINK_FLAGS}")) + list(APPEND _mpi_link_flags ${MPI_Fortran_LINK_FLAGS}) endif() endif() # Fixes for linking with NVCC From ba02d27499e7a839a8ecc6bf43cda4cfd4c41fa6 Mon Sep 17 00:00:00 2001 From: Chris White Date: Wed, 22 Apr 2020 13:29:56 -0700 Subject: [PATCH 27/40] Very selectively remove possible spaces in link flags --- cmake/thirdparty/SetupMPI.cmake | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmake/thirdparty/SetupMPI.cmake b/cmake/thirdparty/SetupMPI.cmake index 577b4c4b6..cae17d21f 100644 --- a/cmake/thirdparty/SetupMPI.cmake +++ b/cmake/thirdparty/SetupMPI.cmake @@ -38,8 +38,11 @@ if (ENABLE_FIND_MPI) #------------------- # Merge found MPI info and remove duplication + #------------------- + #------------------- # Compile flags + #------------------- set(_c_flag ${MPI_C_${_mpi_compile_flags_suffix}}) if (_c_flag AND ENABLE_CUDA) list(APPEND _mpi_compile_flags @@ -70,7 +73,9 @@ if (ENABLE_FIND_MPI) unset(_cxx_flag) unset(_f_flag) + #------------------- # Include paths + #------------------- list(APPEND _mpi_includes ${MPI_C_${_mpi_includes_suffix}} ${MPI_CXX_${_mpi_includes_suffix}}) if (ENABLE_FORTRAN) @@ -78,7 +83,9 @@ if (ENABLE_FIND_MPI) endif() blt_list_remove_duplicates(TO _mpi_includes) + #------------------- # Link flags + #------------------- set(_mpi_link_flags ${MPI_C_LINK_FLAGS}) if (NOT "${MPI_C_LINK_FLAGS}" STREQUAL "${MPI_CXX_LINK_FLAGS}") list(APPEND _mpi_link_flags ${MPI_CXX_LINK_FLAGS}) @@ -89,6 +96,11 @@ if (ENABLE_FIND_MPI) list(APPEND _mpi_link_flags ${MPI_Fortran_LINK_FLAGS}) endif() endif() + + # Selectively remove set of known locations of spaces + string(REPLACE " -Wl" ";-Wl" _mpi_link_flags "${_mpi_link_flags}") + string(REPLACE " -L" ";-L" _mpi_link_flags "${_mpi_link_flags}") + # Fixes for linking with NVCC if (CUDA_LINK_WITH_NVCC) # Convert rpath flag if linking with CUDA @@ -99,7 +111,9 @@ if (ENABLE_FIND_MPI) _mpi_link_flags "${_mpi_link_flags}") endif() + #------------------- # Libraries + #------------------- set(_mpi_libraries ${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES}) if (ENABLE_FORTRAN) list(APPEND _mpi_libraries ${MPI_Fortran_LIBRARIES}) From ef9977c005e23802729ca5f62e365a646a25be9b Mon Sep 17 00:00:00 2001 From: Chris White Date: Wed, 22 Apr 2020 13:55:43 -0700 Subject: [PATCH 28/40] Add space --- docs/tutorial/calc_pi/example_2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tutorial/calc_pi/example_2.cpp b/docs/tutorial/calc_pi/example_2.cpp index ab61beeba..5a1be6d86 100644 --- a/docs/tutorial/calc_pi/example_2.cpp +++ b/docs/tutorial/calc_pi/example_2.cpp @@ -40,4 +40,4 @@ int main(int argc, char * argv[] ) << fabs(pi - PI_REF) << std::endl; -} \ No newline at end of file +} From 017bcf397d45902bfe033fd7f4b7cfe94b8f9559 Mon Sep 17 00:00:00 2001 From: George Zagaris Date: Mon, 27 Apr 2020 15:52:00 -0700 Subject: [PATCH 29/40] ENH: add NVIDIA SDK path to the CUDA link flags This commit adds the path to the NVDIA SDK libraries to the CMAKE_CUDA_LINK_FLAGS. Moreover, it ensures that these link flags are specified to the registered CUDA library that is used with BLT. This allows applications to link additional libraries that are supplied with the NVIDIA SDK by listing them in the list of dependencies, e.g., nvToolsExt, cublas, etc. In addition, CMAKE_CUDA_LINK_FLAGS may also be specified in a host-config or at the command line and those will now be correctly propagated and associated with BLT's registered CUDA library. --- cmake/thirdparty/SetupCUDA.cmake | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cmake/thirdparty/SetupCUDA.cmake b/cmake/thirdparty/SetupCUDA.cmake index a574b920e..8b4a61022 100644 --- a/cmake/thirdparty/SetupCUDA.cmake +++ b/cmake/thirdparty/SetupCUDA.cmake @@ -7,6 +7,15 @@ # Sanity Checks ################################ +# Ensure CUDA_TOOLKIT_ROOT_DIR is specified, since it is needed +# by the call to find_package(CUDA) below. +if (NOT DEFINED CUDA_TOOLKIT_ROOT_DIR) + message( FATAL_ERROR + "Please specify CUDA_TOOLKIT_ROOT_DIR to use CUDA" ) +endif() + +blt_assert_exists( DIRECTORIES ${CUDA_TOOLKIT_ROOT_DIR} ) + # Rare case of two flags being incompatible if (DEFINED CMAKE_SKIP_BUILD_RPATH AND DEFINED CUDA_LINK_WITH_NVCC) if (NOT CMAKE_SKIP_BUILD_RPATH AND CUDA_LINK_WITH_NVCC) @@ -88,7 +97,16 @@ endif() find_package(CUDA REQUIRED) +# Append the path to the NVIDIA SDK to the link flags +if ( IS_DIRECTORY "${CUDA_TOOLKIT_ROOT_DIR}/lib64" ) + list(APPEND CMAKE_CUDA_LINK_FLAGS "-L${CUDA_TOOLKIT_ROOT_DIR}/lib64" ) +endif() +if ( IS_DIRECTORY "${CUDA_TOOLKIT_ROOT_DIR}/lib}" ) + list(APPEND CMAKE_CUDA_LINK_FLAGS "-L${CUDA_TOOLKIT_ROOT_DIR}/lib" ) +endif() + message(STATUS "CUDA Version: ${CUDA_VERSION_STRING}") +message(STATUS "CUDA Toolkit Root Dir: ${CUDA_TOOLKIT_ROOT_DIR}") message(STATUS "CUDA Compiler: ${CMAKE_CUDA_COMPILER}") if( ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.9.0" ) message(STATUS "CUDA Host Compiler: ${CMAKE_CUDA_HOST_COMPILER}") @@ -125,7 +143,9 @@ endif() blt_register_library(NAME cuda COMPILE_FLAGS ${_cuda_compile_flags} INCLUDES ${CUDA_INCLUDE_DIRS} - LIBRARIES ${CUDA_LIBRARIES}) + LIBRARIES ${CUDA_LIBRARIES} + LINK_FLAGS "${CMAKE_CUDA_LINK_FLAGS}" + ) # same as 'cuda' but we don't flag your source files as # CUDA language. This causes your source files to use From 24004ac245ccb94259ab7d3e39657b86b33c158f Mon Sep 17 00:00:00 2001 From: George Zagaris Date: Mon, 27 Apr 2020 20:37:53 -0700 Subject: [PATCH 30/40] ENH: specify explicitly path to CMake on Linux CI --- azure-pipelines.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5e826556f..84600b697 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -13,6 +13,7 @@ strategy: Compiler_ImageName: 'axom/tpls:gcc-7' C_COMPILER: '/usr/bin/gcc' CXX_COMPILER: '/usr/bin/g++' + CMAKE_BIN_DIR: '/home/axom/axom_tpls/gcc-7.3.0/cmake-3.9.6/bin' MPI_DIR: '/home/axom/axom_tpls/gcc-7.3.0/mpich-3.2.1' MPI_FLAGS: '-DENABLE_MPI=ON -DMPI_C_COMPILER=$(MPI_DIR)/bin/mpicc -DMPI_CXX_COMPILER=$(MPI_DIR)/bin/mpicxx -DMPIEXEC=$(MPI_DIR)/bin/mpiexec -DMPIEXEC_NUMPROC_FLAG=-n' CMAKE_FLAGS: '-DCMAKE_C_COMPILER=$(C_COMPILER) -DCMAKE_CXX_COMPILER=$(CXX_COMPILER) -DENABLE_GTEST_DEATH_TESTS=OFF $(MPI_FLAGS) -DENABLE_OPENMP=ON' @@ -22,6 +23,7 @@ strategy: Compiler_ImageName: 'axom/tpls:gcc-8' C_COMPILER: '/usr/bin/gcc' CXX_COMPILER: '/usr/bin/g++' + CMAKE_BIN_DIR: '/home/axom/axom_tpls/gcc-8.1.0/cmake-3.9.6/bin' MPI_DIR: '/home/axom/axom_tpls/gcc-8.1.0/mpich-3.2.1' MPI_FLAGS: '-DENABLE_MPI=ON -DMPI_C_COMPILER=$(MPI_DIR)/bin/mpicc -DMPI_CXX_COMPILER=$(MPI_DIR)/bin/mpicxx -DMPIEXEC=$(MPI_DIR)/bin/mpiexec -DMPIEXEC_NUMPROC_FLAG=-n' CMAKE_FLAGS: '-DCMAKE_C_COMPILER=$(C_COMPILER) -DCMAKE_CXX_COMPILER=$(CXX_COMPILER) -DENABLE_GTEST_DEATH_TESTS=OFF $(MPI_FLAGS) -DENABLE_OPENMP=ON' @@ -31,6 +33,7 @@ strategy: Compiler_ImageName: 'axom/tpls:clang-4' C_COMPILER: '/usr/bin/clang' CXX_COMPILER: '/usr/bin/clang++' + CMAKE_BIN_DIR: '/home/axom/axom_tpls/clang-4.0.0/cmake-3.10.1/bin' MPI_DIR: '/home/axom/axom_tpls/clang-4.0.0/mpich-3.0.4' MPI_FLAGS: '-DENABLE_MPI=ON -DMPI_C_COMPILER=$(MPI_DIR)/bin/mpicc -DMPI_CXX_COMPILER=$(MPI_DIR)/bin/mpicxx -DMPIEXEC=$(MPI_DIR)/bin/mpiexec -DMPIEXEC_NUMPROC_FLAG=-n' CMAKE_FLAGS: '-DCMAKE_C_COMPILER=$(C_COMPILER) -DCMAKE_CXX_COMPILER=$(CXX_COMPILER) -DENABLE_GTEST_DEATH_TESTS=OFF $(MPI_FLAGS) -DENABLE_OPENMP=ON' @@ -40,6 +43,7 @@ strategy: Compiler_ImageName: 'axom/tpls:clang-6' C_COMPILER: '/usr/bin/clang' CXX_COMPILER: '/usr/bin/clang++' + CMAKE_BIN_DIR: '/home/axom/axom_tpls/clang-6.0.0/cmake-3.10.1/bin' MPI_DIR: '/home/axom/axom_tpls/clang-6.0.0/mpich-3.0.4' MPI_FLAGS: '-DENABLE_MPI=ON -DMPI_C_COMPILER=$(MPI_DIR)/bin/mpicc -DMPI_CXX_COMPILER=$(MPI_DIR)/bin/mpicxx -DMPIEXEC=$(MPI_DIR)/bin/mpiexec -DMPIEXEC_NUMPROC_FLAG=-n' CMAKE_FLAGS: '-DCMAKE_C_COMPILER=$(C_COMPILER) -DCMAKE_CXX_COMPILER=$(CXX_COMPILER) -DENABLE_GTEST_DEATH_TESTS=OFF $(MPI_FLAGS) -DENABLE_OPENMP=ON' @@ -79,7 +83,7 @@ steps: # Linux - script: | - docker run $(DOCKER_FLAGS) cmake $(CMAKE_FLAGS) ../tests/internal + docker run $(DOCKER_FLAGS) $(CMAKE_BIN_DIR)/cmake $(CMAKE_FLAGS) ../tests/internal condition: eq( variables['Agent.OS'], 'Linux') displayName: 'Linux CMake' - script: | @@ -87,7 +91,7 @@ steps: condition: eq( variables['Agent.OS'], 'Linux') displayName: 'Linux Build' - script: | - docker run $(DOCKER_FLAGS) ctest -T Test --output-on-failure -V + docker run $(DOCKER_FLAGS) $(CMAKE_BIN_DIR)/ctest -T Test --output-on-failure -V condition: eq( variables['Agent.OS'], 'Linux') displayName: 'Linux Test' From d01ca350f5ac14babfa280ab6741cd71cadea5f3 Mon Sep 17 00:00:00 2001 From: George Zagaris Date: Mon, 27 Apr 2020 18:16:51 -0700 Subject: [PATCH 31/40] DOC: document updates for CUDA in RELEASE-NOTES --- RELEASE-NOTES.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index b643fbcd9..20c32037d 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -11,6 +11,13 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/ ### 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 + or at the command-line. + +### Changed +- ``CUDA_TOOLKIT_ROOT_DIR`` must now be set in order to use CUDA. If it is not + specified, BLT will produce an error message. ## [Version 0.3.0] - Release date 2020-01-08 From 5efce769ee72952d7a181e85e9666aed540f9093 Mon Sep 17 00:00:00 2001 From: George Zagaris Date: Tue, 28 Apr 2020 09:43:01 -0700 Subject: [PATCH 32/40] BUGFIX: fix CMake path/version on Linux_gcc8 CI --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 84600b697..0eb0fcb8f 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -23,7 +23,7 @@ strategy: Compiler_ImageName: 'axom/tpls:gcc-8' C_COMPILER: '/usr/bin/gcc' CXX_COMPILER: '/usr/bin/g++' - CMAKE_BIN_DIR: '/home/axom/axom_tpls/gcc-8.1.0/cmake-3.9.6/bin' + CMAKE_BIN_DIR: '/home/axom/axom_tpls/gcc-8.1.0/cmake-3.10.1/bin' MPI_DIR: '/home/axom/axom_tpls/gcc-8.1.0/mpich-3.2.1' MPI_FLAGS: '-DENABLE_MPI=ON -DMPI_C_COMPILER=$(MPI_DIR)/bin/mpicc -DMPI_CXX_COMPILER=$(MPI_DIR)/bin/mpicxx -DMPIEXEC=$(MPI_DIR)/bin/mpiexec -DMPIEXEC_NUMPROC_FLAG=-n' CMAKE_FLAGS: '-DCMAKE_C_COMPILER=$(C_COMPILER) -DCMAKE_CXX_COMPILER=$(CXX_COMPILER) -DENABLE_GTEST_DEATH_TESTS=OFF $(MPI_FLAGS) -DENABLE_OPENMP=ON' From 7012458ee58acd32ed57a886ab89a5a22e453b38 Mon Sep 17 00:00:00 2001 From: George Zagaris Date: Tue, 28 Apr 2020 09:59:35 -0700 Subject: [PATCH 33/40] BUGFIX: correct path to MPI for Linux_gcc8 CI --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 0eb0fcb8f..96ff2a38d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -24,7 +24,7 @@ strategy: C_COMPILER: '/usr/bin/gcc' CXX_COMPILER: '/usr/bin/g++' CMAKE_BIN_DIR: '/home/axom/axom_tpls/gcc-8.1.0/cmake-3.10.1/bin' - MPI_DIR: '/home/axom/axom_tpls/gcc-8.1.0/mpich-3.2.1' + MPI_DIR: '/home/axom/axom_tpls/gcc-8.1.0/mpich-3.3.2' MPI_FLAGS: '-DENABLE_MPI=ON -DMPI_C_COMPILER=$(MPI_DIR)/bin/mpicc -DMPI_CXX_COMPILER=$(MPI_DIR)/bin/mpicxx -DMPIEXEC=$(MPI_DIR)/bin/mpiexec -DMPIEXEC_NUMPROC_FLAG=-n' CMAKE_FLAGS: '-DCMAKE_C_COMPILER=$(C_COMPILER) -DCMAKE_CXX_COMPILER=$(CXX_COMPILER) -DENABLE_GTEST_DEATH_TESTS=OFF $(MPI_FLAGS) -DENABLE_OPENMP=ON' TEST_TARGET: 'linux_gcc8' From 07dfe253523cf73d5195d38dc9e9813e33b7b90f Mon Sep 17 00:00:00 2001 From: Chris White Date: Tue, 28 Apr 2020 15:55:23 -0700 Subject: [PATCH 34/40] Fix property flag for CMake 3.13+, Fix another extra space --- cmake/BLTPrivateMacros.cmake | 15 ++++++++++----- cmake/thirdparty/SetupMPI.cmake | 5 +++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cmake/BLTPrivateMacros.cmake b/cmake/BLTPrivateMacros.cmake index 32337c480..584872400 100644 --- a/cmake/BLTPrivateMacros.cmake +++ b/cmake/BLTPrivateMacros.cmake @@ -84,17 +84,22 @@ function(blt_error_if_target_exists target_name error_msg) endfunction() ##----------------------------------------------------------------------------- -## blt_fix_fortran_openmp_flags() +## blt_fix_fortran_openmp_flags() ## ## Fixes the openmp flags for a Fortran target if they are different from the -## corresponding C/C++ openmp flags. +## corresponding C/C++ OpenMP flags. ##----------------------------------------------------------------------------- function(blt_fix_fortran_openmp_flags target_name) - if (ENABLE_FORTRAN AND ENABLE_OPENMP AND BLT_OPENMP_FLAGS_DIFFER) - get_target_property(target_link_flags ${target_name} LINK_FLAGS) + 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 ) message(STATUS "Fixing OpenMP Flags for target[${target_name}]") @@ -104,7 +109,7 @@ function(blt_fix_fortran_openmp_flags target_name) "${target_link_flags}" ) - set_target_properties( ${target_name} PROPERTIES LINK_FLAGS + set_target_properties( ${target_name} PROPERTIES ${_property_name} "${correct_link_flags}" ) endif() diff --git a/cmake/thirdparty/SetupMPI.cmake b/cmake/thirdparty/SetupMPI.cmake index cae17d21f..bfb131e2f 100644 --- a/cmake/thirdparty/SetupMPI.cmake +++ b/cmake/thirdparty/SetupMPI.cmake @@ -98,8 +98,9 @@ if (ENABLE_FIND_MPI) endif() # Selectively remove set of known locations of spaces - string(REPLACE " -Wl" ";-Wl" _mpi_link_flags "${_mpi_link_flags}") - string(REPLACE " -L" ";-L" _mpi_link_flags "${_mpi_link_flags}") + string(REPLACE " -Wl" ";-Wl" _mpi_link_flags "${_mpi_link_flags}") + string(REPLACE " -L" ";-L" _mpi_link_flags "${_mpi_link_flags}") + string(REPLACE " -pthread" ";-pthread" _mpi_link_flags "${_mpi_link_flags}") # Fixes for linking with NVCC if (CUDA_LINK_WITH_NVCC) From aea25d35a07169df4d5586f3200926e4b99ab211 Mon Sep 17 00:00:00 2001 From: Sergey Klevtsov Date: Wed, 29 Apr 2020 01:35:52 -0700 Subject: [PATCH 35/40] Fix a typo in SetupMPI.cmake --- cmake/thirdparty/SetupMPI.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/thirdparty/SetupMPI.cmake b/cmake/thirdparty/SetupMPI.cmake index bfb131e2f..c618dc3c2 100644 --- a/cmake/thirdparty/SetupMPI.cmake +++ b/cmake/thirdparty/SetupMPI.cmake @@ -65,7 +65,7 @@ if (ENABLE_FIND_MPI) if (ENABLE_FORTRAN) set(_f_flag ${MPI_Fortran_${_mpi_compile_flags_suffix}}) - if (_f_flag AND NOT "${c_flg}" STREQUAL "${_f_flag}") + if (_f_flag AND NOT "${_c_flag}" STREQUAL "${_f_flag}") list(APPEND _mpi_compile_flags ${_f_flag}) endif() endif() From ac32e2cdabd6fc5a90264b696f8c3403b55ed00f Mon Sep 17 00:00:00 2001 From: Chris White Date: Mon, 1 Jun 2020 17:39:52 -0700 Subject: [PATCH 36/40] Fix bug in blt_add_test for executables that are not targets (#365) Guard against non-target executables in blt_add_test --- RELEASE-NOTES.md | 3 +++ azure-pipelines.yml | 9 +++++---- cmake/BLTMacros.cmake | 31 +++++++++++++++++++---------- tests/internal/CMakeLists.txt | 11 ++++++++++ tests/internal/return_true.in | 3 +++ tests/internal/return_true_win32.in | 1 + 6 files changed, 43 insertions(+), 15 deletions(-) create mode 100755 tests/internal/return_true.in create mode 100644 tests/internal/return_true_win32.in diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 20c32037d..f449a1284 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -19,6 +19,9 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/ - ``CUDA_TOOLKIT_ROOT_DIR`` must now be set in order to use CUDA. If it is not specified, BLT will produce an error message. +### Fixed +- blt_add_test is no longer trying to extract target properties from non-targets. + ## [Version 0.3.0] - Release date 2020-01-08 ### Added diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 96ff2a38d..d6ff65ae4 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -66,10 +66,11 @@ steps: clean: true # OSX and Windows -- task: CMake@1 - inputs: - workingDir: 'build' - cmakeArgs: '$(CMAKE_FLAGS) ../tests/internal' +- script: | + mkdir build + cd build + cmake $(CMAKE_FLAGS) ../tests/internal + displayName: 'OSX/Windows CMake' condition: or( eq( variables['Agent.OS'], 'Windows_NT'), eq( variables['Agent.OS'], 'Darwin')) - script: | cmake --build build --config Release diff --git a/cmake/BLTMacros.cmake b/cmake/BLTMacros.cmake index bceec7d0d..5dc382b36 100644 --- a/cmake/BLTMacros.cmake +++ b/cmake/BLTMacros.cmake @@ -667,23 +667,32 @@ macro(blt_add_test) endif() # Extract test directory and executable from arg_NAME and arg_COMMAND - if ( NOT TARGET ${arg_NAME} ) + set(_test_directory) + if(NOT TARGET ${arg_NAME}) # Handle cases where multiple tests are run against one executable # the NAME will not be the target - list(GET arg_COMMAND 0 test_executable) - get_target_property(test_directory ${test_executable} RUNTIME_OUTPUT_DIRECTORY ) + list(GET arg_COMMAND 0 _test_executable) + if(TARGET ${_test_executable}) + get_target_property(_test_directory ${_test_executable} RUNTIME_OUTPUT_DIRECTORY ) + endif() else() - set(test_executable ${arg_NAME}) - get_target_property(test_directory ${arg_NAME} RUNTIME_OUTPUT_DIRECTORY ) + set(_test_executable ${arg_NAME}) + get_target_property(_test_directory ${arg_NAME} RUNTIME_OUTPUT_DIRECTORY ) endif() # Append the test_directory to the test argument, accounting for multi-config generators if(NOT CMAKE_CONFIGURATION_TYPES) - set(test_command ${test_directory}/${arg_COMMAND} ) + if(NOT "${_test_directory}" STREQUAL "") + set(_test_command ${_test_directory}/${arg_COMMAND} ) + else() + set(_test_command ${arg_COMMAND}) + endif() else() - list(INSERT arg_COMMAND 0 "$") - list(REMOVE_AT arg_COMMAND 1) - set(test_command ${arg_COMMAND}) + if(TARGET ${_test_executable}) + list(INSERT arg_COMMAND 0 "$") + list(REMOVE_AT arg_COMMAND 1) + endif() + set(_test_command ${arg_COMMAND}) endif() # If configuration option ENABLE_WRAP_ALL_TESTS_WITH_MPIEXEC is set, @@ -702,11 +711,11 @@ macro(blt_add_test) set(_mpiexec ${MPIEXEC}) endif() - set(test_command ${_mpiexec} ${MPIEXEC_NUMPROC_FLAG} ${arg_NUM_MPI_TASKS} ${BLT_MPI_COMMAND_APPEND} ${test_command} ) + set(_test_command ${_mpiexec} ${MPIEXEC_NUMPROC_FLAG} ${arg_NUM_MPI_TASKS} ${BLT_MPI_COMMAND_APPEND} ${_test_command} ) endif() add_test(NAME ${arg_NAME} - COMMAND ${test_command} + COMMAND ${_test_command} CONFIGURATIONS ${arg_CONFIGURATIONS}) # Handle OpenMP diff --git a/tests/internal/CMakeLists.txt b/tests/internal/CMakeLists.txt index 0779b0b9a..321e8362c 100644 --- a/tests/internal/CMakeLists.txt +++ b/tests/internal/CMakeLists.txt @@ -339,5 +339,16 @@ if(CLANGFORMAT_FOUND) endif() +# 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) + blt_add_test(NAME test_executable_not_a_target + COMMAND tests/return_true.bat) +else() + configure_file(return_true.in tests/return_true COPYONLY) + blt_add_test(NAME test_executable_not_a_target + COMMAND tests/return_true) +endif() + # Add tutorials add_subdirectory(../../docs/tutorial/calc_pi calc_pi) diff --git a/tests/internal/return_true.in b/tests/internal/return_true.in new file mode 100755 index 000000000..8c3cbfc39 --- /dev/null +++ b/tests/internal/return_true.in @@ -0,0 +1,3 @@ +#!/bin/bash + +exit 0 diff --git a/tests/internal/return_true_win32.in b/tests/internal/return_true_win32.in new file mode 100644 index 000000000..38407235f --- /dev/null +++ b/tests/internal/return_true_win32.in @@ -0,0 +1 @@ +exit /b 0 From 525900d26dc1fd0c4b4460ac8d22bce60e1d968e Mon Sep 17 00:00:00 2001 From: Jason Burmark Date: Mon, 29 Jun 2020 10:47:20 -0700 Subject: [PATCH 37/40] Copy FindHIP cmake from rocm 3.5 --- cmake/thirdparty/FindHIP.cmake | 188 ++++++++++++++++------- cmake/thirdparty/FindHIP/run_hipcc.cmake | 24 ++- 2 files changed, 153 insertions(+), 59 deletions(-) diff --git a/cmake/thirdparty/FindHIP.cmake b/cmake/thirdparty/FindHIP.cmake index 942a20b2c..165bbd7c6 100644 --- a/cmake/thirdparty/FindHIP.cmake +++ b/cmake/thirdparty/FindHIP.cmake @@ -6,52 +6,36 @@ ############################################################################### # FindHIP.cmake ############################################################################### - +include(CheckCXXCompilerFlag) ############################################################################### # SET: Variable defaults ############################################################################### # User defined flags set(HIP_HIPCC_FLAGS "" CACHE STRING "Semicolon delimited flags for HIPCC") 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_NVCC_FLAGS) +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}) string(TOUPPER ${config} config_upper) set(HIP_HIPCC_FLAGS_${config_upper} "" CACHE STRING "Semicolon delimited flags for HIPCC") set(HIP_HCC_FLAGS_${config_upper} "" CACHE STRING "Semicolon delimited flags for HCC") + set(HIP_CLANG_FLAGS_${config_upper} "" CACHE STRING "Semicolon delimited flags for CLANG") set(HIP_NVCC_FLAGS_${config_upper} "" CACHE STRING "Semicolon delimited flags for NVCC") - mark_as_advanced(HIP_HIPCC_FLAGS_${config_upper} HIP_HCC_FLAGS_${config_upper} HIP_NVCC_FLAGS_${config_upper}) + mark_as_advanced(HIP_HIPCC_FLAGS_${config_upper} HIP_HCC_FLAGS_${config_upper} HIP_CLANG_FLAGS_${config_upper} HIP_NVCC_FLAGS_${config_upper}) endforeach() option(HIP_HOST_COMPILATION_CPP "Host code compilation mode" ON) option(HIP_VERBOSE_BUILD "Print out the commands run while compiling the HIP source file. With the Makefile generator this defaults to VERBOSE variable specified on the command line, but can be forced on with this option." OFF) mark_as_advanced(HIP_HOST_COMPILATION_CPP) ############################################################################### -# Set HIP CMAKE Flags +# FIND: HIP and associated helper binaries ############################################################################### -# Copy the invocation styles from CXX to HIP -set(CMAKE_HIP_ARCHIVE_CREATE ${CMAKE_CXX_ARCHIVE_CREATE}) -set(CMAKE_HIP_ARCHIVE_APPEND ${CMAKE_CXX_ARCHIVE_APPEND}) -set(CMAKE_HIP_ARCHIVE_FINISH ${CMAKE_CXX_ARCHIVE_FINISH}) -set(CMAKE_SHARED_LIBRARY_SONAME_HIP_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG}) -set(CMAKE_SHARED_LIBRARY_CREATE_HIP_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS}) -set(CMAKE_SHARED_LIBRARY_HIP_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) -#set(CMAKE_SHARED_LIBRARY_LINK_HIP_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}) -set(CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG}) -set(CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP}) -set(CMAKE_SHARED_LIBRARY_LINK_STATIC_HIP_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_STATIC_CXX_FLAGS}) -set(CMAKE_SHARED_LIBRARY_LINK_DYNAMIC_HIP_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_DYNAMIC_CXX_FLAGS}) -# Set the CMake Flags to use the HCC Compilier. -set(CMAKE_HIP_CREATE_SHARED_LIBRARY "${HIP_HIPCC_CMAKE_LINKER_HELPER} ${HCC_PATH} -o ") -set(CMAKE_HIP_CREATE_SHARED_MODULE "${HIP_HIPCC_CMAKE_LINKER_HELPER} ${HCC_PATH} -o -shared" ) -set(CMAKE_HIP_LINK_EXECUTABLE "${HIP_HIPCC_CMAKE_LINKER_HELPER} ${HCC_PATH} -o ") +get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_DIR}/../" REALPATH) -############################################################################### -# FIND: HIP and associated helper binaries -############################################################################### # HIP is supported on Linux only if(UNIX AND NOT APPLE AND NOT CYGWIN) # Search for HIP installation @@ -59,32 +43,15 @@ if(UNIX AND NOT APPLE AND NOT CYGWIN) # Search in user specified path first find_path( HIP_ROOT_DIR - NAMES hipconfig + NAMES bin/hipconfig PATHS - ENV ROCM_PATH + "$ENV{ROCM_PATH}/hip" ENV HIP_PATH - PATH_SUFFIXES bin - DOC "HIP installed location" - NO_DEFAULT_PATH - ) - # Now search in default path - find_path( - HIP_ROOT_DIR - NAMES hipconfig - PATHS - /opt/rocm + ${_IMPORT_PREFIX} /opt/rocm/hip - PATH_SUFFIXES bin DOC "HIP installed location" + NO_DEFAULT_PATH ) - - # Check if we found HIP installation - if(HIP_ROOT_DIR) - # If so, fix the path - string(REGEX REPLACE "[/\\\\]?bin[64]*[/\\\\]?$" "" HIP_ROOT_DIR ${HIP_ROOT_DIR}) - # And push it back to the cache - set(HIP_ROOT_DIR ${HIP_ROOT_DIR} CACHE PATH "HIP installed location" FORCE) - endif() if(NOT EXISTS ${HIP_ROOT_DIR}) if(HIP_FIND_REQUIRED) message(FATAL_ERROR "Specify HIP_ROOT_DIR") @@ -92,6 +59,8 @@ if(UNIX AND NOT APPLE AND NOT CYGWIN) message("HIP_ROOT_DIR not found or specified") endif() endif() + # And push it back to the cache + set(HIP_ROOT_DIR ${HIP_ROOT_DIR} CACHE PATH "HIP installed location" FORCE) endif() # Find HIPCC executable @@ -185,6 +154,28 @@ if(UNIX AND NOT APPLE AND NOT CYGWIN) set(HIP_PLATFORM ${_hip_platform} CACHE STRING "HIP platform as computed by hipconfig") mark_as_advanced(HIP_PLATFORM) endif() + + if(HIP_HIPCONFIG_EXECUTABLE AND NOT HIP_COMPILER) + # Compute the compiler + execute_process( + COMMAND ${HIP_HIPCONFIG_EXECUTABLE} --compiler + OUTPUT_VARIABLE _hip_compiler + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + set(HIP_COMPILER ${_hip_compiler} CACHE STRING "HIP compiler as computed by hipconfig") + mark_as_advanced(HIP_COMPILER) + endif() + + if(HIP_HIPCONFIG_EXECUTABLE AND NOT HIP_RUNTIME) + # Compute the runtime + execute_process( + COMMAND ${HIP_HIPCONFIG_EXECUTABLE} --runtime + OUTPUT_VARIABLE _hip_runtime + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + set(HIP_RUNTIME ${_hip_runtime} CACHE STRING "HIP runtime as computed by hipconfig") + mark_as_advanced(HIP_RUNTIME) + endif() endif() include(FindPackageHandleStandardArgs) @@ -195,9 +186,59 @@ find_package_handle_standard_args( HIP_HIPCC_EXECUTABLE HIP_HIPCONFIG_EXECUTABLE HIP_PLATFORM + HIP_COMPILER + HIP_RUNTIME VERSION_VAR HIP_VERSION ) +############################################################################### +# Set HIP CMAKE Flags +############################################################################### +# Copy the invocation styles from CXX to HIP +set(CMAKE_HIP_ARCHIVE_CREATE ${CMAKE_CXX_ARCHIVE_CREATE}) +set(CMAKE_HIP_ARCHIVE_APPEND ${CMAKE_CXX_ARCHIVE_APPEND}) +set(CMAKE_HIP_ARCHIVE_FINISH ${CMAKE_CXX_ARCHIVE_FINISH}) +set(CMAKE_SHARED_LIBRARY_SONAME_HIP_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG}) +set(CMAKE_SHARED_LIBRARY_CREATE_HIP_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS}) +set(CMAKE_SHARED_LIBRARY_HIP_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) +#set(CMAKE_SHARED_LIBRARY_LINK_HIP_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}) +set(CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG}) +set(CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP}) +set(CMAKE_SHARED_LIBRARY_LINK_STATIC_HIP_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_STATIC_CXX_FLAGS}) +set(CMAKE_SHARED_LIBRARY_LINK_DYNAMIC_HIP_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_DYNAMIC_CXX_FLAGS}) + +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. + 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 ") +elseif("${HIP_COMPILER}" STREQUAL "clang") + #Number of parallel jobs by default is 1 + if(NOT DEFINED HIP_CLANG_NUM_PARALLEL_JOBS) + set(HIP_CLANG_NUM_PARALLEL_JOBS 1) + endif() + #Add support for parallel build and link + if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") + check_cxx_compiler_flag("-parallel-jobs=1" HIP_CLANG_SUPPORTS_PARALLEL_JOBS) + 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_LINK_OPTIONS "-parallel-jobs=${HIP_CLANG_NUM_PARALLEL_JOBS}") + else() + message("clang compiler doesn't support parallel jobs") + endif() + endif() + + # Set the CMake Flags to use the HIP-Clang Compiler. + 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 ") +endif() + ############################################################################### # MACRO: Locate helper files ############################################################################### @@ -230,11 +271,13 @@ hip_find_helper_file(run_hipcc cmake) macro(HIP_RESET_FLAGS) unset(HIP_HIPCC_FLAGS) unset(HIP_HCC_FLAGS) + unset(HIP_CLANG_FLAGS) unset(HIP_NVCC_FLAGS) foreach(config ${_hip_configuration_types}) string(TOUPPER ${config} config_upper) unset(HIP_HIPCC_FLAGS_${config_upper}) unset(HIP_HCC_FLAGS_${config_upper}) + unset(HIP_CLANG_FLAGS_${config_upper}) unset(HIP_NVCC_FLAGS_${config_upper}) endforeach() endmacro() @@ -242,27 +285,37 @@ endmacro() ############################################################################### # MACRO: Separate the options from the sources ############################################################################### -macro(HIP_GET_SOURCES_AND_OPTIONS _sources _cmake_options _hipcc_options _hcc_options _nvcc_options) +macro(HIP_GET_SOURCES_AND_OPTIONS _sources _cmake_options _hipcc_options _hcc_options _clang_options _nvcc_options) set(${_sources}) set(${_cmake_options}) set(${_hipcc_options}) set(${_hcc_options}) + set(${_clang_options}) set(${_nvcc_options}) set(_hipcc_found_options FALSE) set(_hcc_found_options FALSE) + set(_clang_found_options FALSE) set(_nvcc_found_options FALSE) foreach(arg ${ARGN}) if("x${arg}" STREQUAL "xHIPCC_OPTIONS") set(_hipcc_found_options TRUE) set(_hcc_found_options FALSE) + set(_clang_found_options FALSE) set(_nvcc_found_options FALSE) elseif("x${arg}" STREQUAL "xHCC_OPTIONS") set(_hipcc_found_options FALSE) set(_hcc_found_options TRUE) + set(_clang_found_options FALSE) + set(_nvcc_found_options FALSE) + elseif("x${arg}" STREQUAL "xCLANG_OPTIONS") + set(_hipcc_found_options FALSE) + set(_hcc_found_options FALSE) + set(_clang_found_options TRUE) set(_nvcc_found_options FALSE) elseif("x${arg}" STREQUAL "xNVCC_OPTIONS") set(_hipcc_found_options FALSE) set(_hcc_found_options FALSE) + set(_clang_found_options FALSE) set(_nvcc_found_options TRUE) elseif( "x${arg}" STREQUAL "xEXCLUDE_FROM_ALL" OR @@ -276,6 +329,8 @@ macro(HIP_GET_SOURCES_AND_OPTIONS _sources _cmake_options _hipcc_options _hcc_op list(APPEND ${_hipcc_options} ${arg}) elseif(_hcc_found_options) list(APPEND ${_hcc_options} ${arg}) + elseif(_clang_found_options) + list(APPEND ${_clang_options} ${arg}) elseif(_nvcc_found_options) list(APPEND ${_nvcc_options} ${arg}) else() @@ -409,9 +464,10 @@ macro(HIP_PREPARE_TARGET_COMMANDS _target _format _generated_files _source_files endforeach() endif() - HIP_GET_SOURCES_AND_OPTIONS(_hip_sources _hip_cmake_options _hipcc_options _hcc_options _nvcc_options ${ARGN}) + HIP_GET_SOURCES_AND_OPTIONS(_hip_sources _hip_cmake_options _hipcc_options _hcc_options _clang_options _nvcc_options ${ARGN}) HIP_PARSE_HIPCC_OPTIONS(HIP_HIPCC_FLAGS ${_hipcc_options}) HIP_PARSE_HIPCC_OPTIONS(HIP_HCC_FLAGS ${_hcc_options}) + HIP_PARSE_HIPCC_OPTIONS(HIP_CLANG_FLAGS ${_clang_options}) HIP_PARSE_HIPCC_OPTIONS(HIP_NVCC_FLAGS ${_nvcc_options}) # Add the compile definitions @@ -433,6 +489,7 @@ macro(HIP_PREPARE_TARGET_COMMANDS _target _format _generated_files _source_files # If we are building a shared library, add extra flags to HIP_HIPCC_FLAGS if(_hip_build_shared_libs) list(APPEND HIP_HCC_FLAGS "-fPIC") + list(APPEND HIP_CLANG_FLAGS "-fPIC") list(APPEND HIP_NVCC_FLAGS "--shared -Xcompiler '-fPIC'") endif() @@ -443,12 +500,14 @@ macro(HIP_PREPARE_TARGET_COMMANDS _target _format _generated_files _source_files set(_HIP_HOST_FLAGS "set(CMAKE_HOST_FLAGS ${CMAKE_${HIP_C_OR_CXX}_FLAGS})") set(_HIP_HIPCC_FLAGS "set(HIP_HIPCC_FLAGS ${HIP_HIPCC_FLAGS})") set(_HIP_HCC_FLAGS "set(HIP_HCC_FLAGS ${HIP_HCC_FLAGS})") + set(_HIP_CLANG_FLAGS "set(HIP_CLANG_FLAGS ${HIP_CLANG_FLAGS})") set(_HIP_NVCC_FLAGS "set(HIP_NVCC_FLAGS ${HIP_NVCC_FLAGS})") foreach(config ${_hip_configuration_types}) string(TOUPPER ${config} config_upper) set(_HIP_HOST_FLAGS "${_HIP_HOST_FLAGS}\nset(CMAKE_HOST_FLAGS_${config_upper} ${CMAKE_${HIP_C_OR_CXX}_FLAGS_${config_upper}})") set(_HIP_HIPCC_FLAGS "${_HIP_HIPCC_FLAGS}\nset(HIP_HIPCC_FLAGS_${config_upper} ${HIP_HIPCC_FLAGS_${config_upper}})") set(_HIP_HCC_FLAGS "${_HIP_HCC_FLAGS}\nset(HIP_HCC_FLAGS_${config_upper} ${HIP_HCC_FLAGS_${config_upper}})") + set(_HIP_CLANG_FLAGS "${_HIP_CLANG_FLAGS}\nset(HIP_CLANG_FLAGS_${config_upper} ${HIP_CLANG_FLAGS_${config_upper}})") set(_HIP_NVCC_FLAGS "${_HIP_NVCC_FLAGS}\nset(HIP_NVCC_FLAGS_${config_upper} ${HIP_NVCC_FLAGS_${config_upper}})") endforeach() @@ -554,15 +613,34 @@ endmacro() ############################################################################### macro(HIP_ADD_EXECUTABLE hip_target) # Separate the sources from the options - HIP_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _hipcc_options _hcc_options _nvcc_options ${ARGN}) - HIP_PREPARE_TARGET_COMMANDS(${hip_target} OBJ _generated_files _source_files ${_sources} HIPCC_OPTIONS ${_hipcc_options} HCC_OPTIONS ${_hcc_options} NVCC_OPTIONS ${_nvcc_options}) + HIP_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _hipcc_options _hcc_options _clang_options _nvcc_options ${ARGN}) + HIP_PREPARE_TARGET_COMMANDS(${hip_target} OBJ _generated_files _source_files ${_sources} HIPCC_OPTIONS ${_hipcc_options} HCC_OPTIONS ${_hcc_options} CLANG_OPTIONS ${_clang_options} NVCC_OPTIONS ${_nvcc_options}) if(_source_files) list(REMOVE_ITEM _sources ${_source_files}) endif() - if("x${HCC_HOME}" STREQUAL "x") - set(HCC_HOME "/opt/rocm/hcc") + 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") + else() + 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") + else() + 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 ") endif() - set(CMAKE_HIP_LINK_EXECUTABLE "${HIP_HIPCC_CMAKE_LINKER_HELPER} ${HCC_HOME} -o ") add_executable(${hip_target} ${_cmake_options} ${_generated_files} ${_sources}) set_target_properties(${hip_target} PROPERTIES LINKER_LANGUAGE HIP) endmacro() @@ -572,11 +650,13 @@ endmacro() ############################################################################### macro(HIP_ADD_LIBRARY hip_target) # Separate the sources from the options - HIP_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _hipcc_options _hcc_options _nvcc_options ${ARGN}) - HIP_PREPARE_TARGET_COMMANDS(${hip_target} OBJ _generated_files _source_files ${_sources} ${_cmake_options} HIPCC_OPTIONS ${_hipcc_options} HCC_OPTIONS ${_hcc_options} NVCC_OPTIONS ${_nvcc_options}) + HIP_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _hipcc_options _hcc_options _clang_options _nvcc_options ${ARGN}) + HIP_PREPARE_TARGET_COMMANDS(${hip_target} OBJ _generated_files _source_files ${_sources} ${_cmake_options} HIPCC_OPTIONS ${_hipcc_options} HCC_OPTIONS ${_hcc_options} CLANG_OPTIONS ${_clang_options} NVCC_OPTIONS ${_nvcc_options}) if(_source_files) list(REMOVE_ITEM _sources ${_source_files}) endif() add_library(${hip_target} ${_cmake_options} ${_generated_files} ${_sources}) set_target_properties(${hip_target} PROPERTIES LINKER_LANGUAGE ${HIP_C_OR_CXX}) -endmacro() \ No newline at end of file +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 05356c993..ec8f91da5 100644 --- a/cmake/thirdparty/FindHIP/run_hipcc.cmake +++ b/cmake/thirdparty/FindHIP/run_hipcc.cmake @@ -32,12 +32,16 @@ set(HIP_HOST_COMPILER "@HIP_HOST_COMPILER@") # path set(CMAKE_COMMAND "@CMAKE_COMMAND@") # path set(HIP_run_make2cmake "@HIP_run_make2cmake@") # path set(HCC_HOME "@HCC_HOME@") #path +set(HIP_CLANG_PATH "@HIP_CLANG_PATH@") #path +set(HIP_CLANG_PARALLEL_BUILD_COMPILE_OPTIONS "@HIP_CLANG_PARALLEL_BUILD_COMPILE_OPTIONS@") @HIP_HOST_FLAGS@ @_HIP_HIPCC_FLAGS@ @_HIP_HCC_FLAGS@ +@_HIP_CLANG_FLAGS@ @_HIP_NVCC_FLAGS@ -set(HIP_HIPCC_INCLUDE_ARGS "@HIP_HIPCC_INCLUDE_ARGS@") # list (needs to be in quotes to handle spaces properly) +#Needed to bring the HIP_HIPCC_INCLUDE_ARGS variable in scope +set(HIP_HIPCC_INCLUDE_ARGS @HIP_HIPCC_INCLUDE_ARGS@) # list set(cmake_dependency_file "@cmake_dependency_file@") # path set(source_file "@source_file@") # path @@ -45,13 +49,23 @@ set(host_flag "@host_flag@") # bool # Determine compiler and compiler flags execute_process(COMMAND ${HIP_HIPCONFIG_EXECUTABLE} --platform OUTPUT_VARIABLE HIP_PLATFORM OUTPUT_STRIP_TRAILING_WHITESPACE) +execute_process(COMMAND ${HIP_HIPCONFIG_EXECUTABLE} --compiler OUTPUT_VARIABLE HIP_COMPILER OUTPUT_STRIP_TRAILING_WHITESPACE) +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") - if(NOT "x${HCC_HOME}" STREQUAL "x") - set(ENV{HCC_HOME} ${HCC_HOME}) + if("${HIP_PLATFORM}" STREQUAL "hcc") + if("${HIP_COMPILER}" STREQUAL "hcc") + if(NOT "x${HCC_HOME}" STREQUAL "x") + set(ENV{HCC_HOME} ${HCC_HOME}) + endif() + set(__CC_FLAGS ${HIP_HIPCC_FLAGS} ${HIP_HCC_FLAGS} ${HIP_HIPCC_FLAGS_${build_configuration}} ${HIP_HCC_FLAGS_${build_configuration}}) + elseif("${HIP_COMPILER}" STREQUAL "clang") + if(NOT "x${HIP_CLANG_PATH}" STREQUAL "x") + 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}}) endif() - set(__CC_FLAGS ${HIP_HIPCC_FLAGS} ${HIP_HCC_FLAGS} ${HIP_HIPCC_FLAGS_${build_configuration}} ${HIP_HCC_FLAGS_${build_configuration}}) else() set(__CC_FLAGS ${HIP_HIPCC_FLAGS} ${HIP_NVCC_FLAGS} ${HIP_HIPCC_FLAGS_${build_configuration}} ${HIP_NVCC_FLAGS_${build_configuration}}) endif() From c20a64da509e1db183aa35d4a1f1aed3a0093343 Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Thu, 2 Jul 2020 08:49:26 -0700 Subject: [PATCH 38/40] fix linking issue in hip 3.5 This fixes the rest of #366 so that the smoke test links with hip 3.5. I'm going to feed this bug up to AMD as well, since this change should not be necessary. The `STR_LENGTH` should also be constexpr, or at least __host__ __device__, since the current version is only valid because of over-eager constant propagation by the hip compiler, but I'm leaving that alone for now. --- tests/smoke/blt_hip_smoke.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/smoke/blt_hip_smoke.cpp b/tests/smoke/blt_hip_smoke.cpp index ac825099a..702ff2b2d 100644 --- a/tests/smoke/blt_hip_smoke.cpp +++ b/tests/smoke/blt_hip_smoke.cpp @@ -13,7 +13,7 @@ #include #include "hip/hip_runtime.h" -__device__ const char *STR = "HELLO WORLD!"; +__device__ const char STR[] = "HELLO WORLD!"; const char STR_LENGTH = 12; __global__ void hello() From 23476d232503db59711820a6534c80d05416cebe Mon Sep 17 00:00:00 2001 From: Chris White Date: Mon, 20 Jul 2020 18:33:44 -0700 Subject: [PATCH 39/40] Add missing release notes --- RELEASE-NOTES.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index f449a1284..69e890d3f 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -14,6 +14,7 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/ - 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. ### Changed - ``CUDA_TOOLKIT_ROOT_DIR`` must now be set in order to use CUDA. If it is not @@ -21,6 +22,10 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/ ### Fixed - blt_add_test is no longer trying to extract target properties from non-targets. +- Improved support for HIP 3.5. +- Improved support for CMake 3.13.0+. +- Remove some known spaces that show up in MPI link flags. +- Remove GTest and GBenchmark adding '-Werror' that got inherited. ## [Version 0.3.0] - Release date 2020-01-08 From b20a351c2a90eaf19c76d5e7335ca0b0d93d5646 Mon Sep 17 00:00:00 2001 From: Chris White Date: Mon, 20 Jul 2020 18:47:15 -0700 Subject: [PATCH 40/40] Add another missing release note --- RELEASE-NOTES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 69e890d3f..5e54ee683 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -58,6 +58,10 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/ - Fixed some warnings in CMake 3.14+ - Duplication of MPI link flags in CMake 3.14+ when Fortran was enabled. +### Removed +- Removed unused ``HEADERS_OUTPUT_SUBDIR`` argument from blt_add_library(). + + ## [Version 0.2.5] - Release date 2019-06-13 ### Added