CMakeLists.txt 27.9 KB
Newer Older
1
cmake_minimum_required (VERSION 3.10.0 FATAL_ERROR)
2

3
#
4
# Project Declaration
5 6
#--------------------
project(scalfmm CXX)
7
# check if compiling into source directories
8
string(COMPARE EQUAL "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" insource)
9
if(insource)
10
  message(FATAL_ERROR "${PROJECT_NAME} requires an out of source build. Goto ./Build and tapes cmake ../")
11
endif(insource)
12

13
#
COULAUD Olivier's avatar
COULAUD Olivier committed
14
# Version Number
15
# --------------
COULAUD Olivier's avatar
COULAUD Olivier committed
16

17
# SCALFMM version number.  An even minor number corresponds to releases.
18 19 20 21
set(${CMAKE_PROJECT_NAME}_MAJOR_VERSION 2)
set(${CMAKE_PROJECT_NAME}_MINOR_VERSION 0)
set(${CMAKE_PROJECT_NAME}_PATCH_VERSION rc0)
set(${CMAKE_PROJECT_NAME}_VERSION  "${${CMAKE_PROJECT_NAME}_MAJOR_VERSION}.${${CMAKE_PROJECT_NAME}_MINOR_VERSION}.${${CMAKE_PROJECT_NAME}_PATCH_VERSION}" )
COULAUD Olivier's avatar
COULAUD Olivier committed
22

23 24 25 26
#
# Set global c++ support
# ----------------------
set(CMAKE_CXX_STANDARD 14)
27

28 29 30 31
#
# Update cmake path
# -----------------
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/)
BRAMAS Berenger's avatar
BRAMAS Berenger committed
32

33 34 35 36 37
#
# Creating main lib
# -----------------
list(APPEND SCALFMM_SOURCES FAlgorithmTimers.cpp FLog.cpp FMemStats.cpp FSignalHandler.cpp)
list(TRANSFORM SCALFMM_SOURCES PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/src/")
38
add_library(${CMAKE_PROJECT_NAME} STATIC ${SCALFMM_SOURCES})
39 40 41 42 43 44 45 46 47
# Set library includes
# --------------------
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC
  $<BUILD_INTERFACE:${${CMAKE_PROJECT_NAME}_BINARY_DIR}/include>
  $<BUILD_INTERFACE:${${CMAKE_PROJECT_NAME}_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
  )

if(MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/morse_cmake")
48 49 50 51

  # Add extra cmake module path and initialize morse cmake modules
  # --------------------------------------------------------------
  if(MORSE_DISTRIB_DIR)
52 53 54 55 56
    list(APPEND CMAKE_MODULE_PATH ${MORSE_DISTRIB_DIR}/modules)
    set(MORSE_CMAKE_MODULE_PATH ${MORSE_DISTRIB_DIR}/modules )
  elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/morse_cmake")
    list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/morse_cmake/modules)
    set(MORSE_CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/morse_cmake/modules )
57
  endif()
58

59
  include(MorseInit)
60

61
  # Set the RPATH config
62
  # These options allow all installed executables to run correctly
63
  # when installed to the install diretory
64 65 66 67 68 69 70 71
  # --------------------
  # use, i.e. don't skip the full RPATH for the build tree
  set(CMAKE_SKIP_BUILD_RPATH  FALSE)
  # when building, don't use the install RPATH already
  # (but later on when installing)
  set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
  # the RPATH to be used when installing
  set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
72 73 74 75
  # add the automatically determined parts of the RPATH
  # which point to directories outside the build tree to the install RPATH
  set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

76

77 78
  # Build ScalFmm as static or dynamic lib
  # --------------------------------------
79
  # option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
80 81
  #
  # Options
82
  #
83 84 85 86 87 88 89 90 91 92 93
  # Cmake options for dependencies
  option( SCALFMM_USE_MPI              "Set to ON to build ScaFMM with MPI"         OFF )
  option( SCALFMM_USE_BLAS             "Set to ON to build ScaFMM with BLAS"        ON  )
  option( SCALFMM_USE_FFT              "Set to ON to build ScaFMM with FFTW"        OFF )
  option( SCALFMM_USE_STARPU           "Set to ON to build SCALFMM with StarPU"     OFF )

  # Cmake options that impact the build tree
  option( SCALFMM_BUILD_EXAMPLES       "Set to ON to compile examples "                ON  )
  option( SCALFMM_BUILD_TESTS          "Set to ON to build functionalities Tests"      OFF )
  option( SCALFMM_BUILD_UTESTS         "Set to ON to build UTests"                     OFF )
  option( SCALFMM_BUILD_UTILS          "Set to ON to build utils Tests"                OFF )
94
  option( SCALFMM_BUILD_DOC            "Set to ON to build the Doxygen documentation " OFF )
95

96
  # Cmake options to install additional content
97
  option( SCALFMM_INSTALL_DATA         "Set to ON to include the data when proceeding to the installtion " OFF )
98

99
  # Cmake options related to trace, logging and statistics
100 101
  option( SCALFMM_USE_LOG              "Set to ON to print output debug information" OFF )
  option( SCALFMM_USE_MEM_STATS        "Set to ON to profile memory"                 OFF )
102
  option( SCALFMM_USE_ASSERT           "Set to ON to enable safe tests during execution" ON  )
103
  option( SCALFMM_ONLY_DEVEL           "Set to ON to compile Development tools (only scalfmm team)" OFF )
104

105 106
  # Cmake options related to the targeted architecture
  option( SCALFMM_USE_MIC_NATIVE       "Set to ON to compile in native mode for MIC" OFF  )
Berenger Bramas's avatar
Berenger Bramas committed
107

108

Berenger Bramas's avatar
Berenger Bramas committed
109

110
  #
111 112 113 114 115 116 117 118 119
  # Set scalfmm global lists
  # ------------------------
  list(APPEND SCALFMM_CXX_FLAGS -fpic -Wall)

  # TODO: Find new way to resolve dependencies...
  # Set FUSE LIST
  # -------------
  set(FUSE_LIST "") # Construct during configure
  set(FUSE_DEP_AVAILABLE "MPI;CUDA;STARPU;OMP4;BLAS;FFT;OPENCL") # List to compare against when compiling tests, etc...
120
  #
121 122 123 124 125 126 127 128 129
  # OpenMP
  # ------
  if(NOT OpenMP_CXX_FOUND)
    find_package(OpenMP)
    if(OpenMP_CXX_FOUND)
      target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC OpenMP::OpenMP_CXX)
      list(APPEND SCALFMM_LIBRARIES OpenMP)
      if(OpenMP_CXX_VERSION_MAJOR GREATER_EQUAL 4)
        list(APPEND FUSE_LIST OMP4)
