diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..4d67604d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.code-workspace diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 620d4da42..5b5d969db 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -35,4 +35,4 @@ stages: include: - local: .gitlab/build_quartz.yml - local: .gitlab/build_lassen.yml - - local: .gitlab/build_corona.yml + - local: .gitlab/build_tioga.yml diff --git a/.gitlab/build_corona.yml b/.gitlab/build_corona.yml deleted file mode 100644 index ee19a551a..000000000 --- a/.gitlab/build_corona.yml +++ /dev/null @@ -1,51 +0,0 @@ -#### -# This is the share configuration of jobs for corona -.on_corona: - tags: - - shell - - corona - rules: - - if: '$CI_COMMIT_BRANCH =~ /_qnone/ || $ON_CORONA == "OFF"' #run except if ... - when: never - - if: '$CI_JOB_NAME =~ /corona_release/' - when: always - - when: on_success - -#### -# In pre-build phase, allocate a node for builds -corona_allocate: - variables: - GIT_STRATEGY: none - extends: [.on_corona] - stage: allocate - script: - - salloc -p pbatch -N 1 -t 10 --no-shell --job-name=${PROJECT_ALLOC_NAME} --mpibind=off - needs: [] - -#### -# In post-build phase, deallocate resources -# Note : make sure this is run even on build phase failure -corona_release: - variables: - GIT_STRATEGY: none - extends: [.on_corona] - stage: release - script: - - export JOBID=$(squeue -h --name=${PROJECT_ALLOC_NAME} --format=%A) - - if [[ -n "${JOBID}" ]]; then scancel ${JOBID}; fi - -#### -# Template -.build_on_corona: - stage: build - variables: - ALLOC_COMMAND: "srun -p pbatch -t 10 -N 1 ${ASSIGN_ID} --interactive" - extends: [.build_script, .on_corona] - needs: [corona_allocate] - -#### -# Build jobs -corona-rocm_4_5_2_hip: - variables: - HOST_CONFIG: "rocm@4.5.2_hip.cmake" - extends: [.build_on_corona] diff --git a/.gitlab/build_tioga.yml b/.gitlab/build_tioga.yml new file mode 100644 index 000000000..32f94c857 --- /dev/null +++ b/.gitlab/build_tioga.yml @@ -0,0 +1,26 @@ +#### +# This is the shared configuration of jobs for tioga +.on_tioga: + tags: + - shell + - tioga + rules: + - if: '$CI_COMMIT_BRANCH =~ /_qnone/ || $ON_TIOGA == "OFF"' #run except if ... + when: never + - when: on_success + +#### +# Template +.src_build_on_tioga: + stage: build + variables: + ALLOC_COMMAND: "flux mini run -t10m -n1" + extends: [.build_script, .on_tioga] + +#### +# Build jobs +tioga-clang_14_0_0_hip: + variables: + HOST_CONFIG: "clang@14.0.0_hip.cmake" + extends: .src_build_on_tioga + allow_failure: true diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 60519a26e..7142d55ba 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -9,6 +9,22 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/ ## [Unreleased] - Release date yyyy-mm-dd +## [Version 0.5.2] - Release date 2022-10-05 + +### Added +- Added `blt_convert_to_system_includes` macro to convert existing interface includes to system interface includes. +- `blt_check_code_compiles` which compiles a C++ code snippet and returns the result. +- Added variable ``BLT_CMAKE_IMPLICIT_LINK_LIBRARIES_EXCLUDE`` for filtering + link libraries implicitly added by CMake. See the following example host-config: + ``host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_xlf.cmake`` + +### Changed +- Added three extra options to `blt_print_target_properties` macro to print properties of + target's children as well as limit the properties printed with regular expressions: + - CHILDREN (true/ false) whether or not you want to print the target's children's properties as well (recursively) + - PROPERTY_NAME_REGEX (regular expression string) reduce which properties to print by name + - PROPERTY_VALUE_REGEX (regular expression string) reduce which properties to print by value + ## [Version 0.5.1] - Release date 2022-04-22 ### Added @@ -21,6 +37,7 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/ CMAKE_CUDA_STANDARD if set otherwise falls back on BLT_CXX_STD or CMAKE_CXX_STANDARD. - Removed extra HIP offload flags that were being added as generator expressions as opposed to simple flags. +- Skip check for valid `ELEMENTS` parameter in `blt_list_append` macro when not appending ### Removed - Removed support for deprecated HCC. @@ -251,7 +268,8 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/ -[Unreleased]: https://github.com/LLNL/blt/compare/v0.5.1...develop +[Unreleased]: https://github.com/LLNL/blt/compare/v0.5.2...develop +[Version 0.5.2]: https://github.com/LLNL/blt/compare/v0.5.1...v0.5.2 [Version 0.5.1]: https://github.com/LLNL/blt/compare/v0.5.0...v0.5.1 [Version 0.5.0]: https://github.com/LLNL/blt/compare/v0.4.1...v0.5.0 [Version 0.4.1]: https://github.com/LLNL/blt/compare/v0.4.0...v0.4.1 diff --git a/SetupBLT.cmake b/SetupBLT.cmake index 460c8d75c..9de833e14 100644 --- a/SetupBLT.cmake +++ b/SetupBLT.cmake @@ -4,7 +4,7 @@ # SPDX-License-Identifier: (BSD-3-Clause) if (NOT BLT_LOADED) - set(BLT_VERSION "0.5.1" CACHE STRING "") + set(BLT_VERSION "0.5.2" CACHE STRING "") mark_as_advanced(BLT_VERSION) message(STATUS "BLT Version: ${BLT_VERSION}") @@ -66,6 +66,13 @@ if (NOT BLT_LOADED) cmake_policy(SET CMP0057 NEW) endif() + # Make `check_cxx_source_compiles` honor `CMAKE_CXX_STANDARD` + # NOTE: This only works on a few CMake versions even though it was + # added in CMake 3.14. (for example, 3.20.2, 3.21.1, and 3.23.1 did not work) + if(POLICY CMP0067) + cmake_policy(SET CMP0067 NEW) + endif() + # Policy to use _ROOT variable in find_ commands # Policy added in 3.12+ if(POLICY CMP0074) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 293eba47d..fdde52e81 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -51,7 +51,7 @@ strategy: MPI_DIR: '/usr' CMAKE_FLAGS: '$(C_COMPILERS) $(MPI_FLAGS) -DENABLE_GTEST_DEATH_TESTS=OFF -DENABLE_OPENMP=ON' osx_gcc: - VM_ImageName: 'macos-1015' + VM_ImageName: 'macos-12' CMAKE_FLAGS: '' windows: VM_ImageName: 'windows-2019' diff --git a/cmake/BLTMacros.cmake b/cmake/BLTMacros.cmake index 6d5d78547..5601933f5 100644 --- a/cmake/BLTMacros.cmake +++ b/cmake/BLTMacros.cmake @@ -69,10 +69,6 @@ macro(blt_list_append) message(FATAL_ERROR "blt_list_append() requires a TO argument") endif() - if ( NOT DEFINED arg_ELEMENTS ) - message(FATAL_ERROR "blt_list_append() requires ELEMENTS to be specified" ) - endif() - # determine if we should add the elements to the list set(_shouldAdd FALSE ) set(_listVar "${ARGN}") # convert macro arguments to list variable @@ -84,6 +80,11 @@ macro(blt_list_append) # append if if ( ${_shouldAdd} ) + # check that ELEMENTS parameter is defined/non-empty before appending + if ( NOT DEFINED arg_ELEMENTS ) + message(FATAL_ERROR "blt_list_append() requires ELEMENTS to be specified and non-empty" ) + endif() + list( APPEND ${arg_TO} ${arg_ELEMENTS} ) endif() @@ -1273,89 +1274,87 @@ endmacro(blt_combine_static_libraries) ##------------------------------------------------------------------------------ -## blt_print_target_properties(TARGET ) +## blt_print_target_properties(TARGET +## CHILDREN +## PROPERTY_NAME_REGEX +## PROPERTY_VALUE_REGEX ) +## +## Prints all (or filtered) properties of a given target and optionally its +## dependencies as well. ## -## Prints out all properties of the given target. +## Has the options to print target's link libraries and interface link libraries +## with the CHILDREN argument, as well as specific properties using regular +## expressions. +## +## Defaults: +## CHILDREN = false (non recursive) +## PROPERTY_NAME_REGEX = .* (print every property name) +## PROPERTY_VALUE_REGEX = .* (print every property value) +## ##------------------------------------------------------------------------------ macro(blt_print_target_properties) set(options) - set(singleValuedArgs TARGET) + set(singleValuedArgs TARGET CHILDREN PROPERTY_NAME_REGEX PROPERTY_VALUE_REGEX) set(multiValuedArgs) - ## parse the arguments to the macro + # parse the arguments to the macro cmake_parse_arguments(arg "${options}" "${singleValuedArgs}" "${multiValuedArgs}" ${ARGN}) - ## check for required arguments + # check for required arguments if(NOT DEFINED arg_TARGET) message(FATAL_ERROR "TARGET is a required parameter for the blt_print_target_properties macro") endif() - ## check if this is a valid cmake target of blt_registered target + # set default values + if(NOT DEFINED arg_CHILDREN) + set(arg_CHILDREN FALSE) + endif() + + if(NOT DEFINED arg_PROPERTY_NAME_REGEX) + set(arg_PROPERTY_NAME_REGEX ".*") + endif() + + if(NOT DEFINED arg_PROPERTY_VALUE_REGEX) + set(arg_PROPERTY_VALUE_REGEX ".*") + endif() + + # check if this is a valid cmake target or blt_registered target set(_is_cmake_target FALSE) if(TARGET ${arg_TARGET}) set(_is_cmake_target TRUE) - message (STATUS "[${arg_TARGET} property] '${arg_TARGET}' is a cmake target") endif() set(_is_blt_registered_target FALSE) string(TOUPPER ${arg_TARGET} _target_upper) if(_BLT_${_target_upper}_IS_REGISTERED_LIBRARY) set(_is_blt_registered_target TRUE) - message (STATUS "[${arg_TARGET} property] '${arg_TARGET}' is a blt_registered target") endif() if(NOT _is_cmake_target AND NOT _is_blt_registered_target) - message (STATUS "[blt_print_target_properties] Invalid argument '${arg_TARGET}'. " + message (STATUS "[blt_print_target_properties] Invalid argument '${arg_TARGET}'." "This macro applies only to valid cmake targets or blt_registered targets.") - endif() - - - if(_is_cmake_target) - ## Solution adapted from https://stackoverflow.com/q/32183975 - ## Create list of cmake properties - set(_property_list) - execute_process(COMMAND cmake --help-property-list OUTPUT_VARIABLE _property_list) - string(REGEX REPLACE ";" "\\\\;" _property_list "${_property_list}") - string(REGEX REPLACE "\n" ";" _property_list "${_property_list}") - blt_filter_list(TO _property_list REGEX "^LOCATION$|^LOCATION_|_LOCATION$" OPERATION "exclude") - blt_list_remove_duplicates(TO _property_list) - - ## For interface targets, filter against whitelist of valid properties - get_property(_target_type TARGET ${arg_TARGET} PROPERTY TYPE) - if("${_target_type}" STREQUAL "INTERFACE_LIBRARY") - blt_filter_list(TO _property_list - REGEX "^(INTERFACE_|IMPORTED_LIBNAME_|COMPATIBLE_INTERFACE_|MAP_IMPORTED_CONFIG_)|^(NAME|TYPE|EXPORT_NAME)$" - OPERATION "include") + else() + # print properties + blt_print_target_properties_private(TARGET ${arg_TARGET} + PROPERTY_NAME_REGEX ${arg_PROPERTY_NAME_REGEX} + PROPERTY_VALUE_REGEX ${arg_PROPERTY_VALUE_REGEX}) + + if(${arg_CHILDREN}) + # find all targets from dependency tree + set(tlist "") + blt_find_target_dependencies(TARGET ${arg_TARGET} TLIST tlist) + blt_list_remove_duplicates(TO tlist) + + # print all targets from dependency tree + foreach(t ${tlist}) + blt_print_target_properties_private(TARGET ${t} + PROPERTY_NAME_REGEX ${arg_PROPERTY_NAME_REGEX} + PROPERTY_VALUE_REGEX ${arg_PROPERTY_VALUE_REGEX}) + endforeach() + unset(tlist) endif() - - ## Print all such properties that have been SET - foreach (prop ${_property_list}) - string(REPLACE "" "${CMAKE_BUILD_TYPE}" prop ${prop}) - get_property(_propval TARGET ${arg_TARGET} PROPERTY ${prop} SET) - if (_propval) - get_target_property(_propval ${arg_TARGET} ${prop}) - message (STATUS "[${arg_TARGET} property] ${prop}: ${_propval}") - endif() - endforeach() - unset(_property_list) - unset(_propval) - endif() - - ## Additionally, output variables generated via blt_register_target of the form "_BLT__*" - if(_is_blt_registered_target) - set(_target_prefix "_BLT_${_target_upper}_") - - ## Filter to get variables of the form _BLT__ and print - get_cmake_property(_variable_names VARIABLES) - foreach (prop ${_variable_names}) - if(prop MATCHES "^${_target_prefix}") - message (STATUS "[${arg_TARGET} property] ${prop}: ${${prop}}") - endif() - endforeach() - unset(_target_prefix) - unset(_variable_names) endif() unset(_target_upper) @@ -1363,6 +1362,7 @@ macro(blt_print_target_properties) unset(_is_cmake_target) endmacro(blt_print_target_properties) + ##------------------------------------------------------------------------------ ## blt_export_tpl_targets(EXPORT NAMESPACE ) ## @@ -1401,3 +1401,99 @@ macro(blt_export_tpl_targets) endif() endforeach() endmacro() + +##------------------------------------------------------------------------------ +## blt_convert_to_system_includes(TARGET ) +## +## Converts existing interface includes to system interface includes. +##------------------------------------------------------------------------------ +macro(blt_convert_to_system_includes) + set(options) + set(singleValuedArgs TARGET) + set(multiValuedArgs) + + ## parse the arguments to the macro + cmake_parse_arguments(arg + "${options}" "${singleValuedArgs}" "${multiValuedArgs}" ${ARGN}) + + if(NOT DEFINED arg_TARGET) + message(FATAL_ERROR "TARGET is a required parameter for the blt_convert_to_system_includes macro.") + endif() + + get_target_property(_include_dirs ${arg_TARGET} INTERFACE_INCLUDE_DIRECTORIES) + set_property(TARGET ${arg_TARGET} APPEND PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${_include_dirs}") + unset(_include_dirs) +endmacro() + + +##------------------------------------------------------------------------------ +## blt_check_code_compiles(CODE_COMPILES +## VERBOSE_OUTPUT +## SOURCE_STRING ) +## +## This macro checks if a snippet of C++ code compiles. +## +## SOURCE_STRING The source snippet to compile. +## Must be a valid C++ program with a main() function. +## Note: This parameter should be passed in as a quoted string variable. Otherwise, +## cmake will convert the string into a list and lose the semicolons. +## E.g. blt_check_code_compiles(SOURCE_STRING "${str_var}" ...) +## +## CODE_COMPILES A boolean variable the contains the compilation result. +## +## VERBOSE_OUTPUT Optional parameter to output debug information (Default: off) +##------------------------------------------------------------------------------ +macro(blt_check_code_compiles) + + set(options) + set(singleValueArgs CODE_COMPILES VERBOSE_OUTPUT ) + # NOTE: SOURCE_STRING must be a multiValueArg otherwise CMake removes all semi-colons + set(multiValueArgs SOURCE_STRING) + + # Parse the arguments to the macro + cmake_parse_arguments(arg + "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN}) + + # Check the arguments + if(NOT DEFINED arg_SOURCE_STRING) + message(FATAL_ERROR "blt_check_code_compiles() requires SOURCE_STRING to be specified") + endif() + + if(NOT DEFINED arg_CODE_COMPILES) + message(FATAL_ERROR "blt_check_code_compiles() requires CODE_COMPILES to be specified") + endif() + + if(NOT DEFINED arg_VERBOSE_OUTPUT) + set(arg_VERBOSE_OUTPUT FALSE) + endif() + + if(${arg_VERBOSE_OUTPUT}) + message(STATUS "[blt_check_code_compiles] Attempting to compile source string: \n${arg_SOURCE_STRING}") + endif() + + # Write string as temp file, try to compile it and then remove file + string(RANDOM LENGTH 5 _rand) + set(_fname ${CMAKE_CURRENT_BINARY_DIR}/_bltCheckCompiles${_rand}.cpp) + file(WRITE ${_fname} "${arg_SOURCE_STRING}") + try_compile(${arg_CODE_COMPILES} + ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp + SOURCES ${_fname} + CXX_STANDARD ${CMAKE_CXX_STANDARD} + OUTPUT_VARIABLE _res) + file(REMOVE ${_fname}) + + if(${arg_VERBOSE_OUTPUT}) + message(STATUS "[blt_check_code_compiles] Compiler output: \n${_res}\n") + + if(${arg_CODE_COMPILES}) + message(STATUS "[blt_check_code_compiles] The code snippet successfully compiled") + else() + message(STATUS "[blt_check_code_compiles] The code snippet failed to compile") + endif() + endif() + + # clear the variables set within the macro + unset(_fname) + unset(_res) + +endmacro(blt_check_code_compiles) diff --git a/cmake/BLTPrivateMacros.cmake b/cmake/BLTPrivateMacros.cmake index 5c980accd..34f19a625 100644 --- a/cmake/BLTPrivateMacros.cmake +++ b/cmake/BLTPrivateMacros.cmake @@ -190,7 +190,7 @@ macro(blt_find_executable) string(TOUPPER ${arg_NAME} _ucname) message(STATUS "${arg_NAME} support is ${ENABLE_${_ucname}}") - if (${ENABLE_${_ucname}}) + if (ENABLE_${_ucname}) set(_exes ${arg_NAME}) if (DEFINED arg_EXECUTABLES) set(_exes ${arg_EXECUTABLES}) @@ -842,3 +842,166 @@ macro(blt_clean_target) endforeach() endmacro(blt_clean_target) + + +##------------------------------------------------------------------------------ +## blt_print_target_properties_private(TARGET +## PROPERTY_NAME_REGEX +## PROPERTY_VALUE_REGEX ) +## +## Prints target properties of one target +##------------------------------------------------------------------------------ +macro(blt_print_target_properties_private) + + set(options) + set(singleValuedArgs TARGET PROPERTY_NAME_REGEX PROPERTY_VALUE_REGEX) + set(multiValuedArgs) + + ## parse the arguments to the macro + cmake_parse_arguments(arg + "${options}" "${singleValuedArgs}" "${multiValuedArgs}" ${ARGN}) + + ## check if this is a valid cmake target or blt_registered target + set(_is_cmake_target FALSE) + set(_target_type_str "") + if(TARGET ${arg_TARGET}) + set(_is_cmake_target TRUE) + set(_target_type_str "CMake target") + endif() + + set(_is_blt_registered_target FALSE) + string(TOUPPER ${arg_TARGET} _target_upper) + if(_BLT_${_target_upper}_IS_REGISTERED_LIBRARY) + set(_is_blt_registered_target TRUE) + if (_is_cmake_target) + set(_target_type_str "${_target_type_str} and a ") + endif() + set(_target_type_str "${_target_type_str}BLT Registered target") + endif() + + if (_is_cmake_target OR _is_blt_registered_target) + message(STATUS "[${arg_TARGET} property] '${arg_TARGET}' is a ${_target_type_str}") + endif() + unset(_target_type_str) + + if(_is_cmake_target) + ## Solution adapted from https://stackoverflow.com/q/32183975 + ## Create list of cmake properties + set(_property_list) + execute_process(COMMAND cmake --help-property-list OUTPUT_VARIABLE _property_list) + string(REGEX REPLACE ";" "\\\\;" _property_list "${_property_list}") + string(REGEX REPLACE "\n" ";" _property_list "${_property_list}") + blt_filter_list(TO _property_list REGEX "^LOCATION$|^LOCATION_|_LOCATION$" OPERATION "exclude") + blt_list_remove_duplicates(TO _property_list) + + ## For interface targets, filter against whitelist of valid properties + get_property(_target_type TARGET ${arg_TARGET} PROPERTY TYPE) + if("${_target_type}" STREQUAL "INTERFACE_LIBRARY") + blt_filter_list(TO _property_list + REGEX "^(INTERFACE_|IMPORTED_LIBNAME_|COMPATIBLE_INTERFACE_|MAP_IMPORTED_CONFIG_)|^(NAME|TYPE|EXPORT_NAME)$" + OPERATION "include") + endif() + + ## Print all such properties that have been SET + foreach (prop ${_property_list}) + string(REPLACE "" "${CMAKE_BUILD_TYPE}" prop ${prop}) + get_property(_propval TARGET ${arg_TARGET} PROPERTY ${prop} SET) + if ("${_propval}" AND "${prop}" MATCHES "${arg_PROPERTY_NAME_REGEX}") + get_target_property(_propval ${arg_TARGET} ${prop}) + if ("${_propval}" MATCHES "${arg_PROPERTY_VALUE_REGEX}") + message (STATUS "[${arg_TARGET} property] ${prop}: ${_propval}") + endif() + endif() + endforeach() + unset(_property_list) + unset(_propval) + endif() + + ## Additionally, output variables generated via blt_register_target of the form "_BLT__*" + if(_is_blt_registered_target) + set(_target_prefix "_BLT_${_target_upper}_") + + ## Filter to get variables of the form _BLT__ and print + get_cmake_property(_variable_names VARIABLES) + foreach (prop ${_variable_names}) + if("${prop}" MATCHES "^${_target_prefix}" AND "${prop}" MATCHES "${arg_PROPERTY_NAME_REGEX}" AND "${${prop}}" MATCHES "${arg_PROPERTY_VALUE_REGEX}") + message (STATUS "[${arg_TARGET} property] ${prop}: ${${prop}}") + endif() + endforeach() + unset(_target_prefix) + unset(_variable_names) + endif() + + unset(_target_upper) + unset(_is_blt_registered_target) + unset(_is_cmake_target) +endmacro(blt_print_target_properties_private) + +##------------------------------------------------------------------------------ +## blt_find_target_dependencies(TARGET TLIST ) +## +## Store all target's dependencies (link libraries and interface link libraries) +## recursively in the variable name TLIST holds. +##------------------------------------------------------------------------------ +macro(blt_find_target_dependencies) + + set(options) + set(singleValuedArgs TARGET TLIST) + set(multiValuedArgs) + + # parse the arguments to the macro + cmake_parse_arguments(arg + "${options}" "${singleValuedArgs}" "${multiValuedArgs}" ${ARGN}) + + # check for required arguments + if(NOT DEFINED arg_TARGET) + message(FATAL_ERROR "TARGET is a required parameter for the blt_find_target_dependencies macro") + endif() + + if(NOT DEFINED arg_TLIST OR NOT DEFINED ${arg_TLIST}) + message(FATAL_ERROR "TLIST is a required parameter for the blt_find_target_dependencies macro") + endif() + + string(TOUPPER ${arg_TARGET} _target_upper) + if(_BLT_${_target_upper}_IS_REGISTERED_LIBRARY) + # recursive call + set (_depends_on "${_BLT_${_target_upper}_DEPENDS_ON}") + foreach(t ${_depends_on}) + if (NOT "${t}" IN_LIST ${arg_TLIST}) + list(APPEND ${arg_TLIST} ${t}) + blt_find_target_dependencies(TARGET ${t} TLIST ${arg_TLIST}) + endif() + endforeach() + unset(_depends_on) + endif() + + # check if this is a valid cmake target + if(TARGET ${arg_TARGET}) + # get link libaries if whitelisted + set(_property_list "") + get_property(_target_type TARGET ${arg_TARGET} PROPERTY TYPE) + if(NOT "${_target_type}" STREQUAL "INTERFACE_LIBRARY") + get_property(_propval TARGET ${arg_TARGET} PROPERTY LINK_LIBRARIES SET) + get_target_property(_propval ${arg_TARGET} LINK_LIBRARIES) + if (_propval AND NOT "${_propval}" IN_LIST ${arg_TLIST}) + list(APPEND _property_list ${_propval}) + endif() + endif() + + # get interface link libraries + get_property(_propval TARGET ${arg_TARGET} PROPERTY INTERFACE_LINK_LIBRARIES SET) + get_target_property(_propval ${arg_TARGET} INTERFACE_LINK_LIBRARIES) + if (_propval AND NOT "${_propval}" IN_LIST ${arg_TLIST}) + list(APPEND _property_list ${_propval}) + endif() + + # recursive call + foreach(t ${_property_list}) + list(APPEND ${arg_TLIST} ${t}) + blt_find_target_dependencies(TARGET ${t} TLIST ${arg_TLIST}) + endforeach() + + unset(_property_list) + unset(_propval) + endif() +endmacro(blt_find_target_dependencies) diff --git a/cmake/SetupCompilerOptions.cmake b/cmake/SetupCompilerOptions.cmake index 2af48cd8d..d78263694 100644 --- a/cmake/SetupCompilerOptions.cmake +++ b/cmake/SetupCompilerOptions.cmake @@ -373,3 +373,22 @@ if(BLT_CMAKE_IMPLICIT_LINK_DIRECTORIES_EXCLUDE) message(STATUS "Updated CUDA implicit Link Directories: ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}") endif () endif() + +################################## +# Remove implicit link libraries +################################## +if(BLT_CMAKE_IMPLICIT_LINK_LIBRARIES_EXCLUDE) + message(STATUS "Removing implicit link libraries: ${BLT_CMAKE_IMPLICIT_LINK_LIBRARIES_EXCLUDE}") + list(REMOVE_ITEM CMAKE_CXX_IMPLICIT_LINK_LIBRARIES ${BLT_CMAKE_IMPLICIT_LINK_LIBRARIES_EXCLUDE}) + message(STATUS "Updated CXX implicit Link Libraries: ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES}") + list(REMOVE_ITEM CMAKE_C_IMPLICIT_LINK_LIBRARIES ${BLT_CMAKE_IMPLICIT_LINK_LIBRARIES_EXCLUDE}) + message(STATUS "Updated C implicit Link Libraries: ${CMAKE_C_IMPLICIT_LINK_LIBRARIES}") + if (ENABLE_FORTRAN) + list(REMOVE_ITEM CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES ${BLT_CMAKE_IMPLICIT_LINK_LIBRARIES_EXCLUDE}) + message(STATUS "Updated Fortran implicit Link Libraries: ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}") + endif () + if (ENABLE_CUDA) + list(REMOVE_ITEM CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES ${BLT_CMAKE_IMPLICIT_LINK_LIBRARIES_EXCLUDE}) + message(STATUS "Updated CUDA implicit Link Libraries: ${CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES}") + endif () +endif() diff --git a/docs/api/target_properties.rst b/docs/api/target_properties.rst index 70af9464a..2c4bf652b 100644 --- a/docs/api/target_properties.rst +++ b/docs/api/target_properties.rst @@ -155,12 +155,24 @@ blt_print_target_properties .. code-block:: cmake - blt_print_target_properties(TARGET ) + blt_print_target_properties(TARGET + CHILDREN + PROPERTY_NAME_REGEX + PROPERTY_VALUE_REGEX ) -Prints out all properties of the given target. +Prints all (or filtered) properties of a given target and optionally its dependencies as well. TARGET - Name of CMake target + Name of CMake target (required) + +CHILDREN + Whether or not to print the properties of the target's children recursively (false by default) + +PROPERTY_NAME_REGEX + Limit the properties to print by name (all by default) + +PROPERTY_VALUE_REGEX + Limit the properties to print by value (all by default) The given target must be added via ``add_executable()`` or ``add_library()`` or with the corresponding :ref:`blt_add_executable`, :ref:`blt_add_library`, @@ -169,6 +181,14 @@ with the corresponding :ref:`blt_add_executable`, :ref:`blt_add_library`, Output is of the form for each property: | [ property] : +.. code-block:: cmake + :caption: **Example** + :linenos: + + blt_print_target_properties(TARGET foo) + blt_print_target_properties(TARGET foo CHILDREN TRUE) + blt_print_target_properties(TARGET foo CHILDREN TRUE PROPERTY_NAME_REGEX "CXX") + blt_print_target_properties(TARGET foo PROPERTY_NAME_REGEX "CXX" PROPERTY_VALUE_REGEX "ON") .. _blt_set_target_folder: diff --git a/docs/api/utility.rst b/docs/api/utility.rst index 85753f2cf..94fe70ca4 100644 --- a/docs/api/utility.rst +++ b/docs/api/utility.rst @@ -77,6 +77,54 @@ When using the Intel toolchain within Visual Studio, we use the ``MSVC_INTEL`` flag, when provided, with a fallback to the ``MSVC`` flag. +.. blt_check_code_compiles: + +blt_check_code_compiles +~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: cmake + + blt_check_code_compiles(CODE_COMPILES + VERBOSE_OUTPUT + SOURCE_STRING ) + +This macro checks if a snippet of C++ code compiles. + +CODE_COMPILES + The boolean variable that will be filled with the compilation result. + +VERBOSE_OUTPUT + Optional parameter to output debug information (Default: OFF) + +SOURCE_STRING + The source snippet to compile. + +``SOURCE_STRING`` must be a valid C++ program with a main() function and +must be passed in as a quoted string variable. Otherwise, CMake will convert +the string into a list and lose the semicolons. You can use any CMake method +of sending a string, but we recommend the +`bracket argument method `_ +shown below so you do not have to escape your quotes: + +.. code-block:: cmake + + blt_check_code_compiles(CODE_COMPILES hello_world_compiled + SOURCE_STRING + [=[ + #include + + int main(int, char**) + { + + std::cout << "Hello World!" << std::endl; + + return 0; + } + ]=]) + + + + .. _blt_find_libraries: blt_find_libraries @@ -167,3 +215,21 @@ command but doesn't throw an error if the list is empty or not defined. set(mylist A B A) blt_list_remove_duplicates( TO mylist ) +.. _blt_convert_to_system_includes: + +blt_convert_to_system_includes +~~~~~~~~~~~~~~~~~~~ + +.. code-block:: cmake + + blt_convert_to_system_includes(TARGET ) + +Converts existing interface includes to system interface includes. + +.. code-block:: cmake + :caption: **Example** + :linenos: + + ## convert to system includes for the foo target + blt_convert_to_system_includes(TARGET foo) + diff --git a/docs/tutorial/third_party_libraries.rst b/docs/tutorial/third_party_libraries.rst index 2d6a6b2d2..0e92b0baa 100644 --- a/docs/tutorial/third_party_libraries.rst +++ b/docs/tutorial/third_party_libraries.rst @@ -102,7 +102,7 @@ Then ``lua`` is available to be used in the ``DEPENDS_ON`` list in the following option to :ref:`blt_import_library` can also be used to manage visibility. -Cmake's Find Modules +CMake's Find Modules ~~~~~~~~~~~~~~~~~~~~ This time we will do exactly the same thing but using the new CMake provided ``FindLua.cmake`` module. diff --git a/host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_xlf.cmake b/host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_xlf.cmake index 90f78288f..a4513012b 100644 --- a/host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_xlf.cmake +++ b/host-configs/llnl/blueos_3_ppc64le_ib_p9/clang@upstream_nvcc_xlf.cmake @@ -57,6 +57,8 @@ set(BLT_MPI_COMMAND_APPEND "mpibind" CACHE PATH "") set(CMAKE_Fortran_COMPILER_ID "XL" CACHE PATH "All of BlueOS compilers report clang due to nvcc, override to proper compiler family") set(BLT_FORTRAN_FLAGS "-WF,-C!" CACHE PATH "Converts C-style comments to Fortran style in preprocessed files") +set(BLT_CMAKE_IMPLICIT_LINK_LIBRARIES_EXCLUDE "xlomp_ser" CACHE STRING "") + #------------------------------------------------------------------------------ # CUDA support #------------------------------------------------------------------------------ diff --git a/host-configs/llnl/toss_4_x86_64_ib_cray/clang@14.0.0_hip.cmake b/host-configs/llnl/toss_4_x86_64_ib_cray/clang@14.0.0_hip.cmake new file mode 100644 index 000000000..2c5302944 --- /dev/null +++ b/host-configs/llnl/toss_4_x86_64_ib_cray/clang@14.0.0_hip.cmake @@ -0,0 +1,65 @@ +#------------------------------------------------------------------------------ +# !!!! This is a generated file, edit at own risk !!!! +#------------------------------------------------------------------------------ +# CMake executable path: /usr/tce/packages/cmake/cmake-3.21.1/bin/cmake +#------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ +# Compilers +#------------------------------------------------------------------------------ +# Compiler Spec: clang@14.0.0 +#------------------------------------------------------------------------------ +set(CMAKE_C_COMPILER "/opt/rocm-5.1.1/llvm/bin/amdclang" CACHE PATH "") + +set(CMAKE_CXX_COMPILER "/opt/rocm-5.1.1/llvm/bin/amdclang++" CACHE PATH "") + +set(CMAKE_Fortran_COMPILER "/opt/rocm-5.1.1/llvm/bin/amdflang" CACHE PATH "") + +set(CMAKE_Fortran_FLAGS "-Mfreeform" CACHE STRING "") + +set(ENABLE_FORTRAN ON CACHE BOOL "") + +#------------------------------------------------------------------------------ +# MPI +#------------------------------------------------------------------------------ + +set(MPI_C_COMPILER "/usr/tce/packages/cray-mpich-tce/cray-mpich-8.1.16-rocmcc-5.1.1/bin/mpicc" CACHE PATH "") + +set(MPI_CXX_COMPILER "/usr/tce/packages/cray-mpich-tce/cray-mpich-8.1.16-rocmcc-5.1.1/bin/mpicxx" CACHE PATH "") + +set(MPI_Fortran_COMPILER "/usr/tce/packages/cray-mpich-tce/cray-mpich-8.1.16-rocmcc-5.1.1/bin/mpif90" CACHE PATH "") + +set(MPIEXEC_EXECUTABLE "/usr/bin/srun" CACHE PATH "") + +set(MPIEXEC_NUMPROC_FLAG "-n" CACHE STRING "") + +set(ENABLE_MPI ON CACHE BOOL "") + +#------------------------------------------------------------------------------ +# Hardware +#------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ + +# HIP + +#------------------------------------------------------------------------------ + + +set(ENABLE_HIP ON CACHE BOOL "") + +set(HIP_ROOT_DIR "/opt/rocm-5.1.1/hip" CACHE STRING "") + +set(HIP_CLANG_PATH "/opt/rocm-5.1.1/hip/../llvm/bin" CACHE STRING "") + +set(CMAKE_HIP_ARCHITECTURES "gfx90a" CACHE STRING "") + +set(CMAKE_EXE_LINKER_FLAGS "-Wl,--disable-new-dtags -L/opt/rocm-5.1.1/hip/../llvm/lib -L/opt/rocm-5.1.1/hip/lib -Wl,-rpath,/opt/rocm-5.1.1/hip/../llvm/lib:/opt/rocm-5.1.1/hip/lib -lpgmath -lflang -lflangrti -lompstub -lamdhip64 -L/opt/rocm-5.1.1/hip/../lib64 -Wl,-rpath,/opt/rocm-5.1.1/hip/../lib64 -lhsakmt -lamd_comgr" CACHE STRING "") + +#------------------------------------------------ +# Hardware Specifics +#------------------------------------------------ + +set(ENABLE_OPENMP OFF CACHE BOOL "") + +set(ENABLE_GTEST_DEATH_TESTS ON CACHE BOOL "") diff --git a/host-configs/other/radiuss-aws-ec2.cmake b/host-configs/other/radiuss-aws-ec2.cmake new file mode 100644 index 000000000..c6de49370 --- /dev/null +++ b/host-configs/other/radiuss-aws-ec2.cmake @@ -0,0 +1,38 @@ +# Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details +# +# SPDX-License-Identifier: (BSD-3-Clause) + +#------------------------------------------------------------------------------ +# Example host-config file for the a basic AWS EC2 instance with OpenMPI +#------------------------------------------------------------------------------ +# +# This file provides CMake with paths / details for: +# C, C++, & Fortran compilers + MPI +# +#------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ +# gcc@7.3.1 compilers +#------------------------------------------------------------------------------ + +set(CMAKE_C_COMPILER "/usr/bin/gcc" CACHE PATH "") +set(CMAKE_CXX_COMPILER "/usr/bin/g++" CACHE PATH "") + +set(ENABLE_FORTRAN ON CACHE BOOL "") +set(CMAKE_Fortran_COMPILER "/usr/bin/gfortran" CACHE PATH "") + +#------------------------------------------------------------------------------ +# MPI Support +#------------------------------------------------------------------------------ +set(ENABLE_MPI ON CACHE BOOL "") + +set(MPI_HOME "/usr/lib64/openmpi" CACHE PATH "") + +set(MPI_C_COMPILER "${MPI_HOME}/bin/mpicc" CACHE PATH "") +set(MPI_CXX_COMPILER "${MPI_HOME}/bin/mpicxx" CACHE PATH "") +set(MPI_Fortran_COMPILER "${MPI_HOME}/bin/mpif90" CACHE PATH "") + +set(MPIEXEC "${MPI_HOME}/bin/mpirun" CACHE PATH "") +set(MPIEXEC_NUMPROC_FLAG "-np" CACHE STRING "") +set(BLT_MPI_COMMAND_APPEND "--oversubscribe" CACHE STRING "") diff --git a/scripts/make_local_branch_from_fork_pr.sh b/scripts/make_local_branch_from_fork_pr.sh new file mode 100755 index 000000000..75a72f044 --- /dev/null +++ b/scripts/make_local_branch_from_fork_pr.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +############################################################################### +# Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and +# other BLT Project Developers. See the top-level LICENSE file for details +# +# SPDX-License-Identifier: (BSD-3-Clause) +############################################################################### + +############################################################################### +# Help +############################################################################### +Help() +{ + # Display Help + echo + echo "This script will make a branch in a local git repo for a PR from a " + echo "branch in a forked repo. The script must be run inside the local repo." + echo + echo "Syntax: make_local_branch_from_fork_pr [-h | -c num | num]" + echo "options:" + echo "-h Print this help usage message." + echo "-c <#> Check whether there is a PR with given number." + echo "-b <#> Make local branch from branch associated with given PR number." + echo +} + +############################################################################### +# Process the input args. +############################################################################### +if [ "$1" == "" ]; then + echo + echo "You must pass an arg to script. Pass -h to see correct usage." + exit +fi + +while [ "$1" != "" ]; do + case $1 in + -h) # display help message + Help + exit;; + -c) # check PR exists + shift + num=$1 + echo + echo "Running git ls-remote on origin to see if PR ${num} exists..." + echo "If you don't see it in the output, it does not exist." + echo + git ls-remote --refs origin | grep "pull/${num}" + exit;; + -b) # make local branch for given PR number + shift + num=$1 + echo + echo "Attempting to make local branch from branch on fork for PR ${num}" + echo + echo "If successful, you will be on local branch pr-from-fork/${num}" + echo "when script exits." + echo + echo "Run 'git branch' to be sure the new branch exists." + echo + echo "You can then push the new branch to the main repo; e.g.," + echo " git push " + echo + echo "If you make a PR for the new branch, it is a good idea to " + echo "reference the original PR from the forked repo to track the " + echo "original PR discussion." + echo + git fetch origin pull/${num}/head:pr-from-fork/${num} && git checkout pr-from-fork/${num} + echo + + exit;; + \?) # incorrect option + echo + echo "Error: $1 is an invalid option" + exit;; + esac +done diff --git a/tests/internal/CMakeLists.txt b/tests/internal/CMakeLists.txt index 3bcacf7d2..c746f368e 100644 --- a/tests/internal/CMakeLists.txt +++ b/tests/internal/CMakeLists.txt @@ -227,6 +227,10 @@ if(ENABLE_GTEST) blt_list_append(TO _actual_list ELEMENTS "empty_escaped" IF ${_defined_empty_var}) blt_list_append(TO _actual_list ELEMENTS "nonempty_escaped" IF ${_defined_nonempty_var}) + # Check that ELEMENTS can be empty or missing when the IF condition is false + blt_list_append(TO _actual_list IF FALSE) + blt_list_append(TO _actual_list ELEMENTS "" IF FALSE) + # Check the results list(LENGTH _actual_list _actual_size) if(NOT "${_actual_list}" STREQUAL "${_expected_list}" @@ -253,20 +257,38 @@ if (ENABLE_CUDA AND ENABLE_MPI AND NUM_MPI_TASKS 4) endif() -message(STATUS "Exercising blt_print_target_properties macro on some targets and non-targets.") message(STATUS "") +message(STATUS "Exercising blt_print_target_properties macro default options.") foreach(_target gtest example t_example_smoke not-a-target blt_header_only mpi cuda cuda_runtime blt::hip blt::hip_runtime) blt_print_target_properties(TARGET ${_target}) endforeach() +message(STATUS "") +message(STATUS "Exercising blt_print_target_properties macro using regex arguments.") +foreach(_target gtest example t_example_smoke not-a-target blt_header_only mpi cuda cuda_runtime blt::hip blt::hip_runtime) + blt_print_target_properties(TARGET ${_target} CHILDREN true PROPERTY_NAME_REGEX "CXX_STANDARD_REQUIRED" PROPERTY_VALUE_REGEX "ON") +endforeach() + +message(STATUS "") +message(STATUS "Exercising blt_print_target_properties macro on dummy blt_registered target.") +blt_register_library(NAME foo) +blt_register_library(NAME bar DEPENDS_ON foo) +blt_print_target_properties(TARGET bar CHILDREN true) + +message(STATUS "") +message(STATUS "Exercising blt_print_target_properties macro. Testing infinite recursion") +blt_register_library(NAME foo DEPENDS_ON bar) +blt_register_library(NAME bar DEPENDS_ON foo) +blt_print_target_properties(TARGET bar CHILDREN true) + add_subdirectory(src/object_library_test) if(ENABLE_CLANGQUERY OR ENABLE_CLANGTIDY) - add_subdirectory(src/static_analysis) + add_subdirectory(src/static_analysis) endif() if(ENABLE_HIP) - add_subdirectory(src/hip_defines_test) + add_subdirectory(src/hip_defines_test) endif() add_subdirectory(unit) diff --git a/tests/internal/unit/CMakeLists.txt b/tests/internal/unit/CMakeLists.txt index edcad9ae2..5d7887361 100644 --- a/tests/internal/unit/CMakeLists.txt +++ b/tests/internal/unit/CMakeLists.txt @@ -151,3 +151,25 @@ message( "Tests passed for `blt_split_source_list_by_language`.\n" "*****************************************************") +message(STATUS "Checking for blt_check_code_compiles") + +blt_check_code_compiles(CODE_COMPILES _hello_world_compiled + VERBOSE_OUTPUT ON + SOURCE_STRING +[=[ +#include + +int main(int, char**) +{ + + std::cout << "Hello World!" << std::endl; + + return 0; +} +]=]) + +if(_hello_world_compiled) + message(STATUS "... passed") +else() + message(FATAL_ERROR "... failed to compile.") +endif() diff --git a/thirdparty_builtin/googletest-master-2020-01-07/googlemock/CMakeLists.txt b/thirdparty_builtin/googletest-master-2020-01-07/googlemock/CMakeLists.txt index 17ca62f5a..dde8aec39 100644 --- a/thirdparty_builtin/googletest-master-2020-01-07/googlemock/CMakeLists.txt +++ b/thirdparty_builtin/googletest-master-2020-01-07/googlemock/CMakeLists.txt @@ -42,7 +42,7 @@ else() cmake_policy(SET CMP0048 NEW) project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) endif() -cmake_minimum_required(VERSION 2.6.4) +cmake_minimum_required(VERSION 3.0) if (COMMAND set_up_hermetic_build) set_up_hermetic_build() diff --git a/thirdparty_builtin/googletest-master-2020-01-07/googletest/CMakeLists.txt b/thirdparty_builtin/googletest-master-2020-01-07/googletest/CMakeLists.txt index ae080855c..c956939ed 100644 --- a/thirdparty_builtin/googletest-master-2020-01-07/googletest/CMakeLists.txt +++ b/thirdparty_builtin/googletest-master-2020-01-07/googletest/CMakeLists.txt @@ -53,7 +53,7 @@ else() cmake_policy(SET CMP0048 NEW) project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) endif() -cmake_minimum_required(VERSION 2.6.4) +cmake_minimum_required(VERSION 3.0) if (POLICY CMP0063) # Visibility cmake_policy(SET CMP0063 NEW)