From 7001a88a746073a46200dde7c6613789cf4b9cc8 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 29 Aug 2006 13:59:15 -0400 Subject: BUG: Search for the compiler only once and store a full path to it in the cache. This avoids problems with the case of locations in the PATH variable on Windows that change the compiler name when CMake is re-run. CMakeFiles/CMake*Compiler.cmake files should hold the full path to the compiler always. --- Modules/CMakeDetermineCCompiler.cmake | 21 +++++++++++---------- Modules/CMakeDetermineCXXCompiler.cmake | 21 +++++++++++---------- Modules/CMakeDetermineFortranCompiler.cmake | 29 +++++++++++++++-------------- Modules/CMakeDetermineRCCompiler.cmake | 24 ++++++++++++------------ 4 files changed, 49 insertions(+), 46 deletions(-) diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake index 4d7ced5..c085947 100644 --- a/Modules/CMakeDetermineCCompiler.cmake +++ b/Modules/CMakeDetermineCCompiler.cmake @@ -28,17 +28,18 @@ IF(NOT CMAKE_C_COMPILER) ENDIF(NOT CMAKE_C_COMPILER_INIT) ENDIF(CMAKE_GENERATOR_CC) - # if no compiler has been specified yet, then look for one - IF(NOT CMAKE_C_COMPILER_INIT) - # if not in the envionment then search for the compiler in the path - SET(CMAKE_C_COMPILER_LIST gcc cc cl bcc xlc) - FIND_PROGRAM(CMAKE_C_COMPILER_FULLPATH NAMES ${CMAKE_C_COMPILER_LIST} ) - GET_FILENAME_COMPONENT(CMAKE_C_COMPILER_INIT - ${CMAKE_C_COMPILER_FULLPATH} NAME) - SET(CMAKE_C_COMPILER_FULLPATH "${CMAKE_C_COMPILER_FULLPATH}" CACHE INTERNAL "full path to the compiler cmake found") - ENDIF(NOT CMAKE_C_COMPILER_INIT) + # finally list compilers to try + IF(CMAKE_C_COMPILER_INIT) + SET(CMAKE_C_COMPILER_LIST ${CMAKE_C_COMPILER_INIT}) + ELSE(CMAKE_C_COMPILER_INIT) + SET(CMAKE_C_COMPILER_LIST gcc cc cl bcc xlc) + ENDIF(CMAKE_C_COMPILER_INIT) - SET(CMAKE_C_COMPILER ${CMAKE_C_COMPILER_INIT} CACHE STRING "C compiler") + # Find the compiler. + FIND_PROGRAM(CMAKE_C_COMPILER NAMES ${CMAKE_C_COMPILER_LIST} DOC "C compiler") + 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) ENDIF(NOT CMAKE_C_COMPILER) MARK_AS_ADVANCED(CMAKE_C_COMPILER) GET_FILENAME_COMPONENT(COMPILER_LOCATION "${CMAKE_C_COMPILER}" diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake index 79683f5..ed909ce 100644 --- a/Modules/CMakeDetermineCXXCompiler.cmake +++ b/Modules/CMakeDetermineCXXCompiler.cmake @@ -28,17 +28,18 @@ IF(NOT CMAKE_CXX_COMPILER) ENDIF(NOT CMAKE_CXX_COMPILER_INIT) ENDIF(CMAKE_GENERATOR_CXX) - # if no compiler has been found yet, then try to find one - IF(NOT CMAKE_CXX_COMPILER_INIT) - # if not in the envionment then search for the compiler in the path + # finally list compilers to try + IF(CMAKE_CXX_COMPILER_INIT) + SET(CMAKE_CXX_COMPILER_LIST ${CMAKE_CXX_COMPILER_INIT}) + ELSE(CMAKE_CXX_COMPILER_INIT) SET(CMAKE_CXX_COMPILER_LIST c++ g++ CC aCC cl bcc xlC) - FIND_PROGRAM(CMAKE_CXX_COMPILER_FULLPATH NAMES ${CMAKE_CXX_COMPILER_LIST}) - GET_FILENAME_COMPONENT(CMAKE_CXX_COMPILER_INIT - ${CMAKE_CXX_COMPILER_FULLPATH} NAME) - SET(CMAKE_CXX_COMPILER_FULLPATH "${CMAKE_CXX_COMPILER_FULLPATH}" CACHE INTERNAL "full path to the compiler cmake found") - ENDIF(NOT CMAKE_CXX_COMPILER_INIT) - SET(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER_INIT} - CACHE STRING "C++ compiler") + ENDIF(CMAKE_CXX_COMPILER_INIT) + + # Find the compiler. + FIND_PROGRAM(CMAKE_CXX_COMPILER NAMES ${CMAKE_CXX_COMPILER_LIST} DOC "C++ compiler") + 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) ENDIF(NOT CMAKE_CXX_COMPILER) MARK_AS_ADVANCED(CMAKE_CXX_COMPILER) diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake index edec369..eaa7f0d 100644 --- a/Modules/CMakeDetermineFortranCompiler.cmake +++ b/Modules/CMakeDetermineFortranCompiler.cmake @@ -24,11 +24,11 @@ IF(NOT CMAKE_Fortran_COMPILER) SET(CMAKE_Fortran_COMPILER_INIT ${CMAKE_GENERATOR_FC}) ENDIF(NOT CMAKE_Fortran_COMPILER_INIT) ENDIF(CMAKE_GENERATOR_FC) - - - # if no compiler has been specified yet, then look for one - IF(NOT CMAKE_Fortran_COMPILER_INIT) - # if not in the envionment then search for the compiler in the path + + # finally list compilers to try + IF(CMAKE_Fortran_COMPILER_INIT) + SET(CMAKE_Fortran_COMPILER_LIST ${CMAKE_Fortran_COMPILER_INIT}) + ELSE(CMAKE_Fortran_COMPILER_INIT) # Known compilers: # f77/f90/f95: generic compiler names # g77: GNU Fortran 77 compiler @@ -51,16 +51,17 @@ IF(NOT CMAKE_Fortran_COMPILER) # NOTE for testing purposes this list is DUPLICATED in # CMake/Source/CMakeLists.txt, IF YOU CHANGE THIS LIST, # PLEASE UPDATE THAT FILE AS WELL! - SET(CMAKE_Fortran_COMPILER_LIST ifort ifc efc f95 pgf95 - lf95 xlf95 fort gfortran f90 pgf90 xlf90 epcf90 fort77 frt pgf77 xlf fl32 af77 g77 f77 ) - FIND_PROGRAM(CMAKE_Fortran_COMPILER_FULLPATH NAMES ${CMAKE_Fortran_COMPILER_LIST} ) - GET_FILENAME_COMPONENT(CMAKE_Fortran_COMPILER_INIT - ${CMAKE_Fortran_COMPILER_FULLPATH} NAME) - SET(CMAKE_Fortran_COMPILER_FULLPATH "${CMAKE_Fortran_COMPILER_FULLPATH}" - CACHE INTERNAL "full path to the compiler cmake found") - ENDIF(NOT CMAKE_Fortran_COMPILER_INIT) + SET(CMAKE_Fortran_COMPILER_LIST + ifort ifc efc f95 pgf95 lf95 xlf95 fort gfortran f90 + pgf90 xlf90 epcf90 fort77 frt pgf77 xlf fl32 af77 g77 f77 + ) + ENDIF(CMAKE_Fortran_COMPILER_INIT) - SET(CMAKE_Fortran_COMPILER ${CMAKE_Fortran_COMPILER_INIT} CACHE STRING "Fortran compiler") + # Find the compiler. + 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) ENDIF(NOT CMAKE_Fortran_COMPILER) MARK_AS_ADVANCED(CMAKE_Fortran_COMPILER) diff --git a/Modules/CMakeDetermineRCCompiler.cmake b/Modules/CMakeDetermineRCCompiler.cmake index e48f21f..51b0ecf 100644 --- a/Modules/CMakeDetermineRCCompiler.cmake +++ b/Modules/CMakeDetermineRCCompiler.cmake @@ -24,19 +24,19 @@ IF(NOT CMAKE_RC_COMPILER) SET(CMAKE_RC_COMPILER_INIT ${CMAKE_GENERATOR_RC}) ENDIF(NOT CMAKE_RC_COMPILER_INIT) ENDIF(CMAKE_GENERATOR_RC) - - - # if no compiler has been specified yet, then look for one - IF(NOT CMAKE_RC_COMPILER_INIT) - SET(CMAKE_RC_COMPILER_LIST rc) - FIND_PROGRAM(CMAKE_RC_COMPILER_FULLPATH NAMES ${CMAKE_RC_COMPILER_LIST} ) - GET_FILENAME_COMPONENT(CMAKE_RC_COMPILER_INIT - ${CMAKE_RC_COMPILER_FULLPATH} NAME) - SET(CMAKE_RC_COMPILER_FULLPATH "${CMAKE_RC_COMPILER_FULLPATH}" - CACHE INTERNAL "full path to the compiler cmake found") - ENDIF(NOT CMAKE_RC_COMPILER_INIT) - SET(CMAKE_RC_COMPILER ${CMAKE_RC_COMPILER_INIT} CACHE STRING "RC compiler") + # finally list compilers to try + IF(CMAKE_RC_COMPILER_INIT) + SET(CMAKE_RC_COMPILER_LIST ${CMAKE_RC_COMPILER_INIT}) + ELSE(CMAKE_RC_COMPILER_INIT) + SET(CMAKE_RC_COMPILER_LIST c++ g++ CC aCC cl bcc xlC) + ENDIF(CMAKE_RC_COMPILER_INIT) + + # Find the compiler. + FIND_PROGRAM(CMAKE_RC_COMPILER NAMES ${CMAKE_RC_COMPILER_LIST} DOC "RC compiler") + IF(CMAKE_RC_COMPILER_INIT AND NOT CMAKE_RC_COMPILER) + SET(CMAKE_RC_COMPILER "${CMAKE_RC_COMPILER_INIT}" CACHE FILEPATH "RC compiler" FORCE) + ENDIF(CMAKE_RC_COMPILER_INIT AND NOT CMAKE_RC_COMPILER) ENDIF(NOT CMAKE_RC_COMPILER) MARK_AS_ADVANCED(CMAKE_RC_COMPILER) -- cgit v0.12