|
| 1 | +if(NOT CMAKE_BUILD_TYPE) |
| 2 | + set(CMAKE_BUILD_TYPE "Release" CACHE |
| 3 | + STRING "Choose the type of build." FORCE) |
| 4 | +endif(NOT CMAKE_BUILD_TYPE) |
| 5 | + |
| 6 | +if(Kokkos_ENABLE_CUDA) |
| 7 | + set(Kokkos_ENABLE_CUDA_LAMBDA ON CACHE BOOL "don't touch") |
| 8 | + set(CMAKE_CXX_COMPILER ${CMAKE_CURRENT_SOURCE_DIR}/lib/kokkos/bin/nvcc_wrapper) |
| 9 | +endif() |
| 10 | + |
| 11 | +cmake_minimum_required(VERSION 3.16) |
| 12 | +set(CMAKE_CXX_STANDARD 14) |
| 13 | + |
| 14 | +project(Phoebe LANGUAGES C CXX Fortran VERSION 1.0) |
| 15 | + |
| 16 | +configure_file(src/main.h.in ../src/main.h) |
| 17 | + |
| 18 | +## load custom cmake find_package |
| 19 | +set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") |
| 20 | + |
| 21 | +if(CMAKE_CXX_COMPILER_ID MATCHES GNU) |
| 22 | + SET(GCC_COVERAGE_COMPILE_FLAGS "-Wall -Wextra -ggdb -fno-omit-frame-pointer -Wno-deprecated-copy -Wno-ignored-attributes") |
| 23 | + add_definitions(${GCC_COVERAGE_COMPILE_FLAGS}) |
| 24 | + add_compile_options(-Wno-error=parentheses) |
| 25 | +endif() |
| 26 | + |
| 27 | +############ OPTIONS ################ |
| 28 | +# these can be toggled in a build script by |
| 29 | +# supplying arguments to cmake like cmake -DHDF5_AVAIL=OFF ../ |
| 30 | +option(MPI_AVAIL "Build with MPI wrappers" ON) |
| 31 | +option(OMP_AVAIL "Build with OMP" ON) |
| 32 | +option(HDF5_AVAIL "Build with HDF5" ON) |
| 33 | +option(HDF5_SERIAL "Force build to accomodate serial only HDF5, but still use MPI" OFF) |
| 34 | +option(BUILD_DOC "Build documentation" ON) |
| 35 | + |
| 36 | +############### SOURCE ############### |
| 37 | + |
| 38 | +FILE(GLOB_RECURSE SOURCE_FILES src src/*.cpp) |
| 39 | +list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp) |
| 40 | + |
| 41 | +message(${CMAKE_CURRENT_SOURCE_DIR}) |
| 42 | +message(${SOURCE_FILES}) |
| 43 | + |
| 44 | +FILE(GLOB TEST_SOURCES test/*.cpp test/interaction3ph/*.cpp) |
| 45 | + |
| 46 | +include_directories(src src/algebra src/apps src/bands src/bte src/constants src/harmonic src/interaction src/mpi src/observable src/parser src/points) |
| 47 | + |
| 48 | +include(lib/CMakeLists.txt) |
| 49 | +include(GoogleTest) |
| 50 | + |
| 51 | +add_executable(phoebe src/main.cpp ${SOURCE_FILES}) |
| 52 | +add_executable(runTests ${TEST_SOURCES} ${SOURCE_FILES}) |
| 53 | +set_target_properties(runTests PROPERTIES EXCLUDE_FROM_ALL TRUE) |
| 54 | + |
| 55 | +# dependencies |
| 56 | +add_dependencies(phoebe spglib_dep pugixml_dep eigen_dep) |
| 57 | +add_dependencies(runTests spglib_dep pugixml_dep eigen_dep) |
| 58 | + |
| 59 | +target_link_libraries(phoebe symspg pugixml kokkos nlohmann_json::nlohmann_json) |
| 60 | +enable_testing() |
| 61 | +target_link_libraries(runTests symspg pugixml gtest_main kokkos nlohmann_json::nlohmann_json) |
| 62 | + |
| 63 | +gtest_discover_tests( |
| 64 | + runTests |
| 65 | + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 66 | +) |
| 67 | + |
| 68 | +################ PARALLEL #################### |
| 69 | +# build with MPI and scalapack |
| 70 | +if (MPI_AVAIL) |
| 71 | + find_package(MPI REQUIRED) |
| 72 | + target_link_libraries(phoebe MPI::MPI_CXX) |
| 73 | + target_link_libraries(runTests MPI::MPI_CXX) |
| 74 | + add_definitions("-DMPI_AVAIL") # this sets turns on ifdefs for mpi in the cpp |
| 75 | + |
| 76 | + find_library(SCALAPACK_LIB NAMES scalapack scalapack-openmpi mkl_scalapack_lp64 PATHS ENV LD_LIBRARY_PATH) |
| 77 | + if(${SCALAPACK_LIB} MATCHES NOTFOUND) |
| 78 | + ExternalProject_Add(scalapack_dep |
| 79 | + BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/scalapack_build |
| 80 | + SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/scalapack_src |
| 81 | + GIT_REPOSITORY https://github.com/Reference-ScaLAPACK/scalapack.git |
| 82 | + INSTALL_COMMAND "" |
| 83 | + UPDATE_COMMAND "" |
| 84 | + CMAKE_ARGS |
| 85 | + -DCMAKE_BUILD_TYPE=Release |
| 86 | + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} |
| 87 | + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} |
| 88 | + -DCMAKE_Fortran_COMPILER=${CMAKE_Fortran_COMPILER} |
| 89 | + ) |
| 90 | + set(SCALAPACK_LIB scalapack) |
| 91 | + message(WARNING "No SCALAPACK library found in CMAKE_LIBRARY_PATH, building our own.") |
| 92 | + add_dependencies(phoebe scalapack_dep) |
| 93 | + else() |
| 94 | + if(${SCALAPACK_LIB} MATCHES mkl) |
| 95 | + if("${MPI_CXX_LIBRARIES}" MATCHES openmpi) |
| 96 | + find_library(BLACS_LIB NAMES mkl_blacs_openmpi_lp64 PATHS ENV LD_LIBRARY_PATH) |
| 97 | + elseif("${MPI_CXX_LIBRARIES}" MATCHES intel) |
| 98 | + find_library(BLACS_LIB NAMES mkl_blacs_intelmpi_lp64 PATHS ENV LD_LIBRARY_PATH) |
| 99 | + else() |
| 100 | + message(FATAL_ERROR "Confused by MPI library when looking for BLACS.") |
| 101 | + endif() |
| 102 | + if(${BLACS_LIB} MATCHES NOTFOUND) |
| 103 | + message(FATAL_ERROR "Found Intel SCALAPACK but not BLACS") |
| 104 | + endif() |
| 105 | + message(STATUS "Found BLACS: ${BLACS_LIB}") |
| 106 | + endif() |
| 107 | + message(STATUS "Found SCALAPACK: ${SCALAPACK_LIB}") |
| 108 | + endif() |
| 109 | + |
| 110 | + find_package(BLAS REQUIRED) |
| 111 | + find_package(LAPACK REQUIRED) |
| 112 | + include_directories(${BLAS_INCLUDE_DIR}) |
| 113 | + include_directories(${LAPACK_INCLUDE_DIR}) |
| 114 | + ## Very important to link scalapack before blas and lapack |
| 115 | + target_link_libraries(phoebe ${SCALAPACK_LIB} ${BLACS_LIB} ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} -lgfortran) |
| 116 | + target_link_libraries(runTests ${SCALAPACK_LIB} ${BLACS_LIB} ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} -lgfortran) |
| 117 | + |
| 118 | +else() |
| 119 | + set(HDF5_SERIAL ON) |
| 120 | + |
| 121 | + ## even for the serial version, we require lapack |
| 122 | + find_package(BLAS REQUIRED) |
| 123 | + find_package(LAPACK REQUIRED) |
| 124 | + include_directories(${BLAS_INCLUDE_DIR}) |
| 125 | + include_directories(${LAPACK_INCLUDE_DIR}) |
| 126 | + target_link_libraries(phoebe ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} -lgfortran) |
| 127 | + target_link_libraries(runTests ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} -lgfortran) |
| 128 | + |
| 129 | +endif() |
| 130 | + |
| 131 | +# build with openMP |
| 132 | +if(OMP_AVAIL) |
| 133 | + find_package(OpenMP) |
| 134 | + target_link_libraries(phoebe OpenMP::OpenMP_CXX) |
| 135 | + target_link_libraries(runTests OpenMP::OpenMP_CXX) |
| 136 | + add_definitions("-DOMP_AVAIL") |
| 137 | +endif() |
| 138 | + |
| 139 | +# build with HDF5 |
| 140 | +if(HDF5_AVAIL) |
| 141 | + if(HDF5_SERIAL) |
| 142 | + add_definitions("-DHDF5_SERIAL") |
| 143 | + else() |
| 144 | + set(HDF5_PREFER_PARALLEL TRUE) |
| 145 | + endif() |
| 146 | + add_dependencies(phoebe highfive_dep) |
| 147 | + add_dependencies(runTests highfive_dep) |
| 148 | + find_package(HDF5 REQUIRED) |
| 149 | + target_link_libraries(phoebe ${HDF5_LIBRARIES}) |
| 150 | + target_link_libraries(runTests ${HDF5_LIBRARIES}) |
| 151 | + include_directories(${HDF5_INCLUDE_DIRS}) |
| 152 | + add_definitions("-DHDF5_AVAIL") |
| 153 | +endif() |
| 154 | + |
| 155 | +############# DOCS ############ |
| 156 | + |
| 157 | +find_package(Doxygen) |
| 158 | +find_package(Sphinx) |
| 159 | + |
| 160 | +IF (BUILD_DOC) |
| 161 | + IF (NOT DOXYGEN_FOUND) |
| 162 | + message("Doxygen need to be installed to generate the doxygen documentation") |
| 163 | + else() |
| 164 | + # set input and output files |
| 165 | + set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/doc/doxygen/Doxyfile) |
| 166 | + set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/doc/doxygen/Doxyfile.out) |
| 167 | + |
| 168 | + # request to configure the file |
| 169 | + configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) |
| 170 | + message("Doxygen configured") |
| 171 | + |
| 172 | + # note the option ALL which allows to build the docs together with the application |
| 173 | + add_custom_target( |
| 174 | + docDevel |
| 175 | + COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_IN} |
| 176 | + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../doc/doxygen |
| 177 | + COMMENT "Generating API documentation with Doxygen" |
| 178 | + VERBATIM) |
| 179 | + |
| 180 | + IF (NOT SPHINX_FOUND) |
| 181 | + message("Documentation needs also sphinx") |
| 182 | + else() |
| 183 | + add_custom_target( |
| 184 | + doc |
| 185 | + COMMAND make html |
| 186 | + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../doc/sphinx |
| 187 | + COMMENT "Building user documentation with Sphinx" |
| 188 | + VERBATIM) |
| 189 | + add_dependencies(doc docDevel) |
| 190 | + endif() |
| 191 | + |
| 192 | + ENDIF() |
| 193 | +endif() |
| 194 | + |
| 195 | + |
| 196 | + |
0 commit comments