diff --git a/demos/simpleBuildAgainstTrilinos/CMakeLists.by_package.cmake b/demos/simpleBuildAgainstTrilinos/CMakeLists.by_package.cmake new file mode 100644 index 000000000000..868975573cc3 --- /dev/null +++ b/demos/simpleBuildAgainstTrilinos/CMakeLists.by_package.cmake @@ -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). diff --git a/demos/simpleBuildAgainstTrilinos/README.md b/demos/simpleBuildAgainstTrilinos/README.md index f93bb2e995db..8c707afb4259 100644 --- a/demos/simpleBuildAgainstTrilinos/README.md +++ b/demos/simpleBuildAgainstTrilinos/README.md @@ -45,6 +45,15 @@ This will put a file called `TrilinosConfig.cmake` under a subdirectory of /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 ``` diff --git a/packages/TrilinosInstallTests/CMakeLists.txt b/packages/TrilinosInstallTests/CMakeLists.txt index d006a1227433..fb0219d4d7e7 100644 --- a/packages/TrilinosInstallTests/CMakeLists.txt +++ b/packages/TrilinosInstallTests/CMakeLists.txt @@ -56,7 +56,7 @@ tribits_package(TrilinosInstallTests) -tribits_add_advanced_test(doInstall +tribits_add_advanced_test(removeInstall OVERALL_NUM_MPI_PROCS 1 TEST_0 @@ -65,7 +65,82 @@ 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= 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} @@ -73,7 +148,7 @@ tribits_add_advanced_test(doInstall 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 @@ -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()