CMakeLists.txt 43.8 KB
Newer Older
1 2
cmake_minimum_required (VERSION 2.8.3 FATAL_ERROR)

3 4 5
if(CMAKE_MAJOR_VERSION GREATER 1 AND CMAKE_MINOR_VERSION GREATER 7 AND CMAKE_PATCH_VERSION GREATER 11)
  cmake_policy(SET CMP0022 OLD)
endif()
6

7
cmake_policy(SET CMP0004 NEW)
BRAMAS Berenger's avatar
BRAMAS Berenger committed
8

9 10 11 12 13
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)

#===========================================================================
# Project Declaration
#===========================================================================
14
project(SCALFMM C CXX)
15

16
# check if compiling into source directories
17
string(COMPARE EQUAL "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" insource)
18
if(insource)
19
  message(FATAL_ERROR "${PROJECT_NAME} requires an out of source build. Goto ./Build and tapes cmake ../")
20
endif(insource)
21

22 23
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/)
set(SCALFMM_CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules)
24 25 26 27
#
# Adds the CMAKE_DEPENDENT_OPTION command
INCLUDE(CMakeDependentOption)
#  Add to check CPU info
28 29 30
include(GetCpuInfos)
GetCpuInfos()

COULAUD Olivier's avatar
COULAUD Olivier committed
31 32 33 34
#===========================================================================
# Version Number
#===========================================================================

35 36
# SCALFMM version number.  An even minor number corresponds to releases.
set(SCALFMM_MAJOR_VERSION 1)
COULAUD Olivier's avatar
COULAUD Olivier committed
37
set(SCALFMM_MINOR_VERSION 5)
38
set(SCALFMM_PATCH_VERSION 1)
39
set(SCALFMM_VERSION  "${SCALFMM_MAJOR_VERSION}.${SCALFMM_MINOR_VERSION}.${SCALFMM_PATCH_VERSION}" )
COULAUD Olivier's avatar
COULAUD Olivier committed
40

41
set( MORSE_DISTRIB_DIR "" CACHE PATH "Directory of MORSE distribution")
BRAMAS Berenger's avatar
BRAMAS Berenger committed
42

43
if (MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/morse")
44 45 46 47

  # Add extra cmake module path and initialize morse cmake modules
  # --------------------------------------------------------------
  if(MORSE_DISTRIB_DIR)
48 49 50
    list(APPEND CMAKE_MODULE_PATH ${MORSE_DISTRIB_DIR}/cmake_modules)
    list(APPEND CMAKE_MODULE_PATH "${MORSE_DISTRIB_DIR}/cmake_modules/morse")
    set(MORSE_CMAKE_MODULE_PATH ${MORSE_DISTRIB_DIR}/cmake_modules/morse )
51 52 53
  else()
    set(MORSE_CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/morse" CACHE PATH "Path to morse_cmake sources")
    list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules" "${MORSE_CMAKE_MODULE_PATH}" )
54
  endif()
55

56
  include(MorseInit)
57 58 59 60 61 62 63 64 65 66
  # Set the RPATH config
  # --------------------
  # 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")

67 68 69 70
  # Build ScalFmm as static or dynamic lib
  # --------------------------------------
  option(BUILD_SHARED_LIBS "Build shared libraries" OFF)

71 72
  #
  # Options
73
  #
74 75 76 77 78 79 80
  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"         ON )
  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_INSTALL_DATA         "Set to ON to include the data when proceeding to the installtion " OFF )
81
  option( SCALFMM_BUILD_DOC            "Set to ON to build the Doxygen documentation " OFF )
82 83 84 85 86
  option( SCALFMM_BUILD_DEBUG          "Set to ON to build in Debug"                 OFF )
  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 )
  option( SCALFMM_ATTACHE_SOURCE       "Set to ON to compile with -g"                OFF )
  option( SCALFMM_USE_ADDONS           "Set to ON to compile add ons"                OFF )
87
  option( SCALFMM_USE_SIGNALS          "Set to ON to catch various signal an print backtrace"  OFF )
88 89
  option( SCALFMM_USE_ASSERT           "Set to ON to enable safe tests during execution" ON  )
  option( SCALFMM_USE_MIC_NATIVE       "Set to ON to compile in native mode for MIC" OFF  )
90
  option( SCALFMM_ONLY_DEVEL           "Set to ON to compile Development tools (only scalfmm team)" OFF )
91 92 93 94
  option( SCALFMM_USE_EZTRACE          "Set to ON to compile with eztrace framwork" OFF )
  option( SCALFMM_USE_STARPU           "Set to ON to build SCALFMM with StarPU"     OFF )
  option( SCALFMM_BUILD_UTILS          "Set to ON to build utils Tests"             OFF )

95 96 97
  #
  #  VECTORISATION
  #
98
  if( APPLE ) # to fix problem with  GCC and avx
99 100
    CMAKE_DEPENDENT_OPTION( SCALFMM_USE_SSE              "Set to ON to compile with SSE support (and use intrinsec SSE P2P)" ON "CPUOPTION_SSE3;NOT CPUOPTION_AVX2" OFF  )
    CMAKE_DEPENDENT_OPTION( SCALFMM_USE_AVX              "Set to ON to compile with AVX support (and use intrinsec AVX P2P)" OFF "CPUOPTION_AVX; NOT CPUOPTION_AVX2" OFF  )
101
  else(APPLE)
102 103
    CMAKE_DEPENDENT_OPTION( SCALFMM_USE_SSE              "Set to ON to compile with SSE support (and use intrinsec SSE P2P)" ON "CPUOPTION_SSE3;NOT CPUOPTION_AVX;NOT CPUOPTION_AVX2" OFF  )
    CMAKE_DEPENDENT_OPTION( SCALFMM_USE_AVX              "Set to ON to compile with AVX support (and use intrinsec AVX P2P)" ON "CPUOPTION_AVX; NOT CPUOPTION_AVX2" OFF  )
104
  endif(APPLE)
105 106
  CMAKE_DEPENDENT_OPTION( SCALFMM_USE_AVX2             "Set to ON to compile with AVX support (and use intrinsec AVX2 P2P)" ON "CPUOPTION_AVX2" OFF )

107
  if( SCALFMM_ONLY_DEVEL )
108
    # OPENMP 4/5 support
109
    option( OPENMP_SUPPORT_COMMUTE   "Set to ON to let tasks commute (KSTAR/StarPU compiler only)" OFF )
110
    option( OPENMP_SUPPORT_PRIORITY  "Set to ON to enable tasks priority (KSTAR/StarPU compiler only)" OFF )
