[Cmake-commits] CMake branch, next, updated. v2.8.8-3608-gfe30d91

Brad King brad.king at kitware.com
Thu Aug 2 16:43:26 EDT 2012


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  fe30d91f29694d4b237308ac993c7b9399611f42 (commit)
       via  7e58e5bb68cb058370b5015f576ee5507e56facc (commit)
       via  796e33734db09d80041872e4ce04e838146466df (commit)
      from  4d249b382de608360b367e8029bae70cb0318bf9 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=fe30d91f29694d4b237308ac993c7b9399611f42
commit fe30d91f29694d4b237308ac993c7b9399611f42
Merge: 4d249b3 7e58e5b
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Thu Aug 2 16:43:23 2012 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Thu Aug 2 16:43:23 2012 -0400

    Merge topic 'select-compiler' into next
    
    7e58e5b Prefer generic system compilers by default for C, C++, and Fortran
    796e337 Factor common code out of CMakeDetermine(ASM|C|CXX|Fortran)Compiler


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7e58e5bb68cb058370b5015f576ee5507e56facc
commit 7e58e5bb68cb058370b5015f576ee5507e56facc
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Thu Aug 2 11:53:25 2012 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Aug 2 13:26:01 2012 -0400

    Prefer generic system compilers by default for C, C++, and Fortran
    
    Teach CMake to prefer the system default compiler automatically when no
    compiler is specified.  By default use "cc" for C, "CC" for C++, and
    "f95" for Fortran.  Load a new Platform/<os>-<lang>.cmake module to
    allow each platform to specify for each language its system compiler
    name(s) and/or exclude certain names.
    
    Create Platform/(CYGWIN|Darwin|Linux|Windows)-CXX.cmake modules to
    specify "c++" as the system C++ compiler name for these platforms.  On
    systems that use case-insensitive filesystems exclude C++ compiler names
    that are distinguished from C compiler names only by case.
    
    This will change the default compiler selection for existing build
    scripts that do not specify a compiler when run on machines with
    separate system and GNU compilers both installed in the PATH.  We do not
    make this change in default behavior lightly.  However:
    
    (1) If a given build really needs specific compilers one should specify
        them explicitly e.g. by setting CC, CXX, and FC in the environment.
    
    (2) The motivating case is to prefer the system Clang on newer OS X
        systems over the older GNU compilers typically also installed.  On
        such systems the names "cc" and "c++" link to Clang.  This is the
        first platform known to CMake on which "c++" is not a GNU compiler.
        The old behavior selected "gcc" for C and "c++" C++ and therefore
        chooses GNU for C and Clang for C++ by default.  The new behavior
        selects GNU or Clang consistently for both languages on older or
        newer OS X systems, respectively.
    
    (3) Other than the motivating OS X case the conditions under which the
        behavior changes do not tend to exist in default OS installations.
        They typically occur only on non-GNU systems with manually-installed
        GNU compilers.
    
    (4) The consequences of the new behavior are not dire.  At worst the
        project fails to compile with the system compiler when it previously
        worked with the non-system GNU compiler.  Such failure is easy to
        work around (see #1).
    
    In short this change creates a more sensible default behavior everywhere
    and fixes poor default behavior on a widely-used platform at the cost of
    a modest change in behavior in less-common conditions.

diff --git a/Modules/CMakeDetermineASMCompiler.cmake b/Modules/CMakeDetermineASMCompiler.cmake
index a56020f..7da6ac0 100644
--- a/Modules/CMakeDetermineASMCompiler.cmake
+++ b/Modules/CMakeDetermineASMCompiler.cmake
@@ -33,8 +33,9 @@ IF(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER)
         SET(CMAKE_ASM_COMPILER_ID "${CMAKE_CXX_COMPILER_ID}")
       ELSE()
         # List all default C and CXX compilers
-        SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST ${_CMAKE_TOOLCHAIN_PREFIX}gcc ${_CMAKE_TOOLCHAIN_PREFIX}cc cl bcc xlc
-                                                  ${_CMAKE_TOOLCHAIN_PREFIX}c++ ${_CMAKE_TOOLCHAIN_PREFIX}g++ CC aCC cl bcc xlC)
+        SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST
+             ${_CMAKE_TOOLCHAIN_PREFIX}cc  ${_CMAKE_TOOLCHAIN_PREFIX}gcc cl bcc xlc
+          CC ${_CMAKE_TOOLCHAIN_PREFIX}c++ ${_CMAKE_TOOLCHAIN_PREFIX}g++ aCC cl bcc xlC)
       ENDIF()
     ENDIF()
   ELSE() # some specific assembler "dialect"
diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake
index 9ebf0b3..3ce968c 100644
--- a/Modules/CMakeDetermineCCompiler.cmake
+++ b/Modules/CMakeDetermineCCompiler.cmake
@@ -33,6 +33,12 @@
 
 INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
 
+# Load system-specific compiler preferences for this language.
+INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-C OPTIONAL)
+IF(NOT CMAKE_C_COMPILER_NAMES)
+  SET(CMAKE_C_COMPILER_NAMES cc)
+ENDIF()
+
 IF(NOT CMAKE_C_COMPILER)
   SET(CMAKE_C_COMPILER_INIT NOTFOUND)
 
@@ -56,7 +62,7 @@ IF(NOT CMAKE_C_COMPILER)
 
   # finally list compilers to try
   IF(NOT CMAKE_C_COMPILER_INIT)
-    SET(CMAKE_C_COMPILER_LIST ${_CMAKE_TOOLCHAIN_PREFIX}gcc ${_CMAKE_TOOLCHAIN_PREFIX}cc cl bcc xlc clang)
+    SET(CMAKE_C_COMPILER_LIST ${_CMAKE_TOOLCHAIN_PREFIX}cc ${_CMAKE_TOOLCHAIN_PREFIX}gcc cl bcc xlc clang)
   ENDIF()
 
   _cmake_find_compiler(C)
diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake
index 43b44ac..0116d34 100644
--- a/Modules/CMakeDetermineCXXCompiler.cmake
+++ b/Modules/CMakeDetermineCXXCompiler.cmake
@@ -32,6 +32,12 @@
 
 INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
 
+# Load system-specific compiler preferences for this language.
+INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-CXX OPTIONAL)
+IF(NOT CMAKE_CXX_COMPILER_NAMES)
+  SET(CMAKE_CXX_COMPILER_NAMES CC)
+ENDIF()
+
 IF(NOT CMAKE_CXX_COMPILER)
   SET(CMAKE_CXX_COMPILER_INIT NOTFOUND)
 
@@ -55,7 +61,7 @@ IF(NOT CMAKE_CXX_COMPILER)
 
   # finally list compilers to try
   IF(NOT CMAKE_CXX_COMPILER_INIT)
-    SET(CMAKE_CXX_COMPILER_LIST ${_CMAKE_TOOLCHAIN_PREFIX}c++ ${_CMAKE_TOOLCHAIN_PREFIX}g++ CC aCC cl bcc xlC clang++)
+    SET(CMAKE_CXX_COMPILER_LIST CC ${_CMAKE_TOOLCHAIN_PREFIX}c++ ${_CMAKE_TOOLCHAIN_PREFIX}g++ aCC cl bcc xlC clang++)
   ENDIF()
 
   _cmake_find_compiler(CXX)
diff --git a/Modules/CMakeDetermineCompiler.cmake b/Modules/CMakeDetermineCompiler.cmake
index 55d554b..2d12c07 100644
--- a/Modules/CMakeDetermineCompiler.cmake
+++ b/Modules/CMakeDetermineCompiler.cmake
@@ -29,10 +29,16 @@ macro(_cmake_find_compiler lang)
       list(APPEND CMAKE_${lang}_COMPILER_LIST
         ${_${lang}_COMPILER_NAMES_${CMAKE_${l}_COMPILER_ID}})
     endforeach()
+    # Prefer vendors based on the platform.
+    list(APPEND CMAKE_${lang}_COMPILER_LIST ${CMAKE_${lang}_COMPILER_NAMES})
     # Append the rest of the list and remove duplicates.
     list(APPEND CMAKE_${lang}_COMPILER_LIST ${_${lang}_COMPILER_LIST})
     unset(_${lang}_COMPILER_LIST)
     list(REMOVE_DUPLICATES CMAKE_${lang}_COMPILER_LIST)
+    if(CMAKE_${lang}_COMPILER_EXCLUDE)
+      list(REMOVE_ITEM CMAKE_${lang}_COMPILER_LIST
+        ${CMAKE_${lang}_COMPILER_EXCLUDE})
+    endif()
   endif()
 
   # Look for directories containing compilers of reference languages.
diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake
index 6d6990e..45033c2 100644
--- a/Modules/CMakeDetermineFortranCompiler.cmake
+++ b/Modules/CMakeDetermineFortranCompiler.cmake
@@ -20,6 +20,10 @@
 # as a default compiler
 
 INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
+INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-Fortran OPTIONAL)
+IF(NOT CMAKE_Fortran_COMPILER_NAMES)
+  SET(CMAKE_Fortran_COMPILER_NAMES f95)
+ENDIF()
 
 IF(NOT CMAKE_Fortran_COMPILER)
   # prefer the environment variable CC
diff --git a/Modules/Platform/CYGWIN-CXX.cmake b/Modules/Platform/CYGWIN-CXX.cmake
new file mode 100644
index 0000000..bf37f79
--- /dev/null
+++ b/Modules/Platform/CYGWIN-CXX.cmake
@@ -0,0 +1,7 @@
+if(NOT CMAKE_CXX_COMPILER_NAMES)
+  set(CMAKE_CXX_COMPILER_NAMES c++)
+endif()
+
+# Exclude C++ compilers differing from C compiler only by case
+# because this platform may have a case-insensitive filesystem.
+set(CMAKE_CXX_COMPILER_EXCLUDE CC aCC xlC)
diff --git a/Modules/Platform/Darwin-CXX.cmake b/Modules/Platform/Darwin-CXX.cmake
new file mode 100644
index 0000000..bf37f79
--- /dev/null
+++ b/Modules/Platform/Darwin-CXX.cmake
@@ -0,0 +1,7 @@
+if(NOT CMAKE_CXX_COMPILER_NAMES)
+  set(CMAKE_CXX_COMPILER_NAMES c++)
+endif()
+
+# Exclude C++ compilers differing from C compiler only by case
+# because this platform may have a case-insensitive filesystem.
+set(CMAKE_CXX_COMPILER_EXCLUDE CC aCC xlC)
diff --git a/Modules/Platform/Linux-CXX.cmake b/Modules/Platform/Linux-CXX.cmake
new file mode 100644
index 0000000..b594dae
--- /dev/null
+++ b/Modules/Platform/Linux-CXX.cmake
@@ -0,0 +1,3 @@
+if(NOT CMAKE_CXX_COMPILER_NAMES)
+  set(CMAKE_CXX_COMPILER_NAMES c++)
+endif()
diff --git a/Modules/Platform/Windows-CXX.cmake b/Modules/Platform/Windows-CXX.cmake
new file mode 100644
index 0000000..bf37f79
--- /dev/null
+++ b/Modules/Platform/Windows-CXX.cmake
@@ -0,0 +1,7 @@
+if(NOT CMAKE_CXX_COMPILER_NAMES)
+  set(CMAKE_CXX_COMPILER_NAMES c++)
+endif()
+
+# Exclude C++ compilers differing from C compiler only by case
+# because this platform may have a case-insensitive filesystem.
+set(CMAKE_CXX_COMPILER_EXCLUDE CC aCC xlC)

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=796e33734db09d80041872e4ce04e838146466df
commit 796e33734db09d80041872e4ce04e838146466df
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Thu Aug 2 11:08:55 2012 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Aug 2 11:33:18 2012 -0400

    Factor common code out of CMakeDetermine(ASM|C|CXX|Fortran)Compiler
    
    The compiler candidate list selection and search code for C, C++, ASM,
    and Fortran languages was duplicated across four modules.  To look for
    compilers adjacent to already-enabled languages the C and CXX modules
    each used _CMAKE_USER_(C|CXX)_COMPILER_PATH and the ASM module used
    _CMAKE_TOOLCHAIN_LOCATION.  Since commit 4debb7ac (Bias Fortran compiler
    search with C/C++ compilers, 2009-09-09) CMake prefers Fortran compilers
    matching the vendor and directory of an enabled C or C++ compiler.
    
    Factor out the common functionality among the four languages into a new
    CMakeDetermineCompiler module.  Generalize the Fortran implementation so
    that all languages may each use the vendor and directory of the other
    languages that have already been enabled.  For now do not list any
    vendor-specific names for C, C++, or ASM so that only the directory
    preference is used for these languages (existing behavior).

