ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/cmake/modules/FindMpiCompilers.cmake
Revision: 1626
Committed: Tue Sep 13 15:39:54 2011 UTC (13 years, 7 months ago) by gezelter
File size: 7416 byte(s)
Log Message:
Cmake fixes and updates.

File Contents

# User Rev Content
1 chuckv 1466 # - Find the MPI compiler wrappers
2 gezelter 1626 # This module locates the MPI compiler wrappers (mpicc, mpicxx/mpic++, mpif77 and mpif90).
3     # It is useful if one wants to force a project to use the MPI compiler wrappers as default
4 chuckv 1466 # compilers.
5     #
6     # The module has the following COMPONENTS:
7     # C searches for mpicc
8     # CXX searches for mpicxx and mpic++
9     # F77 searches for mpif77
10     # F90 searches for mpif90
11     # If no components are specified, all of them are enabled by default.
12     #
13 gezelter 1626 # The module sets the following cache variables (if the corresponding module is enabled):
14 chuckv 1466 # MPICOMPILERS_C the mpicc compiler
15     # MPICOMPILERS_CXX the mpicxx/mpic++ compiler
16     # MPICOMPILERS_F77 the mpif77 compiler
17     # MPICOMPILERS_F90 the mpif90 compiler
18     #
19 gezelter 1626 # If the user wishes to specify a specific compiler wrapper (e.g. one which is
20     # using a non-standard name or one which is not found on the path) can do so
21 chuckv 1466 # by setting the corresponding MPICOMPILERS_XXX variable (e.g. using the
22 gezelter 1626 # -D flag the first time CMake is run). It also honours environment variables
23     # by the same name. The CC, CXX and similar variables are not considered by
24 chuckv 1466 # design.
25     #
26     # If the module is not REQUIRED make sure to check the MPICOMPILERS_XXX
27     # variables.
28     #
29 gezelter 1626 # Beware that although the module can search for both the mpif77 and mpif90
30     # compiler wrappers, CMake only knows the CMAKE_Fortran_COMPILER variable
31     # which means that you can't use both of the wrappers in the same project. This,
32 chuckv 1466 # however, probably is not a big issue as Fortran90 is a superset of
33     # Fortran77 and all Fortran90 compilers I know of also process Fortran77
34     # sources.
35     #
36     # An example CMakeLists.txt could look like this:
37     #
38 gezelter 1626 # # prevent CMake from compiler detection using NONE as the project language
39 chuckv 1466 # project( some_project NONE )
40 gezelter 1626 #
41 chuckv 1466 # cmake_minimum_required( VERSION 2.6 )
42 gezelter 1626 #
43 chuckv 1466 # # find the mpi compiler wrappers
44     # find_package( MpiCompilers REQUIRED CXX F77 )
45 gezelter 1626 #
46 chuckv 1466 # # set the CMAKE_XXX_COMPILER variables
47     # set( CMAKE_CXX_COMPILER ${MPICOMPILERS_CXX} )
48     # set( CMAKE_Fortran_COMPILER ${MPICOMPILERS_F77} )
49     # # enable the corresponding languages to do the compiler detection
50     # enable_language( CXX )
51     # enable_language( Fortran )
52 gezelter 1626 #
53 chuckv 1466 # # now go on as usual
54     # add_executable( fancy_mpi_program source1.cxx source2.f )
55    
56 gezelter 1626 # Copyright 2009 Michael Wild <themiwi@users.sourceforge.net>
57     # All rights reserved.
58     #
59     # Redistribution and use in source and binary forms, with or without
60     # modification, are permitted provided that the following conditions are met:
61     #
62     # * Redistributions of source code must retain the above copyright notice,
63     # this list of conditions and the following disclaimer.
64     # * Redistributions in binary form must reproduce the above copyright notice,
65     # this list of conditions and the following disclaimer in the documentation
66     # and/or other materials provided with the distribution.
67     # * The names of its contributors may not be used to endorse or promote
68     # products derived from this software without specific prior written
69     # permission.
70     #
71     # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
72     # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
73     # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
74     # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
75     # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
76     # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
77     # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
78     # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
79     # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
80     # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
81     # POSSIBILITY OF SUCH DAMAGE.
82 chuckv 1466
83     # check the components that are requested
84     if( MpiCompilers_FIND_COMPONENTS )
85 gezelter 1626 set( __MpiCompilers_C FALSE )
86     set( __MpiCompilers_CXX FALSE )
87     set( __MpiCompilers_F77 FALSE )
88     set( __MpiCompilers_F90 FALSE )
89     foreach( __MpiCompilers_comp ${MpiCompilers_FIND_COMPONENTS} )
90     if( __MpiCompilers_comp STREQUAL C )
91     set( __MpiCompilers_C TRUE )
92     elseif( __MpiCompilers_comp STREQUAL CXX )
93     set( __MpiCompilers_CXX TRUE )
94     elseif(__MpiCompilers_comp STREQUAL F77 )
95     set( __MpiCompilers_F77 TRUE )
96     elseif( __MpiCompilers_comp STREQUAL F90 )
97     set( __MpiCompilers_F90 TRUE )
98     else( __MpiCompilers_comp STREQUAL C )
99     message( FATAL_ERROR "Unknown component ${__MpiCompilers_comp}" )
100     endif( __MpiCompilers_comp STREQUAL C )
101     endforeach( __MpiCompilers_comp )
102 chuckv 1466 else( MpiCompilers_FIND_COMPONENTS )
103 gezelter 1626 # by default turn all components on
104     set( __MpiCompilers_C TRUE )
105     set( __MpiCompilers_CXX TRUE )
106     set( __MpiCompilers_F77 TRUE )
107     set( __MpiCompilers_F90 TRUE )
108 chuckv 1466 endif( MpiCompilers_FIND_COMPONENTS )
109    
110     # find the requested compilers and set up the list
111     # of required variables
112     set( __MpiCompilers_REQVARS "" )
113     set( __MpiCompilers_FOUNDCOMPILERS "" )
114     if( __MpiCompilers_C )
115 gezelter 1626 if( NOT "$ENV{MPICOMPILERS_C}" STREQUAL "" )
116     set( MPICOMPILERS_C $ENV{MPICOMPILERS_C} CACHE FILEPATH "Path to the MPI C compiler" )
117     else( NOT "$ENV{MPICOMPILERS_C}" STREQUAL "" )
118     find_program( MPICOMPILERS_C mpicc DOC "Path to the MPI C compiler" )
119     endif( NOT "$ENV{MPICOMPILERS_C}" STREQUAL "" )
120     list( APPEND __MpiCompilers_REQVARS MPICOMPILERS_C )
121     set( __MpiCompilers_FOUNDCOMPILERS "${__MpiCompilers_FOUNDCOMPILERS} ${MPICOMPILERS_C}" )
122 chuckv 1466 endif( __MpiCompilers_C )
123     if( __MpiCompilers_CXX )
124 gezelter 1626 if( NOT "$ENV{MPICOMPILERS_CXX}" STREQUAL "" )
125     set( MPICOMPILERS_CXX $ENV{MPICOMPILERS_CXX} CACHE FILEPATH "Path to the MPI C++ compiler" )
126     else( NOT "$ENV{MPICOMPILERS_CXX}" STREQUAL "" )
127     find_program( MPICOMPILERS_CXX NAMES mpicxx mpic++ DOC "Path to the MPI C++ compiler" )
128     endif( NOT "$ENV{MPICOMPILERS_CXX}" STREQUAL "" )
129     list( APPEND __MpiCompilers_REQVARS MPICOMPILERS_CXX )
130     set( __MpiCompilers_FOUNDCOMPILERS "${__MpiCompilers_FOUNDCOMPILERS} ${MPICOMPILERS_CXX}" )
131 chuckv 1466 endif( __MpiCompilers_CXX )
132     if( __MpiCompilers_F77 )
133 gezelter 1626 if( NOT "$ENV{MPICOMPILERS_F77}" STREQUAL "" )
134     set( MPICOMPILERS_F77 $ENV{MPICOMPILERS_F77} CACHE FILEPATH "Path to the MPI F77 compiler" )
135     else( NOT "$ENV{MPICOMPILERS_F77}" STREQUAL "" )
136     find_program( MPICOMPILERS_F77 mpif77 DOC "Path to the MPI F77 compiler" )
137     endif( NOT "$ENV{MPICOMPILERS_F77}" STREQUAL "" )
138     list( APPEND __MpiCompilers_REQVARS MPICOMPILERS_F77 )
139     set( __MpiCompilers_FOUNDCOMPILERS "${__MpiCompilers_FOUNDCOMPILERS} ${MPICOMPILERS_F77}" )
140 chuckv 1466 endif( __MpiCompilers_F77 )
141     if( __MpiCompilers_F90 )
142 gezelter 1626 if( NOT "$ENV{MPICOMPILERS_F90}" STREQUAL "" )
143     set( MPICOMPILERS_F90 $ENV{MPICOMPILERS_F90} CACHE FILEPATH "Path to the MPI F90 compiler" )
144     else( NOT "$ENV{MPICOMPILERS_F90}" STREQUAL "" )
145     find_program( MPICOMPILERS_F90 mpif90 DOC "Path to the MPI F77 compiler" )
146     endif( NOT "$ENV{MPICOMPILERS_F90}" STREQUAL "" )
147     list( APPEND __MpiCompilers_REQVARS MPICOMPILERS_F90 )
148     set( __MpiCompilers_FOUNDCOMPILERS "${__MpiCompilers_FOUNDCOMPILERS} ${MPICOMPILERS_F90}" )
149 chuckv 1466 endif( __MpiCompilers_F90 )
150    
151     mark_as_advanced( ${__MpiCompilers_REQVARS} )
152    
153     # handle standard arguments
154     include( FindPackageHandleStandardArgs )
155 gezelter 1626 find_package_handle_standard_args( MpiCompilers DEFAULT_MSG __MpiCompilers_FOUNDCOMPILERS ${__MpiCompilers_REQVARS} )
156 chuckv 1466
157 gezelter 1626 ############################## END OF FindMpiCompilers.cmake ##############################