111
    option( OPENMP_SUPPORT_TASK_NAME "Set to ON to enable a taskname clause for tasks (KSTAR/StarPU compiler only)" OFF )
112
    if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
113
      option( SCALFMM_USE_OMP4 "Set to ON to disable the gcc/intel omp4"    OFF )
114
    else()
115
      option( SCALFMM_USE_OMP4 "Set to ON to disable the gcc/intel omp4"    ON )
116
    endif()
117
    option( SCALFMM_TIME_OMPTASKS "Set to ON to time omp4 tasks and generate output file"    OFF )
118
# SIMGRID and peformance models options
119
    option( SCALFMM_SIMGRID_NODATA "Set to ON to avoid the allocation of numerical parts in the group tree" OFF )
120
    option( STARPU_SIMGRID_MLR_MODELS "Set to ON to enable MLR models need for calibration and simulation" OFF )
121 122 123 124 125
# STARPU options
    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)
126
    CMAKE_DEPENDENT_OPTION(SCALFMM_USE_STARPU_EXTRACT  "Set to ON to enable extract with StarPU mpi implicit" ON  "SCALFMM_USE_STARPU" OFF)
127
  endif()
128
  message(STATUS "AVANT  ${CMAKE_CXX_COMPILER_ID}" )
129 130 131
  #
  #  MPI
  #
132
  if( SCALFMM_USE_MPI )
133
    try_compile(COMPILE_INTEL ${CMAKE_CURRENT_BINARY_DIR}
134 135
      ${SCALFMM_CMAKE_MODULE_PATH}/compileTestIntel.cpp
      COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS}")
136 137 138 139 140 141 142
    if (COMPILE_INTEL)
      set(CMAKE_CXX_COMPILER_ID  "Intel")
    endif()
  endif()
  message(STATUS "CXX  ${CMAKE_CXX_COMPILER_ID}" )
  # Set scalfmm to default libraries
  set(SCALFMM_LIBRARIES "")
143
  set(SCALFMM_CXX_FLAGS "-std=c++14 -fpic -Wall")
144 145 146 147 148 149 150 151 152 153 154 155
  #
  #
  # Test if openmp is here
  #
  find_package (OpenMP)
  if(OPENMP_FOUND)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
  else(OPENMP_FOUND)
    message(WARNING "OPENMP NOT FOUND")
  endif(OPENMP_FOUND)
156
  message(STATUS "SCALFMM_BUILD_DEBUG = ${SCALFMM_BUILD_DEBUG}" )
157 158
  #
  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
159
    set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -m64")
160 161 162 163 164 165 166 167 168
  endif()
  ##############################################################################
  #                           Compile options                                  #
  ##############################################################################
  #  -xHost -mfpmath=sse
  # -Wall Wnosign-conversion
  #
  if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
    # INTEL
169
    IF (APPLE)
170
      IF( CPUOPTION_SSE42 )
171 172 173
        set(SSE_FLAGS  "-msse4  -mfpmath=sse")   # -mtune=native -march=native
      ELSEIF (CPUOPTION_SSE3)
        set(SSE_FLAGS  "-msse3  -mfpmath=sse")   # -mtune=native -march=native
174
      ENDIF (CPUOPTION_SSE42)
175
    else(APPLE)
176 177
      set(AVX_FLAGS  "-fp-model source -march=native -axCORE-AVX2,CORE-AVX-I,AVX") #-mavx
      set(AVX2_FLAGS "-march=native  -axCORE-AVX2,CORE-AVX-I,AVX") #-march=core-avx2
178
      set(SSE_FLAGS  "-axSSE4.2  -march=native")
179
    endif(APPLE)
180
    set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -fma -align -finline-functions")
181
    #-Wshadow -Wpointer-arith -Wcast-qual -Wconversion  -Wall -Wnosign-conversion ")
COULAUD Olivier's avatar
COULAUD Olivier committed
182 183 184
  elseif(CMAKE_CXX_COMPILER_ID STREQUAL "XL")
    set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -mcpu=power8 -mtune=power8")
  else() #if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
185
    # NOT      INTEL
186
    if(NOT SCALFMM_USE_MPI)
187 188 189
      include(CheckCCompilerFlag)
      check_c_compiler_flag(-Wzero-as-null-pointer-constant HAS_WZERO_NULL_PTR_FLAG)
      if(HAS_WZERO_NULL_PTR_FLAG)
190
        set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -Wzero-as-null-pointer-constant")
191
      endif()
192
    else()
193 194 195
      include(CheckCCompilerFlag)
      check_c_compiler_flag(-Wno-literal-suffix HAS_NO_LITERAL_SUFFIX_FLAG)
      if(HAS_NO_LITERAL_SUFFIX_FLAG)
196
        set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -Wno-literal-suffix")
197
      endif()
198
    endif()
199
    IF (APPLE)
200
      #      set(SSE_FLAGS  "-msse4  -mfpmath=sse")   # -mtune=native -march=native
201
      IF( CPUOPTION_SSE42 )
202 203 204 205
        set(SSE_FLAGS  "-msse4  -mfpmath=sse")   # -mtune=native -march=native
      ELSEIF (CPUOPTION_SSE3)
        set(SSE_FLAGS  "-msse3  -mfpmath=sse")   # -mtune=native -march=native
      ENDIF (CPUOPTION_SSE42)
206 207
      set(AVX_FLAGS "-mtune=native -march=avx")
      set(AVX2_FLAGS "-mtune=native -march=native -mmic")
208
    else(APPLE)
209 210 211
      set(SSE_FLAGS  "-mtune=native -march=native")
      set(AVX_FLAGS "-mtune=native -march=native")
      set(AVX2_FLAGS "-mtune=native -march=native -mmic")
212 213
    endif(APPLE)
  endif()
214

215 216 217 218 219 220
  ##############################################################################
  #                           FUSE list                                        #
  ##############################################################################
  set(FUSE_LIST "")
  # then do list(APPEND FUSE_LIST "BLAS") to protect from FUSE_BLAS
  list(APPEND FUSE_LIST "MPI")
221

222 223 224 225
  ##############################################################################
  #                        Debug      flags                                    #
  ##############################################################################
  #
226
  if( SCALFMM_BUILD_DEBUG )
227 228 229 230 231 232
    #
    # Compile Debug flags
    #
    set(CMAKE_BUILD_TYPE Debug)
    ADD_DEFINITIONS(-O0)
    if( APPLE )