diff --git a/Modules/CMakeDetermineASMCompiler.cmake b/Modules/CMakeDetermineASMCompiler.cmake
index 0a70d0a..a56020f 100644
--- a/Modules/CMakeDetermineASMCompiler.cmake
+++ b/Modules/CMakeDetermineASMCompiler.cmake
@@ -14,6 +14,8 @@
 
 # determine the compiler to use for ASM programs
 
+INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
+
 IF(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER)
   # prefer the environment variable ASM
   IF($ENV{ASM${ASM_DIALECT}} MATCHES ".+")
@@ -22,42 +24,27 @@ IF(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER)
 
   # finally list compilers to try
   IF("ASM${ASM_DIALECT}" STREQUAL "ASM") # the generic assembler support
-
-    IF(CMAKE_ASM_COMPILER_INIT)
-      SET(CMAKE_ASM_COMPILER_LIST ${CMAKE_ASM_COMPILER_INIT})
-    ELSE(CMAKE_ASM_COMPILER_INIT)
-
+    IF(NOT CMAKE_ASM_COMPILER_INIT)
       IF(CMAKE_C_COMPILER)
         SET(CMAKE_ASM_COMPILER "${CMAKE_C_COMPILER}" CACHE FILEPATH "The ASM compiler")
         SET(CMAKE_ASM_COMPILER_ID "${CMAKE_C_COMPILER_ID}")
       ELSEIF(CMAKE_CXX_COMPILER)
         SET(CMAKE_ASM_COMPILER "${CMAKE_CXX_COMPILER}" CACHE FILEPATH "The ASM compiler")
         SET(CMAKE_ASM_COMPILER_ID "${CMAKE_CXX_COMPILER_ID}")
-      ELSE(CMAKE_CXX_COMPILER)
+      ELSE()
         # List all default C and CXX compilers
         SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST ${_CMAKE_TOOLCHAIN_PREFIX}gcc ${_CMAKE_TOOLCHAIN_PREFIX}cc cl bcc xlc
                                                   ${_CMAKE_TOOLCHAIN_PREFIX}c++ ${_CMAKE_TOOLCHAIN_PREFIX}g++ CC aCC cl bcc xlC)
-      ENDIF(CMAKE_C_COMPILER)
-
-    ENDIF(CMAKE_ASM_COMPILER_INIT)
-
-
-  ELSE("ASM${ASM_DIALECT}" STREQUAL "ASM") # some specific assembler "dialect"
-
-    IF(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT)
-      SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST ${CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT})
-    ELSE(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT)
+      ENDIF()
+    ENDIF()
+  ELSE() # some specific assembler "dialect"
+    IF(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT)
       MESSAGE(FATAL_ERROR "CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT must be preset !")
-    ENDIF(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT)
-
-  ENDIF("ASM${ASM_DIALECT}" STREQUAL "ASM")
-
+    ENDIF()
+  ENDIF()
 
   # Find the compiler.
-  IF (_CMAKE_USER_CXX_COMPILER_PATH OR _CMAKE_USER_C_COMPILER_PATH)
-    FIND_PROGRAM(CMAKE_ASM${ASM_DIALECT}_COMPILER NAMES ${CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST} PATHS ${_CMAKE_USER_C_COMPILER_PATH} ${_CMAKE_USER_CXX_COMPILER_PATH} DOC "Assembler" NO_DEFAULT_PATH)
-  ENDIF (_CMAKE_USER_CXX_COMPILER_PATH OR _CMAKE_USER_C_COMPILER_PATH)
-  FIND_PROGRAM(CMAKE_ASM${ASM_DIALECT}_COMPILER NAMES ${CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST} PATHS ${_CMAKE_TOOLCHAIN_LOCATION} DOC "Assembler")
+  _cmake_find_compiler(ASM${ASM_DIALECT})
 
 ELSE(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER)
 
diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake
index 5c7bec5..9ebf0b3 100644
--- a/Modules/CMakeDetermineCCompiler.cmake
+++ b/Modules/CMakeDetermineCCompiler.cmake
@@ -31,6 +31,8 @@
 # If not already set before, it also sets
 #   _CMAKE_TOOLCHAIN_PREFIX
 
+INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
+
 IF(NOT CMAKE_C_COMPILER)
   SET(CMAKE_C_COMPILER_INIT NOTFOUND)
 
@@ -53,21 +55,12 @@ IF(NOT CMAKE_C_COMPILER)
   ENDIF(CMAKE_GENERATOR_CC)
 
   # finally list compilers to try