130
      endif()
131 132 133 134
    else(OpenMP_CXX_FOUND)
      message(WARNING "OPENMP NOT FOUND")
    endif(OpenMP_CXX_FOUND)
  endif(NOT OpenMP_CXX_FOUND)
135

136 137 138 139 140 141 142 143 144 145
  #
  # Inastemp
  # --------
  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/inastemp")

    # Set option() CMP0077 to old for inastemp...
    set(CMAKE_POLICY_DEFAULT_CMP0077 OLD)
    set(INASTEMP_JUST_LIB TRUE)
    set(INASTEMP_DO_INSTALL TRUE)
    # Create target
146
    add_subdirectory(inastemp)
147
    add_library(inastemp INTERFACE)
148
    target_include_directories(inastemp INTERFACE
149 150 151 152 153 154 155 156 157 158 159 160 161 162
      $<BUILD_INTERFACE:${INASTEMP_SOURCE_DIR}/Src>
      $<BUILD_INTERFACE:${INASTEMP_BINARY_DIR}/Src>
      $<INSTALL_INTERFACE:include>
      )
    string(REPLACE " -" ";-" INASTEMP_FLAGS "${INASTEMP_CXX_FLAGS}")
    list(REMOVE_DUPLICATES INASTEMP_FLAGS)
    target_compile_options(inastemp INTERFACE ${INASTEMP_FLAGS})
    target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC inastemp)

    message(STATUS "Inastemp flags : ${INASTEMP_FLAGS}")
    message(WARNING "Inastemp configures compile flags according to the current architure "
            "you are compiling on. If you target a different machine, be carefull "
            "with the available SIMD instruction set supported."
            "Thus, use INASTEMP_USE_XXX to target the correct instruction set.")
163

164
  else(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/inastemp")
165

166 167 168
    message(STATUS "Inastemp is not available.")
    message(STATUS "Please, initialize all git submodule.")
    message(FATAL_ERROR "Exit : Inastemp dependency not found.")
169

170 171 172 173 174 175 176
  endif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/inastemp")

  #
  # Specific Debug flags
  # --------------------
  if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    list(APPEND SCALFMM_CXX_FLAGS -funroll-loops)
BRAMAS Berenger's avatar
BRAMAS Berenger committed
177
    if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
178
      list(APPEND SCALFMM_CXX_FLAGS -fp-model\ strict)
BRAMAS Berenger's avatar
BRAMAS Berenger committed
179
    endif()
180 181 182 183 184 185 186 187 188
  endif()

  #
  # Specific Release flags
  # ----------------------
  if(CMAKE_BUILD_TYPE STREQUAL "Release")
    list(APPEND SCALFMM_CXX_FLAGS -funroll-loops)
    if(NOT APPLE)
      list(APPEND -ftree-vectorize)
189
      if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
190
        list(APPEND SCALFMM_CXX_FLAGS  -ipo  -fstrict-aliasing)
191
      endif()
192 193
      list(APPEND SCALFMM_CXX_FLAGS -ffast-math -ftree-vectorize)
    endif(NOT APPLE)
194
  endif()
195

196
  #
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
  # MPI
  # ---
  if(SCALFMM_USE_MPI)
    if(NOT MPI_FOUND)
      try_compile(COMPILE_INTEL ${CMAKE_CURRENT_BINARY_DIR}
      ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/compileTestIntel.cpp
      COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS}")
      if(COMPILE_INTEL)
        set(CMAKE_CXX_COMPILER_ID  "Intel")
      endif()
      message(STATUS "CXX  ${CMAKE_CXX_COMPILER_ID}" )

      find_package(MPI REQUIRED)
      if(MPI_CXX_FOUND)
        target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC MPI::MPI_CXX)
        list(APPEND SCALFMM_LIBRARIES MPI)
        list(APPEND FUSE_LIST MPI)
	target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/FMpi.cpp)
      else(MPI_CXX_FOUND)