233
      set(SCALFMM_FLAGS_OPTI_DEBUG "-funroll-loops" CACHE STRING
234 235 236 237 238 239 240 241 242 243 244
        "Set your optimization flags for debug mode.")
    else(APPLE)
      if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
        set(SCALFMM_FLAGS_OPTI_DEBUG "-fp-model strict  -funroll-loops" CACHE STRING
          "Set your optimization flags for debug mode.")
      else()
        set(SCALFMM_FLAGS_OPTI_DEBUG "-funroll-loops" CACHE STRING
          "Set your optimization flags for debug mode.")
      endif()
    endif(APPLE)
    #  ADD_DEFINITIONS(${SCALFMM_FLAGS_OPTI_DEBUG})
245
    set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} ${SCALFMM_FLAGS_OPTI_DEBUG}")
246 247 248 249 250 251
    set(CMAKE_CXX_FLAGS_TYPE "${CMAKE_CXX_FLAGS_DEBUG}")

  else()
    ##############################################################################
    #                          Release flags                                     #
    ##############################################################################
252

253 254 255
    set(CMAKE_BUILD_TYPE Release)
    set(CMAKE_CXX_FLAGS_TYPE  "${CMAKE_CXX_FLAGS_RELEASE}")
    # if compiler is intel add -ip
256

BRAMAS Berenger's avatar
BRAMAS Berenger committed
257
    if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
COULAUD Olivier's avatar
COULAUD Olivier committed
258
      set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -ipo  -fstrict-aliasing ")# -no-prec-div -no-prec-sqrt")
BRAMAS Berenger's avatar
BRAMAS Berenger committed
259
    endif()
260 261
    # Compile optimization
    if(APPLE)
262
      set(SCALFMM_FLAGS_OPTI_RELEASE "-funroll-loops" CACHE STRING
263 264 265
        "Set your optimization flags for release mode.")
    else(APPLE)
      # Not apple system - Check the compiler flags
266 267 268 269
      if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
        #set(SCALFMM_FLAGS_OPTI_RELEASE "-fp-model precise -fp-model source -fimf-precision=low  -funroll-loops -ftree-vectorize"
        set(SCALFMM_FLAGS_OPTI_RELEASE "-funroll-loops -ftree-vectorize"
          CACHE STRING "Set your optimization flags for release mode.")
270 271
        # set(SCALFMM_FLAGS_OPTI_RELEASE "-funroll-loops -ftree-vectorize" CACHE STRING
        #   "Set your optimization flags for release mode.")
272 273 274 275 276 277
      else()
        set(SCALFMM_FLAGS_OPTI_RELEASE "-ffast-math -funroll-loops -ftree-vectorize" CACHE STRING
          "Set your optimization flags for release mode.")
      endif()
    endif(APPLE)
    #
278
    set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} ${SCALFMM_FLAGS_OPTI_RELEASE}")
279
  endif()
280 281
  MESSAGE(STATUS   " %%%%%%%%%% SCALFMM_CXX_FLAGS  ${SCALFMM_CXX_FLAGS} %%%%%%%%%%%%%")
  MESSAGE(STATUS   " %%%%%%%%%% CMAKE_CXX_FLAGS_RELEASE  ${CMAKE_CXX_FLAGS_RELEASE} %%%%%%%%%%%%%")
282

283 284 285 286
  #
  ##############################################################################
  #                Attach source code to exec                                  #
  ##############################################################################
287 288
  message(STATUS "SCALFMM_ATTACHE_SOURCE       = ${SCALFMM_ATTACHE_SOURCE}" )
  if( SCALFMM_ATTACHE_SOURCE )
289
    message(STATUS "Option -g is used, the code is attached to the binary." )
290 291
    set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -g")
  endif(SCALFMM_ATTACHE_SOURCE)
292 293 294 295 296
  #
  ##############################################################################
  #                                 find MPI                                   #
  ##############################################################################
  #
297
  if( SCALFMM_USE_MPI )
COULAUD Olivier's avatar
COULAUD Olivier committed
298 299
    if( NOT MPI_FOUND)
      find_package(MPI REQUIRED)
300
    endif()
COULAUD Olivier's avatar
COULAUD Olivier committed
301 302 303
    if (MPI_CXX_FOUND)
      message("MPI_CXX is in the place")
      if (MPI_CXX_INCLUDE_PATH)
304
        include_directories( ${MPI_CXX_INCLUDE_PATH} )
COULAUD Olivier's avatar
COULAUD Olivier committed
305 306
      endif()
      if (MPI_CXX_COMPILE_FLAGS)
307
        set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} ${MPI_CXX_COMPILE_FLAGS}")
COULAUD Olivier's avatar
COULAUD Olivier committed
308 309
      endif()
      if (MPI_CXX_INCLUDE_PATH)
310
        list(APPEND SCALFMM_INCLUDES "${MPI_CXX_INCLUDE_PATH}")
COULAUD Olivier's avatar
COULAUD Olivier committed
311 312
      endif()
      if (MPI_CXX_LINK_FLAGS)
313
        list(APPEND "CMAKE_EXE_LINKER_FLAGS ${MPI_CXX_LINK_FLAGS}")
COULAUD Olivier's avatar
COULAUD Olivier committed
314 315
      endif()
      if (MPI_CXX_LIBRARIES)
316
        list(APPEND SCALFMM_LIBRARIES "${MPI_CXX_LIBRARIES}")
COULAUD Olivier's avatar
COULAUD Olivier committed
317 318 319
      endif()
    else (MPI_CXX_FOUND)
      message(FATAL_ERROR "MPI is required but was not found. "
320 321 322
                          "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.")
COULAUD Olivier's avatar
COULAUD Olivier committed
323
     endif (MPI_CXX_FOUND)
324

COULAUD Olivier's avatar
COULAUD Olivier committed
325
  endif( SCALFMM_USE_MPI)
326 327 328 329 330
  #
  ##############################################################################
  #                             Blas option                                    #
  ##############################################################################
  #
331
  if( SCALFMM_USE_BLAS )
COULAUD Olivier's avatar
COULAUD Olivier committed
332 333 334 335 336 337
    #   include(FortranCInterface)
    #    # Define a Fortran interface file (FCMangle.hpp)
    #   FortranCInterface_HEADER( ${CMAKE_CURRENT_SOURCE_DIR}/Src/FCMangle.hpp
    #                            MACRO_NAMESPACE "PM_"
    #                           SYMBOL_NAMESPACE "PM_"
    #                           SYMBOLS init testPPM:init)
338 339
    message(STATUS "CMAKE_CXX_COMPILER_ID STREQUAL  ${CMAKE_CXX_COMPILER_ID}")

340 341
    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 )
342

343
    if( SCALFMM_USE_MKL_AS_BLAS )
