|
| 1 | + |
| 2 | +# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, |
| 3 | +# All rights reserved. |
| 4 | +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). |
| 5 | + |
| 6 | +# @file CMakeLists.txt |
| 7 | +# @brief This is a CMakeLists.txt file for a C++ project ExaGeoStat. |
| 8 | +# The project is a parallel high performance unified framework for geographical statistics on manycore systems. |
| 9 | +# The file sets up variables and finds dependencies required for the project. |
| 10 | +# It also provides options to enable building tests, building examples, building documentation, and enabling a packaging system for distribution. |
| 11 | +# @version 1.0.0 |
| 12 | +# @author Mahmoud ElKarargy |
| 13 | +# @author Sameh Abdulah |
| 14 | +# @date 2023-01-30 |
| 15 | + |
| 16 | +# Set the minimum CMake version required to 3.20 |
| 17 | +cmake_minimum_required(VERSION 3.20 FATAL_ERROR) |
| 18 | +cmake_policy(SET CMP0048 NEW) |
| 19 | + |
| 20 | +# Set project options |
| 21 | +option(USE_CUDA "Use Cuda, if available" false) |
| 22 | +option(USE_MPI "Use MPI, if available" false) |
| 23 | +option(EXAGEOSTAT_BUILD_TESTS "Option to enable building tests" ON) |
| 24 | +option(EXAGEOSTAT_BUILD_EXAMPLES "Option to enable building examples" ON) |
| 25 | +option(EXAGEOSTAT_BUILD_DOCS "Build documentation in docs directory" ON) |
| 26 | +option(EXAGEOSTAT_PACKAGE "Enable a packaging system for distribution" OFF) |
| 27 | + |
| 28 | +# Cmake Module Paths |
| 29 | +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}") |
| 30 | + |
| 31 | +# Select toolchain based on whether CUDA is enabled or not |
| 32 | +if (USE_CUDA) |
| 33 | + # Enable CUDA and include CudaToolchain |
| 34 | + add_definitions(-DUSE_CUDA=TRUE) |
| 35 | + enable_language(CUDA) |
| 36 | + include(toolchains/CudaToolchain) |
| 37 | + # Set BLA_VENDOR to NVHPC for CUDA-enabled builds |
| 38 | + set(BLA_VENDOR NVHPC) |
| 39 | + list(APPEND STARPU_COMPONENT_LIST "CUDA") |
| 40 | +else () |
| 41 | + message("-- Build x86 Support") |
| 42 | + # Include GccToolchain for non-CUDA builds - Gcc |
| 43 | + include(toolchains/GccToolchain) |
| 44 | +endif () |
| 45 | + |
| 46 | +# Project Name and Version |
| 47 | +project(exageostatcpp VERSION 1.0.0 DESCRIPTION "ExaGeoStat is a parallel high performance unified framework for geostatistics on manycore systems.") |
| 48 | + |
| 49 | +# Show the current version of CMake. |
| 50 | +message(STATUS "CMAKE VERSION: ${CMAKE_VERSION}") |
| 51 | +# Enable C++ language |
| 52 | +enable_language(CXX) |
| 53 | + |
| 54 | +add_compile_definitions(PROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}/") |
| 55 | + |
| 56 | +add_definitions( |
| 57 | + -DLOG_PATH="${PROJECT_SOURCE_DIR}/synthetic_ds/" |
| 58 | + -DKERNELS_PATH="${PROJECT_SOURCE_DIR}/inst/include/kernels/concrete/" |
| 59 | +) |
| 60 | + |
| 61 | +# Add all dependencies for ExaGeoStat PP |
| 62 | +if (USE_CUDA) |
| 63 | + message("-- Build CUDA Support") |
| 64 | +else () |
| 65 | + message("-- Build x86 Support") |
| 66 | + set(gpu_backend CACHE STRING "none" FORCE) |
| 67 | + unset(BLA_VENDOR) |
| 68 | +endif () |
| 69 | + |
| 70 | +# EXAGEOSTAT depends on a MPI |
| 71 | +# ------------------------------- |
| 72 | +if (USE_MPI) |
| 73 | + # Enable MPI and include MPI |
| 74 | + add_definitions(-DUSE_MPI=TRUE) |
| 75 | + message(STATUS "Trying to find MPI") |
| 76 | + find_package(MPI REQUIRED) |
| 77 | + list(APPEND STARPU_COMPONENT_LIST "MPI") |
| 78 | +endif () |
| 79 | + |
| 80 | +# EXAGEOSTAT depends on LAPACKE |
| 81 | +#----------------------------- |
| 82 | +find_package(LAPACKE) |
| 83 | +list(APPEND LIBS ${LAPACKE_LIBRARIES}) |
| 84 | +link_directories(${LAPACKE_LIBRARY_DIRS_DEP}) |
| 85 | +include_directories(${LAPACKE_INCLUDE_DIRS}) |
| 86 | + |
| 87 | +# Check if no path is set for installation |
| 88 | +if (NOT EXAGEOSTAT_INSTALL_PREFIX) |
| 89 | + message(FATAL_ERROR "Installation path not set! Please use -DEXAGEOSTAT_INSTALL_PREFIX=path/to/install or use ./config.sh") |
| 90 | +endif () |
| 91 | +# Print installation path of Exageostat. |
| 92 | +message(STATUS "Installation path : ${EXAGEOSTAT_INSTALL_PREFIX}") |
| 93 | + |
| 94 | +# EXAGEOSTAT depends on a Hwloc |
| 95 | +# ------------------------------- |
| 96 | +include(ImportHwloc) |
| 97 | +list(APPEND STARPU_COMPONENT_LIST "HWLOC") |
| 98 | + |
| 99 | +string(REPLACE ";" " " STARPU_COMPONENT_STRING "${STARPU_COMPONENT_LIST}") |
| 100 | + |
| 101 | +# EXAGEOSTAT depends on a runtime |
| 102 | +# ------------------------------- |
| 103 | +include(ImportStarPu) |
| 104 | + |
| 105 | +# EXAGEOSTAT depends on a GSL |
| 106 | +# ------------------------------- |
| 107 | +include(ImportGSL) |
| 108 | + |
| 109 | +# EXAGEOSTAT depends on a NLOPT |
| 110 | +# ------------------------------- |
| 111 | +include(ImportNLOPT) |
| 112 | + |
| 113 | +# EXAGEOSTAT depends on HiCMA |
| 114 | +# ------------------------------- |
| 115 | +if (EXAGEOSTAT_USE_HICMA) |
| 116 | + add_definitions(-DEXAGEOSTAT_USE_HICMA=TRUE) |
| 117 | + message(STATUS "Add Hcore, Dependency needed for HiCMA") |
| 118 | + include(ImportHcore) |
| 119 | + message(STATUS "Add StarsH, Dependency needed for HiCMA") |
| 120 | + include(ImportStarsH) |
| 121 | + include(ImportHiCMA) |
| 122 | +endif () |
| 123 | + |
| 124 | +# EXAGEOSTAT depends on CHAMELEON |
| 125 | +# ------------------------------- |
| 126 | +include(ImportChameleon) |
| 127 | + |
| 128 | +# EXAGEOSTAT depends on a LAPACK/BLASPP |
| 129 | +# ------------------------------- |
| 130 | +include(ImportBlasPP) |
| 131 | +include(ImportLapack) |
| 132 | + |
| 133 | +# EXAGEOSTAT DOCUMENTATIONS |
| 134 | +if (EXAGEOSTAT_BUILD_DOCS) |
| 135 | + find_package(Doxygen) |
| 136 | + |
| 137 | + if (DOXYGEN_FOUND) |
| 138 | + add_subdirectory("docs") |
| 139 | + else () |
| 140 | + message(STATUS "Doxygen NOT found, skipping it") |
| 141 | + endif () |
| 142 | +endif () |
| 143 | + |
| 144 | +# Include directories for Exageostat-cpp |
| 145 | +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inst/include) |
| 146 | +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/prerequisites) |
| 147 | +set(MY_LOGGER_PATH ${CMAKE_CURRENT_SOURCE_DIR}) |
| 148 | +add_definitions(-DMY_LOGGER_PATH="${CMAKE_CURRENT_SOURCE_DIR}") |
| 149 | + |
| 150 | +# Add src Directory to expose added libraries |
| 151 | +add_subdirectory(src) |
| 152 | + |
| 153 | +# Creates a new INTERFACE library target named ${PROJECT_NAME}_INTERFACE. |
| 154 | +# The INTERFACE keyword specifies that this library will not be built, but instead will only be used for its properties. |
| 155 | +add_library(${PROJECT_NAME}_INTERFACE INTERFACE) |
| 156 | +target_link_libraries(${PROJECT_NAME}_INTERFACE INTERFACE ${PROJECT_NAME}) |
| 157 | + |
| 158 | +# Add linker options to the target |
| 159 | +target_link_options(${PROJECT_NAME}_INTERFACE INTERFACE "SHELL:-Wl,--whole-archive $<TARGET_FILE:${PROJECT_NAME}> -Wl,--no-whole-archive") |
| 160 | + |
| 161 | +# Install headers |
| 162 | +install(TARGETS exageostatcpp |
| 163 | + DESTINATION lib/ |
| 164 | + PUBLIC_HEADER DESTINATION include/ |
| 165 | + ) |
| 166 | + |
| 167 | +# Add tests if enabled |
| 168 | +if (${EXAGEOSTAT_BUILD_TESTS}) |
| 169 | + message(STATUS "Building Tests") |
| 170 | + include(ImportCatch2) |
| 171 | + include(Catch) |
| 172 | + include(CTest) |
| 173 | + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests/cpp-tests) |
| 174 | + enable_testing() |
| 175 | +endif () |
| 176 | + |
| 177 | + |
| 178 | +if (EXAGEOSTAT_BUILD_EXAMPLES) |
| 179 | + message(STATUS "Building Examples is Enabled") |
| 180 | + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples) |
| 181 | +endif () |
| 182 | + |
| 183 | +# Installation actions |
| 184 | +install(DIRECTORY include/${PROJECT_NAME} DESTINATION include) |
| 185 | +## Install cmake find package. |
| 186 | +include(CMakePackageConfigHelpers) |
| 187 | +write_basic_package_version_file("${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" COMPATIBILITY ExactVersion) |
| 188 | +install( |
| 189 | + FILES |
| 190 | + "${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" |
| 191 | + DESTINATION lib/cmake/${PROJECT_NAME} |
| 192 | +) |
| 193 | + |
| 194 | +configure_file(${PROJECT_NAME}Config.cmake.in |
| 195 | + ${PROJECT_NAME}Config.cmake @ONLY) |
| 196 | + |
| 197 | +install( |
| 198 | + FILES |
| 199 | + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" |
| 200 | + DESTINATION lib/cmake/${PROJECT_NAME} |
| 201 | +) |
| 202 | + |
| 203 | +install( |
| 204 | + DIRECTORY |
| 205 | + "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 206 | + DESTINATION lib/cmake/${PROJECT_NAME}/Modules |
| 207 | +) |
| 208 | + |
| 209 | +## Generate pkg-config file |
| 210 | +configure_file(package.pc.in |
| 211 | + lib/pkgconfig/${PROJECT_NAME}.pc @ONLY) |
| 212 | +install( |
| 213 | + FILES |
| 214 | + "${PROJECT_BINARY_DIR}/lib/pkgconfig/${PROJECT_NAME}.pc" |
| 215 | + DESTINATION lib/pkgconfig/ |
| 216 | +) |
| 217 | + |
| 218 | +if (EXAGEOSTAT_PACKAGE) |
| 219 | + ################## |
| 220 | + # Release source # |
| 221 | + ################## |
| 222 | + set(CPACK_SOURCE_GENERATOR "TGZ") |
| 223 | + set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") |
| 224 | + set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README.md) |
| 225 | + set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "ExaGeoStat is a parallel high performance unified framework for geostatistics on manycore systems. Its abbreviation stands for 'Exascale Geostatistics'.") |
| 226 | + set(CPACK_PACKAGE_VERSION "${${PROJECT_NAME}_VERSION}") |
| 227 | + set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") |
| 228 | + set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") |
| 229 | + set(CPACK_PACKAGE_VENDOR "KAUST") |
| 230 | + set(CPACK_PACKAGE_CONTACT "[email protected]") |
| 231 | + set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_SOURCE_DIR}/README.md) |
| 232 | + set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE) |
| 233 | + set(CPACK_SOURCE_IGNORE_FILES "bin;.git;.gitmodules;Jenkinsfile") |
| 234 | + include(CPack) |
| 235 | +endif () |
| 236 | + |
| 237 | +message(" \n \t ** Configurations of ExaGeoStat and installation of dependence is done successfully ** ") |
| 238 | +message("\t Export the following line to avoid re-install dependencies each time, This line assume that you haven't changed the installation path. ") |
| 239 | +message("\t If not, Please change the following paths with your installation path. \n") |
| 240 | +message("\t ------------------------------------------------------------------------------------------------------------------------------- ") |
| 241 | +message("\t export PKG_CONFIG_PATH=${EXAGEOSTAT_INSTALL_PREFIX}/CHAMELEON/lib/pkgconfig:${EXAGEOSTAT_INSTALL_PREFIX}/GSL/lib/pkgconfig:$PKG_CONFIG_PATH") |
| 242 | +message("\t export PKG_CONFIG_PATH=${EXAGEOSTAT_INSTALL_PREFIX}/HCORE/lib/pkgconfig:${EXAGEOSTAT_INSTALL_PREFIX}/HICMA/lib/pkgconfig:$PKG_CONFIG_PATH") |
| 243 | +message("\t export PKG_CONFIG_PATH=${EXAGEOSTAT_INSTALL_PREFIX}/HWLOC/lib/pkgconfig:${EXAGEOSTAT_INSTALL_PREFIX}/NLOPT/lib64/pkgconfig:$PKG_CONFIG_PATH") |
| 244 | +message("\t export PKG_CONFIG_PATH=${EXAGEOSTAT_INSTALL_PREFIX}/STARPU/lib/pkgconfig:${EXAGEOSTAT_INSTALL_PREFIX}/STARSH/lib/pkgconfig:$PKG_CONFIG_PATH") |
| 245 | +message("\t ------------------------------------------------------------------------------------------------------------------------------- \n") |
0 commit comments