diff --git a/cmake/tribits/README.DIRECTORY_CONTENTS.rst b/cmake/tribits/README.DIRECTORY_CONTENTS.rst index 80067d5a83f8..a0f3d8ab7421 100644 --- a/cmake/tribits/README.DIRECTORY_CONTENTS.rst +++ b/cmake/tribits/README.DIRECTORY_CONTENTS.rst @@ -22,9 +22,10 @@ TriBITS refactorings of TriBITS. .. _TriBITS Core: -**core/**: Core TriBITS package-based architecture for CMake projects. This -only depends on raw CMake and contains just the minimal support for building, -testing, installing, and deployment. Only depends on CMake and nothing else. +**core/**: Core TriBITS test support and package-based architecture for CMake +projects. This only depends on raw CMake and contains just the minimal support +for building, testing, installing, and deployment. This CMake code depends +only on CMake and nothing else. **python_utils/**: Some basic Python utilities that are not specific to TriBITS but are used in TriBITS CI and testing support software. There are @@ -86,3 +87,49 @@ subdirectory. It supports the argument ``--components`` with values ``core``, * ``examples`` => (external tribits installation) * ``doc`` => ``core``, ``ci_support``, ``examples`` * ``devtools_install`` => ``python_utils`` + + +TriBITS Core Directory Contents +............................... + +The TriBITS ``core/`` directory is broken down into several subdirectories of +its own: + +**core/utils**: General CMake utilities that are not specific to the TriBITS +system and can be reused in any CMake project. + +**core/common**: As small set of common modules that the different TriBITS +Core module files in different directories depend on. These include things +like common TriBITS constants and TriBITS CMake policies. + +**core/test_support**: Modules that help define CTest tests using functions +like `tribits_add_test()`_ and `tribits_add_advanced_test()`_. These can be +used in CMake projects that are not full-blown TriBITS projects. + +**core/config_tests**: Some basic configure-time tests used by the TriBITS +package architecture framework. + +**core/std_tpls**: Some ``Find.cmake`` files for key external +dependencies handled as TriBITS TPLs but are more central to the TriBITS +system. (Examples include CUDA and MPI support.) + +**core/installation**: A collection of ``*.cmake.in`` and related Cmake code +supporting installations. + +**core/package_arch**: Modules for the full-blown TriBITS package architecture +framework including package dependency management, multi-repository support, +installations (including the generation of ``Config.cmake`` files), +etc. + +The dependencies between these different TriBITS `core` subdirectories are: + +* ``core/utils`` => (external CMake) +* ``core/common`` => ``core/utils`` +* ``core/test_support`` => ``core/utils``, ``core/common`` +* ``core/config_tests`` => (external CMake) +* ``core/std_tpls`` => (external CMake) +* ``core/installation`` <=> ``core/package_arch`` (bidirectional) +* ``core/package_arch`` => ``core/utils``, ``core/common``, + ``core/test_support``, ``core/config_tests``, ``core/std_tpls``, + ``core/installation`` + diff --git a/cmake/tribits/ci_support/TribitsDumpDepsXmlScript.cmake b/cmake/tribits/ci_support/TribitsDumpDepsXmlScript.cmake index f55d03364ca4..2d13260c0bd1 100644 --- a/cmake/tribits/ci_support/TribitsDumpDepsXmlScript.cmake +++ b/cmake/tribits/ci_support/TribitsDumpDepsXmlScript.cmake @@ -100,16 +100,16 @@ endif() get_filename_component( ${PROJECT_NAME}_TRIBITS_DIR "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE ) message("-- Setting ${PROJECT_NAME}_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}") +include("${CMAKE_CURRENT_LIST_DIR}/../core/common/TribitsConstants.cmake") +tribits_asesrt_minimum_cmake_version() +include("${CMAKE_CURRENT_LIST_DIR}/../core/common/TribitsCMakePolicies.cmake" NO_POLICY_SCOPE) + set( CMAKE_MODULE_PATH "${${PROJECT_NAME}_TRIBITS_DIR}/core/utils" "${${PROJECT_NAME}_TRIBITS_DIR}/core/package_arch" "${${PROJECT_NAME}_TRIBITS_DIR}/ci_support" ) -include(TribitsConstants) -tribits_asesrt_minimum_cmake_version() -include(TribitsCMakePolicies NO_POLICY_SCOPE) - include(TribitsGlobalMacros) include(TribitsPrintDependencyInfo) include(TribitsWriteXmlDependenciesFiles) diff --git a/cmake/tribits/ci_support/TribitsGetExtraReposForCheckinTest.cmake b/cmake/tribits/ci_support/TribitsGetExtraReposForCheckinTest.cmake index d0afd980bdd9..36853a8d9862 100644 --- a/cmake/tribits/ci_support/TribitsGetExtraReposForCheckinTest.cmake +++ b/cmake/tribits/ci_support/TribitsGetExtraReposForCheckinTest.cmake @@ -82,11 +82,12 @@ set(${PROJECT_NAME}_CHECK_EXTRAREPOS_EXIST ${CHECK_EXTRAREPOS_EXIST}) # B) Include files from TriBITS # +include("${CMAKE_CURRENT_LIST_DIR}/../core/common/TribitsCMakePolicies.cmake" NO_POLICY_SCOPE) + set( CMAKE_MODULE_PATH "${${PROJECT_NAME}_TRIBITS_DIR}/core/utils" "${${PROJECT_NAME}_TRIBITS_DIR}/core/package_arch" ) -include(TribitsCMakePolicies NO_POLICY_SCOPE) include(Split) include(AppendStringVar) include(SetDefaultAndFromEnv) # Used in ExtraRepositoriesList.cmake file? diff --git a/cmake/tribits/core/package_arch/TribitsCMakePolicies.cmake b/cmake/tribits/core/common/TribitsCMakePolicies.cmake similarity index 100% rename from cmake/tribits/core/package_arch/TribitsCMakePolicies.cmake rename to cmake/tribits/core/common/TribitsCMakePolicies.cmake diff --git a/cmake/tribits/core/package_arch/TribitsConstants.cmake b/cmake/tribits/core/common/TribitsConstants.cmake similarity index 100% rename from cmake/tribits/core/package_arch/TribitsConstants.cmake rename to cmake/tribits/core/common/TribitsConstants.cmake diff --git a/cmake/tribits/core/package_arch/TribitsAddExecutable.cmake b/cmake/tribits/core/package_arch/TribitsAddExecutable.cmake index ec989628f82f..567d22f4c242 100644 --- a/cmake/tribits/core/package_arch/TribitsAddExecutable.cmake +++ b/cmake/tribits/core/package_arch/TribitsAddExecutable.cmake @@ -38,9 +38,9 @@ # @HEADER -include(TribitsAddExecutableTestHelpers) +include("${CMAKE_CURRENT_LIST_DIR}/../test_support/TribitsAddExecutableTestHelpers.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../test_support/TribitsAddTestHelpers.cmake") include(TribitsCommonArgsHelpers) -include(TribitsAddTestHelpers) include(TribitsGeneralMacros) include(TribitsLibIsTestOnly) include(TribitsReportInvalidTribitsUsage) diff --git a/cmake/tribits/core/package_arch/TribitsAddExecutableAndTest.cmake b/cmake/tribits/core/package_arch/TribitsAddExecutableAndTest.cmake index 73148b8a8a76..7328f18558c0 100644 --- a/cmake/tribits/core/package_arch/TribitsAddExecutableAndTest.cmake +++ b/cmake/tribits/core/package_arch/TribitsAddExecutableAndTest.cmake @@ -38,8 +38,9 @@ # @HEADER +include("${CMAKE_CURRENT_LIST_DIR}/../test_support/TribitsAddTest.cmake") + include(TribitsAddExecutable) -include(TribitsAddTest) include(TribitsDeprecatedHelpers) diff --git a/cmake/tribits/core/package_arch/TribitsCopyFilesToBinaryDir.cmake b/cmake/tribits/core/package_arch/TribitsCopyFilesToBinaryDir.cmake index f4e1e3bc759c..ffeef4bdbb80 100644 --- a/cmake/tribits/core/package_arch/TribitsCopyFilesToBinaryDir.cmake +++ b/cmake/tribits/core/package_arch/TribitsCopyFilesToBinaryDir.cmake @@ -38,7 +38,6 @@ # @HEADER -include(TribitsAddTestHelpers) include(CMakeParseArguments) diff --git a/cmake/tribits/core/package_arch/TribitsGlobalMacros.cmake b/cmake/tribits/core/package_arch/TribitsGlobalMacros.cmake index 28c0fa807ee0..63149a375002 100644 --- a/cmake/tribits/core/package_arch/TribitsGlobalMacros.cmake +++ b/cmake/tribits/core/package_arch/TribitsGlobalMacros.cmake @@ -38,11 +38,14 @@ # @HEADER # Standard TriBITS system includes -include(TribitsConstants) + +include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsConstants.cmake") + +include("${CMAKE_CURRENT_LIST_DIR}/../test_support/TribitsTestCategories.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../test_support/TribitsAddTestHelpers.cmake") + include(TribitsSetupMPI) -include(TribitsTestCategories) include(TribitsGeneralMacros) -include(TribitsAddTestHelpers) include(TribitsVerbosePrintVar) include(TribitsProcessEnabledTpls) include(TribitsInstallHeaders) @@ -464,13 +467,6 @@ macro(tribits_define_global_options_and_define_extra_repos) "Make the ${PROJECT_NAME} configure process verbose." ) - if ("${${PROJECT_NAME}_TRACE_ADD_TEST_DEFAULT}" STREQUAL "") - set(${PROJECT_NAME}_TRACE_ADD_TEST_DEFAULT ${${PROJECT_NAME}_VERBOSE_CONFIGURE}) - endif() - advanced_set(${PROJECT_NAME}_TRACE_ADD_TEST ${${PROJECT_NAME}_TRACE_ADD_TEST_DEFAULT} - CACHE BOOL - "Show a configure time trace of every test added or not added any why (one line)." ) - advanced_option(${PROJECT_NAME}_DUMP_LINK_LIBS "Dump the link libraries for every library and executable created." "${${PROJECT_NAME}_VERBOSE_CONFIGURE}" ) @@ -2072,17 +2068,20 @@ macro(tribits_configure_enabled_packages) tribits_trace_file_processing(PACKAGE ADD_SUBDIR "${TRIBITS_PACKAGE_CMAKELIST_FILE}") if (NOT ${TRIBITS_PACKAGE}_SOURCE_DIR STREQUAL ${PROJECT_NAME}_SOURCE_DIR) - add_subdirectory(${${TRIBITS_PACKAGE}_SOURCE_DIR} ${${TRIBITS_PACKAGE}_BINARY_DIR}) + add_subdirectory(${${TRIBITS_PACKAGE}_SOURCE_DIR} + ${${TRIBITS_PACKAGE}_BINARY_DIR}) else() include("${TRIBITS_PACKAGE_CMAKELIST_FILE}") endif() - if (NOT ${PACKAGE_NAME}_TRIBITS_PACKAGE_POSTPROCESS) + if ((NOT ${PACKAGE_NAME}_TRIBITS_PACKAGE_POSTPROCESS) AND + (NOT TARGET ${PACKAGE_NAME}::all_libs) + ) tribits_report_invalid_tribits_usage( "ERROR: Forgot to call tribits_package_postprocess() in" " ${TRIBITS_PACKAGE_CMAKELIST_FILE}") endif() - list(APPEND ENABLED_PACKAGE_LIBS_TARGETS ${TRIBITS_PACKAGE}_libs) + list(APPEND ENABLED_PACKAGE_LIBS_TARGETS ${TRIBITS_PACKAGE}::all_libs) list(APPEND ${PROJECT_NAME}_LIBRARIES ${${TRIBITS_PACKAGE}_LIBRARIES}) tribits_package_config_code_stop_timer(PROCESS_THIS_PACKAGE_TIME_START_SECONDS diff --git a/cmake/tribits/core/package_arch/TribitsInternalPackageWriteConfigFile.cmake b/cmake/tribits/core/package_arch/TribitsInternalPackageWriteConfigFile.cmake index 7d3c1bb683b2..e820d6222e49 100644 --- a/cmake/tribits/core/package_arch/TribitsInternalPackageWriteConfigFile.cmake +++ b/cmake/tribits/core/package_arch/TribitsInternalPackageWriteConfigFile.cmake @@ -84,12 +84,12 @@ function(tribits_write_package_client_export_files PACKAGE_NAME) tribits_write_flexible_package_client_export_files(${EXPORT_FILES_ARGS}) - tribits_write_package_client_export_files_install_targets(${EXPORT_FILES_ARGS}) + tribits_write_package_client_export_files_export_and_install_targets(${EXPORT_FILES_ARGS}) endfunction() -# @FUNCTION: tribits_write_package_client_export_files_install_targets() +# @FUNCTION: tribits_write_package_client_export_files_export_and_install_targets() # # Create the ``ConfigTargets.cmake`` file and install rules and the # install() target for the previously generated @@ -98,7 +98,7 @@ endfunction() # # Usage:: # -# tribits_write_package_client_export_files_install_targets( +# tribits_write_package_client_export_files_export_and_install_targets( # PACKAGE_NAME # PACKAGE_CONFIG_FOR_BUILD_BASE_DIR # PACKAGE_CONFIG_FOR_INSTALL_BASE_DIR @@ -107,7 +107,7 @@ endfunction() # The install() commands must be in a different subroutine or CMake will not # allow you to call the routine, even if you if() it out! # -function(tribits_write_package_client_export_files_install_targets) +function(tribits_write_package_client_export_files_export_and_install_targets) cmake_parse_arguments( #prefix @@ -333,10 +333,10 @@ endfunction() # @FUNCTION: tribits_write_flexible_package_client_export_files() # -# Utility function for writing ``${PACKAGE_NAME}Config.cmake`` files for -# package ``${PACKAGE_NAME}`` with some greater flexibility than what is -# provided by the function ``tribits_write_package_client_export_files()`` and -# to allow unit testing the generation of these files.. +# Utility function for writing the ``${PACKAGE_NAME}Config.cmake`` files for +# the build dir and/or for the install dir for the package ```` +# with some flexibility . (See NOTE below for what is actually generated and +# what is *NOT* generated.) # # Usage:: # @@ -352,7 +352,8 @@ endfunction() # ``PACKAGE_NAME `` # # Gives the name of the TriBITS package for which the export files should -# be created. +# be created. (This must match the export set for the libraries for the +# generated/exported ``ConfigTargets.cmake`` file.) # # ``EXPORT_FILE_VAR_PREFIX `` # @@ -362,28 +363,39 @@ endfunction() # # ``PACKAGE_CONFIG_FOR_BUILD_BASE_DIR `` # -# If specified, then the package's ``Config.cmake`` file and -# supporting files will be written under the directory -# ``/`` (and any subdirs that does exist -# will be created). The generated file ``Config.cmake`` is -# for usage of the package in the build tree (not the install tree) and -# points to include directories and libraries in the build tree. +# If specified, then the package's ``Config.cmake`` file will +# be written under the directory ``/`` (and +# any subdirs that do not exist will be created). The generated file +# ``Config.cmake`` is for usage of the package in the build +# tree (not the install tree) and points to include directories and +# libraries in the build tree. (NOTE: The included +# ``Targets.cmake`` file is *NOT* generated in this +# function.) # # ``PACKAGE_CONFIG_FOR_INSTALL_BASE_DIR `` # # If specified, then the package's ``Config_install.cmake`` -# file and supporting files will be written under the directory -# ``/`` (and any subdirs that does exist +# file will be written under the directory +# ``/`` (and any subdirs that do not exist # will be created). The file ``${PACKAGE_NAME}Config_install.cmake`` is # meant to be installed renamed as ``Config.cmake`` in the # install tree and it points to installed include directories and -# libraries. -# -# NOTE: This function does *not* contain any ``install()`` command itself -# because CMake will not allow those to even be present in scripting mode that -# is used for unit testing this function. Instead, the commands to install -# the files are added by the function -# ``tribits_write_package_client_export_files_install_targets()``. +# libraries. (NOTE: The included ``Targets.cmake`` +# file is *NOT* generated in this function.) +# +# NOTE: This function does *not* generate the ``Config.cmake`` +# files (which will be created later using ``export()`` or ``include()`) which +# are included in these generated package config files and this function. +# Also, this function does *not* invoke the ``install()`` command to install +# the package config file for the install directory. The ``export()`` and +# ``install()`` project commands are bot allowed in `cmake -P` scripting mode +# that is used for unit testing this function. Instead, the commands to +# generate the ``Targets.cmake`` files and install the package +# config file for the install tree are produced by the function +# ``tribits_write_package_client_export_files_export_and_install_targets()`` +# which is called after this function. This allows this function +# ``tribits_write_package_client_export_files()`` to be run in unit testing +# with a `cmake -P` script. # function(tribits_write_flexible_package_client_export_files) diff --git a/cmake/tribits/core/package_arch/TribitsPackageDependencies.cmake b/cmake/tribits/core/package_arch/TribitsPackageDependencies.cmake index 0f4a956dd783..5f2e31595b8b 100644 --- a/cmake/tribits/core/package_arch/TribitsPackageDependencies.cmake +++ b/cmake/tribits/core/package_arch/TribitsPackageDependencies.cmake @@ -50,7 +50,8 @@ include_guard() -include(TribitsCMakePolicies NO_POLICY_SCOPE) +include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsCMakePolicies.cmake" + NO_POLICY_SCOPE) include(TribitsParseArgumentsHelpers) include(MessageWrapper) diff --git a/cmake/tribits/core/package_arch/TribitsPackageMacros.cmake b/cmake/tribits/core/package_arch/TribitsPackageMacros.cmake index 0a091c4d2d74..d7931c4067bd 100644 --- a/cmake/tribits/core/package_arch/TribitsPackageMacros.cmake +++ b/cmake/tribits/core/package_arch/TribitsPackageMacros.cmake @@ -51,13 +51,14 @@ include(PrependGlobalSet) include(RemoveGlobalDuplicates) include(TribitsGatherBuildTargets) +include("${CMAKE_CURRENT_LIST_DIR}/../test_support/TribitsAddTest.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../test_support/TribitsAddAdvancedTest.cmake") + include(TribitsAddOptionAndDefine) include(TribitsPkgExportCacheVars) include(TribitsLibraryMacros) include(TribitsAddExecutable) include(TribitsAddExecutableAndTest) -include(TribitsAddTest) -include(TribitsAddAdvancedTest) include(TribitsCopyFilesToBinaryDir) include(TribitsReportInvalidTribitsUsage) diff --git a/cmake/tribits/core/package_arch/TribitsProcessTplsLists.cmake b/cmake/tribits/core/package_arch/TribitsProcessTplsLists.cmake index f5e5a6e55d63..a30a09404537 100644 --- a/cmake/tribits/core/package_arch/TribitsProcessTplsLists.cmake +++ b/cmake/tribits/core/package_arch/TribitsProcessTplsLists.cmake @@ -38,7 +38,7 @@ # @HEADER -include(TribitsConstants) +include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsConstants.cmake") include(TribitsListHelpers) include(PrintVar) diff --git a/cmake/tribits/core/package_arch/TribitsProject.cmake b/cmake/tribits/core/package_arch/TribitsProject.cmake index 035e089e3ad1..c2385f166511 100644 --- a/cmake/tribits/core/package_arch/TribitsProject.cmake +++ b/cmake/tribits/core/package_arch/TribitsProject.cmake @@ -66,7 +66,7 @@ if (${PROJECT_NAME}_VERBOSE_CONFIGURE) endif() # Overrides that we have for CMake functions -include(TribitsCMakePolicies NO_POLICY_SCOPE) +include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsCMakePolicies.cmake" NO_POLICY_SCOPE) include(TribitsProjectImpl) diff --git a/cmake/tribits/core/package_arch/TribitsProjectImpl.cmake b/cmake/tribits/core/package_arch/TribitsProjectImpl.cmake index be62ab071113..8eab07d42c0a 100644 --- a/cmake/tribits/core/package_arch/TribitsProjectImpl.cmake +++ b/cmake/tribits/core/package_arch/TribitsProjectImpl.cmake @@ -47,6 +47,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${${PROJECT_NAME}_TRIBITS_DIR}/core/utils + ${${PROJECT_NAME}_TRIBITS_DIR}/core/common + ${${PROJECT_NAME}_TRIBITS_DIR}/core/test_support ${${PROJECT_NAME}_TRIBITS_DIR}/core/package_arch ${${PROJECT_NAME}_TRIBITS_DIR}/core/config_tests ${${PROJECT_NAME}_TRIBITS_DIR}/core/modules @@ -57,9 +59,9 @@ if (${PROJECT_NAME}_VERBOSE_CONFIGURE) message("CMAKE_MODULE_PATH='${CMAKE_MODULE_PATH}'") endif() -include(TribitsConstants) +include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsConstants.cmake") tribits_asesrt_minimum_cmake_version() -include(TribitsCMakePolicies NO_POLICY_SCOPE) +include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsCMakePolicies.cmake" NO_POLICY_SCOPE) # TriBITS package_arch includes include(TribitsIncludeDirectories) diff --git a/cmake/tribits/core/package_arch/TribitsReadAllProjectDepsFilesCreateDepsGraph.cmake b/cmake/tribits/core/package_arch/TribitsReadAllProjectDepsFilesCreateDepsGraph.cmake index deaa8b5a463b..14175ee5adc0 100644 --- a/cmake/tribits/core/package_arch/TribitsReadAllProjectDepsFilesCreateDepsGraph.cmake +++ b/cmake/tribits/core/package_arch/TribitsReadAllProjectDepsFilesCreateDepsGraph.cmake @@ -39,7 +39,7 @@ # Standard TriBITS system includes -include(TribitsConstants) +include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsConstants.cmake") include(TribitsProcessExtraRepositoriesList) include(TribitsProcessPackagesAndDirsLists) include(TribitsProcessTplsLists) diff --git a/cmake/tribits/core/package_arch/TribitsAddAdvancedTest.cmake b/cmake/tribits/core/test_support/TribitsAddAdvancedTest.cmake similarity index 97% rename from cmake/tribits/core/package_arch/TribitsAddAdvancedTest.cmake rename to cmake/tribits/core/test_support/TribitsAddAdvancedTest.cmake index fca20e1113a6..21deffdea128 100644 --- a/cmake/tribits/core/package_arch/TribitsAddAdvancedTest.cmake +++ b/cmake/tribits/core/test_support/TribitsAddAdvancedTest.cmake @@ -37,14 +37,16 @@ # ************************************************************************ # @HEADER -include(TribitsCMakePolicies NO_POLICY_SCOPE) +include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsCMakePolicies.cmake" NO_POLICY_SCOPE) +include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsConstants.cmake") -include(TribitsAddAdvancedTestHelpers) -include(TribitsConstants) +set(tribitsAddAdvancedTestModuleDir "${CMAKE_CURRENT_LIST_DIR}") -include(TribitsPrintList) -include(AppendStringVar) -include(PrintVar) +include("${CMAKE_CURRENT_LIST_DIR}/TribitsAddAdvancedTestHelpers.cmake") + +include("${CMAKE_CURRENT_LIST_DIR}/../utils/TribitsPrintList.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/AppendStringVar.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/PrintVar.cmake") # @FUNCTION: tribits_add_advanced_test() @@ -853,10 +855,9 @@ include(PrintVar) # # The function ``tribits_add_advanced_test()`` can be used to add tests in # non-TriBITS projects. To do so, one just needs to set the variables -# ``PROJECT_NAME``, ``PACKAGE_NAME`` (which could be the same as -# ``PROJECT_NAME``), ``${PACKAGE_NAME}_ENABLE_TESTS=TRUE``, and -# ``${PROJECT_NAME}_TRIBITS_DIR`` (pointing to the TriBITS location). For example, -# a valid project can be a simple as:: +# ``${PROJECT_NAME}_ENABLE_TESTS=TRUE`` and ``${PROJECT_NAME}_TRIBITS_DIR`` +# (pointing to the TriBITS location). For example, a valid project can be a +# simple as:: # # cmake_minimum_required(VERSION 3.23.0) # set(PROJECT_NAME TAATDriver) @@ -866,36 +867,40 @@ include(PrintVar) # "Location of TriBITS to use." ) # set(PACKAGE_NAME ${PROJECT_NAME}) # set(${PACKAGE_NAME}_ENABLE_TESTS TRUE) -# set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} -# ${TRIBITS_DIR}/core/utils -# ${TRIBITS_DIR}/core/package_arch ) -# include(TribitsAddAdvancedTest) +# include("${${PROJECT_NAME}_TRIBITS_DIR}/core/test_support/TribitsAddAdvancedTest.cmake") # include(CTest) # enable_testing() # -# tribits_add_advanced_test( -# TAAT_COPY_FILES_TO_TEST_DIR_bad_file_name +# tribits_add_advanced_test( HelloWorld # OVERALL_WORKING_DIRECTORY TEST_NAME # TEST_0 CMND echo ARGS "Hello World!" # PASS_REGULAR_EXPRESIOIN "Hello World" # ) # +# Above, one can replace:: +# +# include("${${PROJECT_NAME}_TRIBITS_DIR}/core/test_support/TribitsAddAdvancedTest.cmake") +# +# with:: +# +# list(PREPEND CMAKE_MODULE_PATH "${${PROJECT_NAME}_TRIBITS_DIR}/core/test_support") +# include(TribitsAddAdvancedTest) +# +# and it will have the same effect. +# function(tribits_add_advanced_test TEST_NAME_IN) if (${PROJECT_NAME}_VERBOSE_CONFIGURE) message("\nPACKAGE_ADD_ADVANCED_TEST: ${TEST_NAME_IN}\n") endif() + tribits_set_tribits_package_name() + global_set(TRIBITS_SET_TEST_PROPERTIES_INPUT) global_set(MESSAGE_WRAPPER_INPUT) # Set the full TEST_NAME - if (PACKAGE_NAME) - set(TEST_NAME ${PACKAGE_NAME}_${TEST_NAME_IN}) - else() - set(TEST_NAME ${TEST_NAME_IN}) - endif() - + set(TEST_NAME ${PACKAGE_NAME}_${TEST_NAME_IN}) # # A) Parse the overall arguments and figure out how many tests @@ -1518,6 +1523,8 @@ function(tribits_add_advanced_test TEST_NAME_IN) # F.2) Write the cmake -P script # + set(coreUtilsDir "${tribitsAddAdvancedTestModuleDir}/../utils") + cmake_path(NORMAL_PATH coreUtilsDir) string(APPEND TEST_SCRIPT_STR "\n" "set(PROJECT_NAME ${PROJECT_NAME})\n" @@ -1548,9 +1555,7 @@ function(tribits_add_advanced_test TEST_NAME_IN) "# Test invocation\n" "#\n" "\n" - "set(CMAKE_MODULE_PATH ${${PROJECT_NAME}_TRIBITS_DIR}/${TRIBITS_CMAKE_UTILS_DIR})\n" - "\n" - "include(DriveAdvancedTest)\n" + "include(\"${coreUtilsDir}/DriveAdvancedTest.cmake\")\n" "\n" "drive_advanced_test()\n" ) diff --git a/cmake/tribits/core/package_arch/TribitsAddAdvancedTestHelpers.cmake b/cmake/tribits/core/test_support/TribitsAddAdvancedTestHelpers.cmake similarity index 98% rename from cmake/tribits/core/package_arch/TribitsAddAdvancedTestHelpers.cmake rename to cmake/tribits/core/test_support/TribitsAddAdvancedTestHelpers.cmake index 8c2e11df36ac..c7fb556b4d33 100644 --- a/cmake/tribits/core/package_arch/TribitsAddAdvancedTestHelpers.cmake +++ b/cmake/tribits/core/test_support/TribitsAddAdvancedTestHelpers.cmake @@ -38,7 +38,7 @@ # @HEADER -include(TribitsAddTestHelpers) +include("${CMAKE_CURRENT_LIST_DIR}/TribitsAddTestHelpers.cmake") # Set default ax number of TEST_ blocks in tribits_add_advanced_test() diff --git a/cmake/tribits/core/package_arch/TribitsAddExecutableTestHelpers.cmake b/cmake/tribits/core/test_support/TribitsAddExecutableTestHelpers.cmake similarity index 92% rename from cmake/tribits/core/package_arch/TribitsAddExecutableTestHelpers.cmake rename to cmake/tribits/core/test_support/TribitsAddExecutableTestHelpers.cmake index 78f98f0bac4e..c2bc95d0ddaa 100644 --- a/cmake/tribits/core/package_arch/TribitsAddExecutableTestHelpers.cmake +++ b/cmake/tribits/core/test_support/TribitsAddExecutableTestHelpers.cmake @@ -37,22 +37,23 @@ # ************************************************************************ # @HEADER -include(TribitsCMakePolicies NO_POLICY_SCOPE) +include_guard() -include(AdvancedSet) -include(MessageWrapper) +include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsCMakePolicies.cmake" NO_POLICY_SCOPE) + +include("${CMAKE_CURRENT_LIST_DIR}/../utils/AdvancedSet.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/MessageWrapper.cmake") advanced_set( ${PROJECT_NAME}_CMAKE_EXECUTABLE_SUFFIX ".exe" CACHE STRING "Default exec suffix on all platforms (can be overridden by each executable added)." ) -# + # Process the COMM arguments # # NOTE: The COMM array arguments is passed as ${ARGN} # - -function( tribits_process_comm_args ADD_SERIAL_FEATURE_OUT ADD_MPI_FEATURE_OUT ) +function(tribits_process_comm_args ADD_SERIAL_FEATURE_OUT ADD_MPI_FEATURE_OUT ) set(COMM_ARRAY ${ARGN}) diff --git a/cmake/tribits/core/package_arch/TribitsAddTest.cmake b/cmake/tribits/core/test_support/TribitsAddTest.cmake similarity index 99% rename from cmake/tribits/core/package_arch/TribitsAddTest.cmake rename to cmake/tribits/core/test_support/TribitsAddTest.cmake index 6f388fdaca40..9e23d71c3c06 100644 --- a/cmake/tribits/core/package_arch/TribitsAddTest.cmake +++ b/cmake/tribits/core/test_support/TribitsAddTest.cmake @@ -37,8 +37,9 @@ # ************************************************************************ # @HEADER -include(TribitsCMakePolicies NO_POLICY_SCOPE) -include(TribitsAddTestHelpers) + +include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsCMakePolicies.cmake" NO_POLICY_SCOPE) +include("${CMAKE_CURRENT_LIST_DIR}/TribitsAddTestHelpers.cmake") # @FUNCTION: tribits_add_test() @@ -817,6 +818,8 @@ function(tribits_add_test EXE_NAME) message("TRIBITS_ADD_TEST: ${EXE_NAME} ${ARGN}") endif() + tribits_set_tribits_package_name() + global_set(TRIBITS_ADD_TEST_ADD_TEST_INPUT) global_set(TRIBITS_SET_TEST_PROPERTIES_INPUT) global_set(MESSAGE_WRAPPER_INPUT) @@ -935,8 +938,6 @@ function(tribits_add_test EXE_NAME) tribits_add_test_adjust_directory( ${EXE_BINARY_NAME} "${PARSE_DIRECTORY}" EXECUTABLE_PATH) - #message("TRIBITS_ADD_TEST: ${EXE_NAME}: EXECUTABLE_PATH = ${EXECUTABLE_PATH}") - # # D) Determine if we will add the serial or MPI tests based on input COMM # and TPL_ENABLE_MPI diff --git a/cmake/tribits/core/package_arch/TribitsAddTestHelpers.cmake b/cmake/tribits/core/test_support/TribitsAddTestHelpers.cmake similarity index 96% rename from cmake/tribits/core/package_arch/TribitsAddTestHelpers.cmake rename to cmake/tribits/core/test_support/TribitsAddTestHelpers.cmake index 715bca20f9b0..98190718a47f 100644 --- a/cmake/tribits/core/package_arch/TribitsAddTestHelpers.cmake +++ b/cmake/tribits/core/test_support/TribitsAddTestHelpers.cmake @@ -37,19 +37,25 @@ # ************************************************************************ # @HEADER +include_guard() -include(TribitsAddExecutableTestHelpers) -include(TribitsGeneralMacros) -include(TribitsTestCategories) - -include(CMakeParseArguments) -include(GlobalSet) -include(AppendGlobalSet) -include(AppendStringVarWithSep) -include(PrintVar) -include(AdvancedSet) -include(MessageWrapper) -include(TribitsGetCategoriesString) +include("${CMAKE_CURRENT_LIST_DIR}/TribitsAddExecutableTestHelpers.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/TribitsSetTribitsPackageName.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/TribitsTestCategories.cmake") + +include("${CMAKE_CURRENT_LIST_DIR}/../utils/GlobalSet.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/AppendGlobalSet.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/AppendStringVarWithSep.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/PrintVar.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/AdvancedSet.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/MessageWrapper.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/TribitsGetCategoriesString.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/TribitsSetCacheVarAndDefault.cmake") + + +tribits_advanced_set_cache_var_and_default(${PROJECT_NAME}_TRACE_ADD_TEST BOOL + "${${PROJECT_NAME}_VERBOSE_CONFIGURE}" + "Show a configure-time trace of every test added or not added any why (one line).") # Do initialization for test helpers diff --git a/cmake/tribits/core/test_support/TribitsSetTribitsPackageName.cmake b/cmake/tribits/core/test_support/TribitsSetTribitsPackageName.cmake new file mode 100644 index 000000000000..2a08b4bebf10 --- /dev/null +++ b/cmake/tribits/core/test_support/TribitsSetTribitsPackageName.cmake @@ -0,0 +1,55 @@ +# @HEADER +# ************************************************************************ +# +# TriBITS: Tribal Build, Integrate, and Test System +# Copyright 2013 Sandia Corporation +# +# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +# the U.S. Government retains certain rights in this software. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# 3. Neither the name of the Corporation nor the names of the +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "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 SANDIA CORPORATION OR THE +# 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. +# +# ************************************************************************ +# @HEADER + + +include("${CMAKE_CURRENT_LIST_DIR}/../utils/MessageWrapper.cmake") + + +# Set the TriBITS package name var if it has not already been set +# +macro(tribits_set_tribits_package_name) + if ("${PACKAGE_NAME}" STREQUAL "") + if (NOT "${PROJECT_NAME}" STREQUAL "") + set(PACKAGE_NAME ${PROJECT_NAME}) + else() + message_wrapper(FATAL_ERROR "Error! Can't set default PACKAGE_NAME because" + " PROJECT_NAME is not set!") + endif() + endif() +endmacro() diff --git a/cmake/tribits/core/package_arch/TribitsTestCategories.cmake b/cmake/tribits/core/test_support/TribitsTestCategories.cmake similarity index 94% rename from cmake/tribits/core/package_arch/TribitsTestCategories.cmake rename to cmake/tribits/core/test_support/TribitsTestCategories.cmake index acd55cee153d..a6f053d63977 100644 --- a/cmake/tribits/core/package_arch/TribitsTestCategories.cmake +++ b/cmake/tribits/core/test_support/TribitsTestCategories.cmake @@ -37,10 +37,10 @@ # ************************************************************************ # @HEADER -include(FindListElement) -include(MessageWrapper) -include(Join) -include(TribitsDeprecatedHelpers) +include("${CMAKE_CURRENT_LIST_DIR}/../utils/FindListElement.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/MessageWrapper.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/Join.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/TribitsDeprecatedHelpers.cmake") # Define the valid categories that will be recognized in the CATEGORIES keyword diff --git a/cmake/tribits/core/utils/AppendGlobalSet.cmake b/cmake/tribits/core/utils/AppendGlobalSet.cmake index 51251dc326e9..04d95f2b5493 100644 --- a/cmake/tribits/core/utils/AppendGlobalSet.cmake +++ b/cmake/tribits/core/utils/AppendGlobalSet.cmake @@ -37,8 +37,8 @@ # ************************************************************************ # @HEADER -include(GlobalSet) -include(AssertDefined) +include("${CMAKE_CURRENT_LIST_DIR}/GlobalSet.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/AssertDefined.cmake") # @FUNCTION: append_global_set() diff --git a/cmake/tribits/core/utils/AppendStringVar.cmake b/cmake/tribits/core/utils/AppendStringVar.cmake index dbd0c1fb5d1b..bac3a6bac8f1 100644 --- a/cmake/tribits/core/utils/AppendStringVar.cmake +++ b/cmake/tribits/core/utils/AppendStringVar.cmake @@ -37,9 +37,11 @@ # ************************************************************************ # @HEADER -include(ConcatStrings) -include(PrintVar) -include(TribitsDeprecatedHelpers) +include_guard() + +include("${CMAKE_CURRENT_LIST_DIR}/ConcatStrings.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/PrintVar.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/TribitsDeprecatedHelpers.cmake") # @FUNCTION: append_string_var() diff --git a/cmake/tribits/core/utils/AppendStringVarWithSep.cmake b/cmake/tribits/core/utils/AppendStringVarWithSep.cmake index c671ff582ea0..6e8ccf9fb614 100644 --- a/cmake/tribits/core/utils/AppendStringVarWithSep.cmake +++ b/cmake/tribits/core/utils/AppendStringVarWithSep.cmake @@ -37,7 +37,7 @@ # ************************************************************************ # @HEADER -include(ConcatStrings) +include("${CMAKE_CURRENT_LIST_DIR}/ConcatStrings.cmake") # @FUNCTION: append_string_var_with_sep() diff --git a/cmake/tribits/core/utils/ConcatStrings.cmake b/cmake/tribits/core/utils/ConcatStrings.cmake index a2fdc3c41ae7..cf5fd64e6e3a 100644 --- a/cmake/tribits/core/utils/ConcatStrings.cmake +++ b/cmake/tribits/core/utils/ConcatStrings.cmake @@ -37,7 +37,7 @@ # ************************************************************************ # @HEADER -include(PrintVar) +include("${CMAKE_CURRENT_LIST_DIR}/PrintVar.cmake") # @FUNCTION: concat_strings() diff --git a/cmake/tribits/core/utils/DriveAdvancedTest.cmake b/cmake/tribits/core/utils/DriveAdvancedTest.cmake index 87a4a82308af..6ccb55fd7a3e 100644 --- a/cmake/tribits/core/utils/DriveAdvancedTest.cmake +++ b/cmake/tribits/core/utils/DriveAdvancedTest.cmake @@ -37,11 +37,13 @@ # ************************************************************************ # @HEADER -include(PrintVar) -include(AppendStringVar) -include(Join) -include(TimingUtils) -include(TribitsGetCategoriesString) +include_guard() + +include("${CMAKE_CURRENT_LIST_DIR}/PrintVar.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/AppendStringVar.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/Join.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/TimingUtils.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/TribitsGetCategoriesString.cmake") function(print_current_date_time PREFIX_STR) diff --git a/cmake/tribits/core/utils/MessageWrapper.cmake b/cmake/tribits/core/utils/MessageWrapper.cmake index bdcd9e5e2966..220f9c8ff6dd 100644 --- a/cmake/tribits/core/utils/MessageWrapper.cmake +++ b/cmake/tribits/core/utils/MessageWrapper.cmake @@ -39,7 +39,7 @@ include_guard() -include(GlobalSet) +include("${CMAKE_CURRENT_LIST_DIR}/GlobalSet.cmake") # @FUNCTION: message_wrapper() # diff --git a/cmake/tribits/core/utils/TimingUtils.cmake b/cmake/tribits/core/utils/TimingUtils.cmake index a83445663f02..ac6351ab9d77 100644 --- a/cmake/tribits/core/utils/TimingUtils.cmake +++ b/cmake/tribits/core/utils/TimingUtils.cmake @@ -44,7 +44,7 @@ # platforms so call with care. # -include(Split) +include("${CMAKE_CURRENT_LIST_DIR}/Split.cmake") # @FUNCTION: timer_get_raw_seconds() diff --git a/cmake/tribits/core/utils/TribitsDeprecatedHelpers.cmake b/cmake/tribits/core/utils/TribitsDeprecatedHelpers.cmake index 0ae57138e050..ee6c7fae2267 100644 --- a/cmake/tribits/core/utils/TribitsDeprecatedHelpers.cmake +++ b/cmake/tribits/core/utils/TribitsDeprecatedHelpers.cmake @@ -37,8 +37,10 @@ # ************************************************************************ # @HEADER -include(MessageWrapper) -include(TribitsParseArgumentsHelpers) +include_guard() + +include("${CMAKE_CURRENT_LIST_DIR}/MessageWrapper.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/TribitsParseArgumentsHelpers.cmake") set(TRIBITS_HANDLE_TRIBITS_DEPRECATED_CODE_VALUES_THAT_CALL_MESSAGE diff --git a/cmake/tribits/core/utils/TribitsParseArgumentsHelpers.cmake b/cmake/tribits/core/utils/TribitsParseArgumentsHelpers.cmake index 75327668f67f..9058db674d56 100644 --- a/cmake/tribits/core/utils/TribitsParseArgumentsHelpers.cmake +++ b/cmake/tribits/core/utils/TribitsParseArgumentsHelpers.cmake @@ -46,7 +46,7 @@ ################################################################################ -include(MessageWrapper) +include("${CMAKE_CURRENT_LIST_DIR}/MessageWrapper.cmake") # @FUNCTION: tribits_check_for_unparsed_arguments() diff --git a/cmake/tribits/core/utils/TribitsSetCacheVarAndDefault.cmake b/cmake/tribits/core/utils/TribitsSetCacheVarAndDefault.cmake new file mode 100644 index 000000000000..a90c45aad4a9 --- /dev/null +++ b/cmake/tribits/core/utils/TribitsSetCacheVarAndDefault.cmake @@ -0,0 +1,89 @@ +# @HEADER +# ************************************************************************ +# +# TriBITS: Tribal Build, Integrate, and Test System +# Copyright 2013 Sandia Corporation +# +# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +# the U.S. Government retains certain rights in this software. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# 3. Neither the name of the Corporation nor the names of the +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "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 SANDIA CORPORATION OR THE +# 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. +# +# ************************************************************************ +# @HEADER + +include_guard() + + +# @MACRO: tribits_advanced_set_cache_var_and_default() +# +# Set an advanced cache variable with a default value (passing in a default +# default value). +# +# Usage:: +# +# tribits_advanced_set_cache_var_and_default( +# ) +# +# If the variable ``_DEFAULT`` already exists with a value, that +# is used as the default cache variable. Otherwise, +# ``_DEFAULT`` is set set to ```` first. +# +macro(tribits_advanced_set_cache_var_and_default cacheVarName cacheVarType + defaultDefaultVal docString + ) + tribits_set_cache_var_and_default("${cacheVarName}" "${cacheVarType}" + "${defaultDefaultVal}" "${docString}") + mark_as_advanced(${cacheVarName}) +endmacro() + + +# @MACRO: tribits_set_cache_var_and_default() +# +# Set a cache variable with a default value (passing in a default default +# value). +# +# Usage:: +# +# tribits_set_cache_var_and_default( +# ) +# +# If the variable ``_DEFAULT`` already exists with a value, that +# is used as the default cache variable. Otherwise, +# ``_DEFAULT`` is set set to ```` first. +# +macro(tribits_set_cache_var_and_default cacheVarName cacheVarType + defaultDefaultVal docString + ) + if ("${${cacheVarName}_DEFAULT}" STREQUAL "") + set(${cacheVarName}_DEFAULT "${defaultDefaultVal}") + endif() + set(${cacheVarName} "${${cacheVarName}_DEFAULT}" + CACHE ${cacheVarType} + "${docString}" ) +endmacro() diff --git a/cmake/tribits/core/package_arch/TribitsSortListAccordingToMasterList.cmake b/cmake/tribits/core/utils/TribitsSortListAccordingToMasterList.cmake similarity index 62% rename from cmake/tribits/core/package_arch/TribitsSortListAccordingToMasterList.cmake rename to cmake/tribits/core/utils/TribitsSortListAccordingToMasterList.cmake index 5d079a417461..4b013270277c 100644 --- a/cmake/tribits/core/package_arch/TribitsSortListAccordingToMasterList.cmake +++ b/cmake/tribits/core/utils/TribitsSortListAccordingToMasterList.cmake @@ -37,40 +37,28 @@ # ************************************************************************ # @HEADER -include(PrintVar) -include(AppendSet) +include("${CMAKE_CURRENT_LIST_DIR}/../utils/PrintVar.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/AppendSet.cmake") + +# Do an in-place sort of a list of items according to the ordering in a master +# list. # -# Function that does an in-place sort of a list of items according to the -# ordering in a master list -# -# NOTE: This function has wost-case N^2 complexity as the number of packages N -# or TPLs increases. It actually has N * n complexity where N is the total -# number of packages/TPLs and n is the number of passed-in packages/TPLs. -# However, since N is not likely to ever be more than a few hundred, this is -# likely not going to be a big performance problem. If this does become a -# performance problem, list(SORT ...) could be used but would require some -# work to build up the datastructures to make this very efficient. +# NOTE: This function has worst-case complexity N*n where N is the number of +# elements in the ```` and n is the number of elements in the +# ```` list. # +function(tribits_sort_list_according_to_master_list masterList listVarInOut) -function(tribits_sort_list_according_to_master_list MASTER_LIST LIST_VAR_INOUT) - - #message("TRIBITS_SORT_LIST_ACCORDING_TO_MASTER_LIST:") - #print_var(MASTER_LIST) - #print_var(LIST_VAR_INOUT) - #print_var(${LIST_VAR_INOUT}) + set(sortedList) - set(SORTED_LIST) - - foreach(ITEM ${MASTER_LIST}) - list(FIND ${LIST_VAR_INOUT} ${ITEM} ITEM_IDX) - if (NOT ITEM_IDX EQUAL -1) - list(APPEND SORTED_LIST ${ITEM}) + foreach(item ${masterList}) + list(FIND ${listVarInOut} ${item} itemIdx) + if (NOT itemIdx EQUAL -1) + list(APPEND sortedList ${item}) endif() endforeach() - #print_var(SORTED_LIST) - - set(${LIST_VAR_INOUT} ${SORTED_LIST} PARENT_SCOPE) + set(${listVarInOut} ${sortedList} PARENT_SCOPE) endfunction() diff --git a/cmake/tribits/ctest_driver/TribitsCTestDriverCore.cmake b/cmake/tribits/ctest_driver/TribitsCTestDriverCore.cmake index 563f5de65cb2..1666f5755630 100644 --- a/cmake/tribits/ctest_driver/TribitsCTestDriverCore.cmake +++ b/cmake/tribits/ctest_driver/TribitsCTestDriverCore.cmake @@ -137,6 +137,10 @@ if ("${CTEST_BINARY_DIRECTORY}" STREQUAL "") set(CTEST_BINARY_DIRECTORY $ENV{PWD}/BUILD) endif() +include("${CMAKE_CURRENT_LIST_DIR}/../core/common/TribitsConstants.cmake") +tribits_asesrt_minimum_cmake_version() +include("${CMAKE_CURRENT_LIST_DIR}/../core/common/TribitsCMakePolicies.cmake" NO_POLICY_SCOPE) + # # Set CMAKE_MODULE_PATH # @@ -144,15 +148,13 @@ set( CMAKE_MODULE_PATH "${TRIBITS_PROJECT_ROOT}" "${TRIBITS_PROJECT_ROOT}/cmake" "${${PROJECT_NAME}_TRIBITS_DIR}/core/utils" + "${${PROJECT_NAME}_TRIBITS_DIR}/core/common" + "${${PROJECT_NAME}_TRIBITS_DIR}/core/test_support" "${${PROJECT_NAME}_TRIBITS_DIR}/core/package_arch" "${${PROJECT_NAME}_TRIBITS_DIR}/ci_support" "${${PROJECT_NAME}_TRIBITS_DIR}/ctest_driver" ) -include(TribitsConstants) -tribits_asesrt_minimum_cmake_version() -include(TribitsCMakePolicies NO_POLICY_SCOPE) - include(Split) include(PrintVar) include(MultilineSet) diff --git a/cmake/tribits/doc/build_ref/TribitsBuildReferenceBody.rst b/cmake/tribits/doc/build_ref/TribitsBuildReferenceBody.rst index 74908d9d24c2..06600479e9bf 100644 --- a/cmake/tribits/doc/build_ref/TribitsBuildReferenceBody.rst +++ b/cmake/tribits/doc/build_ref/TribitsBuildReferenceBody.rst @@ -1333,7 +1333,7 @@ c) **Setting up to run MPI programs:** MPI test and example executables are passed to CTest ``add_test()`` as:: - add_test( + add_test(NAME COMMAND ${MPI_EXEC} ${MPI_EXEC_PRE_NUMPROCS_FLAGS} ${MPI_EXEC_NUMPROCS_FLAG} ${MPI_EXEC_POST_NUMPROCS_FLAGS} diff --git a/cmake/tribits/doc/guides/.gitignore b/cmake/tribits/doc/guides/.gitignore index 7f018678f224..6c3878b7fb9d 100644 --- a/cmake/tribits/doc/guides/.gitignore +++ b/cmake/tribits/doc/guides/.gitignore @@ -4,6 +4,9 @@ /TriBITS.README.DIRECTORY_CONTENTS.rst.tmp /TribitsCommonTPLsList.txt /TribitsCommonTPLsList.txt.tmp +/TribitsExampleProject2_Package1_CMakeLists.raw.external.cmake* +/TribitsExampleProject2_Package1_CMakeLists.raw.internal.cmake* +/TribitsExampleProject2_Package1_CMakeLists.raw.tribits_test.cmake* /TribitsGitVersion.txt /TribitsGitVersion.txt.tmp /TribitsHelloWorldDirAndFiles.txt diff --git a/cmake/tribits/doc/guides/Makefile.common_generated_files b/cmake/tribits/doc/guides/Makefile.common_generated_files index c6a352d1228f..6984ee3c63f2 100644 --- a/cmake/tribits/doc/guides/Makefile.common_generated_files +++ b/cmake/tribits/doc/guides/Makefile.common_generated_files @@ -27,6 +27,7 @@ COMMON_DEPENDENT_FILES = \ ../get-tribits-packages-from-files-list.txt \ ../install_devtools-help.txt \ ../TriBITS.README.DIRECTORY_CONTENTS.rst \ + $(wildcard ../*.cmake) \ TribitsMacroFunctionDoc.rst \ UtilsMacroFunctionDoc.rst diff --git a/cmake/tribits/doc/guides/TribitsGuidesBody.rst b/cmake/tribits/doc/guides/TribitsGuidesBody.rst index dbabbce0e924..210e4cc80583 100644 --- a/cmake/tribits/doc/guides/TribitsGuidesBody.rst +++ b/cmake/tribits/doc/guides/TribitsGuidesBody.rst @@ -2970,6 +2970,28 @@ should be copied from this example project as they represent best practice when using TriBITS for the typical use cases. +TribitsExampleProject2 +---------------------- + +``TribitsExampleProject2`` in an example `TriBITS Project`_ and `TriBITS +Repository`_ contained in the TriBITS source tree under:: + + tribits/examples/TribitsExampleProject2/ + +This example TriBITS project provides some examples for a few other features +and testing scenarios. It contains three internal packages ``Package1``, +``Package2``, and ``Package3`` as shown in its ``PackagesList.cmake`` file: + +.. include:: ../../examples/TribitsExampleProject2/PackagesList.cmake + :literal: + +and supports four external packages/TPLs ``Tpl1``, ``Tpl2``, ``Tpl3``, and +``Tpl4`` as shown in its ``TPLsList.cmake`` file: + +.. include:: ../../examples/TribitsExampleProject2/TPLsList.cmake + :literal: + + MockTrilinos ------------- @@ -6240,6 +6262,243 @@ file as well. Then every ``CMakeLists.txt`` file in subdirectories just calls ``include_tribits_build()``. That is it. +How to implement a TriBITS-compliant internal package using raw CMake +--------------------------------------------------------------------- + +As described in `TriBITS-Compliant Internal Packages`_, it is possible to +create a raw CMake build system for a CMake package that can build under a +parent TriBITS CMake project. The raw CMake code for such a package must +provide the ``::all_libs`` target both in the current CMake build +system and also in the generated ``Config.cmake`` file for the build +directory and in the installed ``Config.cmake`` file. Every such +TriBITS-compliant internal package therefore is **also capable of installing a +TriBITS-compliant external package** ``Config.cmake`` file (see `How +to implement a TriBITS-compliant external package using raw CMake`_). + +.. ToDo: Consider listing out the key features of a raw CMake build system + that is needed for a TriBITS-compliant internal package. + +A raw CMake build system for a TriBITS-compliant internal package is +demonstrated in the `TribitsExampleProject2`_ project ``Package1`` package. +The base ``CMakeLists.txt`` file for building ``Package1`` with a raw CMake +build system (called ``package1/CMakeLists.raw.cmake`` in that directory) +looks like: + +.. include:: TribitsExampleProject2_Package1_CMakeLists.raw.internal.cmake + :literal: + +As shown above, this simple CMake package contains the basic features of any +CMake project/package including calling the ``cmake_minimum_required()`` and +``project()`` commands as well as including ``GNUInstallDirs``. In this +example, the project/package being built ``Package1`` has a dependency on an +external upstream package ``Tpl1`` pulled in with ``find_package(Tpl1)``. +Also in this example, the package has native tests it defines with +``include(CTest)`` and ``add_subdirectory()`` (if ``Package1_ENABLE_TESTS`` is +set to ``ON``). + +The file ``package1/src/CMakeLists.raw.cmake`` (which gets included from +``package1/src/CMakeLists.txt``) creates a library and executable for the +package and has the contents: + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/src/CMakeLists.raw.cmake + :literal: + +This creates a single installable library target ``Package1_package1`` which +is aliased as ``Package1::package1`` in the current CMake project and sets up +to create the IMPORTED target ``Package1::package1`` in the generated +``Package1ConfigTarget.cmake`` file, which gets included in the installed +``Package1Config.cmake`` (``Config.cmake``) file (as recommenced in +the book "Professional CMake", see below). In addition, the above code +creates the installable executable ``package1-prg``. + +The ``Package1::all_libs`` (``::all_libs``) target is defined and set +up inside of the included file +``package1/cmake/raw/DefineAllLibsTarget.cmake`` which contains the code: + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/cmake/raw/DefineAllLibsTarget.cmake + :literal: + +The above code contains the ALIAS library target ``Package1::all_libs`` +(``::all_libs``) for the current CMake project as well as sets up for +the IMPORTED target ``Package1::all_libs`` (``::all_libs``) getting +put in the generated ``Package1ConfigTargets.cmake`` file (see below). + +The ``Package1Config.cmake`` (``Config.cmake``) file for the build +directory is generated inside of the included file +``package1/cmake/raw/GeneratePackageConfigFileForBuildDir.cmake`` which has +the contents: + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/cmake/raw/GeneratePackageConfigFileForBuildDir.cmake + :literal: + +The above code uses the ``export(EXPORT ...)`` command to generate the file +``Package1ConfigTargets.cmake`` for the build directory which provides the +IMPORTED targets ``Package1::package1`` and ``Package1::all_libs``. The +command ``configure_file(...)`` generates the ``Package1Config.cmake`` file +that includes it for the build directory +``/cmake_packages/Package1/``. (NOTE: The above code only runs when +the package is being built from inside of a TriBITS project which defines the +command ``tribits_package``. So this code gets skipped when building +``Package1`` as a stand-alone raw CMake project.) + +Finally, the code for generating and installing the ``Package1Config.cmake`` +file for the install directory ``CMAKE_PREFIX_PATH=`` is specified +in the included file +``package1/cmake/raw/GeneratePackageConfigFileForInstallDir.cmake`` with the +contents: + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/cmake/raw/GeneratePackageConfigFileForInstallDir.cmake + :literal: + +The above uses the command ``install(EXPORT ...)`` to have CMake automatically +generate and install the file ``Package1ConfigTargets.cmake`` in the install +directory ``/libs/cmake/Package1/`` which provides the IMPORTED +targets ``Package1::package1`` and ``Package1::all_libs``. The command +``configure_file()`` is used to generate the file +``Package1Config.install.cmake`` in the build directory from the template file +``Package1Config.cmake.in``. Finally, the ``install()`` command is used in +the file ``GeneratePackageConfigFileForInstallDir.cmake`` to set up the +installation of the ``Package1Config.cmake`` file. + +Note, the template file ``package1/cmake/raw/Package1Config.cmake.in`` (which +is unique to ``Package1``) is: + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/cmake/raw/Package1Config.cmake.in + :literal: + +As shown in the all of the above code, there is a lot of boilerplate CMake +code needed to correctly define the targets such that they get put into the +installed ``Package1Config.cmake`` file using the correct namespace +``Package1::`` and care must be taken to ensure that a consistent "export set" +is used for this purpose. (For more details, see the book "Professional +CMake".) + +**NOTE:** One should compare the above raw CMakeLists files to the more +compact TriBITS versions for the base ``package1/CMakeLists.txt`` file (called +``package1/CMakeLists.tribits.cmake`` in the base directory ``pacakge1/``): + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/CMakeLists.tribits.cmake + :literal: + +and the TriBITS ``package1/src/CMakeLists.txt`` file (called +``package1/src/CMakeLists.tribits.cmake``): + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/src/CMakeLists.tribits.cmake + :literal: + +This shows the amount of boilerplate code that TriBITS addresses automatically +(which reduces the overhead of finer-grained packages and avoids common +mistakes with tedious low-level CMake code). + + +How to implement a TriBITS-compliant external package using raw CMake +--------------------------------------------------------------------- + +As described in `TriBITS-Compliant External Packages`_, it is possible to +create a raw CMake build system for a CMake package such that once it is +installed, satisfies the requirements for a TriBITS-compliant external +package. These installed packages provide a ``Config.cmake`` file +that provides the required targets and behaviors as if it was produced by a +TriBITS project. For most existing raw CMake projects that already produce a +"Professional CMake" compliant ``Config.cmake`` file, that usually +just means adding the IMPORTED target called ``::all_libs`` to the +installed ``Config.cmake`` file. + +A raw CMake build system for a TriBITS-compliant external package is +demonstrated in the `TribitsExampleProject2`_ project ``Package1`` package. +The base ``package1/CMakeLists.txt`` file for building ``Package1`` with a raw +CMake build system (called ``package1/CMakeLists.raw.cmake``) for implementing +a TriBITS-compliant internal package looks like: + +.. include:: TribitsExampleProject2_Package1_CMakeLists.raw.external.cmake + :literal: + +Note that the raw build system this example is identical to the build system +for the raw TriBITS-compliant internal package described in `How to implement +a TriBITS-compliant internal package using raw CMake`_. The only differences +are: + +1) The ``Package1Config.cmake`` (``Config.cmake``) file does **not** + need to be generated for the build directory and therefore the code in + ``cmake/raw/GeneratePackageConfigFileForBuildDir.cmake`` does **not** need + to be included. + +2) The ALIAS library target ``Package1::all_libs`` (``::all_libs``) + does **not** need to be generated (but should be to be "Professional CMake" + compliant). + +Other than that, see `How to implement a TriBITS-compliant internal package +using raw CMake`_ for how to implement a TriBITS-compliant external package. + + +How to use TriBITS testing support in non-TriBITS project +--------------------------------------------------------- + +The TriBITS test support functions `tribits_add_test()`_ and +`tribits_add_advanced_test()`_ can be used from any raw (i.e. non-TriBITS) +CMake project. To do so, one just needs to include the TriBITS modules: + +* ``/core/test_support/TribitsAddTest.cmake`` +* ``/core/test_support/TribitsAddAdvancedTest.cmake`` + +and set the variable ``${PROJECT_NAME}_ENABLE_TESTS`` to ``ON``. For an +MPI-enabled CMake project, the CMake variables ``MPI_EXEC``, +``MPI_EXEC_PRE_NUMPROCS_FLAGS``, ``MPI_EXEC_NUMPROCS_FLAG`` and +``MPI_EXEC_POST_NUMPROCS_FLAGS`` must also be set which define the MPI runtime +program launcher command-line used in the TriBITS testing functions:: + + ${MPI_EXEC} ${MPI_EXEC_PRE_NUMPROCS_FLAGS} + ${MPI_EXEC_NUMPROCS_FLAG} + ${MPI_EXEC_POST_NUMPROCS_FLAGS} + + +(NOTE: These variables are defined automatically in a TriBITS project when +``TPL_ENABLE_MPI`` is set to ``ON``.) + +This is demonstrated in the `TribitsExampleProject2`_ project ``Package1`` +package. The base ``pacakge1/CMakeLists.txt`` file for building ``Package1`` +with a raw CMake build system using TriBITS testing functions (called +``package1/CMakeLists.raw.cmake``) looks like: + +.. include:: TribitsExampleProject2_Package1_CMakeLists.raw.tribits_test.cmake + :literal: + +The only difference between this base ``package1/CMakeLists.txt`` file and one +for a raw CMake project is the inclusion of the file +``package1/cmake/raw/EnableTribitsTestSupport.cmake`` which has the contents: + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/cmake/raw/EnableTribitsTestSupport.cmake + :literal: + +The key lines are:: + + include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddTest.cmake") + include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddAdvancedTest.cmake") + +This defines the CMake functions `tribits_add_test()`_ and +`tribits_add_advanced_test()`_, respectively. + +The above code demonstrates that ``CMAKE_MODULE_PATH`` does **not** need to be +updated to use these TriBITS ``test_support`` modules. However, one is free +to update ``CMAKE_MODULE_PATH`` and then include the modules by name only +like:: + + list(PREPEND CMAKE_MODULE_PATH "${Package1_TRIBITS_DIR}/core/test_support") + include(TribitsAddTest) + include(TribitsAddAdvancedTest) + +Once these TriBITS modules are included, one can use the TriBITS functions as +demonstrated in the file ``package1/test/CMakeLists.tribits.cmake`` (which is +included from the file ``package1/test/CMakeLists.txt``) and has the contents: + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake + :literal: + +Note that in this example, the executable ``package1-prg`` was already +created. If new test libraries and executables need to be created, then the +raw CMake commands to create those will need to be added as well. + + How to check for and tweak TriBITS "ENABLE" cache variables ----------------------------------------------------------- diff --git a/cmake/tribits/doc/guides/TribitsSystemMacroFunctionDocTemplate.rst b/cmake/tribits/doc/guides/TribitsSystemMacroFunctionDocTemplate.rst index a2fdb71c978b..3723c3b7c833 100644 --- a/cmake/tribits/doc/guides/TribitsSystemMacroFunctionDocTemplate.rst +++ b/cmake/tribits/doc/guides/TribitsSystemMacroFunctionDocTemplate.rst @@ -51,6 +51,6 @@ understand the internals of TriBITS. @MACRO: tribits_save_off_dependency_vars() + @MACRO: tribits_set_dep_packages() + @FUNCTION: tribits_trace_file_processing() + -@FUNCTION: tribits_write_package_client_export_files_install_targets() + +@FUNCTION: tribits_write_package_client_export_files_export_and_install_targets() + @MACRO: tribits_write_xml_dependency_files() + @FUNCTION: tribits_write_xml_dependency_files_if_supported() + diff --git a/cmake/tribits/doc/guides/UtilsMacroFunctionDocTemplate.rst b/cmake/tribits/doc/guides/UtilsMacroFunctionDocTemplate.rst index acc98214c162..79bb6ea0df10 100644 --- a/cmake/tribits/doc/guides/UtilsMacroFunctionDocTemplate.rst +++ b/cmake/tribits/doc/guides/UtilsMacroFunctionDocTemplate.rst @@ -39,9 +39,11 @@ @FUNCTION: timer_get_rel_seconds() + @FUNCTION: timer_print_rel_time() + @FUNCTION: tribits_add_enum_cache_var() + +@MACRO: tribits_advanced_set_cache_var_and_default() + @FUNCTION: tribits_deprecated() + @FUNCTION: tribits_deprecated_command() + @MACRO: tribits_create_reverse_list() + +@MACRO: tribits_set_cache_var_and_default() + @FUNCTION: tribits_strip_quotes_from_str() + @FUNCTION: unittest_compare_const() + @FUNCTION: unittest_has_substr_const() + diff --git a/cmake/tribits/doc/guides/generate-guide.sh b/cmake/tribits/doc/guides/generate-guide.sh index ce7a2c6565c3..da7e128ebec6 100755 --- a/cmake/tribits/doc/guides/generate-guide.sh +++ b/cmake/tribits/doc/guides/generate-guide.sh @@ -112,7 +112,7 @@ function tribits_extract_rst_cmake_doc { echo "Extracting TriBITS documentation from *.cmake files ..." echo ../../../python_utils/extract_rst_cmake_doc.py \ - --extract-from=../../../core/package_arch/,../../../ci_support/,../../../core/utils/,../../../ctest_driver/ \ + --extract-from=../../../ctest_driver/,../../../ci_support/,../../../core/package_arch/,../../../core/test_support/,../../../core/utils/ \ --rst-file-pairs=../TribitsMacroFunctionDocTemplate.rst:TribitsMacroFunctionDoc.rst.tmp,../UtilsMacroFunctionDocTemplate.rst:UtilsMacroFunctionDoc.rst.tmp,../TribitsSystemMacroFunctionDocTemplate.rst:TribitsSystemMacroFunctionDoc.rst.tmp \ ${extra_args} \ --file-name-path-base-dir=../../.. \ @@ -152,6 +152,30 @@ function tribits_extract_other_doc { &> TribitsHelloWorldDirAndFiles.txt.tmp update_if_different TribitsHelloWorldDirAndFiles.txt tmp + echo + echo "Generating TribitsExampleProject2/Package1 CMakeList file variants ..." + echo + + cat ../../examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake \ + | grep -v EnableTribitsTestSupport \ + | grep -v GeneratePackageConfigFileForBuildDir \ + &> TribitsExampleProject2_Package1_CMakeLists.raw.external.cmake.tmp + update_if_different TribitsExampleProject2_Package1_CMakeLists.raw.external.cmake tmp + + cat ../../examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake \ + | grep -v EnableTribitsTestSupport \ + &> TribitsExampleProject2_Package1_CMakeLists.raw.internal.cmake.tmp + update_if_different TribitsExampleProject2_Package1_CMakeLists.raw.internal.cmake tmp + + cat ../../examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake \ + | grep -v "that TriBITS does automatically" \ + | grep -v DefineAllLibsTarget \ + | grep -v GeneratePackageConfigFileForBuildDir \ + | grep -v GeneratePackageConfigFileForInstallDir \ + &> TribitsExampleProject2_Package1_CMakeLists.raw.tribits_test.cmake.tmp + update_if_different \ + TribitsExampleProject2_Package1_CMakeLists.raw.tribits_test.cmake tmp + echo echo "Generating output for 'checkin-test.py --help' ..." echo @@ -246,8 +270,8 @@ function make_final_doc_in_subdir { if [[ "${skip_final_generation}" == "0" ]] ; then cd $dir_name echo $PWD - make - cd - + time make + cd - > /dev/null else echo echo "Skipping final generation of '${dir_name}' on request!" diff --git a/cmake/tribits/doc/utils/gen_doc_utils.sh b/cmake/tribits/doc/utils/gen_doc_utils.sh index 639aa68ddf1e..253418e44bf9 100644 --- a/cmake/tribits/doc/utils/gen_doc_utils.sh +++ b/cmake/tribits/doc/utils/gen_doc_utils.sh @@ -51,7 +51,8 @@ function generate_git_version_file { echo echo "Generating git version" echo - echo `git describe --match="$_TRIBITS_TAG_PREFIX*"` > TribitsGitVersion.txt + git describe --always --match="$_TRIBITS_TAG_PREFIX*" > TribitsGitVersion.txt || \ + echo "$_TRIBITS_TAG_PREFIX.{Unknown version}" > TribitsGitVersion.txt else echo "$_TRIBITS_TAG_PREFIX.{Unknown version}" > TribitsGitVersion.txt fi diff --git a/cmake/tribits/examples/TribitsExampleApp2/AppHelperFuncs.cmake b/cmake/tribits/examples/TribitsExampleApp2/AppHelperFuncs.cmake index cbed66bcd7e2..ebb23e1789ee 100644 --- a/cmake/tribits/examples/TribitsExampleApp2/AppHelperFuncs.cmake +++ b/cmake/tribits/examples/TribitsExampleApp2/AppHelperFuncs.cmake @@ -37,7 +37,7 @@ macro(getTribitsExProj2StuffForAppByPackage) # Find each package and gather up all the ::all_libs targets set(APP_DEPS_LIB_TARGETS "") foreach (packageName IN LISTS ${PROJECT_NAME}_USE_COMPONENTS) - find_package(${packageName} REQUIRED) + find_package(${packageName} CONFIG REQUIRED) message("Found ${packageName}!") list(APPEND APP_DEPS_LIB_TARGETS ${packageName}::all_libs) endforeach() @@ -59,7 +59,8 @@ endmacro() # macro(getTribitsExProj2StuffForAppByProject) - find_package(TribitsExProj2 REQUIRED COMPONENTS ${${PROJECT_NAME}_USE_COMPONENTS}) + find_package(TribitsExProj2 CONFIG REQUIRED + COMPONENTS ${${PROJECT_NAME}_USE_COMPONENTS}) message("\nFound TribitsExProj2! Here are the details: ") message(" TribitsExProj2_DIR = ${TribitsExProj2_DIR}") diff --git a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake new file mode 100644 index 000000000000..ad2a18182770 --- /dev/null +++ b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.23.0 FATAL_ERROR) + +if (COMMAND tribits_package) + message("Configuring raw CMake package Package1") +else() + message("Configuring raw CMake project Package1") +endif() + +# Standard project-level stuff +project(Package1 LANGUAGES C CXX) +include(GNUInstallDirs) +find_package(Tpl1 CONFIG REQUIRED) +add_subdirectory(src) +if (Package1_ENABLE_TESTS) + include(CTest) + include("${CMAKE_CURRENT_LIST_DIR}/cmake/raw/EnableTribitsTestSupport.cmake") + add_subdirectory(test) +endif() + +# Stuff that TriBITS does automatically +include("${CMAKE_CURRENT_LIST_DIR}/cmake/raw/DefineAllLibsTarget.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/cmake/raw/GeneratePackageConfigFileForBuildDir.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/cmake/raw/GeneratePackageConfigFileForInstallDir.cmake") diff --git a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.tribits.cmake b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.tribits.cmake new file mode 100644 index 000000000000..2c2fc1f8a646 --- /dev/null +++ b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.tribits.cmake @@ -0,0 +1,5 @@ +message("Configuring package Package1 as full TriBITS package") +tribits_package(Package1) +add_subdirectory(src) +tribits_add_test_directories(test) +tribits_package_postprocess() diff --git a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt index 5f3b156eba2f..c8511aab35d3 100644 --- a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt +++ b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt @@ -1,57 +1,18 @@ cmake_minimum_required(VERSION 3.23.0 FATAL_ERROR) -macro(include_raw_cmake_build) - if (NOT COMMAND tribits_project) +set(Package1_USE_RAW_CMAKE OFF CACHE BOOL + "Use raw CMake for package build, even if TriBITS could be used.") + +# Macro to select the TriBITS or the raw CMake build system +macro(include_cmakelists_file) + if ((NOT COMMAND tribits_project) OR Package1_USE_RAW_CMAKE) include("${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.raw.cmake" NO_POLICY_SCOPE) - return() + else() + include("${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.tribits.cmake" + NO_POLICY_SCOPE) endif() endmacro() -if (COMMAND tribits_package) - - # Being processed as a TriBITS package - tribits_package(Package1) - add_subdirectory(src) - tribits_add_test_directories(test) - tribits_package_postprocess() - -else() - - message("Configuring raw CMake project Package1") - project(Package1 LANGUAGES C CXX) - include(GNUInstallDirs) - find_package(Tpl1 CONFIG REQUIRED) - add_subdirectory(src) - if (Package1_ENABLE_TESTS) - include(CTest) - add_subdirectory(test) - endif() - - # Generate the all_libs target - add_library(Package1_all_libs INTERFACE) - set_target_properties(Package1_all_libs PROPERTIES - EXPORT_NAME all_libs) - target_link_libraries(Package1_all_libs INTERFACE Package1_package1) - install( - TARGETS Package1_all_libs - EXPORT ${PROJECT_NAME} - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) - - # Generate and install the Package1Config.cmake file - install(EXPORT ${PROJECT_NAME} - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} - NAMESPACE ${PROJECT_NAME}:: - FILE ${PROJECT_NAME}ConfigTargets.cmake ) - configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/raw/Package1Config.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Package1Config.install.cmake" - @ONLY ) - install( - FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Package1Config.install.cmake" - RENAME "Package1Config.cmake" - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) - -endif() - - +# Pull in the base CMakeLists.txt file variant +include_cmakelists_file() diff --git a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/DefineAllLibsTarget.cmake b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/DefineAllLibsTarget.cmake new file mode 100644 index 000000000000..902b1cdf153a --- /dev/null +++ b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/DefineAllLibsTarget.cmake @@ -0,0 +1,11 @@ +# Generate the all_libs target(s) +add_library(Package1_all_libs INTERFACE) +set_target_properties(Package1_all_libs + PROPERTIES EXPORT_NAME all_libs) +target_link_libraries(Package1_all_libs + INTERFACE Package1_package1) +install(TARGETS Package1_all_libs + EXPORT ${PROJECT_NAME} + COMPONENT ${PROJECT_NAME} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) +add_library(Package1::all_libs ALIAS Package1_all_libs) diff --git a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/EnableTribitsTestSupport.cmake b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/EnableTribitsTestSupport.cmake new file mode 100644 index 000000000000..c4449e543215 --- /dev/null +++ b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/EnableTribitsTestSupport.cmake @@ -0,0 +1,10 @@ +set(Package1_USE_TRIBITS_TEST_FUNCTIONS OFF CACHE BOOL + "Use TriBITS testing functions") +set(Package1_TRIBITS_DIR "" CACHE PATH + "Path to TriBITS implementation base dir (e.g. TriBITS/tribits)") +if (Package1_USE_TRIBITS_TEST_FUNCTIONS AND Package1_TRIBITS_DIR) + # Pull in and turn on TriBITS testing support + include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddTest.cmake") + include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddAdvancedTest.cmake") + set(Package1_ENABLE_TESTS ON) +endif() diff --git a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/GeneratePackageConfigFileForBuildDir.cmake b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/GeneratePackageConfigFileForBuildDir.cmake new file mode 100644 index 000000000000..9f937dcda57d --- /dev/null +++ b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/GeneratePackageConfigFileForBuildDir.cmake @@ -0,0 +1,13 @@ +if (COMMAND tribits_package) + # Generate Package1Config.cmake file for the build tree (for internal + # TriBITS-compliant package) + set(packageBuildDirCMakePackagesDir + "${${CMAKE_PROJECT_NAME}_BINARY_DIR}/cmake_packages/${PROJECT_NAME}") + export(EXPORT ${PROJECT_NAME} + NAMESPACE ${PROJECT_NAME}:: + FILE "${packageBuildDirCMakePackagesDir}/${PROJECT_NAME}ConfigTargets.cmake" ) + configure_file( + "${CMAKE_CURRENT_LIST_DIR}/Package1Config.cmake.in" + "${packageBuildDirCMakePackagesDir}/${PROJECT_NAME}/Package1Config.cmake" + @ONLY ) +endif() diff --git a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/GeneratePackageConfigFileForInstallDir.cmake b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/GeneratePackageConfigFileForInstallDir.cmake new file mode 100644 index 000000000000..535685e61481 --- /dev/null +++ b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/GeneratePackageConfigFileForInstallDir.cmake @@ -0,0 +1,15 @@ +# Generate and install the Package1Config.cmake file for the install tree +# (needed for both internal and external TriBITS package) +set(pkgConfigInstallDir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") +install(EXPORT ${PROJECT_NAME} + DESTINATION "${pkgConfigInstallDir}" + NAMESPACE ${PROJECT_NAME}:: + FILE ${PROJECT_NAME}ConfigTargets.cmake ) +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/raw/Package1Config.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Package1Config.install.cmake" + @ONLY ) +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Package1Config.install.cmake" + RENAME "Package1Config.cmake" + DESTINATION "${pkgConfigInstallDir}" ) diff --git a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.raw.cmake b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.raw.cmake index aa5dffd55aa0..f15cdc589834 100644 --- a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.raw.cmake +++ b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.raw.cmake @@ -7,8 +7,7 @@ target_link_libraries(Package1_package1 set_target_properties(Package1_package1 PROPERTIES EXPORT_NAME package1) add_library(Package1::package1 ALIAS Package1_package1) -install( - TARGETS Package1_package1 +install(TARGETS Package1_package1 EXPORT ${PROJECT_NAME} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) install( diff --git a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.tribits.cmake b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.tribits.cmake new file mode 100644 index 000000000000..8e69c53a57c8 --- /dev/null +++ b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.tribits.cmake @@ -0,0 +1,4 @@ +tribits_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +tribits_add_library(package1 HEADERS Package1.hpp SOURCES Package1.cpp) +tribits_add_executable(package1-prg NOEXEPREFIX NOEXESUFFIX + SOURCES Package1_Prg.cpp INSTALLABLE ) diff --git a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.txt b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.txt index 59e7a3b5b68f..870958046e80 100644 --- a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.txt +++ b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.txt @@ -1,8 +1 @@ -include_raw_cmake_build() - -tribits_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) - -tribits_add_library(package1 HEADERS Package1.hpp SOURCES Package1.cpp) - -tribits_add_executable(package1-prg NOEXEPREFIX NOEXESUFFIX - SOURCES Package1_Prg.cpp INSTALLABLE ) +include_cmakelists_file() diff --git a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/src/Package1_Prg.cpp b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/src/Package1_Prg.cpp index 2ce91f102a79..33d4dc0cef08 100644 --- a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/src/Package1_Prg.cpp +++ b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/src/Package1_Prg.cpp @@ -1,9 +1,13 @@ #include +#include #include "Package1.hpp" -int main() +int main(int argc, char* argv[]) { std::cout << "Package1 Deps: " << Package1::deps() << "\n"; + for (int arg_i = 0; arg_i < argc; ++arg_i) { + std::cout << argv[arg_i+1] << "\n"; + } return 0; } diff --git a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.raw.cmake b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.raw.cmake index 6e4cf3a0f2e8..fef32215268b 100644 --- a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.raw.cmake +++ b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.raw.cmake @@ -1,3 +1,19 @@ add_test(NAME Package1_Prg COMMAND package1-prg) set_tests_properties(Package1_Prg PROPERTIES PASS_REGULAR_EXPRESSION "Package1 Deps: tpl1") + +add_test(NAME Package1_Prg-advanced COMMAND package1-prg something_extra) +set_tests_properties(Package1_Prg-advanced + PROPERTIES PASS_REGULAR_EXPRESSION "something_extra") + +# NOTE: With raw CMake/CTest, it is not possible to require the matches of +# multiple regexes (i.e. not the require the match of *both* "Package1 Deps: +# tpl1" and "something_extra"). Also, it is not possible to require a +# non-zero return code in addition to requiring a regex match the output. +# These more advanced features of tribits_add_advanced_test() would need to be +# provided by writing a wrapper script (e.g. using a Python script, a cmake -P +# script, etc.). Also, these tests don't support other features like: b) +# allow tests to be disabled for a variety of reasons like number of MPI +# processes required, incompatible system, disable cache variables -D +# _DISABLE=ON, etc.; b) printing which tests got added or did +# not get added and why when _TRACE_ADD_TEST=ON, etc. diff --git a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake new file mode 100644 index 000000000000..48d1f6e19205 --- /dev/null +++ b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake @@ -0,0 +1,14 @@ +tribits_add_test(package1-prg NOEXEPREFIX NOEXESUFFIX + NAME Prg DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../src" NUM_MPI_PROCS 1 + PASS_REGULAR_EXPRESSION "Package1 Deps: tpl1" ) + +tribits_add_advanced_test(Prg-advanced + TEST_0 + EXEC package1-prg DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../src" + NOEXEPREFIX NOEXESUFFIX + ARGS "something_extra" + PASS_REGULAR_EXPRESSION_ALL + "Package1 Deps: tpl1" + "something_extra" + ALWAYS_FAIL_ON_NONZERO_RETURN + ) diff --git a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.txt b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.txt index 906e0faf8b94..11b72aec0153 100644 --- a/cmake/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.txt +++ b/cmake/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.txt @@ -1,5 +1,11 @@ -include_raw_cmake_build() - -tribits_add_test(package1-prg NOEXEPREFIX NOEXESUFFIX - NAME Prg DIRECTORY ${PACKAGE_BINARY_DIR}/src NUM_MPI_PROCS 1 - PASS_REGULAR_EXPRESSION "Package1 Deps: tpl1" ) +if ((NOT COMMAND tribits_project) OR Package1_USE_RAW_CMAKE) + if (Package1_USE_TRIBITS_TEST_FUNCTIONS AND (COMMAND tribits_add_test)) + message("-- Using TriBITS Test Functions in raw CMake Package1 build!") + include("${CMAKE_CURRENT_LIST_DIR}/CMakeLists.tribits.cmake") + else() + message("-- Using Raw CMake add_test() in raw CMake Package1 build!") + include("${CMAKE_CURRENT_LIST_DIR}/CMakeLists.raw.cmake") + endif() +else() + include("${CMAKE_CURRENT_LIST_DIR}/CMakeLists.tribits.cmake") +endif() diff --git a/cmake/tribits/python_utils/gitdist-setup.sh b/cmake/tribits/python_utils/gitdist-setup.sh index 0df08515dc9d..928c0588381f 100644 --- a/cmake/tribits/python_utils/gitdist-setup.sh +++ b/cmake/tribits/python_utils/gitdist-setup.sh @@ -44,7 +44,7 @@ if [[ "${existing_gitdist}" == "" ]] ; then fi function gitdist_repo_versions { - gitdist "$@" --dist-no-color log -1 --pretty=format:"%H [%cd] <%ae>%n%s" | grep -v "^$" + gitdist "$@" --dist-no-color log --color=never -1 --pretty=format:"%H [%cd] <%ae>%n%s" | grep -v "^$" } export -f gitdist_repo_versions @@ -60,7 +60,7 @@ function gitdist_show_full_repo_state { echo echo "Repo remotes:" echo - gitdist --dist-no-color "$@" remote -v | grep "\(Git Repo\|push\)" + gitdist --dist-no-color "$@" remote -v | grep --color=never "\(Git Repo\|push\)" } export -f gitdist_show_full_repo_state @@ -73,7 +73,7 @@ alias gitdist-show-full-repo-state=gitdist_show_full_repo_state # Setup for completions for git command and gitdist options commands complete -o default -o nospace -F _git \ - -W "dist-repo-status --dist-help --dist-use-git --dist-repos --dist-not-repos --dist-version-file --dist-version-file2 --dist-no-color --dist-debug --dist-no-opt --dist-mod-only --dist-legend" \ + -W "dist-repo-status --dist-help --dist-use-git --dist-repos --dist-not-repos --dist-version-file --dist-version-file2 --dist-no-color --dist-debug --dist-no-opt --dist-mod-only" \ gitdist gitdist-mod complete -o default -o nospace \ -W "--dist-use-git --dist-repos --dist-not-repos --dist-mod-only" \ @@ -82,5 +82,5 @@ complete -o default -o nospace \ -W "--dist-use-git --dist-repos --dist-not-repos --dist-mod-only" \ gitdist_show_full_repo_state gitdist-show-full-repo-state complete -o default -o nospace \ - -W "--dist-repos --dist-not-repos --dist-mod-only" \ + -W "--dist-repos --dist-not-repos --dist-mod-only --dist-legend" \ gitdist-status diff --git a/cmake/tribits/python_utils/gitdist.py b/cmake/tribits/python_utils/gitdist.py index db20c7ddfa4a..6800e2e20ca7 100755 --- a/cmake/tribits/python_utils/gitdist.py +++ b/cmake/tribits/python_utils/gitdist.py @@ -36,7 +36,7 @@ def s(x): distRepoStatusLegend = r"""Legend: * ID: Repository ID, zero based (order git commands are run) * Repo Dir: Relative to base repo (base repo shown first with '(Base)') -* Branch: Current branch (or detached HEAD) +* Branch: Current branch, or (if detached HEAD) tag name or SHA1 * Tracking Branch: Tracking branch (or empty if no tracking branch exists) * C: Number local commits w.r.t. tracking branch (empty if zero or no TB) * M: Number of tracked modified (uncommitted) files (empty if zero) @@ -333,7 +333,7 @@ def getHelpTopicsStr(): |----|-----------------------|--------|-----------------|---|----|---| | 0 | BaseRepo (Base) | dummy | | | | | | 1 | ExtraRepo1 | master | origin/master | 1 | 2 | | - | 2 | ExtraRepo1/ExtraRepo2 | HEAD | | | 25 | 4 | + | 2 | ExtraRepo1/ExtraRepo2 | abc123 | | | 25 | 4 | | 3 | ExtraRepo3 | master | origin/master | | | | ---------------------------------------------------------------------- @@ -341,6 +341,13 @@ def getHelpTopicsStr(): """+distRepoStatusLegend+\ r""" + +In the case of a detached head state, as shown above with the repo +'ExtraRepo3', the SHA1 (e.g. 'abc123') was printed instead of 'HEAD'. +However, if the repo is in the detached head state but a tag happens to point +to the current commit (e.g. 'git tag --points-at' returns non-empy), then the +tag name (e.g. 'v1.2.3') is printed instead of the SHA1 of the commit. + One can also show the status of only changed repos with the command: $ gitdist dist-repo-status --dist-mod-only # alias 'gitdist-mod-status' @@ -351,7 +358,7 @@ def getHelpTopicsStr(): | ID | Repo Dir | Branch | Tracking Branch | C | M | ? | |----|-----------------------|--------|-----------------|---|----|---| | 1 | ExtraRepo1 | master | origin/master | 1 | 2 | | - | 2 | ExtraRepo1/ExtraRepo2 | HEAD | | | 25 | 4 | + | 2 | ExtraRepo1/ExtraRepo2 | abc123 | | | 25 | 4 | ---------------------------------------------------------------------- (see the alias 'gitdist-mod-status' in --dist-help=aliases). @@ -396,13 +403,13 @@ def getHelpTopicsStr(): with this script listing three lines per repo (e.g. as shown above) using (for example): - $ gitdist --dist-no-color log -1 --pretty=format:"%h [%ad] <%ae>%n%s" \ + $ gitdist --dist-no-color log --color=never -1 --pretty=format:"%h [%ad] <%ae>%n%s" \ | grep -v "^$" &> RepoVersion.txt (which is defined as the alias 'gitdist-repo-versions' in the file 'gitdist-setup.sh') or two lines per repo using (for example): - $ gitdist --dist-no-color log -1 --pretty=format:"%h [%ad] <%ae>" \ + $ gitdist --dist-no-color log --color=never -1 --pretty=format:"%h [%ad] <%ae>" \ | grep -v "^$" &> RepoVersion.txt This allows checking out consistent versions of the set git repos, diffing two @@ -495,7 +502,7 @@ def getHelpTopicsStr(): $ alias gitdist-status="gitdist dist-repo-status" $ alias gitdist-mod="gitdist --dist-mod-only" $ alias gitdist-mod-status="gitdist dist-repo-status --dist-mod-only" - $ alias gitdist-repo-versions="gitdist --dist-no-color log -1 \ + $ alias gitdist-repo-versions="gitdist --dist-no-color log --color=never -1 \ --pretty=format:\"%h [%ad] <%ae>%n%s\" | grep -v \"^$\"" These are added by sourcing the provided file 'gitdist-setup.sh' (which should @@ -844,7 +851,8 @@ def createTable(tableData, utf8=False): if mockSttySize: sttySize = mockSttySize else: - sttySize = os.popen("stty size", "r").read() + with os.popen("stty size", "r") as subprocess: + sttySize = subprocess.read() rows, columns = sttySize.split() except: shrink = False @@ -1071,7 +1079,7 @@ def getCmndOutput(cmnd, rtnCode=False): child = subprocess.Popen(cmnd, shell=True, stdout=subprocess.PIPE, stderr = subprocess.STDOUT) output = child.stdout.read() - child.wait() + child.communicate() if rtnCode: return (s(output), child.returncode) return s(output) @@ -1304,7 +1312,10 @@ def getCommandlineOps(): clp.add_option( noColorArgName, dest="useColor", action="store_false", - help="If set, don't use color in the output for gitdist (better for output to a file).", + help="If set, don't use color in the output for gitdist and set" + +" '-c color.status=never' before the git command (like 'status')." + +" NOTE: user should also pass in --color=never for git commands " + +" accept that argument. (Better for output to a file).", default=True ) clp.add_option( @@ -1544,7 +1555,12 @@ def runRepoCmnd(options, cmndLineArgsArray, repoDirName, baseDir, \ repoDirName, repoVersionDict, repoVersionDict2) cmndLineArgsArrayDefaultBranch = replaceDefaultBranchInCmndLineArgs( \ cmndLineArgsArrayRepo, repoDirName, defaultBranchDict) - egCmndArray = [ options.useGit ] + cmndLineArgsArrayDefaultBranch + egCmndArray = [ options.useGit ] + if options.useColor: + egCmndArray.extend(['-c', 'color.status=always']) + else: + egCmndArray.extend(['-c', 'color.status=never']) + egCmndArray.extend(cmndLineArgsArrayDefaultBranch) runCmnd(options, egCmndArray) @@ -1566,6 +1582,20 @@ def repoExistsAndNotExcluded(options, extraRepo, notReposList): return True +# Get the identifier for the current commit in the repo +def getRepoVersionIdentifier(options, getCmndOutputFunc, showMoreHeadDetails): + branch = getLocalBranch(options, getCmndOutputFunc) + if showMoreHeadDetails != "SHOW_MORE_HEAD_DETAILS": + return branch + if branch != "HEAD": + return branch + tagName = getCmndOutputFunc(options.useGit + " tag --points-at").strip() + if tagName != "": + return tagName + sha1 = getCmndOutputFunc(options.useGit + " log --pretty=%h -1").strip() + return sha1 + + # Get the tracking branch for a repo def getLocalBranch(options, getCmndOutputFunc): (resp, rtnCode) = getCmndOutputFunc( @@ -1655,7 +1685,9 @@ def getNumModifiedAndUntracked(options, getCmndOutputFunc): class RepoStatsStruct: - def __init__(self, branch, trackingBranch, numCommits, numModified, numUntracked): + def __init__(self, branch, trackingBranch, numCommits, numModified, + numUntracked \ + ): self.branch = branch self.trackingBranch = trackingBranch self.numCommits = numCommits @@ -1689,21 +1721,16 @@ def hasLocalChanges(self): return False -def getRepoStats(options, getCmndOutputFunc=None): +def getRepoStats(options, getCmndOutputFunc=None, showMoreHeadDetails=""): if not getCmndOutputFunc: getCmndOutputFunc = getCmndOutput - branch = getLocalBranch(options, getCmndOutputFunc) + branch = getRepoVersionIdentifier(options, getCmndOutputFunc, showMoreHeadDetails) trackingBranch = getTrackingBranch(options, getCmndOutputFunc) - numCommits = getNumCommitsWrtTrackingBranch(options, - trackingBranch, - getCmndOutputFunc) + numCommits = getNumCommitsWrtTrackingBranch(options, trackingBranch, getCmndOutputFunc) (numModified, numUntracked) = getNumModifiedAndUntracked(options, - getCmndOutputFunc) - return RepoStatsStruct(branch, - trackingBranch, - numCommits, - numModified, - numUntracked) + getCmndOutputFunc) + return RepoStatsStruct(branch, trackingBranch, numCommits, + numModified, numUntracked) class RepoVersionStruct: @@ -1894,7 +1921,7 @@ def getRepoName(repoDir, baseRepoName): # Get repo stats repoStats = None if options.modifiedOnly or distRepoStatus: - repoStats = getRepoStats(options) + repoStats = getRepoStats(options, showMoreHeadDetails="SHOW_MORE_HEAD_DETAILS") repoVersions = None if distRepoVersionTable: repoVersions = getRepoVersions(options)