344
      set(BLA_VENDOR "Intel10_64lp_seq")
345
      find_package(BLAS QUIET) # not REQUIRED
346 347 348 349
      unset(LAPACK_LIBRARIES)
      if (BLAS_LIBRARIES)
        set(BLASLAPACK_LIBRARIES ${BLAS_LIBRARIES})
      endif()
350 351
    elseif(SCALFMM_USE_ESSL_AS_BLAS)
      set(BLA_VENDOR "IBMESSL")
352 353
      find_package(BLAS   QUIET) # not REQUIRED
      find_package(LAPACK QUIET) # not REQUIRED
354 355 356 357 358 359
      if (LAPACK_LIBRARIES)
        set(BLASLAPACK_LIBRARIES "${LAPACK_LIBRARIES}")
      endif()
      if (BLAS_LIBRARIES)
        list(APPEND BLASLAPACK_LIBRARIES ${BLAS_LIBRARIES})
      endif()
360
    elseif(SCALFMM_USE_EXTERNAL_BLAS)
361
      message(STATUS "BLAS SET BY EXTERNAL PROGRAM = ${BLAS_LIBRARIES}")
362
      list(APPEND BLASLAPACK_LIBRARIES "${BLAS_LIBRARIES}")
363
    else()
364 365
      find_package(BLAS)  # not REQUIRED
      find_package(LAPACK)  # not REQUIRED
366 367 368 369 370 371 372
      set(BLASLAPACK_LIBRARIES)
      if (LAPACK_LIBRARIES)
        set(BLASLAPACK_LIBRARIES "${LAPACK_LIBRARIES}")
      endif()
      if (BLAS_LIBRARIES)
        list(APPEND BLASLAPACK_LIBRARIES "${BLAS_LIBRARIES}")
      endif()
373
    endif()
374

375
    if(BLAS_FOUND)
376
      list(APPEND SCALFMM_LIBRARIES "${BLASLAPACK_LIBRARIES}")
377 378 379 380
      if(BLAS_LIBRARY_DIRS)
        # the RPATH to be used when installing
        list(APPEND CMAKE_INSTALL_RPATH "${BLAS_LIBRARY_DIRS}")
      endif()
381 382 383 384 385
      if(BLAS_INCLUDE_DIRS)
        foreach(_hdr_dir ${BLAS_INCLUDE_DIRS})
          list(APPEND SCALFMM_INCLUDES "${_hdr_dir}")
        endforeach()
      endif()
386 387 388 389
      if(LAPACK_FOUND AND LAPACK_LIBRARY_DIRS)
        # the RPATH to be used when installing
        list(APPEND CMAKE_INSTALL_RPATH "${LAPACK_LIBRARY_DIRS}")
      endif()
390
      message (STATUS "check BLAS Fortran mangling")
391 392 393 394 395 396 397 398 399
      # add options to let the user be able to force a behavior
      option( SCALFMM_BLAS_ADD_     "Set to ON to force calls to BLAS Fortran symbols with _ (ex: dgemm_)"        OFF )
      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_)
400
        check_function_exists(DGEMV  DGEMV_UPCASE)
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
        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)
438
    else()
439
      message(WARNING "BLAS has not been found, SCALFMM will continue to compile but some applications will be disabled.")
440
      message(WARNING "If you have BLAS set BLAS_LIBDIR, BLAS_INCDIR or BLAS_DIR (CMake variables using -D or environment variables).")
441
      set(SCALFMM_USE_BLAS OFF)
442
    endif()
443

444
  endif(SCALFMM_USE_BLAS)
445 446 447 448
  list(APPEND FUSE_LIST "BLAS")
  #
  # FFT option
  #
449
  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 )
450
  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 )
451
  if( SCALFMM_USE_FFT )
452 453
    message(STATUS "SCALFMM USE FFT Configure:")

454 455 456
    # 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
457
    if( SCALFMM_USE_MKL_AS_FFTW )
458 459 460
      message(STATUS "         SCALFMM USE FFT from MKL")
      find_package(FFTW COMPONENTS MKL)
    elseif (SCALFMM_USE_ESSL_AS_FFTW)
461 462 463
      message(STATUS "         SCALFMM USE FFT from ESSL ")
      find_package(FFTW COMPONENTS ESSL)
      add_definitions(-DSCALFMM_USE_ESSL_AS_FFTW)
464
    else()
465 466
      message(STATUS "         SCALFMM USE FFTW")
      find_package(FFTW COMPONENTS SIMPLE)
467
    endif()
468

469 470 471 472 473 474 475 476 477 478 479 480 481
    if(FFTW_FOUND)
      # add headers paths
      foreach (fft_hdrdir ${FFTW_INCLUDE_DIRS_DEP})
        list(APPEND FFT_INCLUDES "${fft_hdrdir}")
      endforeach()
      # add libraries paths
      foreach (fft_libdir ${FFTW_LIBRARY_DIR_DEP})
        list(APPEND FFT_LIBRARIES "-L${fft_libdir}")
      endforeach()
      # add libraries
      foreach (fft_lib ${FFTW_LIBRARIES_DEP})
        list(APPEND FFT_LIBRARIES "${fft_lib}")
      endforeach()
482
      if (FFT_LIBRARIES)
483
        list(APPEND SCALFMM_LIBRARIES "${FFT_LIBRARIES}")
484 485
      endif()
      if(FFTW_LIBRARY_DIRS)
486 487
        # the RPATH to be used when installing
        list(APPEND CMAKE_INSTALL_RPATH "${FFTW_LIBRARY_DIRS}")
488 489
      endif()
      if (FFT_INCLUDES)
490
        list(APPEND SCALFMM_INCLUDES "${FFT_INCLUDES}")
491 492
      endif()
    else()
493
      message(WARNING "FFTW has not been found, SCALFMM will continue to compile but some applications will be disabled.")
494
      message(WARNING "If you have FFTW set FFTW_LIBDIR, FFTW_INCDIR or FFTW_DIR (CMake variables using -D or environment variables).")
495
      set(SCALFMM_USE_FFT OFF)
496
    endif()
497

498
  endif(SCALFMM_USE_FFT)
499

500
  list(APPEND FUSE_LIST "FFT")
COULAUD Olivier's avatar
COULAUD Olivier committed
501
  message(STATUS "SCALFMM_USE_FFT       =  ${SCALFMM_USE_FFT}")
502 503 504 505 506 507
  if (SCALFMM_INCLUDES)
    list(REMOVE_DUPLICATES SCALFMM_INCLUDES)
  endif()
  if (SCALFMM_LIBRARIES)
    list(REMOVE_DUPLICATES SCALFMM_LIBRARIES)
  endif()