216
        message(FATAL_ERROR "MPI_CXX is required but was not found. "
217 218 219 220 221 222
                "Please provide an MPI compiler in your environment."
                "Note that you can give the path to your MPI installation "
                "by setting MPI_DIR cmake variable.")
      endif(MPI_CXX_FOUND)
    endif(NOT MPI_FOUND)
  endif(SCALFMM_USE_MPI)
223
  #
224 225 226
  # Blas options
  # ------------
  if(SCALFMM_USE_BLAS)
227

228 229 230
    option( SCALFMM_USE_MKL_AS_BLAS   "Set to ON to use MKL BLAS/LAPACK" OFF )
    option( SCALFMM_USE_ESSL_AS_BLAS  "Set to ON to use ESSL BLAS/LAPACK" OFF )
    option( SCALFMM_USE_EXTERNAL_BLAS "Set to ON to use external BLAS. Please, set BLAS_LIBRARIES variable." OFF )
231

232
    if( SCALFMM_USE_MKL_AS_BLAS )
233
      set(BLA_VENDOR "Intel10_64lp_seq")
234
      find_package(BLAS ) # not REQUIRED
235 236
    elseif(SCALFMM_USE_ESSL_AS_BLAS)
      set(BLA_VENDOR "IBMESSL")
237 238
      find_package(BLAS   QUIET) # not REQUIRED
      find_package(LAPACK QUIET) # not REQUIRED
239
    elseif(SCALFMM_USE_EXTERNAL_BLAS)
240
      message(STATUS "BLAS SET BY EXTERNAL PROGRAM = ${BLAS_LIBRARIES}")
241
      list(APPEND BLASLAPACK_LIBRARIES "${BLAS_LIBRARIES}")
242
    else()
243 244
      find_package(BLAS)  # not REQUIRED
      find_package(LAPACK)  # not REQUIRED
245
    endif()
246

247
    if(BLAS_FOUND)
248 249 250 251 252 253 254
      target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC blas::blas)
      list(APPEND SCALFMM_LIBRARIES BLAS)
      list(APPEND FUSE_LIST BLAS)

      if(LAPACK_FOUND)
        target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC lapack::lapack)
        list(APPEND SCALFMM_LIBRARIES LAPACK)
255
      endif()
256 257

      message (STATUS "Check BLAS Fortran mangling")
258
      # add options to let the user be able to force a behavior
259
      option( SCALFMM_BLAS_ADD_     "Set to ON to force calls to BLAS Fortran symbols with _ (ex: dgemm_)"        ON )
260 261 262 263 264 265 266
      option( SCALFMM_BLAS_UPCASE   "Set to ON to force calls to BLAS Fortran symbols in capital (ex: DGEMM)"     OFF )
      option( SCALFMM_BLAS_NOCHANGE "Set to ON to force calls to BLAS Fortran symbols with no change (ex: dgemm)" OFF )
      # if options not changed by user then auto-detection
      if (NOT SCALFMM_BLAS_ADD_ AND NOT SCALFMM_BLAS_UPCASE AND NOT SCALFMM_BLAS_NOCHANGE)
        # give blas libraries and check dgemm symbol
        set(CMAKE_REQUIRED_LIBRARIES "${BLAS_LIBRARIES}")
        check_function_exists(dgemv_ DGEMV_ADD_)
