Skip to content

Commit

Permalink
Add test simpleBuildAgainstTrilinos_by_package_build_tree_name (#11545)
Browse files Browse the repository at this point in the history
This commit does a few things:

* A removeInstall test is split off from the doInstall test

* A new simpleBuildAgainstTrilinos/CMakeLists.by_package.cmake file is created
  to show how to find the packages you want from Trilinos and not actually
  find Trilinos.

* New test simpleBuildAgainstTrilinos_by_package_build_tree_name is added
  which depends on removeInstall and points to the build tree.

This demonstrates and protects using Trilinos packages from the build tree and
how to find Trilinos by packages instead of as a big thing.
  • Loading branch information
bartlettroscoe committed May 12, 2023
1 parent 2e6a11b commit 0d364f8
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 4 deletions.
38 changes: 38 additions & 0 deletions demos/simpleBuildAgainstTrilinos/CMakeLists.by_package.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# CMAKE File for "MyApp" application building against an installed Trilinos

cmake_minimum_required(VERSION 3.0)

# Define the project and the compilers
#
# NOTE: You can't call find_package(Trilinos) for a CUDA build without first
# defining the compilers.
#
project(MyApp C CXX)

# Disable Kokkos warning about not supporting C++ extensions
set(CMAKE_CXX_EXTENSIONS OFF)

# Get just Tpetra as
find_package(Tpetra REQUIRED)

# Echo trilinos build info just for fun
message("\nFound Tpetra! Here are the details: ")
message(" Tpetra_DIR = ${Tpetra_DIR}")

# Build the APP and link to Trilinos
add_executable(MyApp ${CMAKE_CURRENT_SOURCE_DIR}/app.cpp)
target_link_libraries(MyApp Tpetra::all_libs)

# Set up a test
enable_testing()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/input.xml
${CMAKE_CURRENT_BINARY_DIR}/input.xml COPYONLY)
set(NUM_MPI_PROCS 4)
add_test(MyAppTest mpiexec -np ${NUM_MPI_PROCS} "${CMAKE_CURRENT_BINARY_DIR}/MyApp")
set_tests_properties(MyAppTest PROPERTIES
PROCESSORS ${NUM_MPI_PROCS}
PASS_REGULAR_EXPRESSION "vec.norm1[(][)] = 40"
)
# NOTE: Above, mpiexec with mpich-3.2 requires you pass in the abs path to
# MyApp or mpiexec says it can't find it, even though it is running in the
# correct directory (see #10813).
9 changes: 9 additions & 0 deletions demos/simpleBuildAgainstTrilinos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ This will put a file called `TrilinosConfig.cmake` under a subdirectory of
<trilinos-src>/demos/simpleBuildAgainstTrilinos
```

NOTE: To use the alternative `CMakeLists.txt` file that calls
`find_package(Tpetra)` and links to `Tpetra::all_libs` instead of
`find_package(Trilinos)`, copy the source tree `simpleBuildAgainstTrilinos` to
a directory outside of the Trilinos source tree, copy the file
`simpleBuildAgainstTrilinos/CMakeLists.by_package.cmake` to
`simpleBuildAgainstTrilinos/CMakeLists.txt` and then configure as shown above
(pointing to the copied and modified `simpleBuildAgainstTrilinos` source
tree).

## 4. Build the application

```
Expand Down
84 changes: 80 additions & 4 deletions packages/TrilinosInstallTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
tribits_package(TrilinosInstallTests)