508 509 510 511 512 513 514

  #
  # C++ 2011
  message( STATUS "CMAKE_SYSTEM:   ${CMAKE_SYSTEM}  CMAKE_CXX_COMPILER_ID ${CMAKE_CXX_COMPILER_ID}  CMAKE_CXX_COMPILER ${NAME}")
  if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
    execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE INTEL_VERSION)
    message( STATUS "Intel:   ${INTEL_VERSION}")
515
    set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} -Wall")
516 517
  else()
    # Compile option valid on GCC/G++
518
    set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wconversion -Wcast-qual -Wcast-align -Woverloaded-virtual")
519
  endif()
520 521
  #
  ##################################################################
COULAUD Olivier's avatar
COULAUD Olivier committed
522
  #              STARPU Section
523 524
  ##################################################################
  #
525 526
  message( STATUS "SCALFMM_USE_STARPU             = ${SCALFMM_USE_STARPU}" )
  if( SCALFMM_USE_STARPU )
527
    # CUDA could be used with StarPU enabled
528 529 530
    option( SCALFMM_USE_CUDA "Set to ON to use CUDA with StarPU" OFF )
    message( STATUS "SCALFMM_USE_CUDA             = ${SCALFMM_USE_CUDA}" )
    if(SCALFMM_USE_CUDA)
531 532 533 534 535
      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)
536 537
        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")
538 539 540 541
      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}" )
542

543
      find_package(CUDA REQUIRED)
544

545 546 547 548
      if (CUDA_INCLUDE_DIRS)
        include_directories(${CUDA_INCLUDE_DIRS})
      endif()
      if (CUDA_LIBRARIES)
549
        list(APPEND SCALFMM_LIBRARIES "${CUDA_LIBRARIES}")
550
      endif()
551

552
      set(CUDA_NEEDED_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/Src)
553 554 555
    endif()

    # Find StarPU with a list of optional components
556
    set(SCALFMM_STARPU_VERSION "1.1" CACHE STRING "oldest STARPU version desired")
557 558
    # create list of components in order to make a single call to find_package(starpu...)
    set(STARPU_COMPONENT_LIST "HWLOC")
559
    if(SCALFMM_USE_MPI)
560
      list(APPEND STARPU_COMPONENT_LIST "MPI")
561
    endif()
562
    if(SCALFMM_USE_CUDA)
563
      list(APPEND STARPU_COMPONENT_LIST "CUDA")
564
    endif()
565

566
    find_package(STARPU ${SCALFMM_STARPU_VERSION} REQUIRED
567
      COMPONENTS ${STARPU_COMPONENT_LIST})
568

569 570 571 572 573 574 575 576 577 578 579 580 581
    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}")
    endif()

582
    # Append list of libraries and include dirs
583 584 585
    include_directories(${STARPU_INCLUDE_DIRS_DEP})
    foreach (starpu_libdir ${STARPU_LIBRARY_DIRS_DEP})
      if (${starpu_libdir} MATCHES "^ *-L")
586
        list(APPEND SCALFMM_LIBRARIES "${starpu_libdir}")
587
      else()
588
        list(APPEND SCALFMM_LIBRARIES "-L${starpu_libdir}")
589 590 591 592
      endif()
    endforeach()
    foreach (starpu_lib ${STARPU_LIBRARIES_DEP})
      if (EXISTS ${starpu_lib} OR ${starpu_lib} MATCHES "^ *-")
593
        list(APPEND SCALFMM_LIBRARIES "${starpu_lib}")
594
      else()
595
        list(APPEND SCALFMM_LIBRARIES "-l${starpu_lib}")
596 597
      endif()
    endforeach()
598

599
    # TODO: is this very useful? CUDA is already a component of find starpu
600
    if (CUDA_LIBRARIES)
601
      list(APPEND SCALFMM_LIBRARIES "${CUDA_LIBRARIES}")
602
    endif()
603

604
    # Message
605 606
    message(STATUS "         STARPU_LIBRARIES          = ${STARPU_LIBRARIES}")
    if (STARPU_INCLUDE_DIRS)
607
      message(STATUS "         STARPU_INCLUDES           = ${STARPU_INCLUDE_DIRS}")
608
      list(APPEND SCALFMM_INCLUDES "${STARPU_INCLUDE_DIRS}")
609
    endif()
610

611
    # Adding SimGrid includes
612
    list(APPEND SCALFMM_INCLUDES "$ENV{SIMGRID_INCLUDE}")
613 614
    message(STATUS "         Adding SIMGRID           = $ENV{SIMGRID_INCLUDE}")

615
    # TODO: replace this by a component of find starpu
616 617 618
    OPTION( SCALFMM_USE_OPENCL      "Set to ON to use OPENCL with StarPU" OFF )
    MESSAGE( STATUS "SCALFMM_USE_OPENCL             = ${SCALFMM_USE_OPENCL}" )
    if(SCALFMM_USE_OPENCL)
619
      include_directories($ENV{OPENCL_INC})
620
      list(APPEND SCALFMM_LIBRARIES "-L$ENV{OPENCL_LIB};-lOpenCL")
621
    endif()
622
  endif(SCALFMM_USE_STARPU)
623
  list(APPEND FUSE_LIST "STARPU")
624
  list(APPEND FUSE_LIST "CUDA")
625
  list(APPEND FUSE_LIST "OPENCL")
626
  list(APPEND FUSE_LIST "OMP4")
627

628 629 630 631
  ##################################################################
  #                         Use SSE                                #
  ##################################################################

632 633 634 635
  message( STATUS "SCALFMM_USE_SSE              = ${SCALFMM_USE_SSE}" )
  if( SCALFMM_USE_SSE )
    if(NOT EXISTS ${SCALFMM_CMAKE_MODULE_PATH}/compileTestSse.cpp)
      message(FATAL_ERROR "The CompileTestSseFile does not exist (${SCALFMM_CMAKE_MODULE_PATH}/compileTestSse.cpp)" )
636 637 638
    endif()
    message( STATUS "SSE_FLAGS ${SSE_FLAGS}  -- ${CMAKE_CXX_FLAGS}  ")
    try_compile(COMPILE_SSE  ${CMAKE_CURRENT_BINARY_DIR}
639 640 641
      ${SCALFMM_CMAKE_MODULE_PATH}/compileTestSse.cpp
      COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${SSE_FLAGS}"
      OUTPUT_VARIABLE COMPILE_SSE_OUTPUT)
642 643

    if(${COMPILE_SSE})