267
        check_function_exists(DGEMV  DGEMV_UPCASE)
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
        check_function_exists(dgemv  DGEMV_NOCHANGE)
        # here we consider that the first kind of symbol found will be the one used
        # current order is: ADD_, UPCASE, NOCHANGE
        if (DGEMV_ADD_)
          set (SCALFMM_BLAS_ADD_     ON)
          set (SCALFMM_BLAS_UPCASE   OFF)
          set (SCALFMM_BLAS_NOCHANGE OFF)
          message (STATUS "BLAS dgemv_ symbol found, SCALFMM_BLAS_ADD_ is ON")
        else (DGEMV_ADD_)
          if (DGEMV_UPCASE)
            set (SCALFMM_BLAS_ADD_     OFF)
            set (SCALFMM_BLAS_UPCASE   ON)
            set (SCALFMM_BLAS_NOCHANGE OFF)
            message (STATUS "BLAS DGEMV symbol found, SCALFMM_BLAS_UPCASE is ON")
          else (DGEMV_UPCASE)
            if (DGEMV_NOCHANGE)
              set (SCALFMM_BLAS_ADD_     OFF)
              set (SCALFMM_BLAS_UPCASE   OFF)
              set (SCALFMM_BLAS_NOCHANGE ON)
              message (STATUS "BLAS dgemv symbol found, SCALFMM_BLAS_NOCHANGE is ON")
            endif (DGEMV_NOCHANGE)
          endif (DGEMV_UPCASE)
        endif (DGEMV_ADD_)
        if ( (NOT DGEMV_ADD_) AND (NOT DGEMV_UPCASE) AND (NOT DGEMV_NOCHANGE) )
          message(FATAL_ERROR "BLAS Fortran mangling is not properly detected - please check your BLAS libraries")
        endif ()
      else  (NOT SCALFMM_BLAS_ADD_ AND NOT SCALFMM_BLAS_UPCASE AND NOT SCALFMM_BLAS_NOCHANGE)
        if (SCALFMM_BLAS_ADD_)
          message (STATUS "SCALFMM_BLAS_ADD_ is set to ON")
        endif()
        if (SCALFMM_BLAS_UPCASE)
          message (STATUS "SCALFMM_BLAS_UPCASE is set to ON")
        endif()
        if (SCALFMM_BLAS_NOCHANGE)
          message (STATUS "SCALFMM_BLAS_NOCHANGE is set to ON")
        endif()
      endif (NOT SCALFMM_BLAS_ADD_ AND NOT SCALFMM_BLAS_UPCASE AND NOT SCALFMM_BLAS_NOCHANGE)
305
    else()
306
      MESSAGE(WARNING "BLAS: ${BLAS_FOUND}")
307

308
      message(WARNING "BLAS has not been found, SCALFMM will continue to compile but some applications will be disabled.")
309
      message(WARNING "If you have BLAS set BLAS_LIBDIR, BLAS_INCDIR or BLAS_DIR (CMake variables using -D or environment variables).")
COULAUD Olivier's avatar
COULAUD Olivier committed
310
      set(SCALFMM_USE_BLAS OFF)
311
    endif()
312

313
  endif(SCALFMM_USE_BLAS)
314

315
  #
316 317
  # FFT options
  # -----------
318
  CMAKE_DEPENDENT_OPTION(SCALFMM_USE_MKL_AS_FFTW  "Set to ON to use MKL FFTW"  ON  "SCALFMM_USE_FFT;SCALFMM_USE_MKL_AS_BLAS"  OFF )
319
  CMAKE_DEPENDENT_OPTION(SCALFMM_USE_ESSL_AS_FFTW "Set to ON to use ESSL FFTW" ON  "SCALFMM_USE_FFT;SCALFMM_USE_ESSL_AS_BLAS" OFF )
320

321
  if(SCALFMM_USE_FFT)
322 323
    message(STATUS "SCALFMM USE FFT Configure:")

324 325 326
    # The package find_package(FFTW) can be used with the following COMPONENTS:
    # MKL, ESSL, THREADS|OMP and/or SIMPLE|LONG|QUAD
    # Default will find the real double precision fftw library version without THREADS|OMP
327
    if(SCALFMM_USE_MKL_AS_FFTW)
328
      message(STATUS "         SCALFMM USE FFT from MKL")
329 330 331 332 333 334 335 336
      set(BLA_VENDOR "Intel10_64lp_seq")
      if(NOT TARGET blas::blas)
        find_package(FFTW COMPONENTS MKL)
      else()
        set(FFTW_FOUND 1)
        find_package(FFTW COMPONENTS MKL QUIET)
        target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${FFTW_INCLUDE_DIRS})
      endif()
337
    elseif (SCALFMM_USE_ESSL_AS_FFTW)
338 339
      message(STATUS "         SCALFMM USE FFT from ESSL ")
      find_package(FFTW COMPONENTS ESSL)
340
    else()
341 342
      message(STATUS "         SCALFMM USE FFTW")
      find_package(FFTW COMPONENTS SIMPLE)
343
    endif()
344

COULAUD Olivier's avatar
COULAUD Olivier committed
345
    if(FFTW_FOUND)
346 347 348 349
      list(APPEND FUSE_LIST FFT)
      if(NOT SCALFMM_USE_MKL_AS_FFTW)
        target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC fftw::fftw)
        list(APPEND SCALFMM_LIBRARIES FFTW)
COULAUD Olivier's avatar
COULAUD Olivier committed
350 351
      endif()
    else(FFTW_FOUND)
