test_HDF5.cmake 3.87 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 7 8 9 10 11 12
foreach(ADD_String "-lhdf5_fortran;-lhdf5" 
                   "-lhdf5_fortran;-lhdf5_f90cstub;-lhdf5"
		   "-lhdf5_fortran;-lhdf5;-ldl" 
                   "-lhdf5_fortran;-lhdf5_f90cstub;-lhdf5;-ldl"
                   "-lhdf5_fortran;-lhdf5;-lz" 
                   "-lhdf5_fortran;-lhdf5_f90cstub;-lhdf5;-lz"
		   "-lhdf5_fortran;-lhdf5;-ldl;-lz" 
13
                   "-lhdf5_fortran;-lhdf5_f90cstub;-lhdf5;-ldl;-lz")
14
   if (NOT FLEUR_USE_HDF5)
15
     set(TEST_LIBRARIES "${FLEUR_LIBRARIES};${ADD_String}")
16 17 18 19 20 21
     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()       	    
22 23
   endif()
endforeach()
24

25 26 27 28 29 30 31
#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()

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

34 35
if (DEFINED CLI_FLEUR_USE_HDF5)
   if (CLI_FLEUR_USE_HDF5)
Daniel Wortmann's avatar
Daniel Wortmann committed
36
       if (NOT FLEUR_USE_HDF5)
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
           message(WARNING "You asked for HDF5 but cmake couldn't find it. We will try to download and compile HDF5 along with FLEUR")
           if(NOT EXISTS "${PROJECT_SOURCE_DIR}/external/hdf5-git/src" )
    	     find_package(Git REQUIRED)
    	     execute_process(COMMAND ${GIT_EXECUTABLE} submodule init external/hdf5-git WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} RESULT_VARIABLE _res_init OUTPUT_QUIET ERROR_QUIET)
    	     execute_process(COMMAND ${GIT_EXECUTABLE} submodule update  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} RESULT_VARIABLE _res_update OUTPUT_QUIET ERROR_QUIET)
    	     if( ${_res_init} GREATER 0 OR ${_res_update} GREATER 0 )
               message(FATAL_ERROR "HDF5 source could not be downloaded.\n"
                            "We tried: 'git submodule init external/hdf5-git && git submodule update' and resulted in error" )
             endif()
	   endif()
	   set(HDF5_EXTERNALLY_CONFIGURED 1)
	   set(HDF5_EXPORTED_TARGETS "hdf5_fortran-static")
	   set(HDF5_BUILD_FORTRAN ON CACHE BOOL "Build FORTRAN support")
	   set(HDF5_BUILD_CPP_LIB OFF CACHE BOOL "Build HDF5 C++ Library")
	   set(HDF5_BUILD_HL_LIB OFF CACHE BOOL "Build HIGH Level HDF5 Library")
	   set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build Shared Libraries")
	   set(HDF5_BUILD_TOOLS OFF CACHE BOOL "Build HDF5 Tools")
	   set(HDF5_BUILD_EXAMPLES OFF CACHE BOOL "Build HDF5 Library Examples")
	   set(BUILD_TESTING OFF CACHE BOOL "Build HDF5 Unit Testing")
	   if (FLEUR_USE_MPI)
	   set(HDF5_ENABLE_PARALLEL ON CACHE BOOL "Enable parallel build (requires MPI)")
	   else()
		set(HDF5_ENABLE_PARALLEL OFF CACHE BOOL "Enable parallel build (requires MPI)")
	   endif()
	   set(CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/modules/hdf5")
	   add_subdirectory (external/hdf5-git EXCLUDE_FROM_ALL)
63
	   set(FLEUR_USE_HDF5 TRUE)
64
           set(FLEUR_USE_HDF5MPI FLEUR_USE_MPI)
65
           set(FLEUR_COMPILE_HDF true)
66
           include_directories("${CMAKE_CURRENT_BINARY_DIR}/modules/hdf5/static")
Daniel Wortmann's avatar
Daniel Wortmann committed
67 68 69 70 71 72 73 74 75
       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()      

76
if (FLEUR_USE_HDF5)
77
   message("Parallel HDF5 Library found:${FLEUR_USE_HDF5MPI}")
78 79
   set(FLEUR_DEFINITIONS ${FLEUR_DEFINITIONS} "CPP_HDF") 
   set(FLEUR_MPI_DEFINITIONS ${FLEUR_MPI_DEFINITIONS} "CPP_HDF")
80 81 82 83 84
   if (FLEUR_USE_HDF5MPI)
   if (FLEUR_USE_MPI)
      set(FLEUR_MPI_DEFINITIONS ${FLEUR_MPI_DEFINITIONS} "CPP_HDFMPI")
   endif()
   endif()
85
endif()