644
      set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} ${SSE_FLAGS}")
645 646

      try_compile(COMPILE_RESULT_VAR ${CMAKE_CURRENT_BINARY_DIR}
647 648
        ${SCALFMM_CMAKE_MODULE_PATH}/checkSSEpe.cpp
        COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${SSE_FLAGS}")
649 650 651
      if( NOT ${COMPILE_RESULT_VAR})
        set(__SSEPE_INTEL_COMPILER ON)
      endif()
652
      #set(SCALFMM_USE_AVX OFF)
653
    else(${COMPILE_SSE})
654
      message(FATAL_ERROR "SSE NOT SUPPORTED ; Set SCALFMM_USE_SSE  to OFF \n Output from test is : ${COMPILE_SSE_OUTPUT}")
655 656 657
    endif(${COMPILE_SSE})
  endif()
  list(APPEND FUSE_LIST "SSE")
658

659 660 661 662
  ##################################################################
  #                           Use AVX                              #
  ##################################################################

663 664 665 666
  message(STATUS "SCALFMM_USE_AVX               = ${SCALFMM_USE_AVX}")
  if(SCALFMM_USE_AVX)
    if(NOT EXISTS ${SCALFMM_CMAKE_MODULE_PATH}/compileTestAvx.cpp)
      message(FATAL_ERROR "The CompileTestSseFile does not exist (${SCALFMM_CMAKE_MODULE_PATH}/compileTestAvx.cpp)" )
667 668 669
    endif()

    try_compile(COMPILE_AVX ${CMAKE_CURRENT_BINARY_DIR}
670 671 672 673 674
      ${SCALFMM_CMAKE_MODULE_PATH}/compileTestAvx.cpp
      COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${AVX_FLAGS}"
      OUTPUT_VARIABLE COMPILE_AVX_OUTPUT)
    if(${COMPILE_AVX})
      message(STATUS "%%%%%%%%%%%% COMPILE_AVX               = ${COMPILE_AVX}  %%%%<    ${AVX_FLAGS}")
675

676
      set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS}   ${AVX_FLAGS}")
677 678
      message(STATUS "%%%%%%%%%%%% SCALFMM_CXX_FLAGS               = ${SCALFMM_CXX_FLAGS}")
      #set( SCALFMM_USE_SSE   OFF   FORCE) # ne marche pas
679
      try_compile(COMPILE_RESULT_AVSPE ${CMAKE_CURRENT_BINARY_DIR}
680 681 682
        ${SCALFMM_CMAKE_MODULE_PATH}/checkAVXpe.cpp
        COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${AVX_FLAGS}")
      if( NOT ${COMPILE_RESULT_AVSPE})
683 684


685
        set(__AVXPE_INTEL_COMPILER ON)
686
      endif()
687 688 689

      message(STATUS ${CMAKE_CXX_FLAGS} )
    else(${COMPILE_AVX})
690
      message(FATAL_ERROR "AVX NOT SUPPORTED ; Set SCALFMM_USE_AVX  to OFF \n Output from test is : ${COMPILE_AVX_OUTPUT} ")
691
    endif(${COMPILE_AVX})
692
  endif(SCALFMM_USE_AVX)
693 694
  list(APPEND FUSE_LIST "AVX")
  #
695
  # Error if both SCALFMM_USE_AVX AND SCALFMM_USE_SSE are set
696
  #
697 698 699
  if( SCALFMM_USE_AVX AND SCALFMM_USE_SSE)
    message(FATAL_ERROR "Check SCALFMM_USE_SSE or SCALFMM_USE_AVX BUT NOT BOTH. ")
  endif(SCALFMM_USE_AVX AND SCALFMM_USE_SSE)
700
  ##################################################################
701 702 703 704 705 706 707 708 709 710
  #                           Use AVX2                             #
  ##################################################################

  message(STATUS "SCALFMM_USE_AVX2               = ${SCALFMM_USE_AVX2}")
  if(SCALFMM_USE_AVX2)
    if(NOT EXISTS ${SCALFMM_CMAKE_MODULE_PATH}/compileTestAvx2.cpp)
      message(FATAL_ERROR "The CompileTestSseFile does not exist (${SCALFMM_CMAKE_MODULE_PATH}/compileTestAvx.cpp)" )
    endif()

    try_compile(COMPILE_AVX2 ${CMAKE_CURRENT_BINARY_DIR}
711 712 713
      ${SCALFMM_CMAKE_MODULE_PATH}/compileTestAvx2.cpp
      COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${AVX2_FLAGS}"
      OUTPUT_VARIABLE COMPILE_AVX2_OUTPUT)
714 715 716 717
    if(${COMPILE_AVX2})
      set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS}   ${AVX2_FLAGS}")
      #set( SCALFMM_USE_SSE   OFF   FORCE) # ne marche pas
      try_compile(COMPILE_RESULT_AVSPE ${CMAKE_CURRENT_BINARY_DIR}
718 719
        ${SCALFMM_CMAKE_MODULE_PATH}/checkAVX2pe.cpp
        COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${AVX2_FLAGS}")
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
      if( NOT ${COMPILE_RESULT_AVSPE})
        set(__AVX2PE_INTEL_COMPILER ON)
      endif()

      message(STATUS ${CMAKE_CXX_FLAGS} )
    else(${COMPILE_AVX2})
      message(FATAL_ERROR "AVX2 NOT SUPPORTED ; Set SCALFMM_USE_AVX2  to OFF \n Output from test is : ${COMPILE_AVX_OUTPUT} ")
    endif(${COMPILE_AVX2})
  endif(SCALFMM_USE_AVX2)
  list(APPEND FUSE_LIST "AVX2")
  #
  # Error if both SCALFMM_USE_AVX2 AND SCALFMM_USE_SSE are set
  #
  if( SCALFMM_USE_AVX2 AND SCALFMM_USE_SSE)
    message(FATAL_ERROR "Check SCALFMM_USE_SSE or SCALFMM_USE_AVX2 BUT NOT BOTH. ")
  endif(SCALFMM_USE_AVX2 AND SCALFMM_USE_SSE)
  ##################################################################
737 738
  #                     Use  native MIC compilation                #
  ##################################################################
739
  if( SCALFMM_USE_MIC_NATIVE )
740 741
    include(CheckCCompilerFlag)
    check_c_compiler_flag(-mmic HAS_MMIC_FLAG)
742
    if(NOT HAS_MMIC_FLAG)
743
      message(FATAL_ERROR "MIC NOT SUPPORTED ; Set SCALFMM_USE_MIC_NATIVE to OFF")
744 745 746
    endif()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmic")
  else()
747
    #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xhost")
748 749 750 751
  endif()
  list(APPEND FUSE_LIST "MIC")
  ##################################################################
  #
COULAUD Olivier's avatar
COULAUD Olivier committed
752 753
  #   Set EZTRACE
  #
754
  ##################################################################
COULAUD Olivier's avatar
COULAUD Olivier committed
755 756 757 758
  If(SCALFMM_USE_EZTRACE)
    find_package (PkgConfig)
    if(PKG_CONFIG_FOUND)
      set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH "ON")