352
      message(WARNING "FFTW has not been found, SCALFMM will continue to compile but some applications will be disabled.")
353
      message(WARNING "If you have FFTW set FFTW_LIBDIR, FFTW_INCDIR or FFTW_DIR (CMake variables using -D or environment variables).")
354
      set(SCALFMM_USE_FFT OFF)
COULAUD Olivier's avatar
COULAUD Olivier committed
355
    endif(FFTW_FOUND)
356

357
  endif(SCALFMM_USE_FFT)
358
  message(STATUS "SCALFMM_USE_FFT = ${SCALFMM_USE_FFT}")
359 360

  #
361 362
  # C++ 2014
  # --------
363 364
  target_compile_features(${CMAKE_PROJECT_NAME} INTERFACE cxx_std_14)

365
  #
366 367 368 369 370 371
  # Additional flags for the library
  # --------------------------------
  list(APPEND SCALFMM_CXX_FLAGS -Wshadow -Wpointer-arith )
  if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
    list(APPEND SCALFMM_CXX_FLAGS -Wcast-qual -Wconversion -Wcast-align -Woverloaded-virtual)
  endif()
COULAUD Olivier's avatar
COULAUD Olivier committed
372

373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
#  ##################################################################
#  #              STARPU Section
#  ##################################################################
#  #
#  message( STATUS "SCALFMM_USE_STARPU             = ${SCALFMM_USE_STARPU}" )
#  if( SCALFMM_USE_STARPU )
#    # CUDA could be used with StarPU enabled
#    option( SCALFMM_USE_CUDA "Set to ON to use CUDA with StarPU" OFF )
#    if(SCALFMM_USE_CUDA)
#      execute_process(COMMAND nvcc --version ERROR_VARIABLE cuda_error_output OUTPUT_QUIET)
#      if(cuda_error_output)
#        message( FATAL_ERROR "nvcc is needed with CUDA." )
#      endif()
#      if(NOT DEFINED CUSTOM_CUDA_FLAGS)
#        set( CUSTOM_CUDA_FLAGS "-std=c++11;-arch=sm_20;--ptxas-options=-v;-use_fast_math" CACHE
#          STRING "Set your CUDA flags, for example : -arch=sm_20;--ptxas-options=-v;-use_fast_math")
#      endif()
#      # This is needed to remove backslash after space in ADD_CUSTOM_COMMAND
#      separate_arguments(CUSTOM_CUDA_FLAGS)
#      message( STATUS "CUSTOM_CUDA_FLAGS             = ${CUSTOM_CUDA_FLAGS}" )
#      find_package(CUDA REQUIRED)
#
#      if (CUDA_INCLUDE_DIRS)
#        include_directories(${CUDA_INCLUDE_DIRS})
#      endif()
#      if (CUDA_LIBRARIES)
#        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${CUDA_LIBRARIES}")
#      endif()
#
#      set(CUDA_NEEDED_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/Src)
#    endif()
#
#    # Find StarPU with a list of optional components
#    set(SCALFMM_STARPU_VERSION "1.2" CACHE STRING " STARPU version desired")
#    # create list of components in order to make a single call to find_package(starpu...)
#    set(STARPU_COMPONENT_LIST "HWLOC")
#
#
#    if(SCALFMM_USE_CUDA)
#      list(APPEND STARPU_COMPONENT_LIST "CUDA")
#    endif()
#    list(APPEND FUSE_LIST "CUDA")
#
#    if(SCALFMM_USE_MPI)
#      list(APPEND STARPU_COMPONENT_LIST "MPI")
#    endif()
#    # TODO: replace this by a component of find starpu
#    OPTION( SCALFMM_USE_OPENCL      "Set to ON to use OPENCL with StarPU" OFF )
#
#    if(SCALFMM_USE_OPENCL)
#      list(APPEND STARPU_COMPONENT_LIST "OPENCL")
##      include_directories($ENV{OPENCL_INC})
##      SET(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};-L$ENV{OPENCL_LIB};-lOpenCL")
#    endif()
#    list(APPEND FUSE_LIST "OPENCL")
#
#
#    find_package(STARPU ${SCALFMM_STARPU_VERSION} REQUIRED
#      COMPONENTS ${STARPU_COMPONENT_LIST})
#
#    if(HWLOC_FOUND AND HWLOC_LIBRARY_DIRS)
#      # the RPATH to be used when installing
#      list(APPEND CMAKE_INSTALL_RPATH "${HWLOC_LIBRARY_DIRS}")
#    endif()
#
#    if(FXT_FOUND AND FXT_LIBRARY_DIRS)
#      # the RPATH to be used when installing
#      list(APPEND CMAKE_INSTALL_RPATH "${FXT_LIBRARY_DIRS}")
#    endif()
#    if(STARPU_FOUND AND STARPU_LIBRARY_DIRS)
#      # the RPATH to be used when installing
#      list(APPEND CMAKE_INSTALL_RPATH "${STARPU_LIBRARY_DIRS}")
#      # Append list of libraries and include dirs
#      include_directories(${STARPU_INCLUDE_DIRS_DEP})
#      foreach (starpu_libdir ${STARPU_LIBRARY_DIRS_DEP})
#        if (${starpu_libdir} MATCHES "^ *-L")
#          set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${starpu_libdir}")
#        else()
#          set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};-L${starpu_libdir}")
#        endif()
#      endforeach()
#      foreach (starpu_lib ${STARPU_LIBRARIES_DEP})
#        if (EXISTS ${starpu_lib} OR ${starpu_lib} MATCHES "^ *-")
#          set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${starpu_lib}")
#        else()
#          set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};-l${starpu_lib}")
#        endif()
#      endforeach()
#    else()
#      # StarPU not found
#
#    endif()
#
#        # TODO: is this very useful? CUDA is already a component of find starpu
#    if (CUDA_LIBRARIES)
#      set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${CUDA_LIBRARIES}")
#    endif()
#
#    # Message
#    if (STARPU_INCLUDE_DIRS)
#      message(STATUS "         STARPU_INCLUDES           = ${STARPU_INCLUDE_DIRS}")
#      LIST(APPEND SCALFMM_INCLUDES  "${STARPU_INCLUDE_DIRS}")
#    endif()
#
#    # Adding SimGrid includes
#    LIST(APPEND SCALFMM_INCLUDES "$ENV{SIMGRID_INCLUDE}")
#    message(STATUS "         Adding SIMGRID           = $ENV{SIMGRID_INCLUDE}")
#  endif(SCALFMM_USE_STARPU)
#  list(APPEND FUSE_LIST "STARPU")

