Debian Codegraph @

commonTools/importing/README.Export_Makefile

raw
1 Trilinos has the capability to allow Makefiles to import important variables
2 that can be used to compile against either a Trilinos installation or a build
3 tree. This capability is similar to the previously supported autotools
4 Makefile.export system. There are some important differences though as the
5 newer capability also takes some of it's functionality from the similar in
6 concept find Trilinos capability for CMake aware projects.
7
8 There are two versions of this system, one for an installation of Trilinos, and
9 another for a build tree of Trilinos. The only difference between the versions
10 is the information that is stored in the variables being relative to an install
11 tree versus relative to a build tree. The variables still have the same meaning
12 and names regardless of which type you are using.
13
14 The way to import this into your project is to use the following line:
15 include Makefile.export.<package>
16 Where <package> is any Trilinos package or "Trilinos" itself.
17
18
19 The variables most projects will be interested in are those that store which
20 Trilinos packages were enabled, their libraries, and the tpls that Trilinos was
21 configured with. The following variables contain that information. There is a
22 minor difference between these variables for Trilinos as a whole and for an
23 individual package. For projects that import Makefile.export.Trilinos these
24 variables will hold the complete set of packages and tpls that were enabled for
25 Trilinos. This is guaranteed to be the full set of what Trilinos was configured
26 with. When you import Makefile.export.<package> to find individual Trilinos
27 packages, only those packages and tpls which were both enabled for the Trilinos
28 build and enabled for the specific package will be contained in these variables.
29 In this way, the Makefile.export.<package> file is more accurate than the
30 Makefile.export.Trilinos when you are interested in specific dependencies for a
31 package. If you built Trilinos yourself specifically for your project you might
32 find it easier to use Makefile.export.Trilinos as it will have everything you
33 need in one place if you use multiple Trilinos packages. However, if you are
34 using a pre-installed copy of Trilinos it will likely be better for you to
35 import each package you need individually.
36
37 Throughout the rest of this readme you can replace "Trilinos_" with
38 "<package>_" for the cases where you are looking for a specific package.
39
40 Compiler variables:
41
42 The C++ compiler is in Trilinos_CXX_COMPILER and the options for the C++
43 compilier are in Trilinos_CXX_COMPILER_FLAGS.
44
45 The C compiler is in Trilinos_C_COMPILER and the options for the C compiler are
46 in Trilinos_C_COMPILER_FLAGS.
47
48 The Fortran compiler is in Trilinos_Fortran_COMPILER and the options for the
49 Fortran compiler are in Trilinos_Fortran_COMPILER_FLAGS.
50
51 If Trilinos was built as shared libraries, Trilinos_BUILD_SHARED_LIBS will be
52 set to ON, and any additional rpaths needed will be in
53 Trilinos_SHARED_LIB_RPATH_COMMAND.
54
55 Any additional options that were passed to the linker for Trilinos or a package
56 can be found in the variable Trilinos_EXTRA_LD_FLAGS.
57
58 Packages, TPLs and other library variables.
59
60 Trilinos_INCLUDE_DIRS holds the paths to all the header files for all packages
61 that Trilinos was configured with. Each path in this variable will have the -I
62 already prepended to it.
63
64 Trilinos_LIBRARY_DIRS holds the paths to all the library files for all packages
65 that Trilinos was configured with. Each path in this variable wil have the -L
66 already prepended to it.
67
68 Trilinos_LIBRARIES is the complete list of all the libraries for the packages
69 that Trilinos was configured with. This list is in the proper order for linking
70 so it is safe to just add this to a Makefile link target. Each library in this
71 variable will have -l already prepended to it. If you are using multiple
72 packages and are importing several specific Makefile.export.<package> you will
73 need to add each package's <package>_LIBRARIES variable to your link target.
74 Note that if you are doing this there is a good chance that there will be
75 repeated libraries on your link line. If you have a small set of
76 dependencies this might not be a problem, but if you have a large set it could
77 dramatically increase you link time. If this is a concern you will need to strip
78 out the duplicates while making sure not to change the order of the libraries.
79
80 Trilinos_TPL_INCLUDE_DIRS holds the paths to all the header files needed by all
81 TPLs that were enabled. Each path in this variable will have the -I already
82 prepended to it.
83
84 Trilinos_TPL_LIBRARY_DIRS holds the paths to all the library files for all the
85 TPLs that were enabled. Note that some TPLs return their absolute path to their
86 libraries when they are found. In those instances the TPLs typically do not set
87 this variable as well. This won't affect linking, but it does make it harder to
88 rely on only this variable to look for the paths to all enabled TPLs. Each path
89 in this variable wil have the -L already prepended to it.
90
91 Trilinos_TPL_LIBRARIES holds the full list of libraries for the enabled TPLs.
92 For Trilinos this is guaranteed to be in the correct order for linking if there
93 are dependencies between TPLs. This should generally be true for individual
94 packages as well. However, there isn't currently a mechanism in place that
95 guarantees this. There has been some care taken to ensure that these libraries
96 come out in the right order, however, if you run into a case where this is not
97 true please let us know so that we can fix it. Generally each library in this
98 variable will have -l already prepended to it however, some libaries are return
99 their absolute path, in those cases the library path is used verbatim and -l is
100 not prepended to it.
101
102 Trilinos_PACKAGE_LIST holds the complete list of all enabled packages for
103 Trilinos. For individual packages this will only hold the packages which the
104 given package has a dependency on and that dependency was enabled. This list is
105 very useful in determining the actual dependencies of a package for the
106 individual package case. If you just want to link against a package everything
107 required to do that is in the above variables. However, if your project can
108 optionally use features from the package, this variable is useful for
109 determining which features were enabled.
110
111 Trilinos_TPL_LIST holds the complete list of TPLs that were enabled for
112 Trilinos. It is possible for Trilinos to be configured with TPLs that are not
113 used by any of the enabled packages. This won't cause any errors,
114 but if you are interested in getting the minimum set of TPLs then it would be
115 best to check this variable for the packages you are interested in. For
116 individual packages this will hold only those TPLs that the package was
117 configured to use.
118
119
120 Trilinos_VERSION holds the version number for Trilinos. This variable does not
121 exist for individual packages as there is no common package versioning system.
122
123 Other general variables:
124
125 Trilinos_LINKER holds the linker that Trilinos was configured for. Typically
126 it is safe to use any linker that supports the library type that Trilinos was
127 compiled for, but if you want to use the exact same linker executable that
128 Trilinos used, you can get it from this variable.
129
130 Trilinos_AR holds the archiving utility that was used to make the Trilinos
131 libraries if they were compiled as static libraries. Again using a different but
132 compatible archiver is generally fine, but if you want to use the same one as
133 Trilinos you can use this variable.
134
135 Trilinos_MPI_LIBRARIES holds the libraries for MPI specifically. These are
136 duplicated here to make it easier in cases where you do not use MPI wrappers for
137 compiling to make sure you are using the right MPI library. Each library in this
138 variable will have the -l already prepended to it.
139
140 Trilinos_MPI_LIBRARY_DIRS holds any directories that will need to be put on the
141 link line to find the MPI libraries. These are duplicated here to make it easier
142 in cases where you do not use MPI wrappers for compiling to make sure you are
143 using the right MPI library. Each path in this variable will have the -L already
144 prepended to it.
145
146 Trilinos_MPI_INCLUDE_DIRS holds any directories that will need to be put on the
147 compile line to find the MPI headers. These are duplicated here to make it
148 easier in cases where you do not use MPI wrappers for compiling to make sure
149 you are using the right MPI library. Each path in this variable will have the -I
150 already prepended to it.
151
152 Trilinos_MPI_EXEC holds the mpi run program that was used when testing Trilinos.
153 This is useful if you want to make sure you are running your tests with the same
154 mpi run that Trilinos used.
155
156 Trilinos_MPI_EXEC_MAX_NUMPROCS holds the maximum number of processors that
157 Trilinos was tested with. This is useful if you want to make sure that you limit
158 your own testing to the same parameters that Trilinos was tested with.
159
160 Trilinos_MPI_EXEC_NUMPROCS_FLAG holds the flag to pass to Trilinos_MPI_EXEC to
161 specify the number of processors to run on.
162
163 See Export_Makefile.example for a simple example of how to use this capability.
164
165 Transitioning from the previous systems:
166
167 There are some important differences between the previous 2 systems that
168 Trilinos has made available. Mostly these differences are in the names of
169 variables, however, there is not always a one to one relationship between the
170 old variable names and the new ones, which can make it confusing as to which
171 variables are needed and how they are to be used.
172
173 In the Makefile export system that was available in Trilinos 9, there were
174 typically only 2 variables of interest. One is <PACKAGE_NAME>_LIBS, which held
175 all of the libraries and paths to libraries, including tpls, for the given
176 packages. The other is <PACKAGE_NAME>_INCLUDES which held all of the include
177 directories you needed to pull in any header files needed. These variables no
178 longer exist, however all the information is still available, though the
179 equivalent for <PACKAGE_NAME>_LIBS is spread out among several variables now.
180
181 For example if you were including Makefile.export.epetra before you would need
182 to make the following changes:
183
184 EPETRA_LIBS == $(Epetra_EXTRA_LD_FLAGS) $(Epetra_LIBRARY_DIRS)
185 $(Epetra_TPL_LIBRARY_DIRS) $(Epetra_LIBRARIES) $(Epetra_TPL_LIBRARIES)
186
187 EPETRA_INCLUDES == $(Epetra_INCLUDE_DIRS) $(Epetra_TPL_INCLUDE_DIRS)
188
189 Because these variables have changed significantly, to prevent link errors due
190 the variables not being set, the new Makefile export system does define these
191 variables and sets them to a deprecation warning. This will not prevent a link
192 error; however, it should make the problem obvious on the link line.
193
194 For the system that existed in Trilinos 10 the only difference is the names of
195 variables. The previous system had fully capitalized the package names for each
196 variable, however now we use the package name as it exists in the cmake system.
197 For example if you were including Makefile.export.epetra before, you would need
198 to replace all instances of "EPETRA" with "Epetra".
199
200 --------------------------------------------------------------------------------
201 Example Makefile file:
202
203 # CMAKE File for "MyApp" application building against an installed Trilinos
204
205 #This file is an adaptation of the CMakeLists.txt file that was converted from
206 #the buildAgainstTrilinos example. This Makefile was designed to be used in a
207 #flat directory structure. If you would like to run this example you will need
208 #put this file and src_file.cpp, src_file.hpp, main_file.cpp from
209 #buildAgainstTrilinos into a new directory. You will then need to set the
210 #environment variable MYAPP_TRILINOS_DIR to point to your base installation of
211 #Trilinos. Note that this example assumes that the installation of Trilinos that
212 #you point to has Epetra enabled.
213
214 # Get Trilinos as one entity
215 include $(MYAPP_TRILINOS_DIR)/include/Makefile.export.Trilinos
216
217 # Make sure to use same compilers and flags as Trilinos
218 CXX=$(Trilinos_CXX_COMPILER)
219 CC=$(Trilinos_C_COMPILER)
220 FORT=$(Trilinos_Fortran_COMPILER)
221
222 CXX_FLAGS=$(Trilinos_CXX_COMPILER_FLAGS) $(USER_CXX_FLAGS)
223 C_FLAGS=$(Trilinos_C_COMPILER_FLAGS) $(USERC_FLAGS)
224 FORT_FLAGS=$(Trilinos_Fortran_COMPILER_FLAGS) $(USER_FORT_FLAGS)
225
226 INCLUDE_DIRS=$(Trilinos_INCLUDE_DIRS) $(Trilinos_TPL_INCLUDE_DIRS)
227 LIBRARY_DIRS=$(Trilinos_LIBRARY_DIRS) $(Trilinos_TPL_LIBRARY_DIRS)
228 LIBRARIES=$(Trilinos_LIBRARIES) $(Trilinos_TPL_LIBRARIES)
229
230 LINK_FLAGS=$(Trilinos_EXTRA_LD_FLAGS)
231
232 #just assuming that epetra is turned on.
233 DEFINES=-DMYAPP_EPETRA
234
235
236 default: print_info MyApp.exe
237
238 # Echo trilinos build info just for fun
239 print_info:
240 @echo "\nFound Trilinos! Here are the details: "
241 @echo " Trilinos_VERSION = $(Trilinos_VERSION)"
242 @echo " Trilinos_PACKAGE_LIST = $(Trilinos_PACKAGE_LIST)"
243 @echo " Trilinos_LIBRARIES = $(Trilinos_LIBRARIES)"
244 @echo " Trilinos_INCLUDE_DIRS = $(Trilinos_INCLUDE_DIRS)"
245 @echo " Trilinos_LIBRARY_DIRS = $(Trilinos_LIBRARY_DIRS)"
246 @echo " Trilinos_TPL_LIST = $(Trilinos_TPL_LIST)"
247 @echo " Trilinos_TPL_INCLUDE_DIRS = $(Trilinos_TPL_INCLUDE_DIRS)"
248 @echo " Trilinos_TPL_LIBRARIES = $(Trilinos_TPL_LIBRARIES)"
249 @echo " Trilinos_TPL_LIBRARY_DIRS = $(Trilinos_TPL_LIBRARY_DIRS)"
250 @echo " Trilinos_BUILD_SHARED_LIBS = $(Trilinos_BUILD_SHARED_LIBS)"
251 @echo "End of Trilinos details\n"
252
253 # run the given test
254 test: MyApp.exe input.xml
255 ./MyApp.exe
256
257 # build the
258 MyApp.exe: libmyappLib.a
259 $(CXX) $(CXX_FLAGS) libMyappLib.a main_file.cpp -o MyApp.exe $(LINK_FLAGS) $(INCLUDE_DIRS) $(DEFINES) $(LIBRARY_DIRS) $(LIBRARIES)
260
261 libmyappLib.a: src_file.o
262 $(Trilinos_AR) cr libmyappLib.a src_file.o
263
264 src_file.o:
265 $(CXX) -c $(CXX_FLAGS) $(INCLUDE_DIRS) $(DEFINES) src_file.cpp
266
267 .PHONY: clean
268 clean:
269 rm -f *.o *.a *.exe