-  IF(CMAKE_C_COMPILER_INIT)
-    SET(CMAKE_C_COMPILER_LIST ${CMAKE_C_COMPILER_INIT})
-  ELSE(CMAKE_C_COMPILER_INIT)
+  IF(NOT CMAKE_C_COMPILER_INIT)
     SET(CMAKE_C_COMPILER_LIST ${_CMAKE_TOOLCHAIN_PREFIX}gcc ${_CMAKE_TOOLCHAIN_PREFIX}cc cl bcc xlc clang)
-  ENDIF(CMAKE_C_COMPILER_INIT)
+  ENDIF()
 
-  # Find the compiler.
-  IF (_CMAKE_USER_CXX_COMPILER_PATH)
-    FIND_PROGRAM(CMAKE_C_COMPILER NAMES ${CMAKE_C_COMPILER_LIST} PATHS ${_CMAKE_USER_CXX_COMPILER_PATH} DOC "C compiler" NO_DEFAULT_PATH)
-  ENDIF (_CMAKE_USER_CXX_COMPILER_PATH)
-  FIND_PROGRAM(CMAKE_C_COMPILER NAMES ${CMAKE_C_COMPILER_LIST} DOC "C compiler")
+  _cmake_find_compiler(C)
 
-  IF(CMAKE_C_COMPILER_INIT AND NOT CMAKE_C_COMPILER)
-    SET(CMAKE_C_COMPILER "${CMAKE_C_COMPILER_INIT}" CACHE FILEPATH "C compiler" FORCE)
-  ENDIF(CMAKE_C_COMPILER_INIT AND NOT CMAKE_C_COMPILER)
 ELSE(NOT CMAKE_C_COMPILER)
 
   # we only get here if CMAKE_C_COMPILER was specified using -D or a pre-made CMakeCache.txt
diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake
index f78d7a7..43b44ac 100644
--- a/Modules/CMakeDetermineCXXCompiler.cmake
+++ b/Modules/CMakeDetermineCXXCompiler.cmake
@@ -30,6 +30,8 @@
 # If not already set before, it also sets
 #   _CMAKE_TOOLCHAIN_PREFIX
 
+INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
+
 IF(NOT CMAKE_CXX_COMPILER)
   SET(CMAKE_CXX_COMPILER_INIT NOTFOUND)
 
@@ -52,21 +54,11 @@ IF(NOT CMAKE_CXX_COMPILER)
   ENDIF(CMAKE_GENERATOR_CXX)
 
   # finally list compilers to try
-  IF(CMAKE_CXX_COMPILER_INIT)
-    SET(CMAKE_CXX_COMPILER_LIST ${CMAKE_CXX_COMPILER_INIT})
-  ELSE(CMAKE_CXX_COMPILER_INIT)
+  IF(NOT CMAKE_CXX_COMPILER_INIT)
     SET(CMAKE_CXX_COMPILER_LIST ${_CMAKE_TOOLCHAIN_PREFIX}c++ ${_CMAKE_TOOLCHAIN_PREFIX}g++ CC aCC cl bcc xlC clang++)
-  ENDIF(CMAKE_CXX_COMPILER_INIT)
-
-  # Find the compiler.
-  IF (_CMAKE_USER_C_COMPILER_PATH)
-    FIND_PROGRAM(CMAKE_CXX_COMPILER NAMES ${CMAKE_CXX_COMPILER_LIST} PATHS ${_CMAKE_USER_C_COMPILER_PATH} DOC "C++ compiler" NO_DEFAULT_PATH)
-  ENDIF (_CMAKE_USER_C_COMPILER_PATH)
-  FIND_PROGRAM(CMAKE_CXX_COMPILER NAMES ${CMAKE_CXX_COMPILER_LIST} DOC "C++ compiler")
+  ENDIF()
 
-  IF(CMAKE_CXX_COMPILER_INIT AND NOT CMAKE_CXX_COMPILER)
-    SET(CMAKE_CXX_COMPILER "${CMAKE_CXX_COMPILER_INIT}" CACHE FILEPATH "C++ compiler" FORCE)
-  ENDIF(CMAKE_CXX_COMPILER_INIT AND NOT CMAKE_CXX_COMPILER)
+  _cmake_find_compiler(CXX)
 ELSE(NOT CMAKE_CXX_COMPILER)
 
 # we only get here if CMAKE_CXX_COMPILER was specified using -D or a pre-made CMakeCache.txt