759
      pkg_search_module( EZTrace REQUIRED eztrace)
COULAUD Olivier's avatar
COULAUD Olivier committed
760
      if(EZTrace_FOUND)
761 762
        link_directories(${EZTrace_LIBRARY_DIRS})
        link_libraries( ${EZTrace_LIBRARIES})
763 764 765 766
        if (EZTrace_LIBRARY_DIRS)
          # the RPATH to be used when installing
          list(APPEND CMAKE_INSTALL_RPATH "${EZTrace_LIBRARY_DIRS}")
        endif()
767
        IF( SCALFMM_USE_MPI )
COULAUD Olivier's avatar
COULAUD Olivier committed
768
          link_libraries(-leztrace-autostart-mpi)
769 770 771 772 773 774 775 776 777
        ENDIF(SCALFMM_USE_MPI)
        include_directories(${EZTrace_INCLUDE_DIRS})
        MESSAGE(STATUS "EZTRACE:  ${EZTrace_INCLUDE_DIRS}   ${EZTrace_LIBRARY_DIRS}  ${EZTrace_LIBRARIES}")
        CMAKE_DEPENDENT_OPTION(SCALFMM_TRACE_ALGO "Set to ON to trace the full algorithm (all operators)" ON  "SCALFMM_USE_EZTRACE" OFF )
        CMAKE_DEPENDENT_OPTION(SCALFMM_TRACE_P2M   "Set to ON to trace P2M operator" OFF  "SCALFMM_USE_EZTRACE" OFF )
        CMAKE_DEPENDENT_OPTION(SCALFMM_TRACE_M2M   "Set to ON to trace M2M operator" OFF  "SCALFMM_USE_EZTRACE" OFF )
        CMAKE_DEPENDENT_OPTION(SCALFMM_TRACE_M2L   "Set to ON to trace M2L operator" OFF  "SCALFMM_USE_EZTRACE" OFF )
        CMAKE_DEPENDENT_OPTION(SCALFMM_TRACE_L2L   "Set to ON to trace L2L operator" OFF  "SCALFMM_USE_EZTRACE" OFF )
        CMAKE_DEPENDENT_OPTION(SCALFMM_TRACE_P2P   "Set to ON to trace P2P operator" OFF  "SCALFMM_USE_EZTRACE" OFF )
778
      else(EZTrace_FOUND)
779 780
        MESSAGE(WARNING "Eztrace not found - EZTRACE Is set to OFF")
        set(SCALFMM_USE_EZTRACE OFF)
781
      endif(EZTrace_FOUND)
COULAUD Olivier's avatar
COULAUD Olivier committed
782
    else(PKG_CONFIG_FOUND)
783
      MESSAGE(WARNING "PKG-CONFIG not found - EZTRACE Is set to OFF")
COULAUD Olivier's avatar
COULAUD Olivier committed
784 785 786 787
      set(SCALFMM_USE_EZTRACE OFF)
    endif(PKG_CONFIG_FOUND)

  endif(SCALFMM_USE_EZTRACE)
788

789 790 791 792
  ##################################################################
  #
  #   To catch signals
  #
793
  ##################################################################
794 795 796 797 798 799 800 801
  if((WIN32 OR (${CMAKE_SYSTEM_NAME} MATCHES "Windows")) AND SCALFMM_USE_SIGNALS)
    # We are on Windows and we cannot catch signals
    message( FATAL_ERROR "Catching the signals requieres an UNIX system." )
  else()
    IF( NOT APPLE)
      SET(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} -rdynamic")
    ENDIF()
  endif()
802 803 804 805 806 807 808 809
  ##################################################################
  #                                                                #
  #                     END SETTING VARIABLES                      #
  #                                                                #
  ##################################################################
  #
  # Generate  ScalFmmConfig.h
  #
810
  set(SCALFMM_COMPILE_FLAGS "${SCALFMM_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
811
  set(CMAKE_CXX_FLAGS "${SCALFMM_COMPILE_FLAGS}")
812
  # We need the libraries without spaces (inside the config file)
813
  set(SCALFMM_COMPILE_LIBS "")
814
  foreach(lib_var ${SCALFMM_LIBRARIES})
815
    string(STRIP ${lib_var} lib_var)
816
    list(APPEND SCALFMM_COMPILE_LIBS ${lib_var})
817
  endforeach()
818
  configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/Src/ScalFmmConfig.h.cmake
819
    ${CMAKE_CURRENT_BINARY_DIR}/Src/ScalFmmConfig.h  )
820 821 822 823 824 825 826 827 828 829 830 831
  #
  ##################################################################
  #                      Build - lib                               #
  ##################################################################
  #
  add_subdirectory(Src)
  # Link with scalfmm lib
  set(scalfmm_lib scalfmm)
  #
  ##################################################################
  #            Remove compilation  of the drivers                  #
  ##################################################################
832
  message(STATUS "SCALFMM_BUILD_EXAMPLES  =  ${SCALFMM_BUILD_EXAMPLES}" )
833
  if( SCALFMM_BUILD_EXAMPLES )
834 835 836 837 838 839 840
    # Build - Examples and drivers
    add_subdirectory(Examples)
  endif()
  ##################################################################
  #           Build tools (Internal use)                           #
  ##################################################################
  # Build - UTILs
841
  if( SCALFMM_ONLY_DEVEL AND SCALFMM_BUILD_UTILS)
842
    add_subdirectory(Utils)
843
  endif()
844

845 846 847 848
  ##################################################################
  #                Build -Tests to see examples                    #
  ##################################################################
  # Build - Tests
849 850
  message( STATUS "SCALFMM_BUILD_TESTS          = ${SCALFMM_BUILD_TESTS}" )
  if( SCALFMM_BUILD_TESTS )
851 852
    add_subdirectory(Tests)
  endif()
berenger-bramas's avatar
berenger-bramas committed
853

854 855 856 857
  ##################################################################
  #              Build - Unitary and numerical Tests               #
  ##################################################################
  #
858 859
  message( STATUS "SCALFMM_BUILD_UTESTS         = ${SCALFMM_BUILD_UTESTS}" )
  if( SCALFMM_BUILD_UTESTS )
