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 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/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/ExamplesUnitTests/TribitsExampleApp2_Tests.cmake b/test/core/ExamplesUnitTests/TribitsExampleApp2_Tests.cmake index 01c0025c6..d57cd9f61 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,16 +95,32 @@ 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}}") 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() @@ -113,7 +129,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,11 +145,11 @@ 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 - "TribitsExProj2_PACKAGE_LIST = Package3[;]Package2[;]Package1" + "${packageListRegex}" "-- Configuring done" "-- Generating done" "-- Build files have been written to: .*/${testName}/app_build" @@ -169,20 +185,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/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake b/test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake index b4be154f9..adb6d3f63 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 @@ -541,10 +544,45 @@ TribitsExampleProject2_explicit_tpl_vars(SHARED) ######################################################################## -function(TribitsExampleProject2_find_package sharedOrStatic) +function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrRawCMake + package1UseTribitsTestFunctions + ) TribitsExampleProject2_test_setup_header() + if ( (package1TribitsOrRawCMake STREQUAL "") OR + (package1TribitsOrRawCMake STREQUAL "PACKAGE1_USE_TRIBITS") + ) + set(package1UseRawCMakeArgs "") + set(testNameSuffix "") + 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(package1ConfigRegex "Configuring raw CMake package Package1") + else() + message(FATAL_ERROR "package1UseRawCMakeArgs='${package1UseRawCMakeArgs}' Invalid!") + endif() + + 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 ) + string(APPEND testNameSuffix "_${package1UseTribitsTestFunctions}" ) + 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 package1ConfigRegex + "Using Raw CMake add_test[(][)] in 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 @@ -554,7 +592,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,8 +617,11 @@ 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 + -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" ../TribitsExampleProject2 @@ -594,6 +635,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" + "${package1ConfigRegex}" "-- Configuring done" "-- Generating done" ALWAYS_FAIL_ON_NONZERO_RETURN @@ -616,9 +658,10 @@ function(TribitsExampleProject2_find_package 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_4 @@ -646,7 +689,18 @@ function(TribitsExampleProject2_find_package sharedOrStatic) 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) @@ -658,8 +712,12 @@ 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 "") +TribitsExampleProject2_find_package(SHARED PACKAGE1_USE_RAW_CMAKE + PACKAGE1_USE_TRIBITS_TEST_FUNCS) ######################################################################## @@ -776,7 +834,7 @@ endif() ################################################################################ -function(TribitsExampleProject2_External_Package_by_Package +function(TribitsExampleProject2_External_PBP sharedOrStatic findingTplsMethod ) @@ -1061,10 +1119,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. @@ -1073,8 +1131,8 @@ TribitsExampleProject2_External_Package_by_Package(SHARED CMAKE_PREFIX_PATH_CAC ################################################################################ -function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package - sharedOrStatic findingTplsMethod +function(TribitsExampleProject2_External_RawPackage1_PBP + sharedOrStatic findingTplsMethod package1UseTribitsTestFunctions ) TribitsExampleProject2_test_setup_header() @@ -1160,6 +1218,25 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package "Error, findingTplsMethod='${findingTplsMethod}' is invalid!") endif() + 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 ) + string(APPEND testNameSuffix "_${package1UseTribitsTestFunctions}" ) + 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(package1ConfigRegex + "Using Raw CMake add_test[(][)] in 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}") @@ -1176,16 +1253,19 @@ 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} + ${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" + "${package1ConfigRegex}" "-- Configuring done" "-- Generating done" ALWAYS_FAIL_ON_NONZERO_RETURN @@ -1199,6 +1279,17 @@ 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 + "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 MESSAGE "Configure to build, install, and test Package2" WORKING_DIRECTORY Build_Package2 CMND ${CMAKE_COMMAND} @@ -1252,13 +1343,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 @@ -1268,7 +1359,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} @@ -1326,19 +1417,19 @@ 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 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 @@ -1355,10 +1446,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_PBP(STATIC + TPL_LIBRARY_AND_INCLUDE_DIRS "") +TribitsExampleProject2_External_RawPackage1_PBP(SHARED + TPL_LIBRARY_AND_INCLUDE_DIRS "") +TribitsExampleProject2_External_RawPackage1_PBP(STATIC + CMAKE_PREFIX_PATH_CACHE "") +TribitsExampleProject2_External_RawPackage1_PBP(SHARED + CMAKE_PREFIX_PATH_CACHE "") +TribitsExampleProject2_External_RawPackage1_PBP(SHARED + CMAKE_PREFIX_PATH_CACHE PACKAGE1_USE_TRIBITS_TEST_FUNCS) diff --git a/test/core/TestingFunctionMacro_UnitTests.cmake b/test/core/TestingFunctionMacro_UnitTests.cmake index 3945430be..05b8df98c 100644 --- a/test/core/TestingFunctionMacro_UnitTests.cmake +++ b/test/core/TestingFunctionMacro_UnitTests.cmake @@ -49,10 +49,11 @@ 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("${${PROJECT_NAME}_TRIBITS_DIR}/core/test_support/TribitsAddAdvancedTest.cmake") + include(MessageWrapper) -include(TribitsTestCategories) -include(TribitsAddTest) -include(TribitsAddAdvancedTest) include(TribitsAddExecutableAndTest) include(TribitsETISupport) include(TribitsFindPythonInterp) @@ -2566,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" ) @@ -4844,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/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/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 28c0fa807..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) @@ -464,13 +467,6 @@ macro(tribits_define_global_options_and_define_extra_repos) "Make the ${PROJECT_NAME} configure process verbose." ) - if ("${${PROJECT_NAME}_TRACE_ADD_TEST_DEFAULT}" STREQUAL "") - set(${PROJECT_NAME}_TRACE_ADD_TEST_DEFAULT ${${PROJECT_NAME}_VERBOSE_CONFIGURE}) - endif() - advanced_set(${PROJECT_NAME}_TRACE_ADD_TEST ${${PROJECT_NAME}_TRACE_ADD_TEST_DEFAULT} - CACHE BOOL - "Show a configure time trace of every test added or not added any why (one line)." ) - advanced_option(${PROJECT_NAME}_DUMP_LINK_LIBS "Dump the link libraries for every library and executable created." "${${PROJECT_NAME}_VERBOSE_CONFIGURE}" ) @@ -2072,17 +2068,20 @@ macro(tribits_configure_enabled_packages) tribits_trace_file_processing(PACKAGE ADD_SUBDIR "${TRIBITS_PACKAGE_CMAKELIST_FILE}") if (NOT ${TRIBITS_PACKAGE}_SOURCE_DIR STREQUAL ${PROJECT_NAME}_SOURCE_DIR) - add_subdirectory(${${TRIBITS_PACKAGE}_SOURCE_DIR} ${${TRIBITS_PACKAGE}_BINARY_DIR}) + add_subdirectory(${${TRIBITS_PACKAGE}_SOURCE_DIR} + ${${TRIBITS_PACKAGE}_BINARY_DIR}) else() include("${TRIBITS_PACKAGE_CMAKELIST_FILE}") endif() - if (NOT ${PACKAGE_NAME}_TRIBITS_PACKAGE_POSTPROCESS) + if ((NOT ${PACKAGE_NAME}_TRIBITS_PACKAGE_POSTPROCESS) AND + (NOT TARGET ${PACKAGE_NAME}::all_libs) + ) tribits_report_invalid_tribits_usage( "ERROR: Forgot to call tribits_package_postprocess() in" " ${TRIBITS_PACKAGE_CMAKELIST_FILE}") endif() - list(APPEND ENABLED_PACKAGE_LIBS_TARGETS ${TRIBITS_PACKAGE}_libs) + list(APPEND ENABLED_PACKAGE_LIBS_TARGETS ${TRIBITS_PACKAGE}::all_libs) list(APPEND ${PROJECT_NAME}_LIBRARIES ${${TRIBITS_PACKAGE}_LIBRARIES}) tribits_package_config_code_stop_timer(PROCESS_THIS_PACKAGE_TIME_START_SECONDS diff --git a/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/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..d7931c406 100644 --- a/tribits/core/package_arch/TribitsPackageMacros.cmake +++ b/tribits/core/package_arch/TribitsPackageMacros.cmake @@ -51,13 +51,14 @@ include(PrependGlobalSet) include(RemoveGlobalDuplicates) include(TribitsGatherBuildTargets) +include("${CMAKE_CURRENT_LIST_DIR}/../test_support/TribitsAddTest.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../test_support/TribitsAddAdvancedTest.cmake") + include(TribitsAddOptionAndDefine) include(TribitsPkgExportCacheVars) include(TribitsLibraryMacros) include(TribitsAddExecutable) include(TribitsAddExecutableAndTest) -include(TribitsAddTest) -include(TribitsAddAdvancedTest) include(TribitsCopyFilesToBinaryDir) include(TribitsReportInvalidTribitsUsage) diff --git a/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/TribitsAddAdvancedTest.cmake b/tribits/core/test_support/TribitsAddAdvancedTest.cmake similarity index 97% rename from tribits/core/package_arch/TribitsAddAdvancedTest.cmake rename to tribits/core/test_support/TribitsAddAdvancedTest.cmake index fca20e111..21deffdea 100644 --- a/tribits/core/package_arch/TribitsAddAdvancedTest.cmake +++ b/tribits/core/test_support/TribitsAddAdvancedTest.cmake @@ -37,14 +37,16 @@ # ************************************************************************ # @HEADER -include(TribitsCMakePolicies NO_POLICY_SCOPE) +include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsCMakePolicies.cmake" NO_POLICY_SCOPE) +include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsConstants.cmake") -include(TribitsAddAdvancedTestHelpers) -include(TribitsConstants) +set(tribitsAddAdvancedTestModuleDir "${CMAKE_CURRENT_LIST_DIR}") -include(TribitsPrintList) -include(AppendStringVar) -include(PrintVar) +include("${CMAKE_CURRENT_LIST_DIR}/TribitsAddAdvancedTestHelpers.cmake") + +include("${CMAKE_CURRENT_LIST_DIR}/../utils/TribitsPrintList.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/AppendStringVar.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/PrintVar.cmake") # @FUNCTION: tribits_add_advanced_test() @@ -853,10 +855,9 @@ include(PrintVar) # # The function ``tribits_add_advanced_test()`` can be used to add tests in # non-TriBITS projects. To do so, one just needs to set the variables -# ``PROJECT_NAME``, ``PACKAGE_NAME`` (which could be the same as -# ``PROJECT_NAME``), ``${PACKAGE_NAME}_ENABLE_TESTS=TRUE``, and -# ``${PROJECT_NAME}_TRIBITS_DIR`` (pointing to the TriBITS location). For example, -# a valid project can be a simple as:: +# ``${PROJECT_NAME}_ENABLE_TESTS=TRUE`` and ``${PROJECT_NAME}_TRIBITS_DIR`` +# (pointing to the TriBITS location). For example, a valid project can be a +# simple as:: # # cmake_minimum_required(VERSION 3.23.0) # set(PROJECT_NAME TAATDriver) @@ -866,36 +867,40 @@ include(PrintVar) # "Location of TriBITS to use." ) # set(PACKAGE_NAME ${PROJECT_NAME}) # set(${PACKAGE_NAME}_ENABLE_TESTS TRUE) -# set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} -# ${TRIBITS_DIR}/core/utils -# ${TRIBITS_DIR}/core/package_arch ) -# include(TribitsAddAdvancedTest) +# include("${${PROJECT_NAME}_TRIBITS_DIR}/core/test_support/TribitsAddAdvancedTest.cmake") # include(CTest) # enable_testing() # -# tribits_add_advanced_test( -# TAAT_COPY_FILES_TO_TEST_DIR_bad_file_name +# tribits_add_advanced_test( HelloWorld # OVERALL_WORKING_DIRECTORY TEST_NAME # TEST_0 CMND echo ARGS "Hello World!" # PASS_REGULAR_EXPRESIOIN "Hello World" # ) # +# Above, one can replace:: +# +# include("${${PROJECT_NAME}_TRIBITS_DIR}/core/test_support/TribitsAddAdvancedTest.cmake") +# +# with:: +# +# list(PREPEND CMAKE_MODULE_PATH "${${PROJECT_NAME}_TRIBITS_DIR}/core/test_support") +# include(TribitsAddAdvancedTest) +# +# and it will have the same effect. +# function(tribits_add_advanced_test TEST_NAME_IN) if (${PROJECT_NAME}_VERBOSE_CONFIGURE) message("\nPACKAGE_ADD_ADVANCED_TEST: ${TEST_NAME_IN}\n") endif() + tribits_set_tribits_package_name() + global_set(TRIBITS_SET_TEST_PROPERTIES_INPUT) global_set(MESSAGE_WRAPPER_INPUT) # Set the full TEST_NAME - if (PACKAGE_NAME) - set(TEST_NAME ${PACKAGE_NAME}_${TEST_NAME_IN}) - else() - set(TEST_NAME ${TEST_NAME_IN}) - endif() - + set(TEST_NAME ${PACKAGE_NAME}_${TEST_NAME_IN}) # # A) Parse the overall arguments and figure out how many tests @@ -1518,6 +1523,8 @@ function(tribits_add_advanced_test TEST_NAME_IN) # F.2) Write the cmake -P script # + set(coreUtilsDir "${tribitsAddAdvancedTestModuleDir}/../utils") + cmake_path(NORMAL_PATH coreUtilsDir) string(APPEND TEST_SCRIPT_STR "\n" "set(PROJECT_NAME ${PROJECT_NAME})\n" @@ -1548,9 +1555,7 @@ function(tribits_add_advanced_test TEST_NAME_IN) "# Test invocation\n" "#\n" "\n" - "set(CMAKE_MODULE_PATH ${${PROJECT_NAME}_TRIBITS_DIR}/${TRIBITS_CMAKE_UTILS_DIR})\n" - "\n" - "include(DriveAdvancedTest)\n" + "include(\"${coreUtilsDir}/DriveAdvancedTest.cmake\")\n" "\n" "drive_advanced_test()\n" ) diff --git a/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 8c2e11df3..c7fb556b4 100644 --- a/tribits/core/package_arch/TribitsAddAdvancedTestHelpers.cmake +++ b/tribits/core/test_support/TribitsAddAdvancedTestHelpers.cmake @@ -38,7 +38,7 @@ # @HEADER -include(TribitsAddTestHelpers) +include("${CMAKE_CURRENT_LIST_DIR}/TribitsAddTestHelpers.cmake") # Set default ax number of TEST_ blocks in tribits_add_advanced_test() diff --git a/tribits/core/package_arch/TribitsAddExecutableTestHelpers.cmake b/tribits/core/test_support/TribitsAddExecutableTestHelpers.cmake similarity index 92% rename from tribits/core/package_arch/TribitsAddExecutableTestHelpers.cmake rename to tribits/core/test_support/TribitsAddExecutableTestHelpers.cmake index 78f98f0ba..c2bc95d0d 100644 --- a/tribits/core/package_arch/TribitsAddExecutableTestHelpers.cmake +++ b/tribits/core/test_support/TribitsAddExecutableTestHelpers.cmake @@ -37,22 +37,23 @@ # ************************************************************************ # @HEADER -include(TribitsCMakePolicies NO_POLICY_SCOPE) +include_guard() -include(AdvancedSet) -include(MessageWrapper) +include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsCMakePolicies.cmake" NO_POLICY_SCOPE) + +include("${CMAKE_CURRENT_LIST_DIR}/../utils/AdvancedSet.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/MessageWrapper.cmake") advanced_set( ${PROJECT_NAME}_CMAKE_EXECUTABLE_SUFFIX ".exe" CACHE STRING "Default exec suffix on all platforms (can be overridden by each executable added)." ) -# + # Process the COMM arguments # # NOTE: The COMM array arguments is passed as ${ARGN} # - -function( tribits_process_comm_args ADD_SERIAL_FEATURE_OUT ADD_MPI_FEATURE_OUT ) +function(tribits_process_comm_args ADD_SERIAL_FEATURE_OUT ADD_MPI_FEATURE_OUT ) set(COMM_ARRAY ${ARGN}) diff --git a/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 6f388fdac..9e23d71c3 100644 --- a/tribits/core/package_arch/TribitsAddTest.cmake +++ b/tribits/core/test_support/TribitsAddTest.cmake @@ -37,8 +37,9 @@ # ************************************************************************ # @HEADER -include(TribitsCMakePolicies NO_POLICY_SCOPE) -include(TribitsAddTestHelpers) + +include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsCMakePolicies.cmake" NO_POLICY_SCOPE) +include("${CMAKE_CURRENT_LIST_DIR}/TribitsAddTestHelpers.cmake") # @FUNCTION: tribits_add_test() @@ -817,6 +818,8 @@ function(tribits_add_test EXE_NAME) message("TRIBITS_ADD_TEST: ${EXE_NAME} ${ARGN}") endif() + tribits_set_tribits_package_name() + global_set(TRIBITS_ADD_TEST_ADD_TEST_INPUT) global_set(TRIBITS_SET_TEST_PROPERTIES_INPUT) global_set(MESSAGE_WRAPPER_INPUT) @@ -935,8 +938,6 @@ function(tribits_add_test EXE_NAME) tribits_add_test_adjust_directory( ${EXE_BINARY_NAME} "${PARSE_DIRECTORY}" EXECUTABLE_PATH) - #message("TRIBITS_ADD_TEST: ${EXE_NAME}: EXECUTABLE_PATH = ${EXECUTABLE_PATH}") - # # D) Determine if we will add the serial or MPI tests based on input COMM # and TPL_ENABLE_MPI diff --git a/tribits/core/package_arch/TribitsAddTestHelpers.cmake b/tribits/core/test_support/TribitsAddTestHelpers.cmake similarity index 96% rename from tribits/core/package_arch/TribitsAddTestHelpers.cmake rename to tribits/core/test_support/TribitsAddTestHelpers.cmake index 715bca20f..98190718a 100644 --- a/tribits/core/package_arch/TribitsAddTestHelpers.cmake +++ b/tribits/core/test_support/TribitsAddTestHelpers.cmake @@ -37,19 +37,25 @@ # ************************************************************************ # @HEADER +include_guard() -include(TribitsAddExecutableTestHelpers) -include(TribitsGeneralMacros) -include(TribitsTestCategories) - -include(CMakeParseArguments) -include(GlobalSet) -include(AppendGlobalSet) -include(AppendStringVarWithSep) -include(PrintVar) -include(AdvancedSet) -include(MessageWrapper) -include(TribitsGetCategoriesString) +include("${CMAKE_CURRENT_LIST_DIR}/TribitsAddExecutableTestHelpers.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/TribitsSetTribitsPackageName.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/TribitsTestCategories.cmake") + +include("${CMAKE_CURRENT_LIST_DIR}/../utils/GlobalSet.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/AppendGlobalSet.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/AppendStringVarWithSep.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/PrintVar.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/AdvancedSet.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/MessageWrapper.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/TribitsGetCategoriesString.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/TribitsSetCacheVarAndDefault.cmake") + + +tribits_advanced_set_cache_var_and_default(${PROJECT_NAME}_TRACE_ADD_TEST BOOL + "${${PROJECT_NAME}_VERBOSE_CONFIGURE}" + "Show a configure-time trace of every test added or not added any why (one line).") # Do initialization for test helpers diff --git a/tribits/core/test_support/TribitsSetTribitsPackageName.cmake b/tribits/core/test_support/TribitsSetTribitsPackageName.cmake new file mode 100644 index 000000000..2a08b4beb --- /dev/null +++ b/tribits/core/test_support/TribitsSetTribitsPackageName.cmake @@ -0,0 +1,55 @@ +# @HEADER +# ************************************************************************ +# +# TriBITS: Tribal Build, Integrate, and Test System +# Copyright 2013 Sandia Corporation +# +# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +# the U.S. Government retains certain rights in this software. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# 3. Neither the name of the Corporation nor the names of the +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# ************************************************************************ +# @HEADER + + +include("${CMAKE_CURRENT_LIST_DIR}/../utils/MessageWrapper.cmake") + + +# Set the TriBITS package name var if it has not already been set +# +macro(tribits_set_tribits_package_name) + if ("${PACKAGE_NAME}" STREQUAL "") + if (NOT "${PROJECT_NAME}" STREQUAL "") + set(PACKAGE_NAME ${PROJECT_NAME}) + else() + message_wrapper(FATAL_ERROR "Error! Can't set default PACKAGE_NAME because" + " PROJECT_NAME is not set!") + endif() + endif() +endmacro() diff --git a/tribits/core/package_arch/TribitsTestCategories.cmake b/tribits/core/test_support/TribitsTestCategories.cmake similarity index 94% rename from tribits/core/package_arch/TribitsTestCategories.cmake rename to tribits/core/test_support/TribitsTestCategories.cmake index acd55cee1..a6f053d63 100644 --- a/tribits/core/package_arch/TribitsTestCategories.cmake +++ b/tribits/core/test_support/TribitsTestCategories.cmake @@ -37,10 +37,10 @@ # ************************************************************************ # @HEADER -include(FindListElement) -include(MessageWrapper) -include(Join) -include(TribitsDeprecatedHelpers) +include("${CMAKE_CURRENT_LIST_DIR}/../utils/FindListElement.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/MessageWrapper.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/Join.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/TribitsDeprecatedHelpers.cmake") # Define the valid categories that will be recognized in the CATEGORIES keyword diff --git a/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/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/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/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/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/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/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/TribitsSetCacheVarAndDefault.cmake b/tribits/core/utils/TribitsSetCacheVarAndDefault.cmake new file mode 100644 index 000000000..a90c45aad --- /dev/null +++ b/tribits/core/utils/TribitsSetCacheVarAndDefault.cmake @@ -0,0 +1,89 @@ +# @HEADER +# ************************************************************************ +# +# TriBITS: Tribal Build, Integrate, and Test System +# Copyright 2013 Sandia Corporation +# +# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +# the U.S. Government retains certain rights in this software. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# 3. Neither the name of the Corporation nor the names of the +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# ************************************************************************ +# @HEADER + +include_guard() + + +# @MACRO: tribits_advanced_set_cache_var_and_default() +# +# Set an advanced cache variable with a default value (passing in a default +# default value). +# +# Usage:: +# +# tribits_advanced_set_cache_var_and_default( +# ) +# +# If the variable ``_DEFAULT`` already exists with a value, that +# is used as the default cache variable. Otherwise, +# ``_DEFAULT`` is set set to ```` first. +# +macro(tribits_advanced_set_cache_var_and_default cacheVarName cacheVarType + defaultDefaultVal docString + ) + tribits_set_cache_var_and_default("${cacheVarName}" "${cacheVarType}" + "${defaultDefaultVal}" "${docString}") + mark_as_advanced(${cacheVarName}) +endmacro() + + +# @MACRO: tribits_set_cache_var_and_default() +# +# Set a cache variable with a default value (passing in a default default +# value). +# +# Usage:: +# +# tribits_set_cache_var_and_default( +# ) +# +# If the variable ``_DEFAULT`` already exists with a value, that +# is used as the default cache variable. Otherwise, +# ``_DEFAULT`` is set set to ```` first. +# +macro(tribits_set_cache_var_and_default cacheVarName cacheVarType + defaultDefaultVal docString + ) + if ("${${cacheVarName}_DEFAULT}" STREQUAL "") + set(${cacheVarName}_DEFAULT "${defaultDefaultVal}") + endif() + set(${cacheVarName} "${${cacheVarName}_DEFAULT}" + CACHE ${cacheVarType} + "${docString}" ) +endmacro() diff --git a/tribits/core/package_arch/TribitsSortListAccordingToMasterList.cmake b/tribits/core/utils/TribitsSortListAccordingToMasterList.cmake similarity index 62% rename from tribits/core/package_arch/TribitsSortListAccordingToMasterList.cmake rename to tribits/core/utils/TribitsSortListAccordingToMasterList.cmake index 5d079a417..4b0132702 100644 --- a/tribits/core/package_arch/TribitsSortListAccordingToMasterList.cmake +++ b/tribits/core/utils/TribitsSortListAccordingToMasterList.cmake @@ -37,40 +37,28 @@ # ************************************************************************ # @HEADER -include(PrintVar) -include(AppendSet) +include("${CMAKE_CURRENT_LIST_DIR}/../utils/PrintVar.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../utils/AppendSet.cmake") + +# Do an in-place sort of a list of items according to the ordering in a master +# list. # -# Function that does an in-place sort of a list of items according to the -# ordering in a master list -# -# NOTE: This function has wost-case N^2 complexity as the number of packages N -# or TPLs increases. It actually has N * n complexity where N is the total -# number of packages/TPLs and n is the number of passed-in packages/TPLs. -# However, since N is not likely to ever be more than a few hundred, this is -# likely not going to be a big performance problem. If this does become a -# performance problem, list(SORT ...) could be used but would require some -# work to build up the datastructures to make this very efficient. +# NOTE: This function has worst-case complexity N*n where N is the number of +# elements in the ```` and n is the number of elements in the +# ```` list. # +function(tribits_sort_list_according_to_master_list masterList listVarInOut) -function(tribits_sort_list_according_to_master_list MASTER_LIST LIST_VAR_INOUT) - - #message("TRIBITS_SORT_LIST_ACCORDING_TO_MASTER_LIST:") - #print_var(MASTER_LIST) - #print_var(LIST_VAR_INOUT) - #print_var(${LIST_VAR_INOUT}) + set(sortedList) - set(SORTED_LIST) - - foreach(ITEM ${MASTER_LIST}) - list(FIND ${LIST_VAR_INOUT} ${ITEM} ITEM_IDX) - if (NOT ITEM_IDX EQUAL -1) - list(APPEND SORTED_LIST ${ITEM}) + foreach(item ${masterList}) + list(FIND ${listVarInOut} ${item} itemIdx) + if (NOT itemIdx EQUAL -1) + list(APPEND sortedList ${item}) endif() endforeach() - #print_var(SORTED_LIST) - - set(${LIST_VAR_INOUT} ${SORTED_LIST} PARENT_SCOPE) + set(${listVarInOut} ${sortedList} PARENT_SCOPE) endfunction() diff --git a/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/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} diff --git a/tribits/doc/guides/.gitignore b/tribits/doc/guides/.gitignore index 7f018678f..6c3878b7f 100644 --- a/tribits/doc/guides/.gitignore +++ b/tribits/doc/guides/.gitignore @@ -4,6 +4,9 @@ /TriBITS.README.DIRECTORY_CONTENTS.rst.tmp /TribitsCommonTPLsList.txt /TribitsCommonTPLsList.txt.tmp +/TribitsExampleProject2_Package1_CMakeLists.raw.external.cmake* +/TribitsExampleProject2_Package1_CMakeLists.raw.internal.cmake* +/TribitsExampleProject2_Package1_CMakeLists.raw.tribits_test.cmake* /TribitsGitVersion.txt /TribitsGitVersion.txt.tmp /TribitsHelloWorldDirAndFiles.txt diff --git a/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..210e4cc80 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,243 @@ file as well. Then every ``CMakeLists.txt`` file in subdirectories just calls ``include_tribits_build()``. That is it. +How to implement a TriBITS-compliant internal package using raw CMake +--------------------------------------------------------------------- + +As described in `TriBITS-Compliant Internal Packages`_, it is possible to +create a raw CMake build system for a CMake package that can build under a +parent TriBITS CMake project. The raw CMake code for such a package must +provide the ``::all_libs`` target both in the current CMake build +system and also in the generated ``Config.cmake`` file for the build +directory and in the installed ``Config.cmake`` file. Every such +TriBITS-compliant internal package therefore is **also capable of installing a +TriBITS-compliant external package** ``Config.cmake`` file (see `How +to implement a TriBITS-compliant external package using raw CMake`_). + +.. ToDo: Consider listing out the key features of a raw CMake build system + that is needed for a TriBITS-compliant internal package. + +A raw CMake build system for a TriBITS-compliant internal package is +demonstrated in the `TribitsExampleProject2`_ project ``Package1`` package. +The base ``CMakeLists.txt`` file for building ``Package1`` with a raw CMake +build system (called ``package1/CMakeLists.raw.cmake`` in that directory) +looks like: + +.. include:: TribitsExampleProject2_Package1_CMakeLists.raw.internal.cmake + :literal: + +As shown above, this simple CMake package contains the basic features of any +CMake project/package including calling the ``cmake_minimum_required()`` and +``project()`` commands as well as including ``GNUInstallDirs``. In this +example, the project/package being built ``Package1`` has a dependency on an +external upstream package ``Tpl1`` pulled in with ``find_package(Tpl1)``. +Also in this example, the package has native tests it defines with +``include(CTest)`` and ``add_subdirectory()`` (if ``Package1_ENABLE_TESTS`` is +set to ``ON``). + +The file ``package1/src/CMakeLists.raw.cmake`` (which gets included from +``package1/src/CMakeLists.txt``) creates a library and executable for the +package and has the contents: + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/src/CMakeLists.raw.cmake + :literal: + +This creates a single installable library target ``Package1_package1`` which +is aliased as ``Package1::package1`` in the current CMake project and sets up +to create the IMPORTED target ``Package1::package1`` in the generated +``Package1ConfigTarget.cmake`` file, which gets included in the installed +``Package1Config.cmake`` (``Config.cmake``) file (as recommenced in +the book "Professional CMake", see below). In addition, the above code +creates the installable executable ``package1-prg``. + +The ``Package1::all_libs`` (``::all_libs``) target is defined and set +up inside of the included file +``package1/cmake/raw/DefineAllLibsTarget.cmake`` which contains the code: + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/cmake/raw/DefineAllLibsTarget.cmake + :literal: + +The above code contains the ALIAS library target ``Package1::all_libs`` +(``::all_libs``) for the current CMake project as well as sets up for +the IMPORTED target ``Package1::all_libs`` (``::all_libs``) getting +put in the generated ``Package1ConfigTargets.cmake`` file (see below). + +The ``Package1Config.cmake`` (``Config.cmake``) file for the build +directory is generated inside of the included file +``package1/cmake/raw/GeneratePackageConfigFileForBuildDir.cmake`` which has +the contents: + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/cmake/raw/GeneratePackageConfigFileForBuildDir.cmake + :literal: + +The above code uses the ``export(EXPORT ...)`` command to generate the file +``Package1ConfigTargets.cmake`` for the build directory which provides the +IMPORTED targets ``Package1::package1`` and ``Package1::all_libs``. The +command ``configure_file(...)`` generates the ``Package1Config.cmake`` file +that includes it for the build directory +``/cmake_packages/Package1/``. (NOTE: The above code only runs when +the package is being built from inside of a TriBITS project which defines the +command ``tribits_package``. So this code gets skipped when building +``Package1`` as a stand-alone raw CMake project.) + +Finally, the code for generating and installing the ``Package1Config.cmake`` +file for the install directory ``CMAKE_PREFIX_PATH=`` is specified +in the included file +``package1/cmake/raw/GeneratePackageConfigFileForInstallDir.cmake`` with the +contents: + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/cmake/raw/GeneratePackageConfigFileForInstallDir.cmake + :literal: + +The above uses the command ``install(EXPORT ...)`` to have CMake automatically +generate and install the file ``Package1ConfigTargets.cmake`` in the install +directory ``/libs/cmake/Package1/`` which provides the IMPORTED +targets ``Package1::package1`` and ``Package1::all_libs``. The command +``configure_file()`` is used to generate the file +``Package1Config.install.cmake`` in the build directory from the template file +``Package1Config.cmake.in``. Finally, the ``install()`` command is used in +the file ``GeneratePackageConfigFileForInstallDir.cmake`` to set up the +installation of the ``Package1Config.cmake`` file. + +Note, the template file ``package1/cmake/raw/Package1Config.cmake.in`` (which +is unique to ``Package1``) is: + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/cmake/raw/Package1Config.cmake.in + :literal: + +As shown in the all of the above code, there is a lot of boilerplate CMake +code needed to correctly define the targets such that they get put into the +installed ``Package1Config.cmake`` file using the correct namespace +``Package1::`` and care must be taken to ensure that a consistent "export set" +is used for this purpose. (For more details, see the book "Professional +CMake".) + +**NOTE:** One should compare the above raw CMakeLists files to the more +compact TriBITS versions for the base ``package1/CMakeLists.txt`` file (called +``package1/CMakeLists.tribits.cmake`` in the base directory ``pacakge1/``): + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/CMakeLists.tribits.cmake + :literal: + +and the TriBITS ``package1/src/CMakeLists.txt`` file (called +``package1/src/CMakeLists.tribits.cmake``): + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/src/CMakeLists.tribits.cmake + :literal: + +This shows the amount of boilerplate code that TriBITS addresses automatically +(which reduces the overhead of finer-grained packages and avoids common +mistakes with tedious low-level CMake code). + + +How to implement a TriBITS-compliant external package using raw CMake +--------------------------------------------------------------------- + +As described in `TriBITS-Compliant External Packages`_, it is possible to +create a raw CMake build system for a CMake package such that once it is +installed, satisfies the requirements for a TriBITS-compliant external +package. These installed packages provide a ``Config.cmake`` file +that provides the required targets and behaviors as if it was produced by a +TriBITS project. For most existing raw CMake projects that already produce a +"Professional CMake" compliant ``Config.cmake`` file, that usually +just means adding the IMPORTED target called ``::all_libs`` to the +installed ``Config.cmake`` file. + +A raw CMake build system for a TriBITS-compliant external package is +demonstrated in the `TribitsExampleProject2`_ project ``Package1`` package. +The base ``package1/CMakeLists.txt`` file for building ``Package1`` with a raw +CMake build system (called ``package1/CMakeLists.raw.cmake``) for implementing +a TriBITS-compliant internal package looks like: + +.. include:: TribitsExampleProject2_Package1_CMakeLists.raw.external.cmake + :literal: + +Note that the raw build system this example is identical to the build system +for the raw TriBITS-compliant internal package described in `How to implement +a TriBITS-compliant internal package using raw CMake`_. The only differences +are: + +1) The ``Package1Config.cmake`` (``Config.cmake``) file does **not** + need to be generated for the build directory and therefore the code in + ``cmake/raw/GeneratePackageConfigFileForBuildDir.cmake`` does **not** need + to be included. + +2) The ALIAS library target ``Package1::all_libs`` (``::all_libs``) + does **not** need to be generated (but should be to be "Professional CMake" + compliant). + +Other than that, see `How to implement a TriBITS-compliant internal package +using raw CMake`_ for how to implement a TriBITS-compliant external package. + + +How to use TriBITS testing support in non-TriBITS project +--------------------------------------------------------- + +The TriBITS test support functions `tribits_add_test()`_ and +`tribits_add_advanced_test()`_ can be used from any raw (i.e. non-TriBITS) +CMake project. To do so, one just needs to include the TriBITS modules: + +* ``/core/test_support/TribitsAddTest.cmake`` +* ``/core/test_support/TribitsAddAdvancedTest.cmake`` + +and set the variable ``${PROJECT_NAME}_ENABLE_TESTS`` to ``ON``. For an +MPI-enabled CMake project, the CMake variables ``MPI_EXEC``, +``MPI_EXEC_PRE_NUMPROCS_FLAGS``, ``MPI_EXEC_NUMPROCS_FLAG`` and +``MPI_EXEC_POST_NUMPROCS_FLAGS`` must also be set which define the MPI runtime +program launcher command-line used in the TriBITS testing functions:: + + ${MPI_EXEC} ${MPI_EXEC_PRE_NUMPROCS_FLAGS} + ${MPI_EXEC_NUMPROCS_FLAG} + ${MPI_EXEC_POST_NUMPROCS_FLAGS} + + +(NOTE: These variables are defined automatically in a TriBITS project when +``TPL_ENABLE_MPI`` is set to ``ON``.) + +This is demonstrated in the `TribitsExampleProject2`_ project ``Package1`` +package. The base ``pacakge1/CMakeLists.txt`` file for building ``Package1`` +with a raw CMake build system using TriBITS testing functions (called +``package1/CMakeLists.raw.cmake``) looks like: + +.. include:: TribitsExampleProject2_Package1_CMakeLists.raw.tribits_test.cmake + :literal: + +The only difference between this base ``package1/CMakeLists.txt`` file and one +for a raw CMake project is the inclusion of the file +``package1/cmake/raw/EnableTribitsTestSupport.cmake`` which has the contents: + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/cmake/raw/EnableTribitsTestSupport.cmake + :literal: + +The key lines are:: + + include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddTest.cmake") + include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddAdvancedTest.cmake") + +This defines the CMake functions `tribits_add_test()`_ and +`tribits_add_advanced_test()`_, respectively. + +The above code demonstrates that ``CMAKE_MODULE_PATH`` does **not** need to be +updated to use these TriBITS ``test_support`` modules. However, one is free +to update ``CMAKE_MODULE_PATH`` and then include the modules by name only +like:: + + list(PREPEND CMAKE_MODULE_PATH "${Package1_TRIBITS_DIR}/core/test_support") + include(TribitsAddTest) + include(TribitsAddAdvancedTest) + +Once these TriBITS modules are included, one can use the TriBITS functions as +demonstrated in the file ``package1/test/CMakeLists.tribits.cmake`` (which is +included from the file ``package1/test/CMakeLists.txt``) and has the contents: + +.. include:: ../../examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake + :literal: + +Note that in this example, the executable ``package1-prg`` was already +created. If new test libraries and executables need to be created, then the +raw CMake commands to create those will need to be added as well. + + How to check for and tweak TriBITS "ENABLE" cache variables ----------------------------------------------------------- diff --git a/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() + 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() + diff --git a/tribits/doc/guides/generate-guide.sh b/tribits/doc/guides/generate-guide.sh index ce7a2c656..da7e128eb 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=../../.. \ @@ -152,6 +152,30 @@ function tribits_extract_other_doc { &> TribitsHelloWorldDirAndFiles.txt.tmp update_if_different TribitsHelloWorldDirAndFiles.txt tmp + echo + echo "Generating TribitsExampleProject2/Package1 CMakeList file variants ..." + echo + + cat ../../examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake \ + | grep -v EnableTribitsTestSupport \ + | grep -v GeneratePackageConfigFileForBuildDir \ + &> TribitsExampleProject2_Package1_CMakeLists.raw.external.cmake.tmp + update_if_different TribitsExampleProject2_Package1_CMakeLists.raw.external.cmake tmp + + cat ../../examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake \ + | grep -v EnableTribitsTestSupport \ + &> TribitsExampleProject2_Package1_CMakeLists.raw.internal.cmake.tmp + update_if_different TribitsExampleProject2_Package1_CMakeLists.raw.internal.cmake tmp + + cat ../../examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake \ + | grep -v "that TriBITS does automatically" \ + | grep -v DefineAllLibsTarget \ + | grep -v GeneratePackageConfigFileForBuildDir \ + | grep -v GeneratePackageConfigFileForInstallDir \ + &> TribitsExampleProject2_Package1_CMakeLists.raw.tribits_test.cmake.tmp + update_if_different \ + TribitsExampleProject2_Package1_CMakeLists.raw.tribits_test.cmake tmp + echo echo "Generating output for 'checkin-test.py --help' ..." echo @@ -246,8 +270,8 @@ function make_final_doc_in_subdir { if [[ "${skip_final_generation}" == "0" ]] ; then cd $dir_name echo $PWD - make - cd - + time make + cd - > /dev/null else echo echo "Skipping final generation of '${dir_name}' on request!" diff --git a/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/packages/package1/CMakeLists.raw.cmake b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake new file mode 100644 index 000000000..ad2a18182 --- /dev/null +++ b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.23.0 FATAL_ERROR) + +if (COMMAND tribits_package) + message("Configuring raw CMake package Package1") +else() + message("Configuring raw CMake project Package1") +endif() + +# Standard project-level stuff +project(Package1 LANGUAGES C CXX) +include(GNUInstallDirs) +find_package(Tpl1 CONFIG REQUIRED) +add_subdirectory(src) +if (Package1_ENABLE_TESTS) + include(CTest) + include("${CMAKE_CURRENT_LIST_DIR}/cmake/raw/EnableTribitsTestSupport.cmake") + add_subdirectory(test) +endif() + +# Stuff that TriBITS does automatically +include("${CMAKE_CURRENT_LIST_DIR}/cmake/raw/DefineAllLibsTarget.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/cmake/raw/GeneratePackageConfigFileForBuildDir.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/cmake/raw/GeneratePackageConfigFileForInstallDir.cmake") diff --git a/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 5f3b156eb..c8511aab3 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt +++ b/tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt @@ -1,57 +1,18 @@ cmake_minimum_required(VERSION 3.23.0 FATAL_ERROR) -macro(include_raw_cmake_build) - if (NOT COMMAND tribits_project) +set(Package1_USE_RAW_CMAKE OFF CACHE BOOL + "Use raw CMake for package build, even if TriBITS could be used.") + +# Macro to select the TriBITS or the raw CMake build system +macro(include_cmakelists_file) + if ((NOT COMMAND tribits_project) OR Package1_USE_RAW_CMAKE) include("${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.raw.cmake" NO_POLICY_SCOPE) - return() + else() + include("${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.tribits.cmake" + NO_POLICY_SCOPE) endif() endmacro() -if (COMMAND tribits_package) - - # Being processed as a TriBITS package - tribits_package(Package1) - add_subdirectory(src) - tribits_add_test_directories(test) - tribits_package_postprocess() - -else() - - message("Configuring raw CMake project Package1") - project(Package1 LANGUAGES C CXX) - include(GNUInstallDirs) - find_package(Tpl1 CONFIG REQUIRED) - add_subdirectory(src) - if (Package1_ENABLE_TESTS) - include(CTest) - add_subdirectory(test) - endif() - - # Generate the all_libs target - add_library(Package1_all_libs INTERFACE) - set_target_properties(Package1_all_libs PROPERTIES - EXPORT_NAME all_libs) - target_link_libraries(Package1_all_libs INTERFACE Package1_package1) - install( - TARGETS Package1_all_libs - EXPORT ${PROJECT_NAME} - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) - - # Generate and install the Package1Config.cmake file - install(EXPORT ${PROJECT_NAME} - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} - NAMESPACE ${PROJECT_NAME}:: - FILE ${PROJECT_NAME}ConfigTargets.cmake ) - configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/raw/Package1Config.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Package1Config.install.cmake" - @ONLY ) - install( - FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Package1Config.install.cmake" - RENAME "Package1Config.cmake" - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) - -endif() - - +# Pull in the base CMakeLists.txt file variant +include_cmakelists_file() diff --git a/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/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( 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/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..fef322152 100644 --- a/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.raw.cmake +++ b/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.raw.cmake @@ -1,3 +1,19 @@ add_test(NAME Package1_Prg COMMAND package1-prg) set_tests_properties(Package1_Prg PROPERTIES PASS_REGULAR_EXPRESSION "Package1 Deps: tpl1") + +add_test(NAME Package1_Prg-advanced COMMAND package1-prg something_extra) +set_tests_properties(Package1_Prg-advanced + PROPERTIES PASS_REGULAR_EXPRESSION "something_extra") + +# NOTE: With raw CMake/CTest, it is not possible to require the matches of +# multiple regexes (i.e. not the require the match of *both* "Package1 Deps: +# tpl1" and "something_extra"). Also, it is not possible to require a +# non-zero return code in addition to requiring a regex match the output. +# These more advanced features of tribits_add_advanced_test() would need to be +# provided by writing a wrapper script (e.g. using a Python script, a cmake -P +# script, etc.). Also, these tests don't support other features like: b) +# allow tests to be disabled for a variety of reasons like number of MPI +# processes required, incompatible system, disable cache variables -D +# _DISABLE=ON, etc.; b) printing which tests got added or did +# not get added and why when _TRACE_ADD_TEST=ON, etc. diff --git a/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..48d1f6e19 --- /dev/null +++ b/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.tribits.cmake @@ -0,0 +1,14 @@ +tribits_add_test(package1-prg NOEXEPREFIX NOEXESUFFIX + NAME Prg DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../src" NUM_MPI_PROCS 1 + PASS_REGULAR_EXPRESSION "Package1 Deps: tpl1" ) + +tribits_add_advanced_test(Prg-advanced + TEST_0 + EXEC package1-prg DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../src" + NOEXEPREFIX NOEXESUFFIX + ARGS "something_extra" + PASS_REGULAR_EXPRESSION_ALL + "Package1 Deps: tpl1" + "something_extra" + ALWAYS_FAIL_ON_NONZERO_RETURN + ) diff --git a/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.txt b/tribits/examples/TribitsExampleProject2/packages/package1/test/CMakeLists.txt index 906e0faf8..11b72aec0 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 AND (COMMAND tribits_add_test)) + message("-- Using TriBITS Test Functions in raw CMake Package1 build!") + include("${CMAKE_CURRENT_LIST_DIR}/CMakeLists.tribits.cmake") + else() + message("-- Using Raw CMake add_test() in raw CMake Package1 build!") + include("${CMAKE_CURRENT_LIST_DIR}/CMakeLists.raw.cmake") + endif() +else() + include("${CMAKE_CURRENT_LIST_DIR}/CMakeLists.tribits.cmake") +endif()