483
#  # Additional options for developers
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
#  if( SCALFMM_ONLY_DEVEL )
#    if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
#      option( SCALFMM_USE_OMP4 "Set to ON to disable the gcc/intel omp4"    OFF )
#    else()
#      option( SCALFMM_USE_OMP4 "Set to ON to disable the gcc/intel omp4"    ON )
#    endif()
#    option( SCALFMM_TIME_OMPTASKS "Set to ON to time omp4 tasks and generate output file"    OFF )
#    # SIMGRID and peformance models options
#    option( SCALFMM_SIMGRID_NODATA "Set to ON to avoid the allocation of numerical parts in the group tree" OFF )
#    option( STARPU_SIMGRID_MLR_MODELS "Set to ON to enable MLR models need for calibration and simulation" OFF )
#    # OPENMP 4/5 support
#    message(WARNING "OpenMP_VERSION:  ${OpenMP_VERSION}")
#    option( OPENMP_SUPPORT_PRIORITY  "Set to ON to enable tasks priority (OMP4.x/KSTAR/StarPU compiler only)" OFF )
#    # STARPU options
#    cmake_dependent_option(OPENMP_SUPPORT_COMMUTE        "Set to ON to let tasks commute (KSTAR/StarPU compiler only)" OFF
#      "SCALFMM_USE_STARPU" OFF)
#    cmake_dependent_option(OPENMP_SUPPORT_TASK_NAME       "Set to ON to enable a taskname clause for tasks (KSTAR/StarPU compiler only)" OFF
#      "SCALFMM_USE_STARPU" OFF)
#    cmake_dependent_option(SCALFMM_STARPU_USE_COMMUTE  "Set to ON to enable commute with StarPU" ON  "SCALFMM_USE_STARPU" OFF)
#    cmake_dependent_option(SCALFMM_STARPU_USE_REDUX  "Set to ON to enable redux with StarPU"     OFF "SCALFMM_USE_STARPU" OFF)
#    cmake_dependent_option(SCALFMM_STARPU_USE_PRIO  "Set to ON to enable priority with StarPU"   ON  "SCALFMM_USE_STARPU" OFF)
#    cmake_dependent_option(SCALFMM_STARPU_FORCE_NO_SCHEDULER  "Set to ON to disable heteroprio even if supported" OFF "SCALFMM_USE_STARPU" OFF)
#    cmake_dependent_option(SCALFMM_USE_STARPU_EXTRACT  "Set to ON to enable extract with StarPU mpi implicit" ON  "SCALFMM_USE_STARPU" OFF)
#  endif()
COULAUD Olivier's avatar
COULAUD Olivier committed
508

509 510 511 512 513 514 515 516
  #
  # Set ScalFMM compile flags
  # -------------------------
  string(REPLACE ";" " " SCALFMM_COMPILE_FLAGS "${SCALFMM_CXX_FLAGS}")
  set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS}" CACHE STRING "Global compile flags for ScalFMM")
  message(STATUS "ScalFMM final flags : ${SCALFMM_CXX_FLAGS}")
  # And adding flags to target
  # --------------------------
517
  target_compile_options(${CMAKE_PROJECT_NAME} PUBLIC "${SCALFMM_CXX_FLAGS}")
