From 8326a972ee36357ae635e91b43e9c250ed35a202 Mon Sep 17 00:00:00 2001 From: julie Date: Fri, 31 Dec 2010 01:33:24 +0000 Subject: Re-worked the type size check to be much more compact - Chuck Atkins (Kitware) --- CMAKE/CheckFortranIntSize.cmake | 60 --------------------------------------- CMAKE/CheckFortranTypeSizes.cmake | 47 ++++++++++++++++++++++++++++++ CMAKE/FindBLAS.cmake | 7 +++-- 3 files changed, 52 insertions(+), 62 deletions(-) delete mode 100644 CMAKE/CheckFortranIntSize.cmake create mode 100644 CMAKE/CheckFortranTypeSizes.cmake (limited to 'CMAKE') diff --git a/CMAKE/CheckFortranIntSize.cmake b/CMAKE/CheckFortranIntSize.cmake deleted file mode 100644 index d575e2e8..00000000 --- a/CMAKE/CheckFortranIntSize.cmake +++ /dev/null @@ -1,60 +0,0 @@ -# This module perdorms several try-compiles to determine the default integer -# size being used by the fortran compiler -# -# After execution, the following variable is set: -# -# SIZEOF_INTEGER - Number of bytes used to store the default integer type -# Will be set to 1, 2, 4, 8 or 16 if successful, otherwise it -# will be unset -# -#============================================================================= -# Author: Chuck Atkins -# Copyright 2010 -#============================================================================= - -macro( CHECK_FORTRAN_INT_SIZE ) - if( NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90 ) - message( FATAL_ERROR "Type size tests require Fortran 90 support" ) - endif() - if( NOT SIZEOF_INTEGER ) - foreach( _TEST_SIZE 1 2 4 8 16 ) - message( STATUS "Testing default integer*${_TEST_SIZE} - " ) - set( _TEST_FILE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranInteger${_TEST_SIZE}.f90 ) - file( WRITE ${_TEST_FILE} " - module check_int_size - interface int_size - function int_size_${_TEST_SIZE}(a) result(int_size) - integer*${_TEST_SIZE} a - integer int_size - end function int_size_${_TEST_SIZE} - end interface - end module - - program check_int_size_${_TEST_SIZE} - use check_int_size - integer a, b - a = 7 - b = int_size(a) - end program - - function int_size_${_TEST_SIZE}(a) result(int_size) - integer*4 a - int_size = 7 - end function - ") - try_compile( SIZEOF_INTEGER ${CMAKE_BINARY_DIR} ${_TEST_FILE} ) - if( SIZEOF_INTEGER ) - message( STATUS "Testing default integer*${_TEST_SIZE} - found" ) - set( SIZEOF_INTEGER ${_TEST_SIZE} CACHE INTERNAL "Size of the default INTEGER type" FORCE ) - break() - else() - message( STATUS "Testing default integer*${_TEST_SIZE} - not found" ) - endif() - endforeach() - endif() - - if( NOT SIZEOF_INTEGER ) - unset( SIZEOF_INTEGER ) - endif() -endmacro() - diff --git a/CMAKE/CheckFortranTypeSizes.cmake b/CMAKE/CheckFortranTypeSizes.cmake new file mode 100644 index 00000000..e7c6ad6b --- /dev/null +++ b/CMAKE/CheckFortranTypeSizes.cmake @@ -0,0 +1,47 @@ +# This module perdorms several try-compiles to determine the default integer +# size being used by the fortran compiler +# +# After execution, the following variables are set. If they are un set then +# size detection was not possible +# +# SIZEOF_CHARACTER - Number of bytes used to store the default CHARACTER type +# SIZEOF_LOGICAL - Number of bytes used to store the default LOGICAL type +# SIZEOF_INTEGER - Number of bytes used to store the default INTEGER type +# SIZEOF_REAL - Number of bytes used to store the default REAL type +# SIZEOF_COMPLEX - Number of bytes used to store the default COMPLEX type +# +#============================================================================= +# Author: Chuck Atkins +# Copyright 2010 +#============================================================================= + +macro( CHECK_FORTRAN_TYPE_SIZES ) + if( NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90 ) + message( FATAL_ERROR "Type size tests require Fortran 90 support" ) + endif() + foreach( _TEST_TYPE "CHARACTER" "LOGICAL" "INTEGER" "REAL" "COMPLEX" ) + string( REPLACE " " "_" _TEST_TYPE_VAR "${_TEST_TYPE}" ) + foreach( _TEST_SIZE 1 2 4 8 16 32 ) + set( _TEST_FILE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortran${_TEST_TYPE_VAR}Size${_TEST_SIZE}.f90 ) + file( WRITE ${_TEST_FILE} +" + PROGRAM check_size + ${_TEST_TYPE}*${_TEST_SIZE}, TARGET :: a + ${_TEST_TYPE}, POINTER :: pa + pa => a + END PROGRAM +") + try_compile( SIZEOF_${_TEST_TYPE_VAR} ${CMAKE_BINARY_DIR} ${_TEST_FILE} ) + if( SIZEOF_${_TEST_TYPE_VAR} ) + message( STATUS "Testing default ${_TEST_TYPE}*${_TEST_SIZE} - found" ) + set( SIZEOF_${_TEST_TYPE_VAR} ${_TEST_SIZE} CACHE INTERNAL "Size of the default ${_TEST_TYPE} type" FORCE ) + break() + endif() + endforeach() + if( NOT SIZEOF_${_TEST_TYPE_VAR} ) + message( WARNING "Unable to determine default size of type ${_TEST_TYPE}" ) + unset( SIZEOF_${_TEST_TYPE_VAR} CACHE ) + endif() + endforeach() +endmacro() + diff --git a/CMAKE/FindBLAS.cmake b/CMAKE/FindBLAS.cmake index 35442710..03e165f5 100644 --- a/CMAKE/FindBLAS.cmake +++ b/CMAKE/FindBLAS.cmake @@ -79,7 +79,7 @@ endif() include( CheckFortranFunctionExists ) include( CheckLibraryExists ) -include( CheckFortranIntSize ) +include( CheckFortranTypeSizes ) # Check the language being used get_property( _LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES ) @@ -124,7 +124,7 @@ else() endif() # Determine the default integer size -CHECK_FORTRAN_INT_SIZE() +CHECK_FORTRAN_TYPE_SIZES() if( NOT SIZEOF_INTEGER ) message( WARNING "Unable to determine default integer size. Assuming integer*4" ) set( SIZEOF_INTEGER 4 ) @@ -142,6 +142,9 @@ macro( _BLAS_LOCATE_AND_TEST __BLAS_VENDOR __BLAS_LIBNAMES __BLAS_FLAGS ) message( STATUS "FindBLAS: Searching for ${__BLAS_VENDOR} ${__BLAS_LIBNAME} - ${BLAS_${__BLAS_VENDOR}_${__BLAS_LIBNAME}_LIBRARY}" ) if( NOT BLAS_${__BLAS_VENDOR}_${__BLAS_LIBNAME}_LIBRARY ) unset( BLAS_${__BLAS_VENDOR}_LIBRARIES ) + foreach( __BLAS_LIBNAME ${__BLAS_LIBNAMES} ) + unset( BLAS_${__BLAS_VENDOR}_${__BLAS_LIBNAME}_LIBRARY CACHE) + endforeach() break() endif() set( BLAS_${__BLAS_VENDOR}_LIBRARIES -- cgit v1.2.3