diff --git a/Modules/CMakeDetermineCompiler.cmake b/Modules/CMakeDetermineCompiler.cmake
new file mode 100644
index 0000000..55d554b
--- /dev/null
+++ b/Modules/CMakeDetermineCompiler.cmake
@@ -0,0 +1,66 @@
+
+#=============================================================================
+# Copyright 2004-2012 Kitware, Inc.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+macro(_cmake_find_compiler lang)
+  # Use already-enabled languages for reference.
+  get_property(_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
+  list(REMOVE_ITEM _languages "${lang}")
+
+  if(CMAKE_${lang}_COMPILER_INIT)
+    # Search only for the specified compiler.
+    set(CMAKE_${lang}_COMPILER_LIST "${CMAKE_${lang}_COMPILER_INIT}")
+  else()
+    # Re-order the compiler list with preferred vendors first.
+    set(_${lang}_COMPILER_LIST "${CMAKE_${lang}_COMPILER_LIST}")
+    set(CMAKE_${lang}_COMPILER_LIST "")
+    # Prefer vendors of compilers from reference languages.
+    foreach(l ${_languages})
+      list(APPEND CMAKE_${lang}_COMPILER_LIST
+        ${_${lang}_COMPILER_NAMES_${CMAKE_${l}_COMPILER_ID}})
+    endforeach()
+    # Append the rest of the list and remove duplicates.
+    list(APPEND CMAKE_${lang}_COMPILER_LIST ${_${lang}_COMPILER_LIST})
+    unset(_${lang}_COMPILER_LIST)
+    list(REMOVE_DUPLICATES CMAKE_${lang}_COMPILER_LIST)
+  endif()
+
+  # Look for directories containing compilers of reference languages.
+  set(_${lang}_COMPILER_HINTS)
+  foreach(l ${_languages})
+    if(CMAKE_${l}_COMPILER AND IS_ABSOLUTE "${CMAKE_${l}_COMPILER}")
+      get_filename_component(_hint "${CMAKE_${l}_COMPILER}" PATH)
+      if(IS_DIRECTORY "${_hint}")
+        list(APPEND _${lang}_COMPILER_HINTS "${_hint}")
+      endif()
+      unset(_hint)
+    endif()
+  endforeach()
+
+  # Find the compiler.
+  if(_${lang}_COMPILER_HINTS)
+    # Prefer directories containing compilers of reference languages.
+    list(REMOVE_DUPLICATES _${lang}_COMPILER_HINTS)
+    find_program(CMAKE_${lang}_COMPILER
+      NAMES ${CMAKE_${lang}_COMPILER_LIST}
+      PATHS ${_${lang}_COMPILER_HINTS}
+      NO_DEFAULT_PATH
+      DOC "${lang} compiler")
+  endif()
+  find_program(CMAKE_${lang}_COMPILER NAMES ${CMAKE_${lang}_COMPILER_LIST} DOC "${lang} compiler")
+  if(CMAKE_${lang}_COMPILER_INIT AND NOT CMAKE_${lang}_COMPILER)
+    set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER_INIT}" CACHE FILEPATH "${lang} compiler" FORCE)
+  endif()
+  unset(_${lang}_COMPILER_HINTS)
+  unset(_languages)
+endmacro()
diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake
index ade6d58..6d6990e 100644
--- a/Modules/CMakeDetermineFortranCompiler.cmake
+++ b/Modules/CMakeDetermineFortranCompiler.cmake
@@ -19,6 +19,8 @@
 # the cmake variable CMAKE_GENERATOR_FC which can be defined by a generator
 # as a default compiler
 
+INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
+
 IF(NOT CMAKE_Fortran_COMPILER)
   # prefer the environment variable CC
   IF($ENV{FC} MATCHES ".+")
@@ -40,9 +42,7 @@ IF(NOT CMAKE_Fortran_COMPILER)
   ENDIF(CMAKE_GENERATOR_FC)
 
   # finally list compilers to try
-  IF(CMAKE_Fortran_COMPILER_INIT)
-    SET(CMAKE_Fortran_COMPILER_LIST ${CMAKE_Fortran_COMPILER_INIT})
-  ELSE(CMAKE_Fortran_COMPILER_INIT)
+  IF(NOT CMAKE_Fortran_COMPILER_INIT)
     # Known compilers:
     #  f77/f90/f95: generic compiler names
     #  g77: GNU Fortran 77 compiler