518 519 520 521 522 523 524

  #
  # Set ScalFMM dependencies
  # ------------------------
  string(REPLACE ";" " " SCALFMM_COMPILE_LIBS "${SCALFMM_LIBRARIES}")
  set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES}" CACHE STRING "ScalFMM libraries dependencies")
  message(STATUS "ScalFMM dependencies : ${SCALFMM_LIBRARIES}")
525

526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
  #  #
  #  # Set ScalFMM link flags
  #  # ----------------------
  #  string(REPLACE ";" " " SCALFMM_LINK_FLAGS "${SCALFMM_LINK_FLAGS}")
  #  set(SCALFMM_LINK_FLAGS "${SCALFMM_LINK_FLAGS}" CACHE STRING "Global link flags for ScalFMM")
  #  message(STATUS "ScalFMM link flags : ${SCALFMM_LINK_FLAGS}")
  #  # And adding lin flags to the target
  #  # ----------------------------------
  #  target_link_options(${CMAKE_PROJECT_NAME} INTERFACE "${SCALFMM_LIBRARIES}")

  #
  # Set ScalFMM compile definitions
  # -------------------------------
  set(SCALFMM_COMPILE_DEFINITIONS "${SCALFMM_COMPILE_DEFINITIONS}" CACHE STRING "Global compile definitions for ScalFMM")
  message(STATUS "ScalFMM compile definitions : ${SCALFMM_COMPILE_DEFINITIONS}")
  # And adding definitions to target
  # --------------------------------
  target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC "${SCALFMM_COMPILE_DEFINITIONS}")


  #
  # Generate ScalFmmConfig.h
  # ------------------------
  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/ScalFmmConfig.h.cmake
    ${CMAKE_CURRENT_BINARY_DIR}/include/ScalFmmConfig.h)
551

552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
  #
  # Static analysis during build
  # ----------------------------
  option(SCALFMM_USE_STATIC_ANALYSIS "Set to ON to enable static analysis tools." OFF)
  get_target_property(SCALFMM_INCLUDE_DIRS ${CMAKE_PROJECT_NAME} INCLUDE_DIRECTORIES)

  if(SCALFMM_USE_STATIC_ANALYSIS)
    find_program(CPPCHECK "cppcheck")
    if (CPPCHECK)
      set(CMAKE_CXX_CPPCHECK "${CPPCHECK}"
        "--language=c++"
        "$<GENEX_EVAL:-I$<JOIN:$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>, -I>>"
        "-v"
        "--enable=all"
        "--force"
        "--inline-suppr"
        )
      message(STATUS "CPPCHECK analysis is ON.")
COULAUD Olivier's avatar
COULAUD Olivier committed
570
    endif()
571

572 573 574 575
    find_program(CLANGTIDY "clang-tidy")
    if (CLANGTIDY)
      set(CMAKE_CXX_CLANG_TIDY "${CLANGTIDY};-checks=-*,boost-*,cppcoreguidelines-*,clang-analyser-cplusplus*,modernize-*,mpi-*,performance-*,portability-*,readability-*")
      message(STATUS "Clang Tidy analysis is ON.")
576
    endif()
577

578 579 580 581
    find_program(IWYU "include-what-you-use")
    if(IWYU)
      set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${IWYU}")
      message(STATUS "Include What You Use analysis is ON.")
582
    endif()
583
  endif()
584

585
  #
586 587 588
  # Build Examples
  # --------------
  message(STATUS "SCALFMM_BUILD_EXAMPLES = ${SCALFMM_BUILD_EXAMPLES}" )
589
  if( SCALFMM_BUILD_EXAMPLES )
590 591 592
    # Build - Examples and drivers
    add_subdirectory(Examples)
  endif()
593 594 595 596 597

  #
  # Build tools (Internal use)
  # --------------------------
  # Build - Utils
598
  if( SCALFMM_ONLY_DEVEL AND SCALFMM_BUILD_UTILS)
599
    add_subdirectory(Utils)
600
  endif()
601

602 603 604
  #
  # Build Tests to see examples
  # ----------------------------
605
  # Build - Tests
606
  message( STATUS "SCALFMM_BUILD_TESTS = ${SCALFMM_BUILD_TESTS}" )
607
  if( SCALFMM_BUILD_TESTS )
608 609
    add_subdirectory(Tests)
  endif()
berenger-bramas's avatar
berenger-bramas committed
610

611
  #
612 613 614
  # Build - Unitary and numerical Tests
  # -----------------------------------
  message( STATUS "SCALFMM_BUILD_UTESTS = ${SCALFMM_BUILD_UTESTS}" )
615
  if( SCALFMM_BUILD_UTESTS )
616
    enable_testing()
617
    include(CTest)
618 619
    add_subdirectory(UTests)
  endif()
620

621
  #
