ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/cmake/modules/FindMpiCompilers.cmake
Revision: 1466
Committed: Fri Jul 9 23:13:29 2010 UTC (14 years, 9 months ago) by chuckv
File size: 5956 byte(s)
Log Message:
Adding stuff for cmake

File Contents

# User Rev Content
1 chuckv 1466 # - Find the MPI compiler wrappers
2     # This module locates the MPI compiler wrappers (mpicc, mpicxx/mpic++,
3     mpif77 and mpif90).
4     # It is useful if one wants to force a project to use the MPI compiler
5     wrappers as default
6     # compilers.
7     #
8     # The module has the following COMPONENTS:
9     # C searches for mpicc
10     # CXX searches for mpicxx and mpic++
11     # F77 searches for mpif77
12     # F90 searches for mpif90
13     # If no components are specified, all of them are enabled by default.
14     #
15     # The module sets the following cache variables (if the corresponding
16     module is enabled):
17     # MPICOMPILERS_C the mpicc compiler
18     # MPICOMPILERS_CXX the mpicxx/mpic++ compiler
19     # MPICOMPILERS_F77 the mpif77 compiler
20     # MPICOMPILERS_F90 the mpif90 compiler
21     #
22     # If the user wishes to specify a specific compiler wrapper (e.g. one
23     which is
24     # using a non-standard name or one which is not found on the path) can
25     do so
26     # by setting the corresponding MPICOMPILERS_XXX variable (e.g. using the
27     # -D flag the first time CMake is run). It also honours environment
28     variables
29     # by the same name. The CC, CXX and similar variables are not
30     considered by
31     # design.
32     #
33     # If the module is not REQUIRED make sure to check the MPICOMPILERS_XXX
34     # variables.
35     #
36     # Beware that although the module can search for both the mpif77 and
37     mpif90
38     # compiler wrappers, CMake only knows the CMAKE_Fortran_COMPILER
39     variable
40     # which means that you can't use both of the wrappers in the same
41     project. This,
42     # however, probably is not a big issue as Fortran90 is a superset of
43     # Fortran77 and all Fortran90 compilers I know of also process Fortran77
44     # sources.
45     #
46     # An example CMakeLists.txt could look like this:
47     #
48     # # prevent CMake from compiler detection using NONE as the project
49     language
50     # project( some_project NONE )
51     #
52     # cmake_minimum_required( VERSION 2.6 )
53     #
54     # # find the mpi compiler wrappers
55     # find_package( MpiCompilers REQUIRED CXX F77 )
56     #
57     # # set the CMAKE_XXX_COMPILER variables
58     # set( CMAKE_CXX_COMPILER ${MPICOMPILERS_CXX} )
59     # set( CMAKE_Fortran_COMPILER ${MPICOMPILERS_F77} )
60     # # enable the corresponding languages to do the compiler detection
61     # enable_language( CXX )
62     # enable_language( Fortran )
63     #
64     # # now go on as usual
65     # add_executable( fancy_mpi_program source1.cxx source2.f )
66    
67     # Copyright 2009 Michael Wild <themiwi at users.sourceforge.net>
68    
69     # check the components that are requested
70     if( MpiCompilers_FIND_COMPONENTS )
71     set( __MpiCompilers_C FALSE )
72     set( __MpiCompilers_CXX FALSE )
73     set( __MpiCompilers_F77 FALSE )
74     set( __MpiCompilers_F90 FALSE )
75     foreach( __MpiCompilers_comp ${MpiCompilers_FIND_COMPONENTS} )
76     if( __MpiCompilers_comp STREQUAL C )
77     set( __MpiCompilers_C TRUE )
78     elseif( __MpiCompilers_comp STREQUAL CXX )
79     set( __MpiCompilers_CXX TRUE )
80     elseif(__MpiCompilers_comp STREQUAL F77 )
81     set( __MpiCompilers_F77 TRUE )
82     elseif( __MpiCompilers_comp STREQUAL F90 )
83     set( __MpiCompilers_F90 TRUE )
84     else( __MpiCompilers_comp STREQUAL C )
85     message( FATAL_ERROR "Unknown component ${__MpiCompilers_comp}" )
86     endif( __MpiCompilers_comp STREQUAL C )
87     endforeach( __MpiCompilers_comp )
88     else( MpiCompilers_FIND_COMPONENTS )
89     # by default turn all components on
90     set( __MpiCompilers_C TRUE )
91     set( __MpiCompilers_CXX TRUE )
92     set( __MpiCompilers_F77 TRUE )
93     set( __MpiCompilers_F90 TRUE )
94     endif( MpiCompilers_FIND_COMPONENTS )
95    
96     # find the requested compilers and set up the list
97     # of required variables
98     set( __MpiCompilers_REQVARS "" )
99     set( __MpiCompilers_FOUNDCOMPILERS "" )
100     if( __MpiCompilers_C )
101     if( NOT "$ENV{MPICOMPILERS_C}" STREQUAL "" )
102     set( MPICOMPILERS_C $ENV{MPICOMPILERS_C} CACHE FILEPATH "Path to
103     the MPI C compiler" )
104     else( NOT "$ENV{MPICOMPILERS_C}" STREQUAL "" )
105     find_program( MPICOMPILERS_C mpicc DOC "Path to the MPI C
106     compiler" )
107     endif( NOT "$ENV{MPICOMPILERS_C}" STREQUAL "" )
108     list( APPEND __MpiCompilers_REQVARS MPICOMPILERS_C )
109     set( __MpiCompilers_FOUNDCOMPILERS "$
110     {__MpiCompilers_FOUNDCOMPILERS} ${MPICOMPILERS_C}" )
111     endif( __MpiCompilers_C )
112     if( __MpiCompilers_CXX )
113     if( NOT "$ENV{MPICOMPILERS_CXX}" STREQUAL "" )
114     set( MPICOMPILERS_CXX $ENV{MPICOMPILERS_CXX} CACHE FILEPATH "Path
115     to the MPI C++ compiler" )
116     else( NOT "$ENV{MPICOMPILERS_CXX}" STREQUAL "" )
117     find_program( MPICOMPILERS_CXX NAMES mpicxx mpic++ DOC "Path to
118     the MPI C++ compiler" )
119     endif( NOT "$ENV{MPICOMPILERS_CXX}" STREQUAL "" )
120     list( APPEND __MpiCompilers_REQVARS MPICOMPILERS_CXX )
121     set( __MpiCompilers_FOUNDCOMPILERS "$
122     {__MpiCompilers_FOUNDCOMPILERS} ${MPICOMPILERS_CXX}" )
123     endif( __MpiCompilers_CXX )
124     if( __MpiCompilers_F77 )
125     if( NOT "$ENV{MPICOMPILERS_F77}" STREQUAL "" )
126     set( MPICOMPILERS_F77 $ENV{MPICOMPILERS_F77} CACHE FILEPATH "Path
127     to the MPI F77 compiler" )
128     else( NOT "$ENV{MPICOMPILERS_F77}" STREQUAL "" )
129     find_program( MPICOMPILERS_F77 mpif77 DOC "Path to the MPI F77
130     compiler" )
131     endif( NOT "$ENV{MPICOMPILERS_F77}" STREQUAL "" )
132     list( APPEND __MpiCompilers_REQVARS MPICOMPILERS_F77 )
133     set( __MpiCompilers_FOUNDCOMPILERS "$
134     {__MpiCompilers_FOUNDCOMPILERS} ${MPICOMPILERS_F77}" )
135     endif( __MpiCompilers_F77 )
136     if( __MpiCompilers_F90 )
137     if( NOT "$ENV{MPICOMPILERS_F90}" STREQUAL "" )
138     set( MPICOMPILERS_F90 $ENV{MPICOMPILERS_F90} CACHE FILEPATH "Path
139     to the MPI F90 compiler" )
140     else( NOT "$ENV{MPICOMPILERS_F90}" STREQUAL "" )
141     find_program( MPICOMPILERS_F90 mpif90 DOC "Path to the MPI F77
142     compiler" )
143     endif( NOT "$ENV{MPICOMPILERS_F90}" STREQUAL "" )
144     list( APPEND __MpiCompilers_REQVARS MPICOMPILERS_F90 )
145     set( __MpiCompilers_FOUNDCOMPILERS "$
146     {__MpiCompilers_FOUNDCOMPILERS} ${MPICOMPILERS_F90}" )
147     endif( __MpiCompilers_F90 )
148    
149     mark_as_advanced( ${__MpiCompilers_REQVARS} )
150    
151     # handle standard arguments
152     include( FindPackageHandleStandardArgs )
153     find_package_handle_standard_args( MpiCompilers DEFAULT_MSG
154     __MpiCompilers_FOUNDCOMPILERS ${__MpiCompilers_REQVARS} )
155