test_HDF5.cmake 3.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#first try if hdf already works
try_compile(FLEUR_USE_HDF5 ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/tests/test_HDF5.f90
	    LINK_LIBRARIES ${FLEUR_LIBRARIES}
            )
#now try to find the library using HDF5_ROOT variable
if (NOT FLEUR_USE_HDF5)
   if (DEFINED ENV{HDF5_ROOT})
     find_path(HDF5_INCLUDE hdf5.mod PATHS $ENV{HDF5_ROOT} PATH_SUFFIXES include NO_DEFAULT_PATH)
     find_path(HDF5_LIB libhdf5_fortran.a PATHS $ENV{HDF5_ROOT} PATH_SUFFIXES lib NO_DEFAULT_PATH)
     if (HDF5_LIB) 
        set(TEST_LIBRARIES "-L${HDF5_LIB};-lhdf5_fortran;-lhdf5;${FLEUR_LIBRARIES}")
     endif()
     if (HDF5_INCLUDE)
        set(STORE_FLAGS ${CMAKE_Fortran_FLAGS})
        set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -I${HDF5_INCLUDE}")
     endif()
	try_compile(FLEUR_USE_HDF5 ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/tests/test_HDF5.f90
   	    LINK_LIBRARIES ${TEST_LIBRARIES}
            )
       if (NOT FLEUR_USE_HDF5)
	       set(CMAKE_Fortran_FLAGS ${STORE_FLAGS})
       else()
               set(FLEUR_LIBRARIES "-L${HDF5_LIB};-lhdf5_fortran;-lhdf5;${FLEUR_LIBRARIES}")
               set(FLEUR_MPI_LIBRARIES "-L${HDF5_LIB};-lhdf5_fortran;-lhdf5;${FLEUR_MPI_LIBRARIES}")
       endif()       	    
   endif()
endif()

#now try the find_package feature
if (NOT FLEUR_USE_HDF5)
      find_package(HDF5)
      if (NOT HDF5_LIBRARIES MATCHES "NOTFOUND")
          set(TEST_LIBRARIES ${HDF5_Fortran_LIBRARIES} ${FLEUR_LIBRARIES})
	  set(STORE_FLAGS ${CMAKE_Fortran_FLAGS})
          set(CMAKE_Fortran_FLAGS "-I${HDF5_INCLUDE_LIBRARIES}" ${CMAKE_Fortran_FLAGS})

try_compile(FLEUR_USE_HDF5 ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/tests/test_HDF5.f90
            LINK_LIBRARIES ${TEST_LIBRARIES}
            )
	    if (${FLEUR_USE_HDF5})
	       set(FLEUR_LIBRARIES ${HDF5_Fortran_LIBRARIES} ${FLEUR_LIBRARIES})
	       set(FLEUR_MPI_LIBRARIES ${HDF5_Fortran_LIBRARIES} ${FLEUR_MPI_LIBRARIES})
	    else()
               set(CMAKE_Fortran_FLAGS ${STORE_FLAGS})
	    endif()   
      endif()	
endif()       

49 50 51 52 53 54 55
#check if HDF is parallel
if ( FLEUR_USE_HDF5)
   try_compile(FLEUR_USE_HDF5MPI ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/tests/test_HDF5MPI.f90
            LINK_LIBRARIES ${FLEUR_LIBRARIES}
            )
endif()

56
message("HDF5 Library found:${FLEUR_USE_HDF5}")
Daniel Wortmann's avatar
Daniel Wortmann committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70

if (DEFINED ENV{FLEUR_USE_HDF5})
   if (ENV{FLEUR_USE_HDF5})
       if (NOT FLEUR_USE_HDF5)
           message(FATAL_ERROR "You asked for HDF5 but cmake couldn't find it. Please set HDF5_ROOT and or give additional compiler/linker flags")
       endif()
   else()
       if (FLEUR_USE_HDF5)
           message("HDF5 library found, but you explicitely asked not to use it")
	   set(FLEUR_USE_HDF5 FALSE)
       endif()
   endif()	   
endif()      

Daniel Wortmann's avatar
Daniel Wortmann committed
71
if (FLEUR_USE_HDF5)
Daniel Wortmann's avatar
Daniel Wortmann committed
72
   message("Parallel HDF5 Library found:${FLEUR_USE_HDF5}")
73 74
   set(FLEUR_DEFINITIONS ${FLEUR_DEFINITIONS} "CPP_HDF") 
   set(FLEUR_MPI_DEFINITIONS ${FLEUR_MPI_DEFINITIONS} "CPP_HDF")
75 76 77 78 79
   if (FLEUR_USE_HDF5MPI)
   if (FLEUR_USE_MPI)
      set(FLEUR_MPI_DEFINITIONS ${FLEUR_MPI_DEFINITIONS} "CPP_HDFMPI")
   endif()
   endif()
Daniel Wortmann's avatar
Daniel Wortmann committed
80
endif()