test_HDF5.cmake 2.84 KB
Newer Older
1 2 3 4
#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}
            )
5
#now try to find the library by adding the -l stuff to the FLEUR_LIBRARIES
6
if (NOT FLEUR_USE_HDF5)
7
     set(TEST_LIBRARIES "${FLEUR_LIBRARIES};-lhdf5_fortran;-lhdf5")
8 9 10 11 12 13 14 15 16 17 18
     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 ${TEST_LIBRARIES})
     endif()       	    
endif()

#now try to find the library by adding the -l stuff to the FLEUR_LIBRARIES
if (NOT FLEUR_USE_HDF5)
     set(TEST_LIBRARIES "${FLEUR_LIBRARIES};-lhdf5_fortran;-lhdf5_f90cstub;-lhdf5")
19
     try_compile(FLEUR_USE_HDF5 ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/tests/test_HDF5.f90
20 21
   	    LINK_LIBRARIES ${TEST_LIBRARIES}
            )
22 23 24
     if (FLEUR_USE_HDF5)
          set(FLEUR_LIBRARIES ${TEST_LIBRARIES})
     endif()       	    
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
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()       

47 48 49 50 51 52 53
#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()

54
message("HDF5 Library found:${FLEUR_USE_HDF5}")
Daniel Wortmann's avatar
Daniel Wortmann committed
55

56 57
if (DEFINED CLI_FLEUR_USE_HDF5})
   if (CLI_FLEUR_USE_HDF5})
Daniel Wortmann's avatar
Daniel Wortmann committed
58 59 60 61 62 63 64 65 66 67 68
       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
69
if (FLEUR_USE_HDF5)
70
   message("Parallel HDF5 Library found:${FLEUR_USE_HDF5MPI}")
71 72
   set(FLEUR_DEFINITIONS ${FLEUR_DEFINITIONS} "CPP_HDF") 
   set(FLEUR_MPI_DEFINITIONS ${FLEUR_MPI_DEFINITIONS} "CPP_HDF")
73 74 75 76 77
   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
78
endif()