860 861 862 863
    include(CTest)
    enable_testing()
    add_subdirectory(UTests)
  endif()
864
  #
865 866 867
  ##################################################################
  #                           Add - doc                            #
  ##################################################################
868
  #
869
  message(STATUS "SCALFMM_BUILD_DOC           =  ${SCALFMM_BUILD_DOC}" )
870 871 872
  if(SCALFMM_BUILD_DOC)
    add_subdirectory(Doc)
  endif()
873
  #
874 875 876 877
  ##################################################################
  #                       Build - Addons                           #
  ##################################################################
  #
878
  if( SCALFMM_USE_ADDONS )
879 880
    file(GLOB all_addons ./Addons/*)
    # Options
881
    option( SCALFMM_ADDON_CKERNELAPI "Set to ON to build ScaFMM FMM API interface" OFF )
882

883 884 885 886
    foreach(addon_name ${all_addons})
      message(STATUS "Addons += ${addon_name}" )
      add_subdirectory(${addon_name})
    endforeach()
887
  endif()
888

889 890 891 892 893 894 895 896 897 898 899 900 901 902 903
  # Add custom clean command
  if("${CMAKE_GENERATOR}" MATCHES "Make")
    add_custom_target(reset
      COMMAND ${CMAKE_MAKE_PROGRAM} clean && rm -r ./CMake* && cmake ..
      WORKING_DIRECTORY ${CMAKE_CURRENT_DIR}
      COMMENT "Cleaning Build dir and CMake cache, then do cmake.."
      )
  endif()
  #
  ##################################################################
  #                                                                #
  #                  Build and export cmake files                  #
  #                                                                #
  ##################################################################
  #
904 905 906
  message(STATUS "SCALFMM_BINARY_DIR:          " ${SCALFMM_BINARY_DIR})
  configure_file(${SCALFMM_SOURCE_DIR}/ScalFMMConfig.cmake.in
    ${SCALFMM_BINARY_DIR}/ScalFMMConfig.cmake
907 908 909
    @ONLY IMMEDIATE
    )
  #
910 911 912
  install(FILES  ${SCALFMM_BINARY_DIR}/ScalFMMConfig.cmake  DESTINATION lib/  )
  if( SCALFMM_INSTALL_DATA )
    install(FILES  ${SCALFMM_SOURCE_DIR}/Data/test20k.fma  DESTINATION Data/   )
913
  endif()
914
  #
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931
  ##################################################################
  #                                                                #
  #              build a CPack driven installer package            #
  #                                                                #
  ##################################################################
  #
  # Use git commit number as CPACK_PACKAGE_VERSION_PATCH
  set(CPACK_PACKAGE_VERSION_PATCH 0)
  execute_process(
    COMMAND git rev-list HEAD --count
    OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
    RESULT_VARIABLE RET
    ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
    )
  #string_TRIM(PATCH1 PATCH)
  set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY "ON")
  #
932
  set (CPACK_RESOURCE_FILE_LICENSE  "${CMAKE_CURRENT_SOURCE_DIR}/LICENCE")
933 934
  set(CPACK_PACKAGE_VERSION_MAJOR "${SCALFMM_MAJOR_VERSION}")
  set(CPACK_PACKAGE_VERSION_MINOR "${SCALFMM_MINOR_VERSION}")
935
  #
936
  set(PACK_PACKAGE_VERSION "${SCALFMM_MAJOR_VERSION}.${SCALFMM_MINOR_VERSION}-${CPACK_PACKAGE_VERSION_PATCH}")
937
  set(CPACK_SOURCE_GENERATOR "TGZ")
938
  set(CPACK_SOURCE_PACKAGE_FILE_NAME  "SCALFMM-${SCALFMM_MAJOR_VERSION}.${SCALFMM_MINOR_VERSION}-${CPACK_PACKAGE_VERSION_PATCH}")
939 940
  set(CPACK_SOURCE_IGNORE_FILES "\\\\.git;.DS_Store;.*~;/*.aux;/*.idx;/*.log;/*.out;/*.toc;/*.ilg;CMakeLists.txt.user;/.settings/")
  list(APPEND CPACK_SOURCE_IGNORE_FILES  "${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}/Utils/;/Build*;/Obsolete/")
941 942 943 944 945 946 947 948 949
  #
  include(CPack)
  #
  #
  ##################################################################
  #                                                                #
  #                      PRINT messages                            #
  #                                                                #
  ##################################################################
950
  message(STATUS "CPACK_SOURCE_IGNORE_FILES      = ${CPACK_SOURCE_IGNORE_FILES}")
951 952 953
  message(STATUS "CPACK_SOURCE_PACKAGE_FILE_NAME = ${CPACK_SOURCE_PACKAGE_FILE_NAME}")
  #
  #                    Use Mem stats
954
  message(STATUS "SCALFMM_USE_MEM_STATS = ${SCALFMM_USE_MEM_STATS}" )
955
  #                    Use Log
956
  message(STATUS "SCALFMM_USE_LOG       = ${SCALFMM_USE_LOG}" )
957
  #                    Use Assert
958
  message(STATUS "SCALFMM_USE_ASSERT    = ${SCALFMM_USE_ASSERT}" )
959
  #
960
  message(STATUS "SCALFMM_USE_BLAS      =  ${SCALFMM_USE_BLAS}")
COULAUD Olivier's avatar
COULAUD Olivier committed
961
  message(STATUS "SCALFMM_USE_FFT       =  ${SCALFMM_USE_FFT}")
962
  message(STATUS "SCALFMM_USE_MKL       =   ${SCALFMM_USE_MKL}")
963
  #
964
  message(STATUS "CMAKE_CXX_FLAGS_TYPE  =  ${CMAKE_CXX_FLAGS_TYPE}")
965 966 967 968
  message(STATUS "CMAKE_CXX_FLAGS       =  ${CMAKE_CXX_FLAGS}")
  message(STATUS "SCALFMM_CXX_FLAGS     =  ${SCALFMM_CXX_FLAGS}")
  message(STATUS "SCALFMM_LIBRARIES     =  ${SCALFMM_LIBRARIES}")
  message(STATUS "SCALFMM_INCLUDES      =  ${SCALFMM_INCLUDES}")
969
  message(STATUS "FUSE_LIST             =  ${FUSE_LIST}")
970
  #
971 972 973
  ##################################################################
  #                               END                              #
  ##################################################################
974
  #
975
else(MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/morse")
976 977 978 979 980 981 982

  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")

983
endif(MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/morse")