tribits_add_advanced_test(doInstall
tribits_add_advanced_test(removeInstall
OVERALL_NUM_MPI_PROCS 1

TEST_0
Expand All @@ -65,15 +65,90 @@ tribits_add_advanced_test(doInstall
ARGS "-DDIR_TO_REMOVE=${PROJECT_BINARY_DIR}/install"
-P "${CMAKE_CURRENT_SOURCE_DIR}/remove_dir_if_exists.cmake"

ADDED_TEST_NAME_OUT removeInstall_name
)
# NOTE: Above works even if Trilinos was configured without setting
# -DCMAKE_PREFIX_PATH=<prefix> and tests proper usage of the install()
# command. However, note that it is not a perfect installation test because
# the source dir and the build dir will still be sticking around in the
# below example build.

if (removeInstall_name)
set_tests_properties(${removeInstall_name}
PROPERTIES FIXTURES_SETUP removeInstall_passed)
endif()


tribits_add_advanced_test(simpleBuildAgainstTrilinos_by_package_build_tree
OVERALL_NUM_MPI_PROCS 1
OVERALL_WORKING_DIRECTORY TEST_NAME
EXCLUDE_IF_NOT_TRUE ${PROJECT_NAME}_ENABLE_Tpetra TPL_ENABLE_MPI

TEST_0
MESSAGE "Copy simpleBuildAgainstTrilinos so we can modify it"
CMND "${CMAKE_COMMAND}"
ARGS -E copy_directory
${PROJECT_SOURCE_DIR}/demos/simpleBuildAgainstTrilinos
simpleBuildAgainstTrilinos

TEST_1
MESSAGE "Copy CMakeLists.by_package.cmake to find by package"
CMND "${CMAKE_COMMAND}"
ARGS -E copy
simpleBuildAgainstTrilinos/CMakeLists.by_package.cmake
simpleBuildAgainstTrilinos/CMakeLists.txt

TEST_2
MESSAGE "Configure simpleBuildAgainstTrilinos against built packages"
CMND "${CMAKE_COMMAND}"
ARGS
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_Fortan_COMPILER=${CMAKE_Fortran_COMPILER}
-DCMAKE_PREFIX_PATH=${PROJECT_BINARY_DIR}/cmake_packages
-DCMAKE_BUILD_TYPE=DEBUG
simpleBuildAgainstTrilinos
PASS_REGULAR_EXPRESSION_ALL
"Found Tpetra. Here are the details:"
"-- Configuring done"
"-- Generating done"
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_3
MESSAGE "Build simpleBuildAgainstTrilinos"
CMND "${CMAKE_COMMAND}"
ARGS --build .

TEST_4
MESSAGE "Test simpleBuildAgainstTrilinos"
CMND "${CMAKE_CTEST_COMMAND}"
ARGS -VV
PASS_REGULAR_EXPRESSION_ALL
"Test #1: MyAppTest [.]+ +Passed"
"100% tests passed, 0 tests failed out of 1"
ALWAYS_FAIL_ON_NONZERO_RETURN

ADDED_TEST_NAME_OUT simpleBuildAgainstTrilinos_by_package_build_tree_name
)

if (simpleBuildAgainstTrilinos_by_package_build_tree_name)
set_tests_properties(${simpleBuildAgainstTrilinos_by_package_build_tree_name}
PROPERTIES FIXTURES_REQUIRED removeInstall_passed)
endif()


tribits_add_advanced_test(doInstall
OVERALL_NUM_MPI_PROCS 1

TEST_0
MESSAGE "Install enabled and built Trilinos packages (NOTE: This test will fail if the project has **any** build errors!)"
CMND "${CMAKE_COMMAND}"
ARGS --install ${PROJECT_BINARY_DIR}
--prefix ${PROJECT_BINARY_DIR}/install
OUTPUT_FILE doInstall.out
NO_ECHO_OUTPUT

TEST_2
TEST_1
MESSAGE "Grep doInstall.out file produced above to see any errors"
CMND grep ARGS -A 50 "CMake Error" doInstall.out
PASS_ANY
Expand All @@ -87,8 +162,9 @@ tribits_add_advanced_test(doInstall
# below example build.

if (doInstall_name)
set_tests_properties(${doInstall_name}
PROPERTIES FIXTURES_SETUP doInstall_passed)
set_tests_properties(${doInstall_name} PROPERTIES
FIXTURES_REQUIRED removeInstall_passed
FIXTURES_SETUP doInstall_passed )
endif()


Expand Down

0 comments on commit 0d364f8

Please sign in to comment.