|
1 |
| -## Copyright 2017-2018, UT-Battelle, LLC |
2 |
| -## |
3 |
| -## SPDX-License-Identifier: BSD-3-Clause |
4 |
| -## License-Filename: LICENSE |
5 |
| - |
6 |
| -##---------------------------------------------------------------------------## |
7 |
| -## Define the package |
8 |
| -##---------------------------------------------------------------------------## |
9 |
| - |
10 |
| -TRIBITS_PACKAGE_DECL(ForTrilinos) |
11 |
| - |
12 |
| -##---------------------------------------------------------------------------## |
13 |
| -## Set up package-specific options |
14 |
| -##---------------------------------------------------------------------------## |
15 |
| - |
16 |
| -TRIBITS_ADD_DEBUG_OPTION() |
17 |
| -TRIBITS_ADD_SHOW_DEPRECATED_WARNINGS_OPTION() |
18 |
| - |
19 |
| -# Pick a default node to compile for in order of Cuda -> OpenMP -> Serial |
20 |
| -# For now we just build for this one node which is selected based on the config. |
21 |
| -# This is an intermediate step and expected to change later for supporting |
22 |
| -# all nodes simultaneously. |
23 |
| -IF (KOKKOS_ENABLE_CUDA) |
24 |
| - SET(Kokkos_NODE_TYPE "KokkosCudaWrapperNode") |
25 |
| -ELSEIF (KOKKOS_ENABLE_OPENMP) |
26 |
| - SET(Kokkos_NODE_TYPE "KokkosOpenMPWrapperNode") |
27 |
| -ELSE () |
28 |
| - SET(Kokkos_NODE_TYPE "KokkosSerialWrapperNode") |
29 |
| -ENDIF() |
30 |
| -MESSAGE(STATUS "ForTrilinos default node type: ${Kokkos_NODE_TYPE}") |
31 |
| - |
32 |
| -# Enable unlimited-length lines |
33 |
| -if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") |
34 |
| - SET(CMAKE_Fortran_FLAGS "-ffree-line-length-none ${CMAKE_Fortran_FLAGS}") |
| 1 | +#---------------------------------*-CMake-*----------------------------------# |
| 2 | +# Copyright 2020 UT-Battelle, LLC |
| 3 | +# License-Filename: LICENSE |
| 4 | +# SPDX-License-Identifier: BSD-3-Clause |
| 5 | +#----------------------------------------------------------------------------# |
| 6 | + |
| 7 | +cmake_minimum_required(VERSION 3.12) |
| 8 | +project(ForTrilinos VERSION 2.0.0 LANGUAGES Fortran CXX) |
| 9 | +cmake_policy(VERSION 3.12...3.18) |
| 10 | + |
| 11 | +list(APPEND CMAKE_MODULE_PATH |
| 12 | + "${CMAKE_CURRENT_LIST_DIR}/cmake" |
| 13 | +) |
| 14 | +if(CMAKE_VERSION VERSION_LESS 3.18) |
| 15 | + list(APPEND CMAKE_MODULE_PATH |
| 16 | + "${CMAKE_CURRENT_LIST_DIR}/cmake/backport/3.18" |
| 17 | + ) |
| 18 | +endif() |
| 19 | + |
| 20 | +include(GNUInstallDirs) |
| 21 | + |
| 22 | +#-----------------------------------------------------------------------------# |
| 23 | +# Component options |
| 24 | +#-----------------------------------------------------------------------------# |
| 25 | + |
| 26 | +# Only enable SWIG fortran when Fortran is enabled |
| 27 | +option(ForTrilinos_USE_SWIG_Fortran |
| 28 | + "Regenerate Fortran bindings with SWIG" OFF) |
| 29 | + |
| 30 | +#-----------------------------------------------------------------------------# |
| 31 | +# Deployment options |
| 32 | +#-----------------------------------------------------------------------------# |
| 33 | + |
| 34 | +option(BUILD_SHARED_LIBS "Default to building shared libraries" ON) |
| 35 | + |
| 36 | +if(NOT DEFINED CMAKE_INSTALL_RPATH_USE_LINK_PATH) |
| 37 | + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON CACHE STRING |
| 38 | + "Inform installed binaries of external library rpaths") |
| 39 | +endif() |
| 40 | +if(BUILD_SHARED_LIBS) |
| 41 | + set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}" CACHE STRING |
| 42 | + "Inform installed binaries of internal library rpaths") |
| 43 | +endif() |
| 44 | +if(APPLE) |
| 45 | + option(CMAKE_MACOSX_RPATH "Support @rpath in install targets" ON) |
35 | 46 | endif()
|
36 | 47 |
|
37 |
| -IF (${PACKAGE_NAME}_ENABLE_DeveloperMode) |
38 |
| - # SWIG setup |
39 |
| - FIND_PACKAGE(SWIG REQUIRED) |
40 |
| - # SWIG is requested and available; make sure it's the Fortran fork. |
41 |
| - INCLUDE(CheckSWIGFortran) |
42 |
| - IF (CMAKE_VERSION VERSION_LESS 3.10) |
43 |
| - # TODO: Old version of cmake modules |
44 |
| - include(SwigModulesOld) |
45 |
| - ELSE() |
46 |
| - include(SwigModules) |
47 |
| - ENDIF() |
48 |
| - |
49 |
| - # Ignore some SWIG warnings: |
50 |
| - # 401: "Nothing known about base class" |
51 |
| - LIST(APPEND CMAKE_SWIG_FLAGS "-w401" "-fext" "F90") |
52 |
| - set(SWIG_FORTRAN_EXTRA_FILE_EXTENSIONS ".F90") |
53 |
| - |
54 |
| - IF (NOT TPL_ENABLE_MPI) |
55 |
| - # Warn if MPI is disabled since not all wrapper functions will be |
56 |
| - # generated. Later this might be extended to other optional packages. |
57 |
| - MESSAGE(WARNING "DeveloperMode is being used without MPI: " |
58 |
| - "the newly generated wrappers will NOT be generated in the source " |
59 |
| - "directory, since they will not contain MPI-related classes.") |
60 |
| - ELSE() |
61 |
| - # Export the newly generated wrappers to the source directory. |
62 |
| - SET(ForTrilinos_EXPORT_SWIG TRUE CACHE BOOL |
63 |
| - "Build SWIG wrapper files in the source directory") |
64 |
| - ENDIF() |
65 |
| -ENDIF() |
66 |
| - |
67 |
| -##---------------------------------------------------------------------------## |
68 |
| -## Add the libraries, tests, and examples |
69 |
| -##---------------------------------------------------------------------------## |
70 |
| - |
71 |
| -# TRIBITS_ADD_EXAMPLE_DIRECTORIES(example) |
72 |
| -# TRIBITS_ADD_TEST_DIRECTORIES(test) |
73 |
| - |
74 |
| -##---------------------------------------------------------------------------## |
75 |
| -## Generate the Doxygen documentation |
76 |
| -##---------------------------------------------------------------------------## |
77 |
| -# There does not currently exist Doxygen documentation |
78 |
| -#IF(ForTrilinos_ENABLE_Doxygen) |
79 |
| -# ADD_SUBDIRECTORY(docs/doxygen) |
80 |
| -#ENDIF() |
81 |
| - |
82 |
| -##---------------------------------------------------------------------------## |
83 |
| -## Build the documentation published on http://fortrilinos.readthedocs.org |
84 |
| -##---------------------------------------------------------------------------## |
85 |
| -IF(ForTrilinos_ENABLE_ReadTheDocs) |
86 |
| - ADD_SUBDIRECTORY(docs) |
87 |
| -ENDIF() |
88 |
| - |
89 |
| -TRIBITS_PROCESS_SUBPACKAGES() |
90 |
| -TRIBITS_PACKAGE_DEF() |
91 |
| -TRIBITS_PACKAGE_POSTPROCESS() |
| 48 | +#-----------------------------------------------------------------------------# |
| 49 | +# Test options |
| 50 | +#-----------------------------------------------------------------------------# |
| 51 | + |
| 52 | +option(ForTrilinos_TESTING "Build ForTrilinos unit tests" OFF) |
| 53 | +option(ForTrilinos_EXAMPLES "Build ForTrilinos examples" OFF) |
| 54 | +set(ForTrilinos_MAX_NUMPROCS "0" CACHE STRING |
| 55 | + "Maximum number of processors to use in tests") |
| 56 | + |
| 57 | +#-----------------------------------------------------------------------------# |
| 58 | +# Internal variables |
| 59 | +#-----------------------------------------------------------------------------# |
| 60 | + |
| 61 | +# Prefix for exported ForTrilinos targets |
| 62 | +set(ForTrilinos_NAMESPACE "ForTrilinos::") |
| 63 | + |
| 64 | +# Destination for configured header files (config.h) during build |
| 65 | +set(ForTrilinos_HEADER_CONFIG_DIRECTORY "${PROJECT_BINARY_DIR}/include") |
| 66 | +# Where to configure cmake files |
| 67 | +set(ForTrilinos_CMAKE_CONFIG_DIRECTORY "${PROJECT_BINARY_DIR}/share") |
| 68 | +# Where to build .mod files |
| 69 | +set(ForTrilinos_Fortran_MODULE_DIRECTORY "${PROJECT_BINARY_DIR}/fortran") |
| 70 | + |
| 71 | +# Where to install cmake config files |
| 72 | +set(ForTrilinos_INSTALL_CMAKECONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/ForTrilinos") |
| 73 | + |
| 74 | +#-----------------------------------------------------------------------------# |
| 75 | +# LANGUAGE SUPPORT |
| 76 | +#-----------------------------------------------------------------------------# |
| 77 | + |
| 78 | +# Don't use compiler language extensions |
| 79 | +set(CMAKE_CXX_EXTENSIONS OFF) |
| 80 | + |
| 81 | +#-----------------------------------------------------------------------------# |
| 82 | +# DEPENDENCIES |
| 83 | +# |
| 84 | +# Derive options from Trilinos configuration where possible. |
| 85 | +#-----------------------------------------------------------------------------# |
| 86 | + |
| 87 | +find_package(Trilinos 12.17 REQUIRED MODULE |
| 88 | + COMPONENTS |
| 89 | + TeuchosCore TeuchosComm TeuchosNumerics TeuchosParameterList |
| 90 | + OPTIONAL_COMPONENTS |
| 91 | + # Optional |
| 92 | + Belos |
| 93 | + Tpetra |
| 94 | + # Required for fortrilinos_hl |
| 95 | + Anasazi NOX Stratimikos Thyra ThyraTpetraAdapters |
| 96 | + # Optional for fortrilinos_hl |
| 97 | + Amesos2 Ifpack2 MueLu |
| 98 | +) |
| 99 | + |
| 100 | +set(Trilinos_COMPONENTS ${COMPONENTS_LIST}) |
| 101 | +if("MPI" IN_LIST Trilinos_TPL_LIST) |
| 102 | + set(Trilinos_USE_MPI ON) |
| 103 | +endif() |
| 104 | + |
| 105 | +set(ForTrilinos_USE_MPI "${Trilinos_USE_MPI}" CACHE BOOL |
| 106 | + "MPI status depends on the Trilinos installation in use" FORCE) |
| 107 | + |
| 108 | +set(_fortrilinos_use_hl OFF) |
| 109 | +if(Trilinos_Anasazi_FOUND |
| 110 | + AND Trilinos_NOX_FOUND |
| 111 | + AND Trilinos_Stratimikos_FOUND |
| 112 | + AND Trilinos_Thyra_FOUND |
| 113 | + AND Trilinos_ThyraTpetraAdapters_FOUND) |
| 114 | + set(_fortrilinos_use_hl ON) |
| 115 | +endif() |
| 116 | +set(ForTrilinos_USE_HL "${_fortrilinos_use_hl}" CACHE BOOL |
| 117 | + "High-level ForTrilinos wrappers depend on Trilinos installation" FORCE) |
| 118 | + |
| 119 | +if(ForTrilinos_USE_MPI) |
| 120 | + if(NOT MPIEXEC_EXECUTABLE) |
| 121 | + # Hint for MPI |
| 122 | + set(MPIEXEC_EXECUTABLE "${TeuchosComm_MPI_EXEC}") |
| 123 | + endif() |
| 124 | + find_package(MPI REQUIRED COMPONENTS CXX Fortran) |
| 125 | + if(NOT ForTrilinos_MAX_NUMPROCS) |
| 126 | + # Not set or default of zero |
| 127 | + set(ForTrilinos_MAX_NUMPROCS "${MPIEXEC_MAX_NUMPROCS}" CACHE STRING |
| 128 | + "Maximum number of processors to use in tests" FORCE) |
| 129 | + elseif(ForTrilinos_MAX_NUMPROCS GREATER MPIEXEC_MAX_NUMPROCS) |
| 130 | + message(WARNING "Maximim number of processors in MPI " |
| 131 | + "tests exceeds the system-detected processor count: " |
| 132 | + "${ForTrilinos_MAX_NUMPROCS} > ${MPIEXEC_MAX_NUMPROCS}" |
| 133 | + ) |
| 134 | + endif() |
| 135 | +else() |
| 136 | + set(ForTrilinos_MAX_NUMPROCS "1" CACHE INTERNAL |
| 137 | + "Maximum number of processors to use in tests") |
| 138 | +endif() |
| 139 | + |
| 140 | +if(ForTrilinos_USE_SWIG_Fortran) |
| 141 | + find_package(SWIG REQUIRED COMPONENTS fortran) |
| 142 | + include(UseSWIG) |
| 143 | + |
| 144 | + if(NOT ForTrilinos_USE_MPI) |
| 145 | + message(WARNING "DeveloperMode is being used without MPI: " |
| 146 | + "the newly generated wrappers will NOT be generated in the source " |
| 147 | + "directory, since they will not contain MPI-related classes.") |
| 148 | + endif() |
| 149 | +endif() |
| 150 | + |
| 151 | +if(ForTrilinos_TESTING OR ForTrilinos_EXAMPLES) |
| 152 | + include(CTest) |
| 153 | +endif() |
| 154 | + |
| 155 | +#---------------------------------------------------------------------------## |
| 156 | +# LIBRARY |
| 157 | +#---------------------------------------------------------------------------## |
| 158 | + |
| 159 | +add_subdirectory(src) |
| 160 | + |
| 161 | +#---------------------------------------------------------------------------## |
| 162 | +# TESTS |
| 163 | +#---------------------------------------------------------------------------## |
| 164 | + |
| 165 | +if(ForTrilinos_TESTING) |
| 166 | + add_subdirectory(test) |
| 167 | +endif() |
| 168 | + |
| 169 | +#---------------------------------------------------------------------------## |
| 170 | +# EXAMPLES |
| 171 | +#---------------------------------------------------------------------------## |
| 172 | + |
| 173 | +if(ForTrilinos_EXAMPLES) |
| 174 | + add_subdirectory(example) |
| 175 | +endif() |
| 176 | + |
| 177 | +#---------------------------------------------------------------------------## |
| 178 | +# INSTALLATION |
| 179 | +#---------------------------------------------------------------------------## |
| 180 | + |
| 181 | +include(ForTrilinosConfigSetup) |
| 182 | +fortrilinos_configure_export() |
| 183 | + |
| 184 | +#---------------------------------------------------------------------------## |
0 commit comments