From 11f57fc5a82ce9b56ec5bcda59cf77c68e6da007 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Fri, 28 Jul 2023 10:40:19 -0600 Subject: [PATCH 01/31] Codespell: Add ignores for sphinx generated documents --- .codespellrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.codespellrc b/.codespellrc index 179b32722..7b86e0d45 100644 --- a/.codespellrc +++ b/.codespellrc @@ -3,5 +3,5 @@ check-filenames = check-hidden = # Disable warnings about binary files quiet-level = 2 -skip = */.git,*/common_tools/cloc,*/TriBITSDoc,*/tribits/doc/guides/rst2latex.tex +skip = */.git,*/common_tools/cloc,*/TriBITSDoc,*/tribits/doc/guides/rst2latex.tex,*/*.js,*/*.svg,*/tribits/doc/sphinx/*/index.html ignore-words-list = thur,inout,te,nd,lod,aci,nin,nnumber,wile,reall,bu,somewhere From 139928c46a3ffb0c3772d940aa1c50afcab3af85 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Mon, 4 Sep 2023 18:37:35 -0600 Subject: [PATCH 02/31] tribits_sort_list_according_to_master_list(): Update doc and var name changes (#582) This is really a very general function so I updated the documentation to be general. This will allow this function to be moved to tribits/core/utils/. I also renamed some local vars to be camelCase. --- ...TribitsSortListAccordingToMasterList.cmake | 38 +++++++------------ 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/tribits/core/package_arch/TribitsSortListAccordingToMasterList.cmake b/tribits/core/package_arch/TribitsSortListAccordingToMasterList.cmake index 5d079a417..d6c8212ef 100644 --- a/tribits/core/package_arch/TribitsSortListAccordingToMasterList.cmake +++ b/tribits/core/package_arch/TribitsSortListAccordingToMasterList.cmake @@ -40,37 +40,25 @@ include(PrintVar) include(AppendSet) + +# 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() From 9bc70927899e68630be432158471e2bdc951a041 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 5 Sep 2023 08:01:00 -0600 Subject: [PATCH 03/31] Move TribitsSortListAccordingToMasterList.cmake to tribits/core/utils/ (#582) This is a generic function (see comments and documentation from previous commit). NOTE: This move of the module was done in a separate commit from the last commit so as to not confuse Git in tracing filename changes. --- .../TribitsSortListAccordingToMasterList.cmake | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tribits/core/{package_arch => utils}/TribitsSortListAccordingToMasterList.cmake (100%) diff --git a/tribits/core/package_arch/TribitsSortListAccordingToMasterList.cmake b/tribits/core/utils/TribitsSortListAccordingToMasterList.cmake similarity index 100% rename from tribits/core/package_arch/TribitsSortListAccordingToMasterList.cmake rename to tribits/core/utils/TribitsSortListAccordingToMasterList.cmake From 4cf58eaed47d6e0d21050fa202acb40e75ceb9ee Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Mon, 4 Sep 2023 18:40:27 -0600 Subject: [PATCH 04/31] Minor formatting update (#582) --- .../core/package_arch/TribitsAddExecutableTestHelpers.cmake | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tribits/core/package_arch/TribitsAddExecutableTestHelpers.cmake b/tribits/core/package_arch/TribitsAddExecutableTestHelpers.cmake index 78f98f0ba..1c0125ef9 100644 --- a/tribits/core/package_arch/TribitsAddExecutableTestHelpers.cmake +++ b/tribits/core/package_arch/TribitsAddExecutableTestHelpers.cmake @@ -46,13 +46,12 @@ 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}) From 297f55ffdc3b7f4542c5e473cd667c1fd7e198ee Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Fri, 14 Jul 2023 11:03:57 -0600 Subject: [PATCH 05/31] WIP: Add failing test for using raw CMake for Package1 in TriBITS project (#582) Now we can update TriBITS and the raw Package1 build system for it to work as a TriBITS package but without calling any TriBITS macros or functions. --- .../TribitsExampleProject2_Tests.cmake | 29 ++++++++++++++----- .../packages/package1/CMakeLists.txt | 10 +++++-- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake index b4be154f9..37cd49565 100644 --- a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake @@ -541,10 +541,24 @@ TribitsExampleProject2_explicit_tpl_vars(SHARED) ######################################################################## -function(TribitsExampleProject2_find_package sharedOrStatic) +function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrRawCMake) TribitsExampleProject2_test_setup_header() + if ( (package1TribitsOrRawCMake STREQUAL "") OR + (package1TribitsOrRawCMake STREQUAL "PACKAGE1_USE_TRIBITS") + ) + set(package1UseRawCMakeArgs "") + set(testNameSuffix "") + set(package1ConfiRegex "Configuring package Package1 as full TriBITS package") + elseif (package1TribitsOrRawCMake STREQUAL "PACKAGE1_USE_RAW_CMAKE") + set(package1UseRawCMakeArgs "-D Package1_USE_RAW_CMAKE=TRUE") + set(testNameSuffix "_${package1TribitsOrRawCMake}") + set(package1ConfiRegex "Configuring raw CMake package Package1") + else() + message(FATAL_ERROR "package1UseRawCMakeArgs='${package1UseRawCMakeArgs}' Invalid!") + endif() + # Allow skipping delete of src and build dirs to aid in debugging if (TribitsExampleProject2_Tests_SKIP_DELETE_SRC_AND_BUILD) set(deleteSrcAndBuildDirsCmndArgs @@ -554,7 +568,7 @@ function(TribitsExampleProject2_find_package sharedOrStatic) CMND ${CMAKE_COMMAND} ARGS -E rm -rf TribitsExampleProject2 BUILD) endif() - set(testNameBase ${CMAKE_CURRENT_FUNCTION}_${sharedOrStatic}) + set(testNameBase ${CMAKE_CURRENT_FUNCTION}_${sharedOrStatic}${testNameSuffix}) set(testName ${PACKAGE_NAME}_${testNameBase}) set(testDir "${CMAKE_CURRENT_BINARY_DIR}/${testName}") @@ -579,6 +593,7 @@ function(TribitsExampleProject2_find_package sharedOrStatic) -DCMAKE_BUILD_TYPE=DEBUG -DTPL_ENABLE_Tpl3=ON -DTPL_ENABLE_Tpl4=ON + ${package1UseRawCMakeArgs} -DTribitsExProj2_ENABLE_ALL_PACKAGES=ON -DTribitsExProj2_ENABLE_TESTS=ON -DCMAKE_INSTALL_PREFIX=${testDir}/install @@ -594,6 +609,7 @@ function(TribitsExampleProject2_find_package sharedOrStatic) "-- Generating Tpl3::all_libs and Tpl3Config.cmake" "-- Found Tpl4_DIR='.*TribitsExampleProject2_Tpls_install_${sharedOrStatic}/install_tpl4/lib/cmake/Tpl4'" "-- Generating Tpl4::all_libs and Tpl4Config.cmake" + "${package1ConfiRegex}" "-- Configuring done" "-- Generating done" ALWAYS_FAIL_ON_NONZERO_RETURN @@ -658,8 +674,10 @@ function(TribitsExampleProject2_find_package sharedOrStatic) endfunction() -TribitsExampleProject2_find_package(STATIC) -TribitsExampleProject2_find_package(SHARED) +TribitsExampleProject2_find_package(STATIC "") +TribitsExampleProject2_find_package(SHARED "") +TribitsExampleProject2_find_package(STATIC PACKAGE1_USE_RAW_CMAKE) +TribitsExampleProject2_find_package(SHARED PACKAGE1_USE_RAW_CMAKE) ######################################################################## @@ -1359,6 +1377,3 @@ TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(STATIC TPL_ TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(SHARED TPL_LIBRARY_AND_INCLUDE_DIRS) TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(STATIC CMAKE_PREFIX_PATH_CACHE) TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(SHARED CMAKE_PREFIX_PATH_CACHE) - - - diff --git a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt index 5f3b156eb..2344a4ef8 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt +++ b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt @@ -1,14 +1,14 @@ cmake_minimum_required(VERSION 3.23.0 FATAL_ERROR) macro(include_raw_cmake_build) - if (NOT COMMAND tribits_project) + if ((NOT COMMAND tribits_project) OR Package1_USE_RAW_CMAKE) include("${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.raw.cmake" NO_POLICY_SCOPE) return() endif() endmacro() -if (COMMAND tribits_package) +if ((COMMAND tribits_package) AND (NOT Package1_USE_RAW_CMAKE)) # Being processed as a TriBITS package tribits_package(Package1) @@ -18,7 +18,11 @@ if (COMMAND tribits_package) else() - message("Configuring raw CMake project Package1") + if (COMMAND tribits_package) + message("Configuring raw CMake package Package1") + else() + message("Configuring raw CMake project Package1") + endif() project(Package1 LANGUAGES C CXX) include(GNUInstallDirs) find_package(Tpl1 CONFIG REQUIRED) From 3fc5a4456af09874ac4b71bd2423d338d07ef350 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 18 Jul 2023 14:10:30 -0600 Subject: [PATCH 06/31] Rename function and improve documentation (#582) This makes the documentation ad code a little more clear. As part of this, I renamed the function `tribits_write_package_client_export_files_install_targets()` to ` tribits_write_package_client_export_files_export_and_install_targets()`. That makes it a little more clear what these functions are doing. --- ...ribitsInternalPackageWriteConfigFile.cmake | 60 +++++++++++-------- .../TribitsSystemMacroFunctionDocTemplate.rst | 2 +- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/tribits/core/package_arch/TribitsInternalPackageWriteConfigFile.cmake b/tribits/core/package_arch/TribitsInternalPackageWriteConfigFile.cmake index 7d3c1bb68..e820d6222 100644 --- a/tribits/core/package_arch/TribitsInternalPackageWriteConfigFile.cmake +++ b/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/tribits/doc/guides/TribitsSystemMacroFunctionDocTemplate.rst b/tribits/doc/guides/TribitsSystemMacroFunctionDocTemplate.rst index a2fdb71c9..3723c3b7c 100644 --- a/tribits/doc/guides/TribitsSystemMacroFunctionDocTemplate.rst +++ b/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() + From 11ad538ca1b9ade76b4d67796c73d796775d9d30 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 18 Jul 2023 17:11:30 -0600 Subject: [PATCH 07/31] Make TriBITS package with raw CMake work (#582) Allow TriBITS package TribitsExampleProject/Package1 to use 100% raw CMake and update TriBITS to allow that. This raw CMake build mode for Package1 uses no TriBITS macros, functions, or other functionality at all. The only changes to TriBITS-proper needed to allow this were: * Skip check for not calling tribits_package_postprocess() if the `::all_libs` target is already defined. * Build up the list of package libraries target for the `_libs` target from `::all_libs` instead of `_libs` (since the latter does not exist for a raw CMake package). However, this also required some changes to the TribitsExampleProject2/Package1 raw build system: * Use `${CMAKE_PROJECT_NAME}_INSTALL_LIB_DIR}` as the library install location instead of `${CMAKE_INSTALL_LIBDIR}` when building as a TriBITS package. This seems to pass all of the TriBITS tests. NOTE: This commit does **not** yet contain the changes to TriBITS to allow calling project() in the package's CMakeLists.txt files and still use TriBITS macros in the package's CMakeLists.txt files. Those changes will come later as we add an example that calls some TriBITS functions. --- .../TribitsExampleApp2_Tests.cmake | 45 +++++++++++++------ .../package_arch/TribitsGlobalMacros.cmake | 9 ++-- .../packages/package1/CMakeLists.txt | 38 +++++++++++++--- .../package1/src/CMakeLists.raw.cmake | 3 +- 4 files changed, 69 insertions(+), 26 deletions(-) diff --git a/test/core/ExamplesUnitTests/TribitsExampleApp2_Tests.cmake b/test/core/ExamplesUnitTests/TribitsExampleApp2_Tests.cmake index 01c0025c6..bccc0e18b 100644 --- a/test/core/ExamplesUnitTests/TribitsExampleApp2_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsExampleApp2_Tests.cmake @@ -87,7 +87,7 @@ endif() function(TribitsExampleApp2 tribitsExProj2TestNameBaseBase - sharedOrStatic fullOrComponents + sharedOrStatic package1TribitsOrRawCMake fullOrComponents ) if (sharedOrStatic STREQUAL "SHARED") @@ -95,8 +95,21 @@ function(TribitsExampleApp2 tribitsExProj2TestNameBaseBase elseif (sharedOrStatic STREQUAL "STATIC") set(buildSharedLibsArg -DBUILD_SHARED_LIBS=OFF) else() - message(FATAL_ERROR "Invalid value of buildSharedLibsArg='${buildSharedLibsArg}'!") + message(FATAL_ERROR "Invalid value of sharedOrStatic='${sharedOrStatic}'!") endif() + set(tribitsExProj2Suffix "${sharedOrStatic}") + + if ( (package1TribitsOrRawCMake STREQUAL "") OR + (package1TribitsOrRawCMake STREQUAL "PACKAGE1_USE_TRIBITS") + ) + set(package1UseRawCMakeArgs "") + elseif (package1TribitsOrRawCMake STREQUAL "PACKAGE1_USE_RAW_CMAKE") + set(package1UseRawCMakeArgs "-D Package1_USE_RAW_CMAKE=TRUE") + string(APPEND tribitsExProj2Suffix "_${package1TribitsOrRawCMake}") + else() + message(FATAL_ERROR "package1UseRawCMakeArgs='${package1UseRawCMakeArgs}' Invalid!") + endif() + set(fullDepsRegex "Full Deps: Package3{Package2{Package1{tpl1}, Tpl3{Tpl2a{tpl1}, Tpl2b{no deps}}}, Package1{tpl1}, Tpl4{Tpl3{Tpl2a{tpl1}, Tpl2b{no deps}}, Tpl2a{tpl1}, Tpl2b{no deps}}, Tpl2a{tpl1}, Tpl2b{no deps}}") @@ -113,7 +126,7 @@ function(TribitsExampleApp2 tribitsExProj2TestNameBaseBase set(fullDepsRegex "Full Deps: Package3{Package1{tpl1}, Tpl2a{tpl1}, Tpl2b{no deps}}") endif() - set(testSuffix ${sharedOrStatic}_${fullOrComponents}) + set(testSuffix ${tribitsExProj2Suffix}_${fullOrComponents}) set(testBaseName ${CMAKE_CURRENT_FUNCTION}_${tribitsExProj2TestNameBaseBase}_${testSuffix}) set(testName ${PACKAGE_NAME}_${testBaseName}) @@ -129,7 +142,7 @@ function(TribitsExampleApp2 tribitsExProj2TestNameBaseBase MESSAGE "Configure TribitsExampleApp2 locally against already installed TribitsExProject2" WORKING_DIRECTORY app_build CMND ${CMAKE_COMMAND} ARGS - -DCMAKE_PREFIX_PATH=${${tribitsExProj2TestNameBaseBase}_${sharedOrStatic}_INSTALL_DIR} + -DCMAKE_PREFIX_PATH=${${tribitsExProj2TestNameBaseBase}_${tribitsExProj2Suffix}_INSTALL_DIR} ${tribitsExProjUseComponentsArg} ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleApp2 PASS_REGULAR_EXPRESSION_ALL @@ -169,20 +182,24 @@ function(TribitsExampleApp2 tribitsExProj2TestNameBaseBase if (${testNameBase}_NAME) set_tests_properties(${${testNameBase}_NAME} - PROPERTIES DEPENDS ${${tribitsExProj2TestNameBaseBase}_${sharedOrStatic}_NAME} ) + PROPERTIES DEPENDS ${${tribitsExProj2TestNameBaseBase}_${tribitsExProj2Suffix}_NAME} + ) endif() endfunction() -TribitsExampleApp2(TribitsExampleProject2_find_tpl_parts STATIC FULL) +TribitsExampleApp2(TribitsExampleProject2_find_tpl_parts STATIC "" FULL) # NOTE: We don't need to test the permutation SHARED FULL as well. That does # not really test anything new given that shared is tested with COMPONENTS. -TribitsExampleApp2(TribitsExampleProject2_find_tpl_parts STATIC COMPONENTS) -TribitsExampleApp2(TribitsExampleProject2_find_tpl_parts SHARED COMPONENTS) -TribitsExampleApp2(TribitsExampleProject2_find_tpl_parts_no_optional_packages_tpls STATIC COMPONENTS) -TribitsExampleApp2(TribitsExampleProject2_find_tpl_parts_no_optional_packages_tpls SHARED COMPONENTS) -TribitsExampleApp2(TribitsExampleProject2_explicit_tpl_vars STATIC COMPONENTS) -TribitsExampleApp2(TribitsExampleProject2_explicit_tpl_vars SHARED COMPONENTS) -TribitsExampleApp2(TribitsExampleProject2_find_package SHARED COMPONENTS) -TribitsExampleApp2(TribitsExampleProject2_find_package STATIC COMPONENTS) +TribitsExampleApp2(TribitsExampleProject2_find_tpl_parts STATIC "" COMPONENTS) +TribitsExampleApp2(TribitsExampleProject2_find_tpl_parts SHARED "" COMPONENTS) +TribitsExampleApp2(TribitsExampleProject2_find_tpl_parts_no_optional_packages_tpls STATIC "" COMPONENTS) +TribitsExampleApp2(TribitsExampleProject2_find_tpl_parts_no_optional_packages_tpls SHARED "" COMPONENTS) +TribitsExampleApp2(TribitsExampleProject2_explicit_tpl_vars STATIC "" COMPONENTS) +TribitsExampleApp2(TribitsExampleProject2_explicit_tpl_vars SHARED "" COMPONENTS) +TribitsExampleApp2(TribitsExampleProject2_find_package SHARED "" COMPONENTS) +TribitsExampleApp2(TribitsExampleProject2_find_package STATIC "" COMPONENTS) +TribitsExampleApp2(TribitsExampleProject2_find_package SHARED PACKAGE1_USE_RAW_CMAKE COMPONENTS) +TribitsExampleApp2(TribitsExampleProject2_find_package STATIC PACKAGE1_USE_RAW_CMAKE COMPONENTS) +TribitsExampleApp2(TribitsExampleProject2_find_package STATIC PACKAGE1_USE_RAW_CMAKE FULL) diff --git a/tribits/core/package_arch/TribitsGlobalMacros.cmake b/tribits/core/package_arch/TribitsGlobalMacros.cmake index 28c0fa807..2a6565d96 100644 --- a/tribits/core/package_arch/TribitsGlobalMacros.cmake +++ b/tribits/core/package_arch/TribitsGlobalMacros.cmake @@ -2072,17 +2072,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/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt index 2344a4ef8..1211cdda6 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt +++ b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt @@ -10,7 +10,7 @@ endmacro() if ((COMMAND tribits_package) AND (NOT Package1_USE_RAW_CMAKE)) - # Being processed as a TriBITS package + message("Configuring package Package1 as full TriBITS package") tribits_package(Package1) add_subdirectory(src) tribits_add_test_directories(test) @@ -32,19 +32,37 @@ else() add_subdirectory(test) endif() - # Generate the all_libs target + # 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 + 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) - # Generate and install the Package1Config.cmake file + # Generate Package1Config.cmake file for the build tree + 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_SOURCE_DIR}/cmake/raw/Package1Config.cmake.in" + "${packageBuildDirCMakePackagesDir}/${PROJECT_NAME}/Package1Config.cmake" + @ONLY ) + + # Generate and install the Package1Config.cmake file for the install tree + if (COMMAND tribits_package) + set(pkgConfigInstallDir + "${${CMAKE_PROJECT_NAME}_INSTALL_LIB_DIR}/cmake/${PACKAGE_NAME}") + else() + set(pkgConfigInstallDir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + endif() install(EXPORT ${PROJECT_NAME} - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + DESTINATION "${pkgConfigInstallDir}" NAMESPACE ${PROJECT_NAME}:: FILE ${PROJECT_NAME}ConfigTargets.cmake ) configure_file( @@ -54,8 +72,14 @@ else() install( FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Package1Config.install.cmake" RENAME "Package1Config.cmake" - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) + DESTINATION "${pkgConfigInstallDir}" ) endif() +# NOTE: Above, the variable CMAKE_INSTALL_LIBDIR set by +# include(GNUInstallDirs) is different that what is used by TriBITS by default +# in at least some cases. That is very irritating and this is something that +# needs to be fixed (see TriBITSPub/TriBITS#411). But note that the location +# of the libraries does not have to be the same as the installed +# `Config.cmake`. \ No newline at end of file diff --git a/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.raw.cmake b/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.raw.cmake index aa5dffd55..f15cdc589 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.raw.cmake +++ b/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( From 5aa2622834f416a9331565979ff3c69d699dca48 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Thu, 3 Aug 2023 17:50:41 -0600 Subject: [PATCH 08/31] Remove special raw CMake package logic for lib install dir (#582) This avoids the special logic in the file package1/CMakeLists.txt by having TribitsExampleProject2/CMakeLists.txt set the var ${PROJECT_NAME}_USE_GNUINSTALLDIRS=ON. This resulted in everything being installed under /lib64/ on my current machine automatically. However, to get this to work I had to set: -DCMAKE_INSTALL_LIBDIR:STRING=lib or the find_package(...) command with CMake 3.23.1 would no longer find Config.cmake files under: /lib64/ This seems inconsistent with CMake documentation for find_package() as of CMake 3.23.1 that suggests that it will look under the location: /(lib/|lib*|share)/cmake/*/ Well that should pick up the directory: /lib*/cmake/*/ But that was not the case :-( Perhaps this is fixed in the latest CMake? In any case, we get around this by by setting CMAKE_INSTALL_LIBDIR=lib. Other changes made in this commit: * Fixed the 'TribitsExampleApp2' tests to correctly switch between searching for the top project-level package-config file or the individual package-config files. (This required passing in -DTribitsExApp2_FIND_INDIVIDUAL_PACKAGES=ON and updating the regex.) --- .../TribitsExampleApp2_Tests.cmake | 5 ++++- .../TribitsExampleProject2_Tests.cmake | 12 ++++++++++++ .../TribitsExampleApp2/AppHelperFuncs.cmake | 5 +++-- .../TribitsExampleProject2/CMakeLists.txt | 1 + .../packages/package1/CMakeLists.txt | 15 +-------------- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/test/core/ExamplesUnitTests/TribitsExampleApp2_Tests.cmake b/test/core/ExamplesUnitTests/TribitsExampleApp2_Tests.cmake index bccc0e18b..d57cd9f61 100644 --- a/test/core/ExamplesUnitTests/TribitsExampleApp2_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsExampleApp2_Tests.cmake @@ -115,9 +115,12 @@ function(TribitsExampleApp2 tribitsExProj2TestNameBaseBase if (fullOrComponents STREQUAL "FULL") set(tribitsExProjUseComponentsArg "") + set(packageListRegex "TribitsExProj2_PACKAGE_LIST = Package3[;]Package2[;]Package1") elseif (fullOrComponents STREQUAL "COMPONENTS") set(tribitsExProjUseComponentsArg + -DTribitsExApp2_FIND_INDIVIDUAL_PACKAGES=ON -DTribitsExApp2_USE_COMPONENTS="Package1,Package2,Package3") + set(packageListRegex "Found Package1;Found Package2;Found Package3") else() message(FATAL_ERROR "Invalid value of fullOrComponents='${fullOrComponents}'!") endif() @@ -146,7 +149,7 @@ function(TribitsExampleApp2 tribitsExProj2TestNameBaseBase ${tribitsExProjUseComponentsArg} ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleApp2 PASS_REGULAR_EXPRESSION_ALL - "TribitsExProj2_PACKAGE_LIST = Package3[;]Package2[;]Package1" + "${packageListRegex}" "-- Configuring done" "-- Generating done" "-- Build files have been written to: .*/${testName}/app_build" diff --git a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake index 37cd49565..bee834b32 100644 --- a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake @@ -187,6 +187,7 @@ function(TribitsExampleProject2_find_tpl_parts sharedOrStatic findingTplsMetho ${tplLibAndIncDirsArgs} ${cmakePrefixPathCacheArg} -DTribitsExProj2_ENABLE_TESTS=ON + -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=${testDir}/install -DTribitsExProj2_ENABLE_ALL_PACKAGES=ON ../TribitsExampleProject2 @@ -352,6 +353,7 @@ function(TribitsExampleProject2_find_tpl_parts_no_optional_packages_tpls shared -DTribitsExProj2_ENABLE_ALL_OPTIONAL_PACKAGES=OFF -DPackage3_ENABLE_Package2=OFF -DTribitsExProj2_ENABLE_TESTS=ON + -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=install -DTribitsExProj2_ENABLE_ALL_PACKAGES=ON ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject2 @@ -469,6 +471,7 @@ function(TribitsExampleProject2_explicit_tpl_vars sharedOrStatic) -DCMAKE_BUILD_TYPE=DEBUG -DTribitsExProj2_ENABLE_ALL_PACKAGES=ON -DTribitsExProj2_ENABLE_TESTS=ON + -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=install ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject2 PASS_REGULAR_EXPRESSION_ALL @@ -596,6 +599,7 @@ function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrR ${package1UseRawCMakeArgs} -DTribitsExProj2_ENABLE_ALL_PACKAGES=ON -DTribitsExProj2_ENABLE_TESTS=ON + -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=${testDir}/install -D CMAKE_PREFIX_PATH="${tplInstallBaseDir}/install_tpl1${tplInstallBaseDir}/install_tpl2${tplInstallBaseDir}/install_tpl3${tplInstallBaseDir}/install_tpl4" ../TribitsExampleProject2 @@ -702,6 +706,7 @@ tribits_add_advanced_test( ${testNameBase} -DCMAKE_BUILD_TYPE=DEBUG -DTpl1_EXTRACT_INFO_AFTER_FIND_PACKAGE=ON -DTribitsExProj2_ENABLE_TESTS=ON + -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=install -DTribitsExProj2_ENABLE_Package1=ON ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject2 @@ -748,6 +753,7 @@ tribits_add_advanced_test( ${testNameBase} -DTpl1_EXTRACT_INFO_AFTER_FIND_PACKAGE=ON -DTribitsExProj2_ENABLE_TESTS=ON -DCMAKE_PREFIX_PATH="${testDir}/install" + -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=install -DTribitsExProj2_ENABLE_Package1=ON ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject2 @@ -905,6 +911,7 @@ function(TribitsExampleProject2_External_Package_by_Package -DTribitsExProj2_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR} -DTribitsExProj2_ENABLE_SECONDARY_TESTED_CODE=ON -DTribitsExProj2_ENABLE_Package1=ON + -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=../install_package1 -DTribitsExProj2_SKIP_INSTALL_PROJECT_CMAKE_CONFIG_FILES=TRUE -DTPL_ENABLE_Tpl1=ON @@ -941,6 +948,7 @@ function(TribitsExampleProject2_External_Package_by_Package -DTribitsExProj2_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR} -DTribitsExProj2_ENABLE_SECONDARY_TESTED_CODE=ON -DTribitsExProj2_ENABLE_Package2=ON + -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=../install_package2 -DTribitsExProj2_SKIP_INSTALL_PROJECT_CMAKE_CONFIG_FILES=TRUE -DTPL_ENABLE_Package1=ON # Pull in already installed Package! @@ -1002,6 +1010,7 @@ function(TribitsExampleProject2_External_Package_by_Package -DTribitsExProj2_ENABLE_SECONDARY_TESTED_CODE=ON -DTribitsExProj2_ENABLE_ALL_PACKAGES=ON -DTribitsExProj2_ENABLE_TESTS=ON + -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=../install -DTribitsExProj2_SKIP_INSTALL_PROJECT_CMAKE_CONFIG_FILES=TRUE -DTPL_ENABLE_Package2=ON # Pull in already installed Package! @@ -1200,6 +1209,7 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package ARGS ${TribitsExampleProject2_COMMON_CONFIG_ARGS} -DCMAKE_PREFIX_PATH=${tplInstallBaseDir}/install_tpl1 + -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=../install_package1 ../TribitsExampleProject2/packages/package1 PASS_REGULAR_EXPRESSION_ALL @@ -1226,6 +1236,7 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package -DTribitsExProj2_ENABLE_SECONDARY_TESTED_CODE=ON -DTribitsExProj2_ENABLE_TESTS=ON -DTribitsExProj2_ENABLE_Package2=ON + -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=../install_package2 -DTribitsExProj2_SKIP_INSTALL_PROJECT_CMAKE_CONFIG_FILES=TRUE -DTPL_ENABLE_Package1=ON # Pull in already installed Package1! @@ -1296,6 +1307,7 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package -DTribitsExProj2_ENABLE_SECONDARY_TESTED_CODE=ON -DTribitsExProj2_ENABLE_ALL_PACKAGES=ON -DTribitsExProj2_ENABLE_TESTS=ON + -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=../install -DTribitsExProj2_SKIP_INSTALL_PROJECT_CMAKE_CONFIG_FILES=TRUE -DTPL_ENABLE_Package2=ON # Pull in already installed Package! diff --git a/tribits/examples/TribitsExampleApp2/AppHelperFuncs.cmake b/tribits/examples/TribitsExampleApp2/AppHelperFuncs.cmake index cbed66bcd..ebb23e178 100644 --- a/tribits/examples/TribitsExampleApp2/AppHelperFuncs.cmake +++ b/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/tribits/examples/TribitsExampleProject2/CMakeLists.txt b/tribits/examples/TribitsExampleProject2/CMakeLists.txt index 7ba3163d9..1c249d2b2 100644 --- a/tribits/examples/TribitsExampleProject2/CMakeLists.txt +++ b/tribits/examples/TribitsExampleProject2/CMakeLists.txt @@ -8,6 +8,7 @@ cmake_minimum_required(VERSION 3.23.0 FATAL_ERROR) include("${CMAKE_CURRENT_SOURCE_DIR}/ProjectName.cmake") project(${PROJECT_NAME} LANGUAGES NONE) set(TRIBITS_HIDE_DEPRECATED_INCLUDE_DIRECTORIES_OVERRIDE TRUE) +set(${PROJECT_NAME}_USE_GNUINSTALLDIRS ON) set(${PROJECT_NAME}_TRIBITS_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." CACHE STRING "TriBITS base directory (default assumes in TriBITS source tree)") diff --git a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt index 1211cdda6..4bc4f7ae9 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt +++ b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt @@ -55,12 +55,7 @@ else() @ONLY ) # Generate and install the Package1Config.cmake file for the install tree - if (COMMAND tribits_package) - set(pkgConfigInstallDir - "${${CMAKE_PROJECT_NAME}_INSTALL_LIB_DIR}/cmake/${PACKAGE_NAME}") - else() - set(pkgConfigInstallDir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") - endif() + set(pkgConfigInstallDir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") install(EXPORT ${PROJECT_NAME} DESTINATION "${pkgConfigInstallDir}" NAMESPACE ${PROJECT_NAME}:: @@ -75,11 +70,3 @@ else() DESTINATION "${pkgConfigInstallDir}" ) endif() - - -# NOTE: Above, the variable CMAKE_INSTALL_LIBDIR set by -# include(GNUInstallDirs) is different that what is used by TriBITS by default -# in at least some cases. That is very irritating and this is something that -# needs to be fixed (see TriBITSPub/TriBITS#411). But note that the location -# of the libraries does not have to be the same as the installed -# `Config.cmake`. \ No newline at end of file From 0cfa82a6622c9bbdc801cf8bf395c7a2dad5adc3 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Fri, 4 Aug 2023 02:54:40 -0600 Subject: [PATCH 09/31] Set TribitsExProj2_USE_GNUINSTALLDIRS=ON only for find_package tests (#582) This avoids having to add: -DCMAKE_INSTALL_LIBDIR:STRING=lib for all of the TribitsExampleProject2_find_package tests. If it was not for the CMake defect with find_package() documented in the new updated comment, then we could set TribitsExProj2_USE_GNUINSTALLDIRS=ON and not have to set CMAKE_INSTALL_LIBDIR=lib. --- .../TribitsExampleProject2_Tests.cmake | 25 ++++++++++--------- .../TribitsExampleProject2/CMakeLists.txt | 1 - 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake index bee834b32..ffb2112e5 100644 --- a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake @@ -187,7 +187,6 @@ function(TribitsExampleProject2_find_tpl_parts sharedOrStatic findingTplsMetho ${tplLibAndIncDirsArgs} ${cmakePrefixPathCacheArg} -DTribitsExProj2_ENABLE_TESTS=ON - -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=${testDir}/install -DTribitsExProj2_ENABLE_ALL_PACKAGES=ON ../TribitsExampleProject2 @@ -353,7 +352,6 @@ function(TribitsExampleProject2_find_tpl_parts_no_optional_packages_tpls shared -DTribitsExProj2_ENABLE_ALL_OPTIONAL_PACKAGES=OFF -DPackage3_ENABLE_Package2=OFF -DTribitsExProj2_ENABLE_TESTS=ON - -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=install -DTribitsExProj2_ENABLE_ALL_PACKAGES=ON ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject2 @@ -471,7 +469,6 @@ function(TribitsExampleProject2_explicit_tpl_vars sharedOrStatic) -DCMAKE_BUILD_TYPE=DEBUG -DTribitsExProj2_ENABLE_ALL_PACKAGES=ON -DTribitsExProj2_ENABLE_TESTS=ON - -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=install ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject2 PASS_REGULAR_EXPRESSION_ALL @@ -599,6 +596,7 @@ function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrR ${package1UseRawCMakeArgs} -DTribitsExProj2_ENABLE_ALL_PACKAGES=ON -DTribitsExProj2_ENABLE_TESTS=ON + -DTribitsExProj2_USE_GNUINSTALLDIRS=ON -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=${testDir}/install -D CMAKE_PREFIX_PATH="${tplInstallBaseDir}/install_tpl1${tplInstallBaseDir}/install_tpl2${tplInstallBaseDir}/install_tpl3${tplInstallBaseDir}/install_tpl4" @@ -666,7 +664,18 @@ function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrR ADDED_TEST_NAME_OUT ${testNameBase}_NAME ) # NOTE: The above test ensures that find_package() works with manual - # building of the target. + # building of the target. For the configure, we have to set + # -DTribitsExProj2_USE_GNUINSTALLDIRS=ON -DCMAKE_INSTALL_LIBDIR:STRING=lib + # so that the Config.cmake files get installed under the same + # location /lib/ or the file Package2Config.cmake can't include the + # file Package1Config.cmake. Just setting + # TribitsExProj2_USE_GNUINSTALLDIRS=ON without setting + # CMAKE_INSTALL_LIBDIR=lib results installing everything consistently under + # /lib64/ on some machines and there is a defect in find_package() + # that can't find packages under /lib64/ where it can under + # /lib/ (see Kitware GitLab cmake/cmake#25157). Therefore, the + # directory location has to be overridden with CMAKE_INSTALL_LIBDIR=lib to + # allow find_package() to work. if (${testNameBase}_NAME) set(${testNameBase}_NAME ${${testNameBase}_NAME} PARENT_SCOPE) @@ -706,7 +715,6 @@ tribits_add_advanced_test( ${testNameBase} -DCMAKE_BUILD_TYPE=DEBUG -DTpl1_EXTRACT_INFO_AFTER_FIND_PACKAGE=ON -DTribitsExProj2_ENABLE_TESTS=ON - -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=install -DTribitsExProj2_ENABLE_Package1=ON ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject2 @@ -753,7 +761,6 @@ tribits_add_advanced_test( ${testNameBase} -DTpl1_EXTRACT_INFO_AFTER_FIND_PACKAGE=ON -DTribitsExProj2_ENABLE_TESTS=ON -DCMAKE_PREFIX_PATH="${testDir}/install" - -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=install -DTribitsExProj2_ENABLE_Package1=ON ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject2 @@ -911,7 +918,6 @@ function(TribitsExampleProject2_External_Package_by_Package -DTribitsExProj2_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR} -DTribitsExProj2_ENABLE_SECONDARY_TESTED_CODE=ON -DTribitsExProj2_ENABLE_Package1=ON - -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=../install_package1 -DTribitsExProj2_SKIP_INSTALL_PROJECT_CMAKE_CONFIG_FILES=TRUE -DTPL_ENABLE_Tpl1=ON @@ -948,7 +954,6 @@ function(TribitsExampleProject2_External_Package_by_Package -DTribitsExProj2_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR} -DTribitsExProj2_ENABLE_SECONDARY_TESTED_CODE=ON -DTribitsExProj2_ENABLE_Package2=ON - -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=../install_package2 -DTribitsExProj2_SKIP_INSTALL_PROJECT_CMAKE_CONFIG_FILES=TRUE -DTPL_ENABLE_Package1=ON # Pull in already installed Package! @@ -1010,7 +1015,6 @@ function(TribitsExampleProject2_External_Package_by_Package -DTribitsExProj2_ENABLE_SECONDARY_TESTED_CODE=ON -DTribitsExProj2_ENABLE_ALL_PACKAGES=ON -DTribitsExProj2_ENABLE_TESTS=ON - -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=../install -DTribitsExProj2_SKIP_INSTALL_PROJECT_CMAKE_CONFIG_FILES=TRUE -DTPL_ENABLE_Package2=ON # Pull in already installed Package! @@ -1209,7 +1213,6 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package ARGS ${TribitsExampleProject2_COMMON_CONFIG_ARGS} -DCMAKE_PREFIX_PATH=${tplInstallBaseDir}/install_tpl1 - -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=../install_package1 ../TribitsExampleProject2/packages/package1 PASS_REGULAR_EXPRESSION_ALL @@ -1236,7 +1239,6 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package -DTribitsExProj2_ENABLE_SECONDARY_TESTED_CODE=ON -DTribitsExProj2_ENABLE_TESTS=ON -DTribitsExProj2_ENABLE_Package2=ON - -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=../install_package2 -DTribitsExProj2_SKIP_INSTALL_PROJECT_CMAKE_CONFIG_FILES=TRUE -DTPL_ENABLE_Package1=ON # Pull in already installed Package1! @@ -1307,7 +1309,6 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package -DTribitsExProj2_ENABLE_SECONDARY_TESTED_CODE=ON -DTribitsExProj2_ENABLE_ALL_PACKAGES=ON -DTribitsExProj2_ENABLE_TESTS=ON - -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_PREFIX=../install -DTribitsExProj2_SKIP_INSTALL_PROJECT_CMAKE_CONFIG_FILES=TRUE -DTPL_ENABLE_Package2=ON # Pull in already installed Package! diff --git a/tribits/examples/TribitsExampleProject2/CMakeLists.txt b/tribits/examples/TribitsExampleProject2/CMakeLists.txt index 1c249d2b2..7ba3163d9 100644 --- a/tribits/examples/TribitsExampleProject2/CMakeLists.txt +++ b/tribits/examples/TribitsExampleProject2/CMakeLists.txt @@ -8,7 +8,6 @@ cmake_minimum_required(VERSION 3.23.0 FATAL_ERROR) include("${CMAKE_CURRENT_SOURCE_DIR}/ProjectName.cmake") project(${PROJECT_NAME} LANGUAGES NONE) set(TRIBITS_HIDE_DEPRECATED_INCLUDE_DIRECTORIES_OVERRIDE TRUE) -set(${PROJECT_NAME}_USE_GNUINSTALLDIRS ON) set(${PROJECT_NAME}_TRIBITS_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." CACHE STRING "TriBITS base directory (default assumes in TriBITS source tree)") From 509cdb096cd0a9d3fd9b9a3645cc199ccb42552d Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 22 Aug 2023 11:48:02 -0600 Subject: [PATCH 10/31] WIP: Add failing test for using tribits_add_test() in raw CMake package1 build under TriBITS project (#582) This test sets up to use the TriBITS test management functions from inside of a raw CMake package under a TriBITS project. --- .../TribitsExampleProject2_Tests.cmake | 30 +++++++++++++++---- .../package1/test/CMakeLists.tribits.cmake | 3 ++ .../packages/package1/test/CMakeLists.txt | 16 ++++++---- 3 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake diff --git a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake index ffb2112e5..bba3bcd86 100644 --- a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake @@ -541,7 +541,9 @@ TribitsExampleProject2_explicit_tpl_vars(SHARED) ######################################################################## -function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrRawCMake) +function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrRawCMake + package1UseTribitsTestFunctions + ) TribitsExampleProject2_test_setup_header() @@ -559,6 +561,22 @@ function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrR message(FATAL_ERROR "package1UseRawCMakeArgs='${package1UseRawCMakeArgs}' Invalid!") endif() + if (package1TribitsOrRawCMake STREQUAL "PACKAGE1_USE_RAW_CMAKE") + if (package1UseTribitsTestFunctions STREQUAL "PACKAGE1_USE_TRIBITS_TEST_FUNCTIONS") + list(APPEND package1UseRawCMakeArgs + "-D Package1_USE_TRIBITS_TEST_FUNCTIONS=TRUE" ) + string(APPEND testNameSuffix "_${package1UseTribitsTestFunctions}" ) + list(APPEND package1ConfiRegex + "Using TriBITS Test Functions in a raw CMake Package1 build" ) + elseif (package1UseTribitsTestFunctions STREQUAL "") + list(APPEND package1ConfiRegex + "Using Raw CMake add_test[(][)] in a raw CMake Package1 build" ) + else() + message(FATAL_ERROR + "Error, package1UseTribitsTestFunctions='${package1UseTribitsTestFunctions}' is invalid!") + endif() + endif() + # Allow skipping delete of src and build dirs to aid in debugging if (TribitsExampleProject2_Tests_SKIP_DELETE_SRC_AND_BUILD) set(deleteSrcAndBuildDirsCmndArgs @@ -687,10 +705,12 @@ function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrR endfunction() -TribitsExampleProject2_find_package(STATIC "") -TribitsExampleProject2_find_package(SHARED "") -TribitsExampleProject2_find_package(STATIC PACKAGE1_USE_RAW_CMAKE) -TribitsExampleProject2_find_package(SHARED PACKAGE1_USE_RAW_CMAKE) +TribitsExampleProject2_find_package(STATIC "" "") +TribitsExampleProject2_find_package(SHARED "" "") +TribitsExampleProject2_find_package(STATIC PACKAGE1_USE_RAW_CMAKE "") +TribitsExampleProject2_find_package(SHARED PACKAGE1_USE_RAW_CMAKE "") +TribitsExampleProject2_find_package(SHARED PACKAGE1_USE_RAW_CMAKE + PACKAGE1_USE_TRIBITS_TEST_FUNCTIONS) ######################################################################## diff --git a/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake b/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake new file mode 100644 index 000000000..308757908 --- /dev/null +++ b/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake @@ -0,0 +1,3 @@ +tribits_add_test(package1-prg NOEXEPREFIX NOEXESUFFIX + NAME Prg DIRECTORY ${PACKAGE_BINARY_DIR}/src NUM_MPI_PROCS 1 + PASS_REGULAR_EXPRESSION "Package1 Deps: tpl1" ) diff --git a/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.txt b/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.txt index 906e0faf8..922e735d1 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.txt +++ b/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) + message("-- Using TriBITS Test Functions in a raw CMake Package1 build!") + include("${CMAKE_CURRENT_LIST_DIR}/CMakeLists.tribits.cmake") + else() + message("-- Using Raw CMake add_test() in a raw CMake Package1 build!") + include("${CMAKE_CURRENT_LIST_DIR}/CMakeLists.raw.cmake") + endif() +else() + include("${CMAKE_CURRENT_LIST_DIR}/CMakeLists.tribits.cmake") +endif() From 67a1f79020901b94a459e72a0784ef60b4c9e286 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 22 Aug 2023 12:23:12 -0600 Subject: [PATCH 11/31] Make tribits_add_test() work from a raw CMake package in TriBITS project (#582) --- .../core/package_arch/TribitsAddTest.cmake | 4 +- .../package_arch/TribitsAddTestHelpers.cmake | 1 + .../TribitsSetTribitsPackageName.cmake | 55 +++++++++++++++++++ .../package1/test/CMakeLists.tribits.cmake | 2 +- 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 tribits/core/package_arch/TribitsSetTribitsPackageName.cmake diff --git a/tribits/core/package_arch/TribitsAddTest.cmake b/tribits/core/package_arch/TribitsAddTest.cmake index 6f388fdac..6578e8d3a 100644 --- a/tribits/core/package_arch/TribitsAddTest.cmake +++ b/tribits/core/package_arch/TribitsAddTest.cmake @@ -817,6 +817,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 +937,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/tribits/core/package_arch/TribitsAddTestHelpers.cmake b/tribits/core/package_arch/TribitsAddTestHelpers.cmake index 715bca20f..9815e538b 100644 --- a/tribits/core/package_arch/TribitsAddTestHelpers.cmake +++ b/tribits/core/package_arch/TribitsAddTestHelpers.cmake @@ -39,6 +39,7 @@ include(TribitsAddExecutableTestHelpers) +include(TribitsSetTribitsPackageName) include(TribitsGeneralMacros) include(TribitsTestCategories) diff --git a/tribits/core/package_arch/TribitsSetTribitsPackageName.cmake b/tribits/core/package_arch/TribitsSetTribitsPackageName.cmake new file mode 100644 index 000000000..2a08b4beb --- /dev/null +++ b/tribits/core/package_arch/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/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake b/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake index 308757908..bc79820e3 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake +++ b/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake @@ -1,3 +1,3 @@ tribits_add_test(package1-prg NOEXEPREFIX NOEXESUFFIX - NAME Prg DIRECTORY ${PACKAGE_BINARY_DIR}/src NUM_MPI_PROCS 1 + NAME Prg DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../src" NUM_MPI_PROCS 1 PASS_REGULAR_EXPRESSION "Package1 Deps: tpl1" ) From 83bc7950b036be099dc44dd6d0fb8756c33014ee Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 22 Aug 2023 12:46:32 -0600 Subject: [PATCH 12/31] Enable tests for raw CMake Package1 stand-alone configuration (#582) This will allow me to define and run the tests for Package1 using tribits_add_test(). --- .../TribitsExampleProject2_Tests.cmake | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake index bba3bcd86..b3c9d672f 100644 --- a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake @@ -1227,11 +1227,12 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package ARGS -s ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject2 . TEST_1 - MESSAGE "Configure to build and install just Package1 using raw CMake build system" + MESSAGE "Configure to build, install, and test just Package1 using its raw CMake build system" WORKING_DIRECTORY Build_Package1 CMND ${CMAKE_COMMAND} ARGS ${TribitsExampleProject2_COMMON_CONFIG_ARGS} + -DPackage1_ENABLE_TESTS=ON -DCMAKE_PREFIX_PATH=${tplInstallBaseDir}/install_tpl1 -DCMAKE_INSTALL_PREFIX=../install_package1 ../TribitsExampleProject2/packages/package1 @@ -1250,6 +1251,16 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package CMND ${CMAKE_COMMAND} ARGS --build . --target install TEST_3 + MESSAGE "Test just Package1" + WORKING_DIRECTORY Build_Package1 + SKIP_CLEAN_WORKING_DIRECTORY + CMND ${CMAKE_CTEST_COMMAND} + PASS_REGULAR_EXPRESSION_ALL + "1/1 Test [#]1: Package1_Prg [.]* *Passed" + "100% tests passed, 0 tests failed out of 1" + ALWAYS_FAIL_ON_NONZERO_RETURN + + TEST_4 MESSAGE "Configure to build, install, and test Package2" WORKING_DIRECTORY Build_Package2 CMND ${CMAKE_COMMAND} @@ -1303,13 +1314,13 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package # dependencies (i.e. Tpl1) as TriBITS-compliant external packages (which # shows that the TriBITS project must find Tpl1 again from scratch). - TEST_4 + TEST_5 MESSAGE "Build and install just Package2" WORKING_DIRECTORY Build_Package2 SKIP_CLEAN_WORKING_DIRECTORY CMND ${CMAKE_COMMAND} ARGS --build . --target install - TEST_5 + TEST_6 MESSAGE "Run tests for Package2" WORKING_DIRECTORY Build_Package2 SKIP_CLEAN_WORKING_DIRECTORY @@ -1319,7 +1330,7 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package "100% tests passed, 0 tests failed out of 1" ALWAYS_FAIL_ON_NONZERO_RETURN - TEST_6 + TEST_7 MESSAGE "Configure to build, test, and install the rest of TribitsExampleProject2 (Package2)" WORKING_DIRECTORY Build CMND ${CMAKE_COMMAND} @@ -1377,13 +1388,13 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package # the needed info from Tpl1, Tpl2, and Tpl3 is pulled in from # find_package(Package2). - TEST_7 + TEST_8 MESSAGE "Build and install the rest of TribitsExampleProject2 (Package3)" WORKING_DIRECTORY Build SKIP_CLEAN_WORKING_DIRECTORY CMND ${CMAKE_COMMAND} ARGS --build . --target install - TEST_8 + TEST_9 MESSAGE "Run remaining tests for TribitsExampleProject2 (Package3)" WORKING_DIRECTORY Build SKIP_CLEAN_WORKING_DIRECTORY From 74ad726128d15d4bf4667bafca4ef06e248b6838 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Fri, 1 Sep 2023 15:11:30 -0600 Subject: [PATCH 13/31] Add TribitsSetCacheVarAndDefault.cmake (#582) This addeds the macros: tribits_advanced_set_cache_var_and_default() tribits_set_cache_var_and_default() This will make it easy to refactor code that sets a cache var and its default. --- .../utils/TribitsSetCacheVarAndDefault.cmake | 93 +++++++++++++++++++ .../guides/UtilsMacroFunctionDocTemplate.rst | 2 + 2 files changed, 95 insertions(+) create mode 100644 tribits/core/utils/TribitsSetCacheVarAndDefault.cmake diff --git a/tribits/core/utils/TribitsSetCacheVarAndDefault.cmake b/tribits/core/utils/TribitsSetCacheVarAndDefault.cmake new file mode 100644 index 000000000..920341755 --- /dev/null +++ b/tribits/core/utils/TribitsSetCacheVarAndDefault.cmake @@ -0,0 +1,93 @@ +# @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 + ) + if ("${${cacheVarName}_DEFAULT}" STREQUAL "") + set(${cacheVarName}_DEFAULT "${defaultDefaultVal}") + endif() + set(${cacheVarName} "${${cacheVarName}_DEFAULT}" + CACHE ${cacheVarType} + "${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/tribits/doc/guides/UtilsMacroFunctionDocTemplate.rst b/tribits/doc/guides/UtilsMacroFunctionDocTemplate.rst index acc98214c..79bb6ea0d 100644 --- a/tribits/doc/guides/UtilsMacroFunctionDocTemplate.rst +++ b/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() + From b49a5b028f2179ef0fdf0ed4797dd64112cba5d2 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Mon, 4 Sep 2023 17:08:37 -0600 Subject: [PATCH 14/31] Move _TRACE_ADD_TEST to TribitsAddTestHelpers.cmake This makes it usable in a project that does not use all of TriBITS. --- tribits/core/package_arch/TribitsAddTestHelpers.cmake | 5 +++++ tribits/core/package_arch/TribitsGlobalMacros.cmake | 7 ------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tribits/core/package_arch/TribitsAddTestHelpers.cmake b/tribits/core/package_arch/TribitsAddTestHelpers.cmake index 9815e538b..e88bec60c 100644 --- a/tribits/core/package_arch/TribitsAddTestHelpers.cmake +++ b/tribits/core/package_arch/TribitsAddTestHelpers.cmake @@ -53,6 +53,11 @@ include(MessageWrapper) include(TribitsGetCategoriesString) +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 # # This must be run just before the packages define their tests and this macro diff --git a/tribits/core/package_arch/TribitsGlobalMacros.cmake b/tribits/core/package_arch/TribitsGlobalMacros.cmake index 2a6565d96..f144f39b0 100644 --- a/tribits/core/package_arch/TribitsGlobalMacros.cmake +++ b/tribits/core/package_arch/TribitsGlobalMacros.cmake @@ -464,13 +464,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}" ) From 3f284fd90afcc8fc5f2c3a9493a88cf5e3f23ea5 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 22 Aug 2023 13:27:39 -0600 Subject: [PATCH 15/31] WIP: Add failing test for using TirBITS tests functions in a raw CMake project build (#582) --- .../TribitsExampleProject2_Tests.cmake | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake index b3c9d672f..dac2bf9d5 100644 --- a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake @@ -1125,7 +1125,7 @@ TribitsExampleProject2_External_Package_by_Package(SHARED CMAKE_PREFIX_PATH_CAC function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package - sharedOrStatic findingTplsMethod + sharedOrStatic findingTplsMethod package1UseTribitsTestFunctions ) TribitsExampleProject2_test_setup_header() @@ -1211,6 +1211,21 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package "Error, findingTplsMethod='${findingTplsMethod}' is invalid!") endif() + if (package1UseTribitsTestFunctions STREQUAL "PACKAGE1_USE_TRIBITS_TEST_FUNCTIONS") + set(package1UseTribitsTestFunctionsArgs + "-D Package1_USE_TRIBITS_TEST_FUNCTIONS=TRUE" ) + string(APPEND testNameSuffix "_${package1UseTribitsTestFunctions}" ) + set(package1ConfiRegex + "Using TriBITS Test Functions in a raw CMake Package1 build" ) + elseif (package1UseTribitsTestFunctions STREQUAL "") + set(package1UseTribitsTestFunctionsArgs "") + set(package1ConfiRegex + "Using Raw CMake add_test[(][)] in a raw CMake Package1 build" ) + else() + message(FATAL_ERROR + "Error, package1UseTribitsTestFunctions='${package1UseTribitsTestFunctions}' is invalid!") + endif() + set(testNameBase ${CMAKE_CURRENT_FUNCTION}_${sharedOrStatic}${testNameSuffix}) set(testName ${PACKAGE_NAME}_${testNameBase}) set(testDir "${CMAKE_CURRENT_BINARY_DIR}/${testName}") @@ -1232,12 +1247,14 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package CMND ${CMAKE_COMMAND} ARGS ${TribitsExampleProject2_COMMON_CONFIG_ARGS} + ${package1UseTribitsTestFunctionsArgs} -DPackage1_ENABLE_TESTS=ON -DCMAKE_PREFIX_PATH=${tplInstallBaseDir}/install_tpl1 -DCMAKE_INSTALL_PREFIX=../install_package1 ../TribitsExampleProject2/packages/package1 PASS_REGULAR_EXPRESSION_ALL "Configuring raw CMake project Package1" + "${package1ConfiRegex}" "-- Configuring done" "-- Generating done" ALWAYS_FAIL_ON_NONZERO_RETURN @@ -1417,7 +1434,13 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package endfunction() -TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(STATIC TPL_LIBRARY_AND_INCLUDE_DIRS) -TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(SHARED TPL_LIBRARY_AND_INCLUDE_DIRS) -TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(STATIC CMAKE_PREFIX_PATH_CACHE) -TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(SHARED CMAKE_PREFIX_PATH_CACHE) +TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(STATIC + TPL_LIBRARY_AND_INCLUDE_DIRS "") +TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(SHARED + TPL_LIBRARY_AND_INCLUDE_DIRS "") +TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(STATIC + CMAKE_PREFIX_PATH_CACHE "") +TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(SHARED + CMAKE_PREFIX_PATH_CACHE "") +TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(SHARED + CMAKE_PREFIX_PATH_CACHE PACKAGE1_USE_TRIBITS_TEST_FUNCTIONS) From 286a2755d397dbcf0d7970c0b3f6faddd9049f0f Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Mon, 4 Sep 2023 18:41:40 -0600 Subject: [PATCH 16/31] Get tribits_add_test() to work with raw CMake project (#582) This makes the failing test added in the last commit to pass. This commit updates TriBITS to allow a raw CMake project to just include: include("/core/package_arch/TribitsAddTest.cmake") and then use tribits_add_test() without having to append CMAKE_MODULE_PATH. To make this work, I had to change from: include() to use explicit file include with base dir: include("/.cmake") This also makes the locations of these files more explicit, which I think is good actually. I updated TribitsExampleProject2/Package1 to use tribits_add_test() in a stand-alone raw CMake build. A few other things done: * Removed the include of TribitsGeneralMacros.cmake from TribitsAddTestHelpers.cmake since none of its macros/functions are used any longer. * Shortened 'PACKAGE1_USE_TRIBITS_TEST_FUCNTIONS' to 'PACKAGE1_USE_TRIBITS_TEST_FUNCS' to shorten the test name some. --- .../TribitsExampleProject2_Tests.cmake | 21 ++++++++------ .../TribitsAddExecutableTestHelpers.cmake | 8 ++++-- .../core/package_arch/TribitsAddTest.cmake | 5 ++-- .../package_arch/TribitsAddTestHelpers.cmake | 28 +++++++++---------- .../package_arch/TribitsTestCategories.cmake | 8 +++--- tribits/core/utils/AppendGlobalSet.cmake | 4 +-- .../core/utils/AppendStringVarWithSep.cmake | 2 +- tribits/core/utils/ConcatStrings.cmake | 2 +- tribits/core/utils/MessageWrapper.cmake | 2 +- .../core/utils/TribitsDeprecatedHelpers.cmake | 6 ++-- .../utils/TribitsParseArgumentsHelpers.cmake | 2 +- ...TribitsSortListAccordingToMasterList.cmake | 4 +-- .../packages/package1/CMakeLists.txt | 4 +++ 13 files changed, 55 insertions(+), 41 deletions(-) diff --git a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake index dac2bf9d5..4f445d70b 100644 --- a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake @@ -562,12 +562,14 @@ function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrR endif() if (package1TribitsOrRawCMake STREQUAL "PACKAGE1_USE_RAW_CMAKE") - if (package1UseTribitsTestFunctions STREQUAL "PACKAGE1_USE_TRIBITS_TEST_FUNCTIONS") + if (package1UseTribitsTestFunctions STREQUAL "PACKAGE1_USE_TRIBITS_TEST_FUNCS") list(APPEND package1UseRawCMakeArgs - "-D Package1_USE_TRIBITS_TEST_FUNCTIONS=TRUE" ) + "-D Package1_USE_TRIBITS_TEST_FUNCTIONS=TRUE" + "-D Package1_TRACE_ADD_TEST=TRUE" ) string(APPEND testNameSuffix "_${package1UseTribitsTestFunctions}" ) list(APPEND package1ConfiRegex - "Using TriBITS Test Functions in a raw CMake Package1 build" ) + "Using TriBITS Test Functions in a raw CMake Package1 build" + "Package1_Prg: Added test [(]BASIC, PROCESSORS=1[)]" ) elseif (package1UseTribitsTestFunctions STREQUAL "") list(APPEND package1ConfiRegex "Using Raw CMake add_test[(][)] in a raw CMake Package1 build" ) @@ -710,7 +712,7 @@ TribitsExampleProject2_find_package(SHARED "" "") TribitsExampleProject2_find_package(STATIC PACKAGE1_USE_RAW_CMAKE "") TribitsExampleProject2_find_package(SHARED PACKAGE1_USE_RAW_CMAKE "") TribitsExampleProject2_find_package(SHARED PACKAGE1_USE_RAW_CMAKE - PACKAGE1_USE_TRIBITS_TEST_FUNCTIONS) + PACKAGE1_USE_TRIBITS_TEST_FUNCS) ######################################################################## @@ -1211,12 +1213,15 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package "Error, findingTplsMethod='${findingTplsMethod}' is invalid!") endif() - if (package1UseTribitsTestFunctions STREQUAL "PACKAGE1_USE_TRIBITS_TEST_FUNCTIONS") + if (package1UseTribitsTestFunctions STREQUAL "PACKAGE1_USE_TRIBITS_TEST_FUNCS") set(package1UseTribitsTestFunctionsArgs - "-D Package1_USE_TRIBITS_TEST_FUNCTIONS=TRUE" ) + "-D Package1_USE_TRIBITS_TEST_FUNCTIONS=TRUE" + "-D Package1_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}" + "-D Package1_TRACE_ADD_TEST=TRUE" ) string(APPEND testNameSuffix "_${package1UseTribitsTestFunctions}" ) set(package1ConfiRegex - "Using TriBITS Test Functions in a raw CMake Package1 build" ) + "Using TriBITS Test Functions in a raw CMake Package1 build" + "Package1_Prg: Added test [(]BASIC, PROCESSORS=1[)]" ) elseif (package1UseTribitsTestFunctions STREQUAL "") set(package1UseTribitsTestFunctionsArgs "") set(package1ConfiRegex @@ -1443,4 +1448,4 @@ TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(STATIC TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(SHARED CMAKE_PREFIX_PATH_CACHE "") TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(SHARED - CMAKE_PREFIX_PATH_CACHE PACKAGE1_USE_TRIBITS_TEST_FUNCTIONS) + CMAKE_PREFIX_PATH_CACHE PACKAGE1_USE_TRIBITS_TEST_FUNCS) diff --git a/tribits/core/package_arch/TribitsAddExecutableTestHelpers.cmake b/tribits/core/package_arch/TribitsAddExecutableTestHelpers.cmake index 1c0125ef9..5eb63c945 100644 --- a/tribits/core/package_arch/TribitsAddExecutableTestHelpers.cmake +++ b/tribits/core/package_arch/TribitsAddExecutableTestHelpers.cmake @@ -37,10 +37,12 @@ # ************************************************************************ # @HEADER -include(TribitsCMakePolicies NO_POLICY_SCOPE) +include_guard() -include(AdvancedSet) -include(MessageWrapper) +include("${CMAKE_CURRENT_LIST_DIR}/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 diff --git a/tribits/core/package_arch/TribitsAddTest.cmake b/tribits/core/package_arch/TribitsAddTest.cmake index 6578e8d3a..02e038390 100644 --- a/tribits/core/package_arch/TribitsAddTest.cmake +++ b/tribits/core/package_arch/TribitsAddTest.cmake @@ -37,8 +37,9 @@ # ************************************************************************ # @HEADER -include(TribitsCMakePolicies NO_POLICY_SCOPE) -include(TribitsAddTestHelpers) + +include("${CMAKE_CURRENT_LIST_DIR}/TribitsCMakePolicies.cmake" NO_POLICY_SCOPE) +include("${CMAKE_CURRENT_LIST_DIR}/TribitsAddTestHelpers.cmake") # @FUNCTION: tribits_add_test() diff --git a/tribits/core/package_arch/TribitsAddTestHelpers.cmake b/tribits/core/package_arch/TribitsAddTestHelpers.cmake index e88bec60c..98190718a 100644 --- a/tribits/core/package_arch/TribitsAddTestHelpers.cmake +++ b/tribits/core/package_arch/TribitsAddTestHelpers.cmake @@ -37,20 +37,20 @@ # ************************************************************************ # @HEADER - -include(TribitsAddExecutableTestHelpers) -include(TribitsSetTribitsPackageName) -include(TribitsGeneralMacros) -include(TribitsTestCategories) - -include(CMakeParseArguments) -include(GlobalSet) -include(AppendGlobalSet) -include(AppendStringVarWithSep) -include(PrintVar) -include(AdvancedSet) -include(MessageWrapper) -include(TribitsGetCategoriesString) +include_guard() + +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 diff --git a/tribits/core/package_arch/TribitsTestCategories.cmake b/tribits/core/package_arch/TribitsTestCategories.cmake index acd55cee1..a6f053d63 100644 --- a/tribits/core/package_arch/TribitsTestCategories.cmake +++ b/tribits/core/package_arch/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/tribits/core/utils/AppendGlobalSet.cmake b/tribits/core/utils/AppendGlobalSet.cmake index 51251dc32..04d95f2b5 100644 --- a/tribits/core/utils/AppendGlobalSet.cmake +++ b/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/tribits/core/utils/AppendStringVarWithSep.cmake b/tribits/core/utils/AppendStringVarWithSep.cmake index c671ff582..6e8ccf9fb 100644 --- a/tribits/core/utils/AppendStringVarWithSep.cmake +++ b/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/tribits/core/utils/ConcatStrings.cmake b/tribits/core/utils/ConcatStrings.cmake index a2fdc3c41..cf5fd64e6 100644 --- a/tribits/core/utils/ConcatStrings.cmake +++ b/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/tribits/core/utils/MessageWrapper.cmake b/tribits/core/utils/MessageWrapper.cmake index bdcd9e5e2..220f9c8ff 100644 --- a/tribits/core/utils/MessageWrapper.cmake +++ b/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/tribits/core/utils/TribitsDeprecatedHelpers.cmake b/tribits/core/utils/TribitsDeprecatedHelpers.cmake index 0ae57138e..ee6c7fae2 100644 --- a/tribits/core/utils/TribitsDeprecatedHelpers.cmake +++ b/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/tribits/core/utils/TribitsParseArgumentsHelpers.cmake b/tribits/core/utils/TribitsParseArgumentsHelpers.cmake index 75327668f..9058db674 100644 --- a/tribits/core/utils/TribitsParseArgumentsHelpers.cmake +++ b/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/tribits/core/utils/TribitsSortListAccordingToMasterList.cmake b/tribits/core/utils/TribitsSortListAccordingToMasterList.cmake index d6c8212ef..4b0132702 100644 --- a/tribits/core/utils/TribitsSortListAccordingToMasterList.cmake +++ b/tribits/core/utils/TribitsSortListAccordingToMasterList.cmake @@ -37,8 +37,8 @@ # ************************************************************************ # @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 diff --git a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt index 4bc4f7ae9..42bd12c86 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt +++ b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt @@ -29,6 +29,10 @@ else() add_subdirectory(src) if (Package1_ENABLE_TESTS) include(CTest) + if (Package1_USE_TRIBITS_TEST_FUNCTIONS AND Package1_TRIBITS_DIR) + set(Package1_ENABLE_TESTS ON) + include("${Package1_TRIBITS_DIR}/core/package_arch/TribitsAddTest.cmake") + endif() add_subdirectory(test) endif() From c4b2745881f1e552e20a493eca86a0ead0269507 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 5 Sep 2023 10:14:17 -0600 Subject: [PATCH 17/31] Break out tribits_add_test() modules to core/test_support/ (#368, #582) This breaks some test support related modules for the function tribits_add_test() into their own subdirectory: tribits/core/test_support/ and include them with explicit relative and absolute includes and not relying on CMAKE_MODULE_PATH. (By using explicit includes we can better see and manage the dependencies between modules on these separate subdirs and better partition TriBITS.) To cleanly break out these test_support modules, I created a new subidr: tribits/core/common/ and put the modules TribitsCMakePolicies.cmake and TribitsConstants.cmake into them. And I also did not add this new subdir to CMAKE_MODULE_PATH for the same reason as above for test_support. This allows some non-test-related modules in tribits/core/package_arch/ to depend on tribits/core/common/ but not tribits/core/test_support/. Technically, this commit is the start of the componitization of TriBITS Core as per #368. --- .../core/TestingFunctionMacro_UnitTests.cmake | 5 +- ...ocessExtraRepositoriesList_UnitTests.cmake | 4 +- tribits/README.DIRECTORY_CONTENTS.rst | 53 +++++++++++++++++-- .../ci_support/TribitsDumpDepsXmlScript.cmake | 8 +-- .../TribitsGetExtraReposForCheckinTest.cmake | 3 +- .../TribitsCMakePolicies.cmake | 0 .../TribitsConstants.cmake | 0 .../package_arch/TribitsAddAdvancedTest.cmake | 4 +- .../TribitsAddAdvancedTestHelpers.cmake | 2 +- .../package_arch/TribitsAddExecutable.cmake | 4 +- .../TribitsAddExecutableAndTest.cmake | 3 +- .../TribitsCopyFilesToBinaryDir.cmake | 1 - .../package_arch/TribitsGlobalMacros.cmake | 9 ++-- .../TribitsPackageDependencies.cmake | 3 +- .../package_arch/TribitsPackageMacros.cmake | 3 +- .../TribitsProcessTplsLists.cmake | 2 +- .../core/package_arch/TribitsProject.cmake | 2 +- .../package_arch/TribitsProjectImpl.cmake | 6 ++- ...adAllProjectDepsFilesCreateDepsGraph.cmake | 2 +- .../TribitsAddExecutableTestHelpers.cmake | 2 +- .../TribitsAddTest.cmake | 2 +- .../TribitsAddTestHelpers.cmake | 0 .../TribitsSetTribitsPackageName.cmake | 0 .../TribitsTestCategories.cmake | 0 .../ctest_driver/TribitsCTestDriverCore.cmake | 10 ++-- tribits/doc/guides/generate-guide.sh | 2 +- .../packages/package1/CMakeLists.txt | 2 +- 27 files changed, 96 insertions(+), 36 deletions(-) rename tribits/core/{package_arch => common}/TribitsCMakePolicies.cmake (100%) rename tribits/core/{package_arch => common}/TribitsConstants.cmake (100%) rename tribits/core/{package_arch => test_support}/TribitsAddExecutableTestHelpers.cmake (97%) rename tribits/core/{package_arch => test_support}/TribitsAddTest.cmake (99%) rename tribits/core/{package_arch => test_support}/TribitsAddTestHelpers.cmake (100%) rename tribits/core/{package_arch => test_support}/TribitsSetTribitsPackageName.cmake (100%) rename tribits/core/{package_arch => test_support}/TribitsTestCategories.cmake (100%) diff --git a/test/core/TestingFunctionMacro_UnitTests.cmake b/test/core/TestingFunctionMacro_UnitTests.cmake index 3945430be..50ae35c77 100644 --- a/test/core/TestingFunctionMacro_UnitTests.cmake +++ b/test/core/TestingFunctionMacro_UnitTests.cmake @@ -49,9 +49,10 @@ set( CMAKE_MODULE_PATH set(TRIBITS_ADD_EXECUTABLE_UNIT_TESTING ON) +include("${${PROJECT_NAME}_TRIBITS_DIR}/core/test_support/TribitsTestCategories.cmake") +include("${${PROJECT_NAME}_TRIBITS_DIR}/core/test_support/TribitsAddTest.cmake") + include(MessageWrapper) -include(TribitsTestCategories) -include(TribitsAddTest) include(TribitsAddAdvancedTest) include(TribitsAddExecutableAndTest) include(TribitsETISupport) diff --git a/test/core/TribitsProcessExtraRepositoriesList_UnitTests.cmake b/test/core/TribitsProcessExtraRepositoriesList_UnitTests.cmake index 1644024f9..9109116d2 100644 --- a/test/core/TribitsProcessExtraRepositoriesList_UnitTests.cmake +++ b/test/core/TribitsProcessExtraRepositoriesList_UnitTests.cmake @@ -42,12 +42,14 @@ cmake_minimum_required(VERSION 3.23.0 FATAL_ERROR) message("PROJECT_NAME = ${PROJECT_NAME}") message("${PROJECT_NAME}_TRIBITS_DIR = ${${PROJECT_NAME}_TRIBITS_DIR}") +include("${${PROJECT_NAME}_TRIBITS_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(TribitsProcessExtraRepositoriesList) include(UnitTestHelpers) include(GlobalSet) diff --git a/tribits/README.DIRECTORY_CONTENTS.rst b/tribits/README.DIRECTORY_CONTENTS.rst index 80067d5a8..a0f3d8ab7 100644 --- a/tribits/README.DIRECTORY_CONTENTS.rst +++ b/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/tribits/ci_support/TribitsDumpDepsXmlScript.cmake b/tribits/ci_support/TribitsDumpDepsXmlScript.cmake index f55d03364..2d13260c0 100644 --- a/tribits/ci_support/TribitsDumpDepsXmlScript.cmake +++ b/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/tribits/ci_support/TribitsGetExtraReposForCheckinTest.cmake b/tribits/ci_support/TribitsGetExtraReposForCheckinTest.cmake index d0afd980b..36853a8d9 100644 --- a/tribits/ci_support/TribitsGetExtraReposForCheckinTest.cmake +++ b/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/tribits/core/package_arch/TribitsCMakePolicies.cmake b/tribits/core/common/TribitsCMakePolicies.cmake similarity index 100% rename from tribits/core/package_arch/TribitsCMakePolicies.cmake rename to tribits/core/common/TribitsCMakePolicies.cmake diff --git a/tribits/core/package_arch/TribitsConstants.cmake b/tribits/core/common/TribitsConstants.cmake similarity index 100% rename from tribits/core/package_arch/TribitsConstants.cmake rename to tribits/core/common/TribitsConstants.cmake diff --git a/tribits/core/package_arch/TribitsAddAdvancedTest.cmake b/tribits/core/package_arch/TribitsAddAdvancedTest.cmake index fca20e111..332c35a32 100644 --- a/tribits/core/package_arch/TribitsAddAdvancedTest.cmake +++ b/tribits/core/package_arch/TribitsAddAdvancedTest.cmake @@ -37,10 +37,10 @@ # ************************************************************************ # @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) include(TribitsPrintList) include(AppendStringVar) diff --git a/tribits/core/package_arch/TribitsAddAdvancedTestHelpers.cmake b/tribits/core/package_arch/TribitsAddAdvancedTestHelpers.cmake index 8c2e11df3..bc9ced8c0 100644 --- a/tribits/core/package_arch/TribitsAddAdvancedTestHelpers.cmake +++ b/tribits/core/package_arch/TribitsAddAdvancedTestHelpers.cmake @@ -38,7 +38,7 @@ # @HEADER -include(TribitsAddTestHelpers) +include("${CMAKE_CURRENT_LIST_DIR}/../test_support/TribitsAddTestHelpers.cmake") # Set default ax number of TEST_ blocks in tribits_add_advanced_test() diff --git a/tribits/core/package_arch/TribitsAddExecutable.cmake b/tribits/core/package_arch/TribitsAddExecutable.cmake index ec989628f..567d22f4c 100644 --- a/tribits/core/package_arch/TribitsAddExecutable.cmake +++ b/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/tribits/core/package_arch/TribitsAddExecutableAndTest.cmake b/tribits/core/package_arch/TribitsAddExecutableAndTest.cmake index 73148b8a8..7328f1855 100644 --- a/tribits/core/package_arch/TribitsAddExecutableAndTest.cmake +++ b/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/tribits/core/package_arch/TribitsCopyFilesToBinaryDir.cmake b/tribits/core/package_arch/TribitsCopyFilesToBinaryDir.cmake index f4e1e3bc7..ffeef4bdb 100644 --- a/tribits/core/package_arch/TribitsCopyFilesToBinaryDir.cmake +++ b/tribits/core/package_arch/TribitsCopyFilesToBinaryDir.cmake @@ -38,7 +38,6 @@ # @HEADER -include(TribitsAddTestHelpers) include(CMakeParseArguments) diff --git a/tribits/core/package_arch/TribitsGlobalMacros.cmake b/tribits/core/package_arch/TribitsGlobalMacros.cmake index f144f39b0..63149a375 100644 --- a/tribits/core/package_arch/TribitsGlobalMacros.cmake +++ b/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) diff --git a/tribits/core/package_arch/TribitsPackageDependencies.cmake b/tribits/core/package_arch/TribitsPackageDependencies.cmake index 0f4a956dd..5f2e31595 100644 --- a/tribits/core/package_arch/TribitsPackageDependencies.cmake +++ b/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/tribits/core/package_arch/TribitsPackageMacros.cmake b/tribits/core/package_arch/TribitsPackageMacros.cmake index 0a091c4d2..b7cdc8621 100644 --- a/tribits/core/package_arch/TribitsPackageMacros.cmake +++ b/tribits/core/package_arch/TribitsPackageMacros.cmake @@ -51,12 +51,13 @@ include(PrependGlobalSet) include(RemoveGlobalDuplicates) include(TribitsGatherBuildTargets) +include("${CMAKE_CURRENT_LIST_DIR}/../test_support/TribitsAddTest.cmake") + include(TribitsAddOptionAndDefine) include(TribitsPkgExportCacheVars) include(TribitsLibraryMacros) include(TribitsAddExecutable) include(TribitsAddExecutableAndTest) -include(TribitsAddTest) include(TribitsAddAdvancedTest) include(TribitsCopyFilesToBinaryDir) include(TribitsReportInvalidTribitsUsage) diff --git a/tribits/core/package_arch/TribitsProcessTplsLists.cmake b/tribits/core/package_arch/TribitsProcessTplsLists.cmake index f5e5a6e55..a30a09404 100644 --- a/tribits/core/package_arch/TribitsProcessTplsLists.cmake +++ b/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/tribits/core/package_arch/TribitsProject.cmake b/tribits/core/package_arch/TribitsProject.cmake index 035e089e3..c2385f166 100644 --- a/tribits/core/package_arch/TribitsProject.cmake +++ b/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/tribits/core/package_arch/TribitsProjectImpl.cmake b/tribits/core/package_arch/TribitsProjectImpl.cmake index be62ab071..8eab07d42 100644 --- a/tribits/core/package_arch/TribitsProjectImpl.cmake +++ b/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/tribits/core/package_arch/TribitsReadAllProjectDepsFilesCreateDepsGraph.cmake b/tribits/core/package_arch/TribitsReadAllProjectDepsFilesCreateDepsGraph.cmake index deaa8b5a4..14175ee5a 100644 --- a/tribits/core/package_arch/TribitsReadAllProjectDepsFilesCreateDepsGraph.cmake +++ b/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/tribits/core/package_arch/TribitsAddExecutableTestHelpers.cmake b/tribits/core/test_support/TribitsAddExecutableTestHelpers.cmake similarity index 97% rename from tribits/core/package_arch/TribitsAddExecutableTestHelpers.cmake rename to tribits/core/test_support/TribitsAddExecutableTestHelpers.cmake index 5eb63c945..c2bc95d0d 100644 --- a/tribits/core/package_arch/TribitsAddExecutableTestHelpers.cmake +++ b/tribits/core/test_support/TribitsAddExecutableTestHelpers.cmake @@ -39,7 +39,7 @@ include_guard() -include("${CMAKE_CURRENT_LIST_DIR}/TribitsCMakePolicies.cmake" NO_POLICY_SCOPE) +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") diff --git a/tribits/core/package_arch/TribitsAddTest.cmake b/tribits/core/test_support/TribitsAddTest.cmake similarity index 99% rename from tribits/core/package_arch/TribitsAddTest.cmake rename to tribits/core/test_support/TribitsAddTest.cmake index 02e038390..9e23d71c3 100644 --- a/tribits/core/package_arch/TribitsAddTest.cmake +++ b/tribits/core/test_support/TribitsAddTest.cmake @@ -38,7 +38,7 @@ # @HEADER -include("${CMAKE_CURRENT_LIST_DIR}/TribitsCMakePolicies.cmake" NO_POLICY_SCOPE) +include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsCMakePolicies.cmake" NO_POLICY_SCOPE) include("${CMAKE_CURRENT_LIST_DIR}/TribitsAddTestHelpers.cmake") diff --git a/tribits/core/package_arch/TribitsAddTestHelpers.cmake b/tribits/core/test_support/TribitsAddTestHelpers.cmake similarity index 100% rename from tribits/core/package_arch/TribitsAddTestHelpers.cmake rename to tribits/core/test_support/TribitsAddTestHelpers.cmake diff --git a/tribits/core/package_arch/TribitsSetTribitsPackageName.cmake b/tribits/core/test_support/TribitsSetTribitsPackageName.cmake similarity index 100% rename from tribits/core/package_arch/TribitsSetTribitsPackageName.cmake rename to tribits/core/test_support/TribitsSetTribitsPackageName.cmake diff --git a/tribits/core/package_arch/TribitsTestCategories.cmake b/tribits/core/test_support/TribitsTestCategories.cmake similarity index 100% rename from tribits/core/package_arch/TribitsTestCategories.cmake rename to tribits/core/test_support/TribitsTestCategories.cmake diff --git a/tribits/ctest_driver/TribitsCTestDriverCore.cmake b/tribits/ctest_driver/TribitsCTestDriverCore.cmake index 563f5de65..1666f5755 100644 --- a/tribits/ctest_driver/TribitsCTestDriverCore.cmake +++ b/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/tribits/doc/guides/generate-guide.sh b/tribits/doc/guides/generate-guide.sh index ce7a2c656..e8e4ae07d 100755 --- a/tribits/doc/guides/generate-guide.sh +++ b/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=../../.. \ diff --git a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt index 42bd12c86..92af55238 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt +++ b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt @@ -31,7 +31,7 @@ else() include(CTest) if (Package1_USE_TRIBITS_TEST_FUNCTIONS AND Package1_TRIBITS_DIR) set(Package1_ENABLE_TESTS ON) - include("${Package1_TRIBITS_DIR}/core/package_arch/TribitsAddTest.cmake") + include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddTest.cmake") endif() add_subdirectory(test) endif() From 1f69bbbc05d539218413a6a319aacf997695b824 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 5 Sep 2023 13:36:13 -0600 Subject: [PATCH 18/31] Rename 'Package_by_Package' to 'PBP' (#582) This shortens the names of tests. I have used the acronym 'PBP' in ctest_driver tests already. --- .../TribitsExampleProject2_Tests.cmake | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake index 4f445d70b..55ba523ae 100644 --- a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake @@ -829,7 +829,7 @@ endif() ################################################################################ -function(TribitsExampleProject2_External_Package_by_Package +function(TribitsExampleProject2_External_PBP sharedOrStatic findingTplsMethod ) @@ -1114,10 +1114,10 @@ function(TribitsExampleProject2_External_Package_by_Package endfunction() -TribitsExampleProject2_External_Package_by_Package(STATIC TPL_LIBRARY_AND_INCLUDE_DIRS) -TribitsExampleProject2_External_Package_by_Package(SHARED TPL_LIBRARY_AND_INCLUDE_DIRS) -TribitsExampleProject2_External_Package_by_Package(STATIC CMAKE_PREFIX_PATH_CACHE) -TribitsExampleProject2_External_Package_by_Package(SHARED CMAKE_PREFIX_PATH_CACHE) +TribitsExampleProject2_External_PBP(STATIC TPL_LIBRARY_AND_INCLUDE_DIRS) +TribitsExampleProject2_External_PBP(SHARED TPL_LIBRARY_AND_INCLUDE_DIRS) +TribitsExampleProject2_External_PBP(STATIC CMAKE_PREFIX_PATH_CACHE) +TribitsExampleProject2_External_PBP(SHARED CMAKE_PREFIX_PATH_CACHE) # NOTE: The above tests check a few different use cases for building and # installing TriBITS packages from a single TriBITS project incrementally. @@ -1126,7 +1126,7 @@ TribitsExampleProject2_External_Package_by_Package(SHARED CMAKE_PREFIX_PATH_CAC ################################################################################ -function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package +function(TribitsExampleProject2_External_RawPackage1_PBP sharedOrStatic findingTplsMethod package1UseTribitsTestFunctions ) @@ -1439,13 +1439,13 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package endfunction() -TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(STATIC +TribitsExampleProject2_External_RawPackage1_PBP(STATIC TPL_LIBRARY_AND_INCLUDE_DIRS "") -TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(SHARED +TribitsExampleProject2_External_RawPackage1_PBP(SHARED TPL_LIBRARY_AND_INCLUDE_DIRS "") -TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(STATIC +TribitsExampleProject2_External_RawPackage1_PBP(STATIC CMAKE_PREFIX_PATH_CACHE "") -TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(SHARED +TribitsExampleProject2_External_RawPackage1_PBP(SHARED CMAKE_PREFIX_PATH_CACHE "") -TribitsExampleProject2_External_RawPackage1_then_Package_by_Package(SHARED +TribitsExampleProject2_External_RawPackage1_PBP(SHARED CMAKE_PREFIX_PATH_CACHE PACKAGE1_USE_TRIBITS_TEST_FUNCS) From 7332f9b07fb809247bbba0f46050e2d3224cf1d3 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 5 Sep 2023 19:07:58 -0600 Subject: [PATCH 19/31] Get tribits_add_advanced_test() to work from non-CMake projects (#368, #582) Changes to TriBITS: * Changed explicit includes from TribitsAddAdvancedTest.cmake (this module and its included modules will be moved to tribits/core/test_support/ in next commit). * Remove option to prefix test base name in tribits_add_advanced_test() by '${PROJECT_NAME}_' (since tribits_set_tribits_package_name() is now being called to set PACKAGE_NAME give PROJECT_NAME). * Changed tribits_add_advanced_test() to set explicit include of DriveAdvancedTest.cmake without setting CMAKE_MODULE_PATH. * Use more explicit includes in tribits/core/utils/*.cmake mdoules needed to get above to work. Changes to TribitsExampleProject2/Packages1: * Updated package1-prg to accept command-line arguments that are echoed to STDOUT. * Added new test Package1_Prg-advanced taking in command-line arguments using tribits_add_advanced_test() and in raw CMake build. Changes to tests: * Removed regex for CMAKE_MODULE_PATH from driver file for tribits_add_advanced_test() (which reduces the total number of checks by 1). --- test/core/CMakeLists.txt | 2 +- .../TribitsExampleProject2_Tests.cmake | 25 ++++++++++++------- .../core/TestingFunctionMacro_UnitTests.cmake | 5 ++-- .../package_arch/TribitsAddAdvancedTest.cmake | 25 +++++++++---------- tribits/core/utils/AppendStringVar.cmake | 8 +++--- tribits/core/utils/DriveAdvancedTest.cmake | 12 +++++---- tribits/core/utils/TimingUtils.cmake | 2 +- .../packages/package1/CMakeLists.txt | 1 + .../packages/package1/src/Package1_Prg.cpp | 6 ++++- .../package1/test/CMakeLists.raw.cmake | 10 ++++++++ .../package1/test/CMakeLists.tribits.cmake | 13 ++++++++++ 11 files changed, 73 insertions(+), 36 deletions(-) diff --git a/test/core/CMakeLists.txt b/test/core/CMakeLists.txt index 16506d4fc..6460753c8 100644 --- a/test/core/CMakeLists.txt +++ b/test/core/CMakeLists.txt @@ -49,7 +49,7 @@ tribits_add_advanced_test( TestingFunctionMacro_UnitTests -D${PROJECT_NAME}_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR} -P "${CMAKE_CURRENT_SOURCE_DIR}/TestingFunctionMacro_UnitTests.cmake" PASS_REGULAR_EXPRESSION_ALL - "Final UnitTests Result: num_run = 721" + "Final UnitTests Result: num_run = 720" "Final UnitTests Result: PASSED" ) diff --git a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake index 55ba523ae..652c2c5f5 100644 --- a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake @@ -250,9 +250,10 @@ function(TribitsExampleProject2_find_tpl_parts sharedOrStatic findingTplsMetho CMND ${CMAKE_CTEST_COMMAND} ARGS -VV PASS_REGULAR_EXPRESSION_ALL "Test.*Package1_Prg.*Passed" + "Test.*Package1_Prg-advanced.*Passed" "Test.*Package2_Prg.*Passed" "Test.*Package3_Prg.*Passed" - "100% tests passed, 0 tests failed out of 3" + "100% tests passed, 0 tests failed out of 4" ALWAYS_FAIL_ON_NONZERO_RETURN TEST_5 @@ -393,9 +394,10 @@ function(TribitsExampleProject2_find_tpl_parts_no_optional_packages_tpls shared CMND ${CMAKE_CTEST_COMMAND} ARGS -VV PASS_REGULAR_EXPRESSION_ALL "Test.*Package1_Prg.*Passed" + "Test.*Package1_Prg-advanced.*Passed" "Test.*Package2_Prg.*Passed" "Test.*Package3_Prg.*Passed" - "100% tests passed, 0 tests failed out of 3" + "100% tests passed, 0 tests failed out of 4" ALWAYS_FAIL_ON_NONZERO_RETURN TEST_4 @@ -496,9 +498,10 @@ function(TribitsExampleProject2_explicit_tpl_vars sharedOrStatic) CMND ${CMAKE_CTEST_COMMAND} ARGS -VV PASS_REGULAR_EXPRESSION_ALL "Test.*Package1_Prg.*Passed" + "Test.*Package1_Prg-advanced.*Passed" "Test.*Package2_Prg.*Passed" "Test.*Package3_Prg.*Passed" - "100% tests passed, 0 tests failed out of 3" + "100% tests passed, 0 tests failed out of 4" ALWAYS_FAIL_ON_NONZERO_RETURN TEST_3 @@ -569,7 +572,8 @@ function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrR string(APPEND testNameSuffix "_${package1UseTribitsTestFunctions}" ) list(APPEND package1ConfiRegex "Using TriBITS Test Functions in a raw CMake Package1 build" - "Package1_Prg: Added test [(]BASIC, PROCESSORS=1[)]" ) + "Package1_Prg: Added test [(]BASIC, PROCESSORS=1[)]" + "Package1_Prg-advanced: Added test [(]BASIC, PROCESSORS=1[)]" ) elseif (package1UseTribitsTestFunctions STREQUAL "") list(APPEND package1ConfiRegex "Using Raw CMake add_test[(][)] in a raw CMake Package1 build" ) @@ -654,9 +658,10 @@ function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrR CMND ${CMAKE_CTEST_COMMAND} ARGS -VV PASS_REGULAR_EXPRESSION_ALL "Test.*Package1_Prg.*Passed" + "Test.*Package1_Prg-advanced.*Passed" "Test.*Package2_Prg.*Passed" "Test.*Package3_Prg.*Passed" - "100% tests passed, 0 tests failed out of 3" + "100% tests passed, 0 tests failed out of 4" ALWAYS_FAIL_ON_NONZERO_RETURN TEST_4 @@ -1221,7 +1226,8 @@ function(TribitsExampleProject2_External_RawPackage1_PBP string(APPEND testNameSuffix "_${package1UseTribitsTestFunctions}" ) set(package1ConfiRegex "Using TriBITS Test Functions in a raw CMake Package1 build" - "Package1_Prg: Added test [(]BASIC, PROCESSORS=1[)]" ) + "Package1_Prg: Added test [(]BASIC, PROCESSORS=1[)]" + "Package1_Prg-advanced: Added test [(]BASIC, PROCESSORS=1[)]" ) elseif (package1UseTribitsTestFunctions STREQUAL "") set(package1UseTribitsTestFunctionsArgs "") set(package1ConfiRegex @@ -1278,8 +1284,9 @@ function(TribitsExampleProject2_External_RawPackage1_PBP SKIP_CLEAN_WORKING_DIRECTORY CMND ${CMAKE_CTEST_COMMAND} PASS_REGULAR_EXPRESSION_ALL - "1/1 Test [#]1: Package1_Prg [.]* *Passed" - "100% tests passed, 0 tests failed out of 1" + "Test.*Package1_Prg [.]* *Passed" + "Test.*Package1_Prg-advanced [.]* *Passed" + "100% tests passed, 0 tests failed out of 2" ALWAYS_FAIL_ON_NONZERO_RETURN TEST_4 @@ -1422,7 +1429,7 @@ function(TribitsExampleProject2_External_RawPackage1_PBP SKIP_CLEAN_WORKING_DIRECTORY CMND ${CMAKE_CTEST_COMMAND} PASS_REGULAR_EXPRESSION_ALL - "Package3_Prg [.]+ *Passed" + "Test.*Package3_Prg [.]+ *Passed" "100% tests passed, 0 tests failed out of 1" ALWAYS_FAIL_ON_NONZERO_RETURN diff --git a/test/core/TestingFunctionMacro_UnitTests.cmake b/test/core/TestingFunctionMacro_UnitTests.cmake index 50ae35c77..f8a672572 100644 --- a/test/core/TestingFunctionMacro_UnitTests.cmake +++ b/test/core/TestingFunctionMacro_UnitTests.cmake @@ -2567,11 +2567,10 @@ function(unittest_tribits_add_advanced_test_basic) "NUM_CMNDS 1" "set[(]OVERALL_WORKING_DIRECTORY .PackageA_TAAT_basic_cmnd_1_args_2.[)]" "set[(]SKIP_CLEAN_OVERALL_WORKING_DIRECTORY .TRUE.[)]" - "CMAKE_MODULE_PATH" "set[(]SHOW_START_END_DATE_TIME OFF[)]" "set[(] TEST_0_WORKING_DIRECTORY .someSubdir. [)]" "set[(] TEST_0_SKIP_CLEAN_WORKING_DIRECTORY TRUE [)]" - "DriveAdvancedTest" + "tribits/core/utils/DriveAdvancedTest" "drive_advanced_test" ) @@ -4845,4 +4844,4 @@ message("*** Determine final result of all unit tests") message("***\n") # Pass in the number of expected tests that must pass! -unittest_final_result(721) +unittest_final_result(720) diff --git a/tribits/core/package_arch/TribitsAddAdvancedTest.cmake b/tribits/core/package_arch/TribitsAddAdvancedTest.cmake index 332c35a32..657f11be7 100644 --- a/tribits/core/package_arch/TribitsAddAdvancedTest.cmake +++ b/tribits/core/package_arch/TribitsAddAdvancedTest.cmake @@ -40,11 +40,13 @@ include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsCMakePolicies.cmake" NO_POLICY_SCOPE) include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsConstants.cmake") -include(TribitsAddAdvancedTestHelpers) +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() @@ -886,16 +888,13 @@ function(tribits_add_advanced_test TEST_NAME_IN) 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 +1517,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 +1549,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/tribits/core/utils/AppendStringVar.cmake b/tribits/core/utils/AppendStringVar.cmake index dbd0c1fb5..bac3a6bac 100644 --- a/tribits/core/utils/AppendStringVar.cmake +++ b/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/tribits/core/utils/DriveAdvancedTest.cmake b/tribits/core/utils/DriveAdvancedTest.cmake index 87a4a8230..6ccb55fd7 100644 --- a/tribits/core/utils/DriveAdvancedTest.cmake +++ b/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/tribits/core/utils/TimingUtils.cmake b/tribits/core/utils/TimingUtils.cmake index a83445663..ac6351ab9 100644 --- a/tribits/core/utils/TimingUtils.cmake +++ b/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/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt index 92af55238..fab23c956 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt +++ b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt @@ -32,6 +32,7 @@ else() if (Package1_USE_TRIBITS_TEST_FUNCTIONS AND Package1_TRIBITS_DIR) set(Package1_ENABLE_TESTS ON) include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddTest.cmake") + include("${Package1_TRIBITS_DIR}/core/package_arch/TribitsAddAdvancedTest.cmake") endif() add_subdirectory(test) endif() diff --git a/tribits/examples/TribitsExampleProject2/packages/package1/src/Package1_Prg.cpp b/tribits/examples/TribitsExampleProject2/packages/package1/src/Package1_Prg.cpp index 2ce91f102..33d4dc0ce 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/src/Package1_Prg.cpp +++ b/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/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.raw.cmake b/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.raw.cmake index 6e4cf3a0f..28389ece3 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.raw.cmake +++ b/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.raw.cmake @@ -1,3 +1,13 @@ 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. 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.) diff --git a/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake b/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake index bc79820e3..07708b719 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake +++ b/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake @@ -1,3 +1,16 @@ 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 + OVERALL_WORKING_DIRECTORY TEST_NAME + OVERALL_NUM_MPI_PROCS 1 + 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 + ) From 9a098732e9e3e1797e50f7885b36e5f36a0cd7ea Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Wed, 6 Sep 2023 11:15:36 -0600 Subject: [PATCH 20/31] Move TribitsAddAdvancedTest[Helper].cmake to core/test_support/ (#368, #582) --- .../TAATDriver/CommonTAATDriverBoilerPlate.cmake | 4 +--- test/core/TestingFunctionMacro_UnitTests.cmake | 2 +- tribits/core/package_arch/TribitsPackageMacros.cmake | 2 +- .../TribitsAddAdvancedTest.cmake | 0 .../TribitsAddAdvancedTestHelpers.cmake | 2 +- .../TribitsExampleProject2/packages/package1/CMakeLists.txt | 2 +- 6 files changed, 5 insertions(+), 7 deletions(-) rename tribits/core/{package_arch => test_support}/TribitsAddAdvancedTest.cmake (100%) rename tribits/core/{package_arch => test_support}/TribitsAddAdvancedTestHelpers.cmake (98%) diff --git a/test/core/CTestScriptsUnitTests/TAATDriver/CommonTAATDriverBoilerPlate.cmake b/test/core/CTestScriptsUnitTests/TAATDriver/CommonTAATDriverBoilerPlate.cmake index a04becc92..9018eada8 100644 --- a/test/core/CTestScriptsUnitTests/TAATDriver/CommonTAATDriverBoilerPlate.cmake +++ b/test/core/CTestScriptsUnitTests/TAATDriver/CommonTAATDriverBoilerPlate.cmake @@ -4,9 +4,7 @@ set(${PROJECT_NAME}_TRACE_ADD_TEST TRUE) set(${PROJECT_NAME}_TRIBITS_DIR ${TRIBITS_DIR}) 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 ) +list(PREPEND CMAKE_MODULE_PATH ${TRIBITS_DIR}/core/test_support) include(TribitsAddAdvancedTest) include(CTest) enable_testing() diff --git a/test/core/TestingFunctionMacro_UnitTests.cmake b/test/core/TestingFunctionMacro_UnitTests.cmake index f8a672572..05b8df98c 100644 --- a/test/core/TestingFunctionMacro_UnitTests.cmake +++ b/test/core/TestingFunctionMacro_UnitTests.cmake @@ -51,9 +51,9 @@ set(TRIBITS_ADD_EXECUTABLE_UNIT_TESTING ON) include("${${PROJECT_NAME}_TRIBITS_DIR}/core/test_support/TribitsTestCategories.cmake") include("${${PROJECT_NAME}_TRIBITS_DIR}/core/test_support/TribitsAddTest.cmake") +include("${${PROJECT_NAME}_TRIBITS_DIR}/core/test_support/TribitsAddAdvancedTest.cmake") include(MessageWrapper) -include(TribitsAddAdvancedTest) include(TribitsAddExecutableAndTest) include(TribitsETISupport) include(TribitsFindPythonInterp) diff --git a/tribits/core/package_arch/TribitsPackageMacros.cmake b/tribits/core/package_arch/TribitsPackageMacros.cmake index b7cdc8621..d7931c406 100644 --- a/tribits/core/package_arch/TribitsPackageMacros.cmake +++ b/tribits/core/package_arch/TribitsPackageMacros.cmake @@ -52,13 +52,13 @@ 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(TribitsAddAdvancedTest) include(TribitsCopyFilesToBinaryDir) include(TribitsReportInvalidTribitsUsage) diff --git a/tribits/core/package_arch/TribitsAddAdvancedTest.cmake b/tribits/core/test_support/TribitsAddAdvancedTest.cmake similarity index 100% rename from tribits/core/package_arch/TribitsAddAdvancedTest.cmake rename to tribits/core/test_support/TribitsAddAdvancedTest.cmake diff --git a/tribits/core/package_arch/TribitsAddAdvancedTestHelpers.cmake b/tribits/core/test_support/TribitsAddAdvancedTestHelpers.cmake similarity index 98% rename from tribits/core/package_arch/TribitsAddAdvancedTestHelpers.cmake rename to tribits/core/test_support/TribitsAddAdvancedTestHelpers.cmake index bc9ced8c0..c7fb556b4 100644 --- a/tribits/core/package_arch/TribitsAddAdvancedTestHelpers.cmake +++ b/tribits/core/test_support/TribitsAddAdvancedTestHelpers.cmake @@ -38,7 +38,7 @@ # @HEADER -include("${CMAKE_CURRENT_LIST_DIR}/../test_support/TribitsAddTestHelpers.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/TribitsAddTestHelpers.cmake") # Set default ax number of TEST_ blocks in tribits_add_advanced_test() diff --git a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt index fab23c956..446305dd4 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt +++ b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt @@ -32,7 +32,7 @@ else() if (Package1_USE_TRIBITS_TEST_FUNCTIONS AND Package1_TRIBITS_DIR) set(Package1_ENABLE_TESTS ON) include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddTest.cmake") - include("${Package1_TRIBITS_DIR}/core/package_arch/TribitsAddAdvancedTest.cmake") + include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddAdvancedTest.cmake") endif() add_subdirectory(test) endif() From fcd82bb11901f4e0eeb46fcbf07e5010a12157e9 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Wed, 6 Sep 2023 11:42:33 -0600 Subject: [PATCH 21/31] tribits_add_advanced_test(): Update section on using in non-TriBITS project (#368, #582) --- .../test_support/TribitsAddAdvancedTest.cmake | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/tribits/core/test_support/TribitsAddAdvancedTest.cmake b/tribits/core/test_support/TribitsAddAdvancedTest.cmake index 657f11be7..21deffdea 100644 --- a/tribits/core/test_support/TribitsAddAdvancedTest.cmake +++ b/tribits/core/test_support/TribitsAddAdvancedTest.cmake @@ -855,10 +855,9 @@ include("${CMAKE_CURRENT_LIST_DIR}/../utils/PrintVar.cmake") # # 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) @@ -868,20 +867,27 @@ include("${CMAKE_CURRENT_LIST_DIR}/../utils/PrintVar.cmake") # "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) From 950e528b2b1a4a49c22c0c5bd0053a1714b96c5c Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Wed, 6 Sep 2023 17:08:28 -0600 Subject: [PATCH 22/31] Break out clean CMakeLists.[raw|tribits].cmake files (#582) This makes it easier to compare the TriBITS build system for a package with a raw CMake build system that is TriBITS-compliant. --- .../packages/package1/CMakeLists.raw.cmake | 61 +++++++++++++++ .../package1/CMakeLists.tribits.cmake | 5 ++ .../packages/package1/CMakeLists.txt | 76 ++----------------- .../package1/src/CMakeLists.tribits.cmake | 4 + .../packages/package1/src/CMakeLists.txt | 9 +-- .../package1/test/CMakeLists.raw.cmake | 14 +++- .../package1/test/CMakeLists.tribits.cmake | 2 - 7 files changed, 88 insertions(+), 83 deletions(-) create mode 100644 tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake create mode 100644 tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.tribits.cmake create mode 100644 tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.tribits.cmake diff --git a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake new file mode 100644 index 000000000..7d4f92513 --- /dev/null +++ b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake @@ -0,0 +1,61 @@ +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) + if (Package1_USE_TRIBITS_TEST_FUNCTIONS AND Package1_TRIBITS_DIR) + set(Package1_ENABLE_TESTS ON) + include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddTest.cmake") + include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddAdvancedTest.cmake") + endif() + add_subdirectory(test) +endif() + +# 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) + +# 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_SOURCE_DIR}/cmake/raw/Package1Config.cmake.in" + "${packageBuildDirCMakePackagesDir}/${PROJECT_NAME}/Package1Config.cmake" + @ONLY ) + +# 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/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.tribits.cmake b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.tribits.cmake new file mode 100644 index 000000000..2c2fc1f8a --- /dev/null +++ b/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/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt index 446305dd4..b0eaea3da 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt +++ b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt @@ -1,77 +1,15 @@ cmake_minimum_required(VERSION 3.23.0 FATAL_ERROR) -macro(include_raw_cmake_build) +# 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() - endif() -endmacro() - -if ((COMMAND tribits_package) AND (NOT Package1_USE_RAW_CMAKE)) - - message("Configuring package Package1 as full TriBITS package") - tribits_package(Package1) - add_subdirectory(src) - tribits_add_test_directories(test) - tribits_package_postprocess() - -else() - - if (COMMAND tribits_package) - message("Configuring raw CMake package Package1") else() - message("Configuring raw CMake project Package1") - endif() - project(Package1 LANGUAGES C CXX) - include(GNUInstallDirs) - find_package(Tpl1 CONFIG REQUIRED) - add_subdirectory(src) - if (Package1_ENABLE_TESTS) - include(CTest) - if (Package1_USE_TRIBITS_TEST_FUNCTIONS AND Package1_TRIBITS_DIR) - set(Package1_ENABLE_TESTS ON) - include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddTest.cmake") - include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddAdvancedTest.cmake") - endif() - add_subdirectory(test) + include("${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.tribits.cmake" + NO_POLICY_SCOPE) endif() +endmacro() - # 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) - - # Generate Package1Config.cmake file for the build tree - 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_SOURCE_DIR}/cmake/raw/Package1Config.cmake.in" - "${packageBuildDirCMakePackagesDir}/${PROJECT_NAME}/Package1Config.cmake" - @ONLY ) - - # Generate and install the Package1Config.cmake file for the install tree - 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}" ) - -endif() +# Pull in the base CMakeLists.txt file variant +include_cmakelists_file() diff --git a/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.tribits.cmake b/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.tribits.cmake new file mode 100644 index 000000000..8e69c53a5 --- /dev/null +++ b/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/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.txt b/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.txt index 59e7a3b5b..870958046 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.txt +++ b/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/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.raw.cmake b/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.raw.cmake index 28389ece3..fef322152 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.raw.cmake +++ b/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.raw.cmake @@ -7,7 +7,13 @@ 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. 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.) +# 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/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake b/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake index 07708b719..48d1f6e19 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake +++ b/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake @@ -3,8 +3,6 @@ tribits_add_test(package1-prg NOEXEPREFIX NOEXESUFFIX PASS_REGULAR_EXPRESSION "Package1 Deps: tpl1" ) tribits_add_advanced_test(Prg-advanced - OVERALL_WORKING_DIRECTORY TEST_NAME - OVERALL_NUM_MPI_PROCS 1 TEST_0 EXEC package1-prg DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../src" NOEXEPREFIX NOEXESUFFIX From 32f8247502fe8169b869f60d920cbffb848885d3 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Wed, 6 Sep 2023 18:51:12 -0600 Subject: [PATCH 23/31] Add conditional for generating Config.cmake for build dir (#582) Makes it more clear what is needed for an internal package and an external package. --- .../packages/package1/CMakeLists.raw.cmake | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake index 7d4f92513..9c43d0b13 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake +++ b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake @@ -32,17 +32,19 @@ install(TARGETS Package1_all_libs INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) add_library(Package1::all_libs ALIAS Package1_all_libs) -# 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_SOURCE_DIR}/cmake/raw/Package1Config.cmake.in" - "${packageBuildDirCMakePackagesDir}/${PROJECT_NAME}/Package1Config.cmake" - @ONLY ) +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_SOURCE_DIR}/cmake/raw/Package1Config.cmake.in" + "${packageBuildDirCMakePackagesDir}/${PROJECT_NAME}/Package1Config.cmake" + @ONLY ) +endif() # Generate and install the Package1Config.cmake file for the install tree # (needed for both internal and external TriBITS package) From 8f66678f99fa9e326eb2042dd99627cb549a50d8 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Fri, 8 Sep 2023 09:29:41 -0600 Subject: [PATCH 24/31] Factor longer parts out of base CMakeLists.raw.cmake to streamline (#582) This will allow me to exclude parts that I don't want to show in the developers guide. NOTE: The only reas the test file TribitsExampleProject2_Tests.cmake is updated is because I took 'a' out of 'in a raw'. --- .../TribitsExampleProject2_Tests.cmake | 8 +-- .../packages/package1/CMakeLists.raw.cmake | 50 ++----------------- .../packages/package1/CMakeLists.txt | 3 ++ .../cmake/raw/DefineAllLibsTarget.cmake | 11 ++++ .../cmake/raw/EnableTribitsTestSupport.cmake | 10 ++++ ...GeneratePackageConfigFileForBuildDir.cmake | 13 +++++ ...neratePackageConfigFileForInstallDir.cmake | 15 ++++++ .../packages/package1/test/CMakeLists.txt | 8 +-- 8 files changed, 65 insertions(+), 53 deletions(-) create mode 100644 tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/DefineAllLibsTarget.cmake create mode 100644 tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/EnableTribitsTestSupport.cmake create mode 100644 tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/GeneratePackageConfigFileForBuildDir.cmake create mode 100644 tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/GeneratePackageConfigFileForInstallDir.cmake diff --git a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake index 652c2c5f5..4f485a1cb 100644 --- a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake @@ -571,12 +571,12 @@ function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrR "-D Package1_TRACE_ADD_TEST=TRUE" ) string(APPEND testNameSuffix "_${package1UseTribitsTestFunctions}" ) list(APPEND package1ConfiRegex - "Using TriBITS Test Functions in a raw CMake Package1 build" + "Using TriBITS Test Functions in raw CMake Package1 build" "Package1_Prg: Added test [(]BASIC, PROCESSORS=1[)]" "Package1_Prg-advanced: Added test [(]BASIC, PROCESSORS=1[)]" ) elseif (package1UseTribitsTestFunctions STREQUAL "") list(APPEND package1ConfiRegex - "Using Raw CMake add_test[(][)] in a raw CMake Package1 build" ) + "Using Raw CMake add_test[(][)] in raw CMake Package1 build" ) else() message(FATAL_ERROR "Error, package1UseTribitsTestFunctions='${package1UseTribitsTestFunctions}' is invalid!") @@ -1225,13 +1225,13 @@ function(TribitsExampleProject2_External_RawPackage1_PBP "-D Package1_TRACE_ADD_TEST=TRUE" ) string(APPEND testNameSuffix "_${package1UseTribitsTestFunctions}" ) set(package1ConfiRegex - "Using TriBITS Test Functions in a raw CMake Package1 build" + "Using TriBITS Test Functions in raw CMake Package1 build" "Package1_Prg: Added test [(]BASIC, PROCESSORS=1[)]" "Package1_Prg-advanced: Added test [(]BASIC, PROCESSORS=1[)]" ) elseif (package1UseTribitsTestFunctions STREQUAL "") set(package1UseTribitsTestFunctionsArgs "") set(package1ConfiRegex - "Using Raw CMake add_test[(][)] in a raw CMake Package1 build" ) + "Using Raw CMake add_test[(][)] in raw CMake Package1 build" ) else() message(FATAL_ERROR "Error, package1UseTribitsTestFunctions='${package1UseTribitsTestFunctions}' is invalid!") diff --git a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake index 9c43d0b13..ad2a18182 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake +++ b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake @@ -13,51 +13,11 @@ find_package(Tpl1 CONFIG REQUIRED) add_subdirectory(src) if (Package1_ENABLE_TESTS) include(CTest) - if (Package1_USE_TRIBITS_TEST_FUNCTIONS AND Package1_TRIBITS_DIR) - set(Package1_ENABLE_TESTS ON) - include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddTest.cmake") - include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddAdvancedTest.cmake") - endif() + include("${CMAKE_CURRENT_LIST_DIR}/cmake/raw/EnableTribitsTestSupport.cmake") add_subdirectory(test) endif() -# 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) - -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_SOURCE_DIR}/cmake/raw/Package1Config.cmake.in" - "${packageBuildDirCMakePackagesDir}/${PROJECT_NAME}/Package1Config.cmake" - @ONLY ) -endif() - -# 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}" ) +# 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/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt index b0eaea3da..c8511aab3 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt +++ b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required(VERSION 3.23.0 FATAL_ERROR) +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) diff --git a/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/DefineAllLibsTarget.cmake b/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/DefineAllLibsTarget.cmake new file mode 100644 index 000000000..902b1cdf1 --- /dev/null +++ b/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/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/EnableTribitsTestSupport.cmake b/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/EnableTribitsTestSupport.cmake new file mode 100644 index 000000000..c4449e543 --- /dev/null +++ b/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/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/GeneratePackageConfigFileForBuildDir.cmake b/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/GeneratePackageConfigFileForBuildDir.cmake new file mode 100644 index 000000000..9f937dcda --- /dev/null +++ b/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/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/GeneratePackageConfigFileForInstallDir.cmake b/tribits/examples/TribitsExampleProject2/packages/package1/cmake/raw/GeneratePackageConfigFileForInstallDir.cmake new file mode 100644 index 000000000..535685e61 --- /dev/null +++ b/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/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.txt b/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.txt index 922e735d1..11b72aec0 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.txt +++ b/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.txt @@ -1,9 +1,9 @@ -if ((NOT COMMAND tribits_project) OR Package1_USE_RAW_CMAKE) - if (Package1_USE_TRIBITS_TEST_FUNCTIONS) - message("-- Using TriBITS Test Functions in a raw CMake Package1 build!") +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 a raw CMake Package1 build!") + message("-- Using Raw CMake add_test() in raw CMake Package1 build!") include("${CMAKE_CURRENT_LIST_DIR}/CMakeLists.raw.cmake") endif() else() From 762db6e2a0547fcb05ff948a84603e687c5be0d1 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Thu, 14 Sep 2023 07:09:04 -0600 Subject: [PATCH 25/31] Add NAME and COMMAND to add_test() command in build ref doc (#582) This change was made several years ago but we forgot to update this documentation. --- tribits/doc/build_ref/TribitsBuildReferenceBody.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tribits/doc/build_ref/TribitsBuildReferenceBody.rst b/tribits/doc/build_ref/TribitsBuildReferenceBody.rst index 74908d9d2..06600479e 100644 --- a/tribits/doc/build_ref/TribitsBuildReferenceBody.rst +++ b/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} From 967b32e6f8487b2aa4d9937a9938196534b69ef1 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Thu, 14 Sep 2023 07:34:37 -0600 Subject: [PATCH 26/31] Add HowTos for TriBITS-compliant raw CMake packages (#582) Several things were done here: * Added new section "How to implement a TriBITS-compliant internal package using raw CMake" * Added new section "How to implement a TriBITS-compliant external package using raw CMake" * Added subsection on example project TribitsExampleProject2 under the "Example TriBITS Projects" section. * Added generation of reduced versions of the package1/CMakeLists.raw.cmake file for different cases. (But will only trigger a re-make if the generated files change.) * Added make dependencies on generated *.cmake files * generate-guide.sh: Added time to 'make' command and discard STDOUT for 'cd -' command (makes output look better) --- tribits/doc/guides/.gitignore | 2 + .../guides/Makefile.common_generated_files | 1 + tribits/doc/guides/TribitsGuidesBody.rst | 180 ++++++++++++++++++ tribits/doc/guides/generate-guide.sh | 19 +- 4 files changed, 200 insertions(+), 2 deletions(-) diff --git a/tribits/doc/guides/.gitignore b/tribits/doc/guides/.gitignore index 7f018678f..266b34812 100644 --- a/tribits/doc/guides/.gitignore +++ b/tribits/doc/guides/.gitignore @@ -4,6 +4,8 @@ /TriBITS.README.DIRECTORY_CONTENTS.rst.tmp /TribitsCommonTPLsList.txt /TribitsCommonTPLsList.txt.tmp +/TribitsExampleProject2_Package1_CMakeLists.raw.external.cmake* +/TribitsExampleProject2_Package1_CMakeLists.raw.internal.cmake* /TribitsGitVersion.txt /TribitsGitVersion.txt.tmp /TribitsHelloWorldDirAndFiles.txt diff --git a/tribits/doc/guides/Makefile.common_generated_files b/tribits/doc/guides/Makefile.common_generated_files index c6a352d12..6984ee3c6 100644 --- a/tribits/doc/guides/Makefile.common_generated_files +++ b/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/tribits/doc/guides/TribitsGuidesBody.rst b/tribits/doc/guides/TribitsGuidesBody.rst index dbabbce0e..3a5e71106 100644 --- a/tribits/doc/guides/TribitsGuidesBody.rst +++ b/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,164 @@ 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. + +.. 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 ``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 a +external 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 +``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/``. + +Finally, the code for generating and installing the ``Package1Config.cmake`` +file for the install directory ``CMAKE_PREFIX_PATH=`` is specified in +the included file ``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 ``CMakeLists.txt`` file (called +``CMakeLists.tribits.cmake`` in the base directory ``pacakge1/``): + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/CMakeLists.tribits.cmake + :literal: + +and the TriBITS ``CMakeLists.txt`` file (called ``CMakeLists.tribits.cmake``) +in the subdirectory ``package1/src/``: + +.. 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). + + +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. 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 ``CMakeLists.txt`` file for building ``Package1`` with a raw CMake +build system (called ``CMakeLists.raw.cmake`` in that directory) for +implementing a TriBITS-compliant internal package (which also, by definition, +creates a TriBITS-compliant external 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 above. 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). + + How to check for and tweak TriBITS "ENABLE" cache variables ----------------------------------------------------------- diff --git a/tribits/doc/guides/generate-guide.sh b/tribits/doc/guides/generate-guide.sh index e8e4ae07d..179fb9334 100755 --- a/tribits/doc/guides/generate-guide.sh +++ b/tribits/doc/guides/generate-guide.sh @@ -152,6 +152,21 @@ 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 + echo echo "Generating output for 'checkin-test.py --help' ..." echo @@ -246,8 +261,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!" From e7f4a016d3bd8bdc1e375bbea3c7ba8f298e18c7 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Thu, 14 Sep 2023 07:36:41 -0600 Subject: [PATCH 27/31] Add section 'How to use TriBITS testing support in non-TriBITS project' (#368) --- tribits/doc/guides/.gitignore | 1 + tribits/doc/guides/TribitsGuidesBody.rst | 67 ++++++++++++++++++++++++ tribits/doc/guides/generate-guide.sh | 9 ++++ 3 files changed, 77 insertions(+) diff --git a/tribits/doc/guides/.gitignore b/tribits/doc/guides/.gitignore index 266b34812..6c3878b7f 100644 --- a/tribits/doc/guides/.gitignore +++ b/tribits/doc/guides/.gitignore @@ -6,6 +6,7 @@ /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/tribits/doc/guides/TribitsGuidesBody.rst b/tribits/doc/guides/TribitsGuidesBody.rst index 3a5e71106..f904e35e8 100644 --- a/tribits/doc/guides/TribitsGuidesBody.rst +++ b/tribits/doc/guides/TribitsGuidesBody.rst @@ -6420,6 +6420,73 @@ differences are: compliant). +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`` +* and ``/core/test_support/TribitsAddAdvancedTest.cmake`` + +and set the variable ``${PROJECT_NAME}_ENABLE_TESTS`` to ``ON``. For an +MPI-enabled CMake project, one needs to define the following CMake variables +``MPI_EXEC``, ``MPI_EXEC_PRE_NUMPROCS_FLAGS``, ``MPI_EXEC_NUMPROCS_FLAG`` and +``MPI_EXEC_POST_NUMPROCS_FLAGS`` which define the MPI runtime program launcher +command-line used in these TriBITS testing functions:: + + ${MPI_EXEC} ${MPI_EXEC_PRE_NUMPROCS_FLAGS} + ${MPI_EXEC_NUMPROCS_FLAG} + ${MPI_EXEC_POST_NUMPROCS_FLAGS} + + +(These are defined automatically in a TriBITS project.) + +This is demonstrated in the `TribitsExampleProject2`_ project ``Package1`` +package. The base ``CMakeLists.txt`` file for building ``Package1`` with a +raw CMake build system using TriBITS testing functions (called +``CMakeLists.raw.cmake`` in that directory) looks like: + +.. include:: TribitsExampleProject2_Package1_CMakeLists.raw.tribits_test.cmake + :literal: + +The only difference between this base ``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()`_. + +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 ``package1/test/CMakeLists.tribits.cmake`` file (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/tribits/doc/guides/generate-guide.sh b/tribits/doc/guides/generate-guide.sh index 179fb9334..da7e128eb 100755 --- a/tribits/doc/guides/generate-guide.sh +++ b/tribits/doc/guides/generate-guide.sh @@ -167,6 +167,15 @@ function tribits_extract_other_doc { &> 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 From 5eae2cad57e7496dc2dbf9be10e51031214f958d Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 19 Sep 2023 11:00:39 -0600 Subject: [PATCH 28/31] Fix spelling of package1ConfigRegex (#582) Caught by @KyleFromKitware --- .../TribitsExampleProject2_Tests.cmake | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake index 4f485a1cb..9a713619f 100644 --- a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake @@ -555,11 +555,11 @@ function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrR ) set(package1UseRawCMakeArgs "") set(testNameSuffix "") - set(package1ConfiRegex "Configuring package Package1 as full TriBITS package") + set(package1ConfigRegex "Configuring package Package1 as full TriBITS package") elseif (package1TribitsOrRawCMake STREQUAL "PACKAGE1_USE_RAW_CMAKE") set(package1UseRawCMakeArgs "-D Package1_USE_RAW_CMAKE=TRUE") set(testNameSuffix "_${package1TribitsOrRawCMake}") - set(package1ConfiRegex "Configuring raw CMake package Package1") + set(package1ConfigRegex "Configuring raw CMake package Package1") else() message(FATAL_ERROR "package1UseRawCMakeArgs='${package1UseRawCMakeArgs}' Invalid!") endif() @@ -570,12 +570,12 @@ function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrR "-D Package1_USE_TRIBITS_TEST_FUNCTIONS=TRUE" "-D Package1_TRACE_ADD_TEST=TRUE" ) string(APPEND testNameSuffix "_${package1UseTribitsTestFunctions}" ) - list(APPEND package1ConfiRegex + list(APPEND package1ConfigRegex "Using TriBITS Test Functions in raw CMake Package1 build" "Package1_Prg: Added test [(]BASIC, PROCESSORS=1[)]" "Package1_Prg-advanced: Added test [(]BASIC, PROCESSORS=1[)]" ) elseif (package1UseTribitsTestFunctions STREQUAL "") - list(APPEND package1ConfiRegex + list(APPEND package1ConfigRegex "Using Raw CMake add_test[(][)] in raw CMake Package1 build" ) else() message(FATAL_ERROR @@ -635,7 +635,7 @@ function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrR "-- Generating Tpl3::all_libs and Tpl3Config.cmake" "-- Found Tpl4_DIR='.*TribitsExampleProject2_Tpls_install_${sharedOrStatic}/install_tpl4/lib/cmake/Tpl4'" "-- Generating Tpl4::all_libs and Tpl4Config.cmake" - "${package1ConfiRegex}" + "${package1ConfigRegex}" "-- Configuring done" "-- Generating done" ALWAYS_FAIL_ON_NONZERO_RETURN @@ -1224,13 +1224,13 @@ function(TribitsExampleProject2_External_RawPackage1_PBP "-D Package1_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}" "-D Package1_TRACE_ADD_TEST=TRUE" ) string(APPEND testNameSuffix "_${package1UseTribitsTestFunctions}" ) - set(package1ConfiRegex + set(package1ConfigRegex "Using TriBITS Test Functions in raw CMake Package1 build" "Package1_Prg: Added test [(]BASIC, PROCESSORS=1[)]" "Package1_Prg-advanced: Added test [(]BASIC, PROCESSORS=1[)]" ) elseif (package1UseTribitsTestFunctions STREQUAL "") set(package1UseTribitsTestFunctionsArgs "") - set(package1ConfiRegex + set(package1ConfigRegex "Using Raw CMake add_test[(][)] in raw CMake Package1 build" ) else() message(FATAL_ERROR @@ -1265,7 +1265,7 @@ function(TribitsExampleProject2_External_RawPackage1_PBP ../TribitsExampleProject2/packages/package1 PASS_REGULAR_EXPRESSION_ALL "Configuring raw CMake project Package1" - "${package1ConfiRegex}" + "${package1ConfigRegex}" "-- Configuring done" "-- Generating done" ALWAYS_FAIL_ON_NONZERO_RETURN From e5076368c389a69afcba0f3653c836799d03829f Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 19 Sep 2023 11:02:42 -0600 Subject: [PATCH 29/31] Remove unneeded quotes around args (#582) Caught by @KyleFromKitware --- .../TribitsExampleProject2_Tests.cmake | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake index 9a713619f..adb6d3f63 100644 --- a/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake +++ b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake @@ -567,8 +567,8 @@ function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrR if (package1TribitsOrRawCMake STREQUAL "PACKAGE1_USE_RAW_CMAKE") if (package1UseTribitsTestFunctions STREQUAL "PACKAGE1_USE_TRIBITS_TEST_FUNCS") list(APPEND package1UseRawCMakeArgs - "-D Package1_USE_TRIBITS_TEST_FUNCTIONS=TRUE" - "-D Package1_TRACE_ADD_TEST=TRUE" ) + -D Package1_USE_TRIBITS_TEST_FUNCTIONS=TRUE + -D Package1_TRACE_ADD_TEST=TRUE ) string(APPEND testNameSuffix "_${package1UseTribitsTestFunctions}" ) list(APPEND package1ConfigRegex "Using TriBITS Test Functions in raw CMake Package1 build" @@ -1220,9 +1220,9 @@ function(TribitsExampleProject2_External_RawPackage1_PBP if (package1UseTribitsTestFunctions STREQUAL "PACKAGE1_USE_TRIBITS_TEST_FUNCS") set(package1UseTribitsTestFunctionsArgs - "-D Package1_USE_TRIBITS_TEST_FUNCTIONS=TRUE" - "-D Package1_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}" - "-D Package1_TRACE_ADD_TEST=TRUE" ) + -D Package1_USE_TRIBITS_TEST_FUNCTIONS=TRUE + -D "Package1_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}" + -D Package1_TRACE_ADD_TEST=TRUE ) string(APPEND testNameSuffix "_${package1UseTribitsTestFunctions}" ) set(package1ConfigRegex "Using TriBITS Test Functions in raw CMake Package1 build" From 4d848d8ce75f433302c0289bcd7065b0d2475079 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 19 Sep 2023 11:10:37 -0600 Subject: [PATCH 30/31] Remove duplication in tribits_advanced_set_cache_var_and_default() (#582) Now just calls tribits_set_cache_var_and_default() then mark_as_advanced(). Suggested by @KyleFromKitware --- tribits/core/utils/TribitsSetCacheVarAndDefault.cmake | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tribits/core/utils/TribitsSetCacheVarAndDefault.cmake b/tribits/core/utils/TribitsSetCacheVarAndDefault.cmake index 920341755..a90c45aad 100644 --- a/tribits/core/utils/TribitsSetCacheVarAndDefault.cmake +++ b/tribits/core/utils/TribitsSetCacheVarAndDefault.cmake @@ -57,12 +57,8 @@ include_guard() macro(tribits_advanced_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}" ) + tribits_set_cache_var_and_default("${cacheVarName}" "${cacheVarType}" + "${defaultDefaultVal}" "${docString}") mark_as_advanced(${cacheVarName}) endmacro() From c9414267aa9fd2eb12cd54bddba0b4110aa7b1f8 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Thu, 21 Sep 2023 16:21:08 -0600 Subject: [PATCH 31/31] Do edits to new howto sections in users guide (#368, #582) --- tribits/doc/guides/TribitsGuidesBody.rst | 102 +++++++++++++---------- 1 file changed, 57 insertions(+), 45 deletions(-) diff --git a/tribits/doc/guides/TribitsGuidesBody.rst b/tribits/doc/guides/TribitsGuidesBody.rst index f904e35e8..210e4cc80 100644 --- a/tribits/doc/guides/TribitsGuidesBody.rst +++ b/tribits/doc/guides/TribitsGuidesBody.rst @@ -6271,8 +6271,9 @@ 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. +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. @@ -6280,7 +6281,8 @@ TriBITS-compliant external package ``Config.cmake`` file. 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 ``CMakeLists.raw.cmake`` in that directory) looks like: +build system (called ``package1/CMakeLists.raw.cmake`` in that directory) +looks like: .. include:: TribitsExampleProject2_Package1_CMakeLists.raw.internal.cmake :literal: @@ -6288,10 +6290,11 @@ build system (called ``CMakeLists.raw.cmake`` in that directory) looks like: 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 a -external 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``). +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 @@ -6322,8 +6325,8 @@ 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 -``cmake/raw/GeneratePackageConfigFileForBuildDir.cmake`` which has the -contents: +``package1/cmake/raw/GeneratePackageConfigFileForBuildDir.cmake`` which has +the contents: .. include:: ../../examples/TribitsExampleProject2/packages/package1/cmake/raw/GeneratePackageConfigFileForBuildDir.cmake :literal: @@ -6333,12 +6336,16 @@ The above code uses the ``export(EXPORT ...)`` command to generate the file 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/``. +``/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 ``cmake/raw/GeneratePackageConfigFileForInstallDir.cmake`` -with the contents: +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: @@ -6367,20 +6374,21 @@ 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 ``CMakeLists.txt`` file (called -``CMakeLists.tribits.cmake`` in the base directory ``pacakge1/``): +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 ``CMakeLists.txt`` file (called ``CMakeLists.tribits.cmake``) -in the subdirectory ``package1/src/``: +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). +(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 @@ -6390,25 +6398,25 @@ 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. 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. +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 ``CMakeLists.txt`` file for building ``Package1`` with a raw CMake -build system (called ``CMakeLists.raw.cmake`` in that directory) for -implementing a TriBITS-compliant internal package (which also, by definition, -creates a TriBITS-compliant external package) looks like: +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 above. The only -differences are: +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 @@ -6419,6 +6427,9 @@ differences are: 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 --------------------------------------------------------- @@ -6428,31 +6439,32 @@ The TriBITS test support functions `tribits_add_test()`_ and CMake project. To do so, one just needs to include the TriBITS modules: * ``/core/test_support/TribitsAddTest.cmake`` -* and ``/core/test_support/TribitsAddAdvancedTest.cmake`` +* ``/core/test_support/TribitsAddAdvancedTest.cmake`` and set the variable ``${PROJECT_NAME}_ENABLE_TESTS`` to ``ON``. For an -MPI-enabled CMake project, one needs to define the following CMake variables -``MPI_EXEC``, ``MPI_EXEC_PRE_NUMPROCS_FLAGS``, ``MPI_EXEC_NUMPROCS_FLAG`` and -``MPI_EXEC_POST_NUMPROCS_FLAGS`` which define the MPI runtime program launcher -command-line used in these TriBITS testing functions:: +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} - + ${MPI_EXEC_NUMPROCS_FLAG} + ${MPI_EXEC_POST_NUMPROCS_FLAGS} + -(These are defined automatically in a TriBITS project.) +(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 ``CMakeLists.txt`` file for building ``Package1`` with a -raw CMake build system using TriBITS testing functions (called -``CMakeLists.raw.cmake`` in that directory) looks like: +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 ``CMakeLists.txt`` file and one for a -raw CMake project is the inclusion of the file +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 @@ -6464,7 +6476,7 @@ The key lines are:: include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddAdvancedTest.cmake") This defines the CMake functions `tribits_add_test()`_ and -`tribits_add_advanced_test()`_. +`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 @@ -6476,7 +6488,7 @@ like:: include(TribitsAddAdvancedTest) Once these TriBITS modules are included, one can use the TriBITS functions as -demonstrated in the ``package1/test/CMakeLists.tribits.cmake`` file (which is +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