summaryrefslogtreecommitdiff
path: root/CMAKE/CheckFortranTypeSizes.cmake
diff options
context:
space:
mode:
authorjulie <julielangou@users.noreply.github.com>2010-12-31 01:33:24 (GMT)
committerjulie <julielangou@users.noreply.github.com>2010-12-31 01:33:24 (GMT)
commit8326a972ee36357ae635e91b43e9c250ed35a202 (patch)
tree6dc83a41d83df695364a17a96674ada3586d68ec /CMAKE/CheckFortranTypeSizes.cmake
parent1a1c5a44dfaa87cb8a6292e03c57d77b987320b4 (diff)
downloadlapack-8326a972ee36357ae635e91b43e9c250ed35a202.zip
lapack-8326a972ee36357ae635e91b43e9c250ed35a202.tar.gz
lapack-8326a972ee36357ae635e91b43e9c250ed35a202.tar.bz2
Re-worked the type size check to be much more compact
- Chuck Atkins (Kitware)
Diffstat (limited to 'CMAKE/CheckFortranTypeSizes.cmake')
-rw-r--r--CMAKE/CheckFortranTypeSizes.cmake47
1 files changed, 47 insertions, 0 deletions
diff --git a/CMAKE/CheckFortranTypeSizes.cmake b/CMAKE/CheckFortranTypeSizes.cmake
new file mode 100644
index 0000000..e7c6ad6
--- /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()
+