622 623 624
  # Add - doc
  # ---------
  message(STATUS "SCALFMM_BUILD_DOC = ${SCALFMM_BUILD_DOC}" )
625 626 627
  if(SCALFMM_BUILD_DOC)
    add_subdirectory(Doc)
  endif()
628

629 630 631
  #
  # Export Library
  # --------------
632
  install(TARGETS ${CMAKE_PROJECT_NAME} inastemp
633 634 635 636
    EXPORT ${CMAKE_PROJECT_NAME}-targets
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
    RUNTIME DESTINATION bin)
637

638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
  install(DIRECTORY ${${CMAKE_PROJECT_NAME}_SOURCE_DIR}/include
    DESTINATION ${CMAKE_INSTALL_PREFIX}
    PATTERN "ScalFmmConfig.h.cmake" EXCLUDE)

  install(FILES ${${CMAKE_PROJECT_NAME}_BINARY_DIR}/include/ScalFmmConfig.h
    DESTINATION include)

  install(EXPORT ${CMAKE_PROJECT_NAME}-targets
    FILE ${CMAKE_PROJECT_NAME}-targets.cmake
    NAMESPACE ${CMAKE_PROJECT_NAME}::
    DESTINATION lib/cmake/${CMAKE_PROJECT_NAME})

  include(CMakePackageConfigHelpers)
  write_basic_package_version_file("${CMAKE_PROJECT_NAME}ConfigVersion.cmake"
    VERSION ${${CMAKE_PROJECT_NAME}_VERSION}
    COMPATIBILITY SameMajorVersion)
654

655 656
  if( SCALFMM_INSTALL_DATA )
    install(FILES  ${SCALFMM_SOURCE_DIR}/Data/test20k.fma  DESTINATION Data/   )
657
  endif()
658 659 660 661 662 663 664 665 666

  configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_PROJECT_NAME}Config.cmake.in
    "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
    INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/${CMAKE_PROJECT_NAME}/)

  install(FILES "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake"
    "${PROJECT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake"
    DESTINATION lib/cmake/${CMAKE_PROJECT_NAME})

667
  #
668 669 670
  # build a CPack driven installer package
  # --------------------------------------
  # See CPackConfig.cmake for the details.
671
  include(CPack)
672

673
  #
674 675
  # Print configure status
  # ----------------------
676
  #                    Use Mem stats
677
  message(STATUS "SCALFMM_USE_MEM_STATS = ${SCALFMM_USE_MEM_STATS}" )
678
  #                    Use Log
679
  message(STATUS "SCALFMM_USE_LOG = ${SCALFMM_USE_LOG}" )
680
  #                    Use Assert
681
  message(STATUS "SCALFMM_USE_ASSERT = ${SCALFMM_USE_ASSERT}" )
682
  #
683
  message(STATUS "SCALFMM_USE_MPI = ${SCALFMM_USE_MPI}" )
COULAUD Olivier's avatar
COULAUD Olivier committed
684

685 686 687
  message(STATUS "SCALFMM_USE_BLAS = ${SCALFMM_USE_BLAS}")
  message(STATUS "SCALFMM_USE_FFT = ${SCALFMM_USE_FFT}")
  message(STATUS "SCALFMM_USE_MKL = ${SCALFMM_USE_MKL}")
COULAUD Olivier's avatar
COULAUD Olivier committed
688
  #
COULAUD Olivier's avatar
COULAUD Olivier committed
689
  if(SCALFMM_USE_STARPU)
690 691 692 693
    message(STATUS "SCALFMM_USE_STARPU = ${SCALFMM_USE_STARPU}" )
    message(STATUS "STARPU_LIBRARIES = ${STARPU_LIBRARIES}")
    message(STATUS "SCALFMM_USE_CUDA = ${SCALFMM_USE_CUDA}" )
    MESSAGE(STATUS "SCALFMM_USE_OPENCL = ${SCALFMM_USE_OPENCL}" )
COULAUD Olivier's avatar
COULAUD Olivier committed
694
  endif(SCALFMM_USE_STARPU)
695 696 697 698
  message(STATUS "SCALFMM_CXX_FLAGS = ${SCALFMM_CXX_FLAGS}")
  message(STATUS "SCALFMM_LIBRARIES = ${SCALFMM_LIBRARIES}")
  message(STATUS "FUSE_LIST = ${FUSE_LIST}")

699
else(MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/morse_cmake")
700 701 702 703 704 705 706

  message(STATUS "MORSE_DISTRIB_DIR is not set")
  message(STATUS "Please indicate where is located your MORSE distribution directory."
    " This is necessary to find cmake_modules.")
  message(STATUS "If you are a MORSE developer, you normally have access to the svn repository of the MORSE_DISTRIB_DIR: "
    "svn checkout svn+ssh://yourlogin@scm.gforge.inria.fr/svnroot/morse/trunk/morse_distrib")

707
endif(MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/morse_cmake")