Debian Codegraph @

commonTools/importing/README.Finding_Trilinos

raw
1 Trilinos has the capability to allow other CMake-aware projects to use the
2 FIND_PACKAGE(...) call to discover the path to Trilinos and its packages and set
3 some important variables. Using FIND_PACKAGE(Trilinos) to discover Trilinos will
4 provide you with a lot of useful information about how Trilinos was built,
5 including compilers, compiler options, which packages were enabled etc. In
6 addition to finding just Trilinos you can also use FIND_PACKAGE to find
7 individual packages.
8
9 There are two versions of this system, one for an installation of Trilinos, and
10 another for a build tree of Trilinos. The only difference between the versions
11 is the information that is stored in the variables being relative to an install
12 tree versus relative to a build tree. The variables still have the same meaning
13 and names regardless of which type you are using.
14
15 The easiest way to use this is to add FIND_PACKAGE(Trilinos PATHS <any search paths>)
16 to your project's CMakeLists.txt file. You can also use
17 FIND_PACKAGE(Trilinos <version number> PATHS <any search paths> [EXACT]) if you
18 want to find a version known to be compatible with the given version number or
19 that exact version of Trilinos if you give the EXACT option. Aside from the
20 normal variables that CMake sets when it finds a package you will be able to
21 make the build of your project consistent with how Trilinos was built. If you
22 are only interested in a set of specific packages you can also use
23 FIND_PACKAGE(<package name>) for each package. All of the same information will
24 be available, however the variables will reflect the name of the package and not
25 Trilinos. Throughout the rest of this readme you can replace "Trilinos_" with
26 "<package>_" for the cases where you are looking for a specific package
27
28 The variables most projects will be interested in are those that store which
29 Trilinos packages were enabled, their libraries, and the tpls that Trilinos was
30 configured with. The following variables contain that information. There is a
31 minor difference between these variables for Trilinos as a whole and for an
32 individual package. For projects that use FIND_PACKAGE(Trilinos) these variables
33 will hold the complete set of packages or tpls that were enabled for Trilinos.
34 This is guaranteed to be the full set of what Trilinos was configured with. When
35 you use FIND_PACKAGE to find individual Trilinos packages, only those packages
36 and tpls which were both enabled for the Trilinos build and enabled for the
37 specific package will be contained in these variables. In this way, the
38 <package>Config.cmake file is more accurate than the TrilinosConfig.cmake when
39 you are interested in specific dependencies for a package. However, the
40 TrilinosConfig.cmake file does include the <package>Config.cmake files for every
41 package that was enabled. So if you want to use FIND_PACKAGE(Trilinos) you still
42 have access to all of the package variables so that you can inspect them for
43 any dependencies that they have which you might need to know about.
44
45 Compiler variables:
46
47 The C++ compiler is in Trilinos_CXX_COMPILER and the options for the C++
48 compilier are in Trilinos_CXX_COMPILER_FLAGS.
49
50 The C compiler is in Trilinos_C_COMPILER and the options for the C compiler are
51 in Trilinos_C_COMPILER_FLAGS
52
53 The Fortran compiler is in Trilinos_Fortran_COMPILER and the options for the
54 Fortran compiler are in Trilinos_Fortran_COMPILER_FLAGS
55
56 If Trilinos was built as shared libraries, Trilinos_BUILD_SHARED_LIBS will be
57 set to ON, and any additional rpaths needed will be in
58 Trilinos_SHARED_LIB_RPATH_COMMAND.
59
60 Any additional options that were passed to the linker for Trilinos or a package
61 can be found in the variable Trilinos_EXTRA_LD_FLAGS.
62
63 Packages, TPLs and other library variables.
64
65 Trilinos_INCLUDE_DIRS holds the paths to all the header files for all packages
66 that Trilinos was configured with.
67
68 Trilinos_LIBRARY_DIRS holds the paths to all the library files for all packages
69 that Trilinos was configured with.
70
71 Trilinos_LIBRARIES is the complete list of all the libraries for the packages
72 that Trilinos was configured with. This list is in the proper order for linking
73 so it is safe to just add this to a "target_link_libraries" command. If you want
74 to loop over this variable and use each library individually you will most
75 likely want to take care not to rearrange the relative ordering of the Trilinos
76 libraries. If you depend on several Trilinos packages and have used FIND_PACKAGE
77 to find the individual packages you will need to concatenate the
78 <package>_LIBRARIES variables from the packages you depend on. It is common for
79 Trilinos packages to have dependencies on other Trilinos packages. simply
80 concatenating these lists together will often result in some libraries being on
81 the link line multiple times. While this isn't typically harmful it isn't ideal.
82 You can avoid this by using the CMake call LIST(REMOVE_DUPLICATES ...), however,
83 you need to do a bit of prep work to make this work right. Since
84 remove_duplicates keeps the first instance and removes the later instances to
85 maintain proper order for linking you will have to reverse the list then remove
86 the duplicates and then reverse the list again. This isn't very intuitive, but
87 thankfully CMake has built in commands to handle this easily. Something like the
88 following should be all you need.
89
90 LIST(REVERSE <full_library_list>)
91 LIST(REMOVE_DUPLICATES <full_library_list>)
92 LIST(REVERSE <full_library_list>)
93
94 Trilinos_TPL_INCLUDE_DIRS holds the paths to all the header files needed by all
95 TPLs that were enabled.
96
97 Trilinos_TPL_LIBRARY_DIRS holds the paths to all the library files for all the
98 TPLs that were enabled. Note that some TPLs return their absolute path to their
99 libraries when they are found. In those instances the TPLs typically do not set
100 this variable as well. This won't affect linking, but it does make it harder to
101 rely on only this variable to look for the paths to all enabled TPLs.
102
103 Trilinos_TPL_LIBRARIES holds the full list of libraries for the enabled TPLs.
104 For Trilinos this is guaranteed to be in the correct order for linking if there
105 are dependencies between TPLs. This should generally be true for individual
106 packages as well. However, there isn't currently a mechanic in place that
107 guarantees this. There has been some care taken to ensure that these libraries
108 come out in the right order, however, if you run into a case where this is not
109 true please let us know so that we can fix it.
110
111 Trilinos_PACKAGE_LIST holds the complete list of all enabled packages for
112 Trilinos. For individual packages this will only hold the packages which the
113 given package has a dependency on and that dependency was enabled. This list is
114 very useful in determining the actual dependencies of a package for the
115 individual package case. If you know which package you would like to check
116 dependency on you can use:
117 LIST(FIND Trilinos_PACKAGE_LIST <package name> package_index)
118 Variable package_index will return -1 if it is not in the list.
119 If you do not know which other packages that your package of
120 interest depends on but want to include their options as well you could loop
121 over this list and then use each individual package name as the argument to a
122 FIND_PACKAGE call. You generally won't need to do this if you just want to link
123 your package of interest as everything required to properly link that package
124 will have already been set in the above variables. However, there are cases
125 where this information is useful, such as if you can optionally use features
126 from the dependencies of your package of interest.
127
128
129 Trilinos_TPL_LIST holds the complete list of TPLs that were enabled for
130 Trilinos. It is possible for Trilinos to be configured with TPLs that are not
131 used by any of the enabled packages. This won't cause any errors in such a case,
132 but if you are interested in getting the minimum set of TPLs then it would be
133 best to check this variable for the packages you are interested in. For
134 individual packages this will hold only those TPLs that the package was
135 configured to use.
136
137
138 Trilinos_VERSION holds the version number for Trilinos. This variable does not
139 exist for individual packages as there is no common versioning system for the
140 packages and many do not state this version in their CMakeLists.txt files.
141
142 Other general variables:
143
144 Trilinos_LINKER holds the linker that Trilinos was configured for. Typically
145 it is safe to use any linker that supports the library type that Trilinos was
146 compiled for, but if you want to use the exact same linker executable that
147 Trilinos used, you can get it from this variable.
148
149 Trilinos_AR holds the archiving utility that was used to make the Trilinos
150 libraries if they were compiled as static libraries. Again using a different but
151 compatible archiver is generally fine, but if you want to use the same one as
152 Trilinos you can use this variable.
153
154 Trilinos_MPI_LIBRARIES holds the libraries for MPI specifically. These
155 duplicated here to make it easier in cases where you do not use MPI wrappers for
156 compiling to make sure you are using the right MPI library.
157
158 Trilinos_MPI_LIBRARY_DIRS holds any directories that will need to be put on the
159 link line to find the MPI libraries. These duplicated here to make it easier in
160 cases where you do not use MPI wrappers for compiling to make sure you are using
161 the right MPI library.
162
163 Trilinos_MPI_INCLUDE_DIRS holds any directories that will need to be put on the
164 compile line to find the MPI headers. These duplicated here to make it easier
165 in cases where you do not use MPI wrappers for compiling to make sure you are
166 using the right MPI library.
167
168 Trilinos_MPI_EXEC holds the mpi run program that was used when testing Trilinos.
169 This is useful if you want to make sure you are running your tests with the same
170 mpi run that Trilinos used.
171
172 Trilinos_MPI_EXEC_MAX_NUMPROCS holds the maximum number of processors that
173 Trilinos was tested with. This is useful if you want to make sure that you limit
174 your own testing to the same parameters that Trilinos was tested with.
175
176 Trilinos_MPI_EXEC_NUMPROCS_FLAG holds the flag to pass to Trilinos_MPI_EXEC to
177 specify the number of processors to run on.
178
179 --------------------------------------------------------------------------------
180 Example CMakeLists.txt file:
181
182 # CMAKE File for "MyApp" application building against an installed Trilinos
183
184 #This file was created by modifiying the files in
185 #Trilinos/demos/buildAgaintsTrilinos. The primary change was to make it a single
186 #file cmake system in a flat directory. If you would like to run a cmake
187 #configure using this file you should grab this file and src_file.cpp,
188 #src_file.hpp, main_file.cpp from buildAgainstTrilinos and place them in a new
189 #directory. From there you can run:
190 #"cmake -DTrilinos_PREFIX=<path to trilinos>." to configure. Another
191 #important change is the buildAgainstTrilinos does some checking to see which
192 #packages and tpls are enabled and behaves accordingly. However, this file does
193 #only a serial configure(no mpi) and assumes that the install of Trilinos it is
194 #pointed to has Epetra enabled.
195
196 cmake_minimum_required(VERSION 2.8)
197
198 # Use Trilinos_PREFIX, if the user set it, to help find Trilinos.
199 # The final location will actually be held in Trilinos_DIR which must
200 # point at "<prefix>/lib/cmake/Trilinos", but this helps the search.
201 SET(CMAKE_PREFIX_PATH ${Trilinos_PREFIX} ${CMAKE_PREFIX_PATH})
202
203 # Get Trilinos as one entity
204 FIND_PACKAGE(Trilinos REQUIRED)
205
206 # Echo trilinos build info just for fun
207 MESSAGE("\nFound Trilinos! Here are the details: ")
208 MESSAGE(" Trilinos_DIR = ${Trilinos_DIR}")
209 MESSAGE(" Trilinos_VERSION = ${Trilinos_VERSION}")
210 MESSAGE(" Trilinos_PACKAGE_LIST = ${Trilinos_PACKAGE_LIST}")
211 MESSAGE(" Trilinos_LIBRARIES = ${Trilinos_LIBRARIES}")
212 MESSAGE(" Trilinos_INCLUDE_DIRS = ${Trilinos_INCLUDE_DIRS}")
213 MESSAGE(" Trilinos_LIBRARY_DIRS = ${Trilinos_LIBRARY_DIRS}")
214 MESSAGE(" Trilinos_TPL_LIST = ${Trilinos_TPL_LIST}")
215 MESSAGE(" Trilinos_TPL_INCLUDE_DIRS = ${Trilinos_TPL_INCLUDE_DIRS}")
216 MESSAGE(" Trilinos_TPL_LIBRARIES = ${Trilinos_TPL_LIBRARIES}")
217 MESSAGE(" Trilinos_TPL_LIBRARY_DIRS = ${Trilinos_TPL_LIBRARY_DIRS}")
218 MESSAGE(" Trilinos_BUILD_SHARED_LIBS = ${Trilinos_BUILD_SHARED_LIBS}")
219 MESSAGE("End of Trilinos details\n")
220
221 # Make sure to use same compilers and flags as Trilinos
222 SET(CMAKE_CXX_COMPILER ${Trilinos_CXX_COMPILER} )
223 SET(CMAKE_C_COMPILER ${Trilinos_C_COMPILER} )
224 SET(CMAKE_Fortran_COMPILER ${Trilinos_Fortran_COMPILER} )
225
226 SET(CMAKE_CXX_FLAGS "${Trilinos_CXX_COMPILER_FLAGS} ${CMAKE_CXX_FLAGS}")
227 SET(CMAKE_C_FLAGS "${Trilinos_C_COMPILER_FLAGS} ${CMAKE_C_FLAGS}")
228 SET(CMAKE_Fortran_FLAGS "${Trilinos_Fortran_COMPILER_FLAGS} ${CMAKE_Fortran_FLAGS}")
229
230 #
231 # End of setup and error checking
232 # NOTE: PROJECT command checks for compilers, so this statement
233 # is moved AFTER setting CMAKE_CXX_COMPILER from Trilinos
234
235 PROJECT(MyApp)
236
237 ADD_DEFINITIONS(-DMYAPP_EPETRA)
238
239 INCLUDE_DIRECTORIES(${Trilinos_INCLUDE_DIRS} ${Trilinos_TPL_INCLUDE_DIRS})
240 LINK_DIRECTORIES(${Trilinos_LIBRARY_DIRS} ${Trilinos_TPL_LIBRARY_DIRS})
241
242 ADD_LIBRARY(myappLib src_file.cpp src_file.hpp)
243
244 ADD_EXECUTABLE(MyApp.exe main_file.cpp)
245
246 TARGET_LINK_LIBRARIES(MyApp.exe myappLib ${Trilinos_LIBRARIES} ${Trilinos_TPL_LIBRARIES})
247
248 enable_testing()
249 add_test(NAME MyTest COMMAND MyApp.exe)
250