@@ -77,41 +77,10 @@ IF(NOT CMAKE_Fortran_COMPILER)
     SET(_Fortran_COMPILER_NAMES_PathScale pathf2003 pathf95 pathf90)
     SET(_Fortran_COMPILER_NAMES_XL        xlf)
     SET(_Fortran_COMPILER_NAMES_VisualAge xlf95 xlf90 xlf)
-
-    # Prefer vendors matching the C and C++ compilers.
-    SET(CMAKE_Fortran_COMPILER_LIST
-      ${_Fortran_COMPILER_NAMES_${CMAKE_C_COMPILER_ID}}
-      ${_Fortran_COMPILER_NAMES_${CMAKE_CXX_COMPILER_ID}}
-      ${CMAKE_Fortran_COMPILER_LIST})
-    LIST(REMOVE_DUPLICATES CMAKE_Fortran_COMPILER_LIST)
-  ENDIF(CMAKE_Fortran_COMPILER_INIT)
-
-  # Look for directories containing the C and C++ compilers.
-  SET(_Fortran_COMPILER_HINTS)
-  FOREACH(lang C CXX)
-    IF(CMAKE_${lang}_COMPILER AND IS_ABSOLUTE "${CMAKE_${lang}_COMPILER}")
-      GET_FILENAME_COMPONENT(_hint "${CMAKE_${lang}_COMPILER}" PATH)
-      IF(IS_DIRECTORY "${_hint}")
-        LIST(APPEND _Fortran_COMPILER_HINTS "${_hint}")
-      ENDIF()
-      SET(_hint)
-    ENDIF()
-  ENDFOREACH()
-
-  # Find the compiler.
-  IF(_Fortran_COMPILER_HINTS)
-    # Prefer directories containing C and C++ compilers.
-    LIST(REMOVE_DUPLICATES _Fortran_COMPILER_HINTS)
-    FIND_PROGRAM(CMAKE_Fortran_COMPILER
-      NAMES ${CMAKE_Fortran_COMPILER_LIST}
-      PATHS ${_Fortran_COMPILER_HINTS}
-      NO_DEFAULT_PATH
-      DOC "Fortran compiler")
   ENDIF()
-  FIND_PROGRAM(CMAKE_Fortran_COMPILER NAMES ${CMAKE_Fortran_COMPILER_LIST} DOC "Fortran compiler")
-  IF(CMAKE_Fortran_COMPILER_INIT AND NOT CMAKE_Fortran_COMPILER)
-    SET(CMAKE_Fortran_COMPILER "${CMAKE_Fortran_COMPILER_INIT}" CACHE FILEPATH "Fortran compiler" FORCE)
-  ENDIF(CMAKE_Fortran_COMPILER_INIT AND NOT CMAKE_Fortran_COMPILER)
+
+  _cmake_find_compiler(Fortran)
+
 ELSE(NOT CMAKE_Fortran_COMPILER)
    # we only get here if CMAKE_Fortran_COMPILER was specified using -D or a pre-made CMakeCache.txt
   # (e.g. via ctest) or set in CMAKE_TOOLCHAIN_FILE

-----------------------------------------------------------------------

Summary of changes:
 Modules/CMakeDetermineASMCompiler.cmake     |   40 +++++----------
 Modules/CMakeDetermineCCompiler.cmake       |   25 +++++-----
 Modules/CMakeDetermineCXXCompiler.cmake     |   26 +++++-----
 Modules/CMakeDetermineCompiler.cmake        |   72 +++++++++++++++++++++++++++
 Modules/CMakeDetermineFortranCompiler.cmake |   45 +++-------------
 Modules/Platform/CYGWIN-CXX.cmake           |    7 +++
 Modules/Platform/Darwin-CXX.cmake           |    7 +++
 Modules/Platform/Linux-CXX.cmake            |    3 +
 Modules/Platform/Windows-CXX.cmake          |    7 +++
 9 files changed, 143 insertions(+), 89 deletions(-)
 create mode 100644 Modules/CMakeDetermineCompiler.cmake
 create mode 100644 Modules/Platform/CYGWIN-CXX.cmake
 create mode 100644 Modules/Platform/Darwin-CXX.cmake
 create mode 100644 Modules/Platform/Linux-CXX.cmake
 create mode 100644 Modules/Platform/Windows-CXX.cmake


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list