CMakeLists.txt 34.3 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 OLD)
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
Florent Pruvost's avatar
Florent Pruvost committed
17
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" insource)
18
if(insource)
Florent Pruvost's avatar
Florent Pruvost committed
19
  message(FATAL_ERROR "${PROJECT_NAME} requires an out of source build. Goto ./Build and tapes cmake ../")
20
endif(insource)
21

22
set(SCALFMM_CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules)
23
24


COULAUD Olivier's avatar
COULAUD Olivier committed
25
26
27
28
#===========================================================================
# Version Number
#===========================================================================

29
30
31
32
33
# SCALFMM version number.  An even minor number corresponds to releases.
set(SCALFMM_MAJOR_VERSION 1)
set(SCALFMM_MINOR_VERSION 3)
set(SCALFMM_PATCH_VERSION 0)
set(SCALFMM_VERSION  "${SCALFMM_MAJOR_VERSION}.${SCALFMM_MINOR_VERSION}.${SCALFMM_PATCH_VERSION}" )
COULAUD Olivier's avatar
COULAUD Olivier committed
34

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

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
if (MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_SOURCE_DIR}/CMakeModules/morse/")

  # Add extra cmake module path and initialize morse cmake modules
  # --------------------------------------------------------------
  if(MORSE_DISTRIB_DIR)
      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 )
  elseif(EXISTS "${CMAKE_SOURCE_DIR}/CMakeModules/morse/")
      list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules/morse/)
      set(MORSE_CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules/morse )
  endif()
  include(MorseInit)

  #
  # Options
53
54
55
56
57
58
59
  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 )
60
  option( SCALFMM_BUILD_DOC            "Set to ON to build the Doxygen documentation " OFF )
61
62
63
64
65
66
67
  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 )
  option( SCALFMM_USE_SSE              "Set to ON to compile with SSE support (and use intrinsec SSE P2P)"  ON  )
  option( SCALFMM_USE_AVX              "Set to ON to compile with AVX support (and use intrinsec AVX P2P)" OFF  )
68
  option( SCALFMM_USE_AVX2             "Set to ON to compile with AVX support (and use intrinsec AVXZ P2P)" OFF )
69
70
71
72
  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  )
  option( SCALFMM_ONLY_DEVEL           "Set to ON to compile Development tools (only scalfmm team)" ON )
  if( SCALFMM_ONLY_DEVEL )
73
    option( OPENMP_SUPPORT_COMMUTE   "Set to ON to let tasks commute (KSTAR/StarPU compiler only)" OFF )
74
75
    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 )
76
  endif()
77
  if( SCALFMM_USE_MPI )
78
    try_compile(COMPILE_INTEL ${CMAKE_CURRENT_BINARY_DIR}
79
                ${SCALFMM_CMAKE_MODULE_PATH}/compileTestIntel.cpp
80
81
82
83
84
85
86
87
                COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS}")
    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 "")
88
  set(SCALFMM_CXX_FLAGS "-std=c++11 -fpic -Wall")
89
90
91
92
93
94
95
96
97
98
99
100
  #
  #
  # 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)
101
  message(STATUS "SCALFMM_BUILD_DEBUG = ${SCALFMM_BUILD_DEBUG}" )
102
103
  #
  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
104
    set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -m64")
105
106
107
108
109
110
111
112
113
  endif()
  ##############################################################################
  #                           Compile options                                  #
  ##############################################################################
  #  -xHost -mfpmath=sse
  # -Wall Wnosign-conversion
  #
  if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
    # INTEL
114
    IF (APPLE)
115
116
      set(SSE_FLAGS  "-msse4  -mfpmath=sse")   # -mtune=native -march=native
    else(APPLE)
117
118
119
      set(AVX_FLAGS  "-mavx  -march=native")
      set(AVX2_FLAGS  "-mavx2  -march=native")
      set(SSE_FLAGS  "-axSSE4.2  -march=native")
120
    endif(APPLE)
Marc-Alexandre Espiaut's avatar
Marc-Alexandre Espiaut committed
121
    #-Wshadow -Wpointer-arith -Wcast-qual -Wconversion  -Wall -Wnosign-conversion ")
122
  else()
Marc-Alexandre Espiaut's avatar
Marc-Alexandre Espiaut committed
123
    # NOT      INTEL
124
    if(NOT SCALFMM_USE_MPI)
125
126
127
      include(CheckCCompilerFlag)
      check_c_compiler_flag(-Wzero-as-null-pointer-constant HAS_WZERO_NULL_PTR_FLAG)
      if(HAS_WZERO_NULL_PTR_FLAG)
128
        set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -Wzero-as-null-pointer-constant")
129
      endif()
130
    else()
131
132
133
      include(CheckCCompilerFlag)
      check_c_compiler_flag(-Wno-literal-suffix HAS_NO_LITERAL_SUFFIX_FLAG)
      if(HAS_NO_LITERAL_SUFFIX_FLAG)
134
        set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -Wno-literal-suffix")
135
      endif()
136
    endif()
137
    set(AVX_FLAGS "-mtune=native -march=native")
138
    set(AVX2_FLAGS "-mtune=native -march=native -mmic")
139
140
141
142
143
144
    IF (APPLE)
      set(SSE_FLAGS  "-msse3  -mfpmath=sse")   # -mtune=native -march=native
    else(APPLE)
      set(SSE_FLAGS  "-mtune=native -march=native")   # -mtune=native -march=native
    endif(APPLE)
  endif()
145

146
147
148
149
150
151
  ##############################################################################
  #                           FUSE list                                        #
  ##############################################################################
  set(FUSE_LIST "")
  # then do list(APPEND FUSE_LIST "BLAS") to protect from FUSE_BLAS
  list(APPEND FUSE_LIST "MPI")
152

153
154
155
156
  ##############################################################################
  #                        Debug      flags                                    #
  ##############################################################################
  #
157
  if( SCALFMM_BUILD_DEBUG )
158
159
160
161
162
163
    #
    # Compile Debug flags
    #
    set(CMAKE_BUILD_TYPE Debug)
    ADD_DEFINITIONS(-O0)
    if( APPLE )
164
      set(SCALFMM_FLAGS_OPTI_DEBUG "-funroll-loops" CACHE STRING
165
166
167
168
169
170
171
172
173
174
175
        "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})
176
    set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} ${SCALFMM_FLAGS_OPTI_DEBUG}")
177
178
179
180
181
182
    set(CMAKE_CXX_FLAGS_TYPE "${CMAKE_CXX_FLAGS_DEBUG}")

  else()
    ##############################################################################
    #                          Release flags                                     #
    ##############################################################################
183

184
185
186
    set(CMAKE_BUILD_TYPE Release)
    set(CMAKE_CXX_FLAGS_TYPE  "${CMAKE_CXX_FLAGS_RELEASE}")
    # if compiler is intel add -ip
187

BRAMAS Berenger's avatar
BRAMAS Berenger committed
188
    if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
189
      set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -ip -no-prec-div -no-prec-sqrt")
BRAMAS Berenger's avatar
BRAMAS Berenger committed
190
    endif()
191
192
    # Compile optimization
    if(APPLE)
193
      set(SCALFMM_FLAGS_OPTI_RELEASE "-funroll-loops" CACHE STRING
194
195
196
        "Set your optimization flags for release mode.")
    else(APPLE)
      # Not apple system - Check the compiler flags
197
198
199
200
201
     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"
           CACHE STRING "Set your optimization flags for release mode.")
       # set(SCALFMM_FLAGS_OPTI_RELEASE "-funroll-loops -ftree-vectorize" CACHE STRING
       #   "Set your optimization flags for release mode.")
202
203
204
205
206
207
      else()
        set(SCALFMM_FLAGS_OPTI_RELEASE "-ffast-math -funroll-loops -ftree-vectorize" CACHE STRING
          "Set your optimization flags for release mode.")
      endif()
    endif(APPLE)
    #
208
    set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} ${SCALFMM_FLAGS_OPTI_RELEASE}")
209
  endif()
210
211
212
    MESSAGE(STATUS   " %%%%%%%%%% SCALFMM_CXX_FLAGS  ${SCALFMM_CXX_FLAGS} %%%%%%%%%%%%%")
    MESSAGE(STATUS   " %%%%%%%%%% CMAKE_CXX_FLAGS_RELEASE  ${CMAKE_CXX_FLAGS_RELEASE} %%%%%%%%%%%%%")

213
214
215
216
  #
  ##############################################################################
  #                Attach source code to exec                                  #
  ##############################################################################
217
218
  message(STATUS "SCALFMM_ATTACHE_SOURCE       = ${SCALFMM_ATTACHE_SOURCE}" )
  if( SCALFMM_ATTACHE_SOURCE )
219
    message(STATUS "Option -g is used, the code is attached to the binary." )
220
221
    set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -g")
  endif(SCALFMM_ATTACHE_SOURCE)
222
223
224
225
226
  #
  ##############################################################################
  #                                 find MPI                                   #
  ##############################################################################
  #
227
  if( SCALFMM_USE_MPI )
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244

    # allows to use an external mpi compilation by setting compilers with
    # -DMPI_C_COMPILER=path/to/mpicc -DMPI_CXX_COMPILER=path/to/mpicxx
    # at cmake configure
    if(NOT MPI_C_COMPILER)
        set(MPI_C_COMPILER mpicc)
    endif()
    if(NOT MPI_CXX_COMPILER)
        set(MPI_CXX_COMPILER mpicxx)
    endif()

    find_package(MPI REQUIRED)

    if (MPI_CXX_INCLUDE_PATH)
        include_directories( ${MPI_CXX_INCLUDE_PATH} )
    endif()
    if (MPI_CXX_COMPILE_FLAGS)
245
        set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} ${MPI_CXX_COMPILE_FLAGS}")
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
    endif()
    if (MPI_CXX_INCLUDE_PATH)
        set(SCALFMM_INCLUDES  "${SCALFMM_INCLUDES}; ${MPI_CXX_INCLUDE_PATH}")
    endif()
    if (MPI_CXX_LINK_FLAGS)
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES}; ${MPI_CXX_LINK_FLAGS}")
    endif()
    if (MPI_CXX_LIBRARIES)
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES}; ${MPI_CXX_LIBRARIES}")
    endif()

  endif()
  #
  ##############################################################################
  #                             Blas option                                    #
  ##############################################################################
  #
263
  if( SCALFMM_USE_BLAS )
264
265
    message(STATUS "CMAKE_CXX_COMPILER_ID STREQUAL  ${CMAKE_CXX_COMPILER_ID}")

266
    option( SCALFMM_USE_MKL_AS_BLAS "Set to ON to use MKL CBLAS" OFF )
267

268
    if( SCALFMM_USE_MKL_AS_BLAS )
269
      set(BLA_VENDOR "Intel10_64lp_seq")
270
      find_package(BLASEXT) # not REQUIRED
271

272
      if(BLAS_LIBRARY_DIRS)
273
274
275
276
277
278
279
        # the RPATH to be used when installing
        list(APPEND CMAKE_INSTALL_RPATH "${BLAS_LIBRARY_DIRS}")
      endif()
      unset(LAPACK_LIBRARIES)
      if (BLAS_LIBRARIES)
        set(BLASLAPACK_LIBRARIES ${BLAS_LIBRARIES})
      endif()
280
    elseif(SCALFMM_USE_EXTERNAL_BLAS)
281
      message(STATUS "BLAS SET BY EXTERNAL PROGRAM = ${BLAS_LIBRARIES}")
282
    else()
283
284
      find_package(BLASEXT)  # not REQUIRED
      find_package(LAPACKEXT)  # not REQUIRED
285
286
287
288
289
290
291
      set(BLASLAPACK_LIBRARIES)
      if (LAPACK_LIBRARIES)
        set(BLASLAPACK_LIBRARIES "${LAPACK_LIBRARIES}")
      endif()
      if (BLAS_LIBRARIES)
        list(APPEND BLASLAPACK_LIBRARIES "${BLAS_LIBRARIES}")
      endif()
292
    endif()
293

294
295
296
297
    if(BLAS_FOUND)
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES}; ${BLASLAPACK_LIBRARIES}")
        #message(STATUS "SCALFMM_LIBRARIES          = ${SCALFMM_LIBRARIES}")
    else()
298
        message(WARNING "BLAS has not been found, SCALFMM will continue to compile but some applications will be disabled.")
299
        message(WARNING "If you have BLAS set BLAS_LIBDIR, BLAS_INCDIR or BLAS_DIR (CMake variables using -D or environment variables).")        
300
        set(SCALFMM_USE_FFT OFF)
301
    endif()
302

303
  endif(SCALFMM_USE_BLAS)
304
305
306
307
  list(APPEND FUSE_LIST "BLAS")
  #
  # FFT option
  #
308
  if( SCALFMM_USE_FFT )
309

310
    option( SCALFMM_USE_MKL_AS_FFTW "Set to ON to use MKL FFTW" OFF )
311
312
313

    message(STATUS "SCALFMM USE FFT Configure:")

314
    if( SCALFMM_USE_MKL_AS_FFTW )
315
316
317

      message(STATUS "         SCALFMM USE MKL ")

318
      if( SCALFMM_USE_MKL_AS_BLAS )
319
320
321
322

        unset(FFT_LIBRARIES CACHE)
        message(STATUS "         SCALFMM USE MKL already defined")
        set(FFT_INCLUDES "$ENV{MKLROOT}/include/fftw" CACHE STRING "Set your MKL flags")
323
324
325
        if (BLAS_FOUND)
            set(FFTW_FOUND ON)
        endif()
326

327
      else(SCALFMM_USE_MKL_AS_BLAS)
328
329
330
331

        # The package can be used with the following COMPONENTS:
        # MKL, THREADS|OMP and/or SIMPLE|DOUBLE|LONG|QUAD
        # Default is DOUBLE and without THREADS|OMP
332
        find_package(FFTW  COMPONENTS MKL) # not REQUIRED
333
334
335
336
337
338
339
340
        if (FFTW_LIBRARY_DIRS_DEP)
            set(FFT_LIBRARIES "-L${FFTW_LIBRARY_DIRS_DEP};" CACHE STRING "Set your MKL flags")
        endif()
        if (FFTW_LIBRARIES_DEP)
            foreach (fft_lib ${FFTW_LIBRARIES_DEP})
              set(FFT_LIBRARIES "${FFT_LIBRARIES} ${fft_lib};")
            endforeach()
        endif()
341
        set(FFT_INCLUDES "${FFTW_INCLUDE_DIRS_DEP}" )
342
343
344
        if (FFT_LIBRARIES)
            set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES}; ${FFT_LIBRARIES}")
        endif()
345

346
      endif(SCALFMM_USE_MKL_AS_BLAS)
347

348
    else(SCALFMM_USE_MKL_AS_FFTW)
349
350
351
352
353

      message(STATUS "         SCALFMM USE FFTW ")
      # The package can be used with the following COMPONENTS:
      # MKL, THREADS|OMP and/or SIMPLE|DOUBLE|LONG|QUAD
      # Default is DOUBLE and without THREADS|OMP
354
      find_package(FFTW) # not REQUIRED
355
356
357
358
359
360
361
362
      if (FFTW_LIBRARY_DIRS_DEP)
        set(FFT_LIBRARIES "-L${FFTW_LIBRARY_DIRS_DEP};" CACHE STRING "Set your MKL flags")
      endif()
      if (FFTW_LIBRARIES_DEP)
        foreach (fft_lib ${FFTW_LIBRARIES_DEP})
          set(FFT_LIBRARIES "${FFT_LIBRARIES} ${fft_lib};")
        endforeach()
      endif()
363
      set(FFT_INCLUDES "${FFTW_INCLUDE_DIRS_DEP}" )
364
365
366
      if (FFT_LIBRARIES)
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES}; ${FFT_LIBRARIES}")
      endif()
367

368
    endif(SCALFMM_USE_MKL_AS_FFTW)
369
370
371
372

    if (FFT_INCLUDES)
        set(SCALFMM_INCLUDES "${SCALFMM_INCLUDES}; ${FFT_INCLUDES}")
    endif()
373

374
375
376
377
    if(FFTW_FOUND)
        message(STATUS "         SCALFMM_LIBRARIES          = ${SCALFMM_LIBRARIES}")
        message(STATUS "         SCALFMM_INCLUDES          = ${SCALFMM_INCLUDES}")
    else()
378
        message(WARNING "FFTW has not been found, SCALFMM will continue to compile but some applications will be disabled.")
379
        message(WARNING "If you have FFTW set FFTW_LIBDIR, FFTW_INCDIR or FFTW_DIR (CMake variables using -D or environment variables).")        
380
        set(SCALFMM_USE_FFT OFF)
381
    endif()
382
  endif(SCALFMM_USE_FFT)
383
  list(APPEND FUSE_LIST "FFT")
384
385
386
         message(STATUS "         SCALFMM_LIBRARIES          = ${SCALFMM_LIBRARIES}")
        message(STATUS "         SCALFMM_INCLUDES          = ${SCALFMM_INCLUDES}")
  
COULAUD Olivier's avatar
??    
COULAUD Olivier committed
387
  message(STATUS "SCALFMM_USE_FFT       =  ${SCALFMM_USE_FFT}")
388
389
390
391
392
393
394

  #
  # 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}")
395
    set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} -Wall")
396
397
  else()
    # Compile option valid on GCC/G++
398
    set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wconversion -Wcast-qual -Wcast-align -Woverloaded-virtual")
399
  endif()
400
401
  #
  ##################################################################
COULAUD Olivier's avatar
??    
COULAUD Olivier committed
402
  #              STARPU Section
403
404
  ##################################################################
  #
405
406
  message( STATUS "SCALFMM_USE_STARPU             = ${SCALFMM_USE_STARPU}" )
  if( SCALFMM_USE_STARPU )
407
    # No fast math with starpu
408
409
    if(SCALFMM_CXX_FLAGS)
        string(REPLACE "-ffast-math" " " SCALFMM_CXX_FLAGS ${SCALFMM_CXX_FLAGS})
410
411
412
413
    endif()
    if(SCALFMM_FLAGS_OPTI_RELEASE)
        string(REPLACE "-ffast-math" " " SCALFMM_FLAGS_OPTI_RELEASE ${SCALFMM_FLAGS_OPTI_RELEASE})     
    endif()
414

415
    # CUDA could be used with StarPU enabled
416
417
418
    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)
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
        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" 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()
BRAMAS Berenger's avatar
BRAMAS Berenger committed
439
440
        
        set(CUDA_NEEDED_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/Src)
441
442
443
    endif()

    # Find StarPU with a list of optional components
444
    set(SCALFMM_STARPU_VERSION "1.1" CACHE STRING "oldest STARPU version desired")
445
446
    # create list of components in order to make a single call to find_package(starpu...)
    set(STARPU_COMPONENT_LIST "HWLOC")
447
    if(SCALFMM_USE_MPI)
448
        list(APPEND STARPU_COMPONENT_LIST "MPI")
449
    endif()
450
    if(SCALFMM_USE_CUDA)
451
452
        list(APPEND STARPU_COMPONENT_LIST "CUDA")
    endif()
453

454
    find_package(STARPU ${SCALFMM_STARPU_VERSION} REQUIRED
455
                 COMPONENTS ${STARPU_COMPONENT_LIST})
456

457
    # Append list of libraries and include dirs
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
    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()
473

474
    # TODO: is this very useful? CUDA is already a component of find starpu
475
476
477
    if (CUDA_LIBRARIES)
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES}; ${CUDA_LIBRARIES}")
    endif()
Florent Pruvost's avatar
Florent Pruvost committed
478

479
    # Message
480
481
    message(STATUS "         STARPU_LIBRARIES          = ${STARPU_LIBRARIES}")
    if (STARPU_INCLUDE_DIRS)
482
        message(STATUS "         STARPU_INCLUDES           = ${STARPU_INCLUDE_DIRS}")
483
        set(SCALFMM_INCLUDES  "${SCALFMM_INCLUDES}; ${STARPU_INCLUDE_DIRS}")
484
    endif()
485

486
    # TODO: replace this by a component of find starpu
487
488
489
    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)
BRAMAS Berenger's avatar
BRAMAS Berenger committed
490
491
492
        include_directories($ENV{OPENCL_INC})
        SET(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES}; -L$ENV{OPENCL_LIB}; -lOpenCL")
    endif()
493
  endif(SCALFMM_USE_STARPU)
494
  list(APPEND FUSE_LIST "STARPU")
Florent Pruvost's avatar
Florent Pruvost committed
495
  list(APPEND FUSE_LIST "CUDA")
BRAMAS Berenger's avatar
BRAMAS Berenger committed
496
  list(APPEND FUSE_LIST "OPENCL")
Florent Pruvost's avatar
Florent Pruvost committed
497

498
499
500
501
  ##################################################################
  #                         Use SSE                                #
  ##################################################################

502
503
504
505
  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)" )
506
507
508
    endif()
    message( STATUS "SSE_FLAGS ${SSE_FLAGS}  -- ${CMAKE_CXX_FLAGS}  ")
    try_compile(COMPILE_SSE  ${CMAKE_CURRENT_BINARY_DIR}
509
                ${SCALFMM_CMAKE_MODULE_PATH}/compileTestSse.cpp
510
511
512
513
                COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${SSE_FLAGS}"
                OUTPUT_VARIABLE COMPILE_SSE_OUTPUT)

    if(${COMPILE_SSE})
514
      set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} ${SSE_FLAGS}")
515
516

      try_compile(COMPILE_RESULT_VAR ${CMAKE_CURRENT_BINARY_DIR}
517
                  ${SCALFMM_CMAKE_MODULE_PATH}/checkSSEpe.cpp
518
519
520
521
                  COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${SSE_FLAGS}")
      if( NOT ${COMPILE_RESULT_VAR})
        set(__SSEPE_INTEL_COMPILER ON)
      endif()
522
      #set(SCALFMM_USE_AVX OFF)
523
    else(${COMPILE_SSE})
524
      message(FATAL_ERROR "SSE NOT SUPPORTED ; Set SCALFMM_USE_SSE  to OFF \n Output from test is : ${COMPILE_SSE_OUTPUT}")
525
526
527
    endif(${COMPILE_SSE})
  endif()
  list(APPEND FUSE_LIST "SSE")
528

529
530
531
532
  ##################################################################
  #                           Use AVX                              #
  ##################################################################

533
534
535
536
  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)" )
537
538
539
    endif()

    try_compile(COMPILE_AVX ${CMAKE_CURRENT_BINARY_DIR}
540
                ${SCALFMM_CMAKE_MODULE_PATH}/compileTestAvx.cpp
541
542
                COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${AVX_FLAGS}"
                OUTPUT_VARIABLE COMPILE_AVX_OUTPUT)
543
544
545
     if(${COMPILE_AVX})
  message(STATUS "%%%%%%%%%%%% COMPILE_AVX               = ${COMPILE_AVX}  %%%%<    ${AVX_FLAGS}")
		
546
      set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS}   ${AVX_FLAGS}")
547
548
    message(STATUS "%%%%%%%%%%%% SCALFMM_CXX_FLAGS               = ${SCALFMM_CXX_FLAGS}")
    #set( SCALFMM_USE_SSE   OFF   FORCE) # ne marche pas
549
      try_compile(COMPILE_RESULT_AVSPE ${CMAKE_CURRENT_BINARY_DIR}
550
                  ${SCALFMM_CMAKE_MODULE_PATH}/checkAVXpe.cpp
551
                  COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${AVX_FLAGS}")
552
		 if( NOT ${COMPILE_RESULT_AVSPE})
553
554


555
        set(__AVXPE_INTEL_COMPILER ON)
556
   endif()
557
558
559

      message(STATUS ${CMAKE_CXX_FLAGS} )
    else(${COMPILE_AVX})
560
      message(FATAL_ERROR "AVX NOT SUPPORTED ; Set SCALFMM_USE_AVX  to OFF \n Output from test is : ${COMPILE_AVX_OUTPUT} ")
561
    endif(${COMPILE_AVX})
562
  endif(SCALFMM_USE_AVX)
563
564
  list(APPEND FUSE_LIST "AVX")
  #
565
  # Error if both SCALFMM_USE_AVX AND SCALFMM_USE_SSE are set
566
  #
567
568
569
  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)
570
  ##################################################################
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
  #                           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}
                ${SCALFMM_CMAKE_MODULE_PATH}/compileTestAvx2.cpp
                COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${AVX2_FLAGS}"
                OUTPUT_VARIABLE COMPILE_AVX2_OUTPUT)
    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}
                  ${SCALFMM_CMAKE_MODULE_PATH}/checkAVX2pe.cpp
                  COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${AVX2_FLAGS}")
      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)
  ##################################################################
607
608
  #                     Use  native MIC compilation                #
  ##################################################################
609
  if( SCALFMM_USE_MIC_NATIVE )
610
611
    include(CheckCCompilerFlag)
    check_c_compiler_flag(-mmic HAS_MMIC_FLAG)
612
    if(NOT HAS_MMIC_FLAG)
613
      message(FATAL_ERROR "MIC NOT SUPPORTED ; Set SCALFMM_USE_MIC_NATIVE to OFF")
614
615
616
    endif()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmic")
  else()
617
    #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xhost")
618
619
620
621
622
  endif()
  list(APPEND FUSE_LIST "MIC")
  ##################################################################
  #
  ##################################################################
623
624


625
626
627
628
629
630
631
632
  ##################################################################
  #                                                                #
  #                     END SETTING VARIABLES                      #
  #                                                                #
  ##################################################################
  #
  # Generate  ScalFmmConfig.h
  #
633
  set(SCALFMM_COMPILE_FLAGS "${SCALFMM_CXX_FLAGS} ${CMAKE_CXX_FLAGS_TYPE} ${CMAKE_CXX_FLAGS}")
634
635
  set(CMAKE_CXX_FLAGS "${SCALFMM_COMPILE_FLAGS}")
#  set(CMAKE_CXX_FLAGS "${SCALFMM_COMPILE_FLAGS} ${CMAKE_CXX_FLAGS_TYPE} ${CMAKE_CXX_FLAGS}")
636
  set(SCALFMM_COMPILE_LIBS   "${SCALFMM_LIBRARIES}")
637
638
639
640
641
642
643
644
645
646
647
648
649
650
  configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/Src/ScalFmmConfig.h.cmake
                  ${CMAKE_BINARY_DIR}/Src/ScalFmmConfig.h  )
  #
  ##################################################################
  #                      Build - lib                               #
  ##################################################################
  #
  add_subdirectory(Src)
  # Link with scalfmm lib
  set(scalfmm_lib scalfmm)
  #
  ##################################################################
  #            Remove compilation  of the drivers                  #
  ##################################################################
651
  if( SCALFMM_BUILD_EXAMPLES )
652
653
654
655
656
657
658
    # Build - Examples and drivers
    add_subdirectory(Examples)
  endif()
  ##################################################################
  #           Build tools (Internal use)                           #
  ##################################################################
  # Build - UTILs
659
  if( SCALFMM_ONLY_DEVEL AND SCALFMM_BUILD_UTILS)
660
    add_subdirectory(Utils)
661
  endif()
662

663
664
665
666
  ##################################################################
  #                Build -Tests to see examples                    #
  ##################################################################
  # Build - Tests
667
668
  message( STATUS "SCALFMM_BUILD_TESTS          = ${SCALFMM_BUILD_TESTS}" )
  if( SCALFMM_BUILD_TESTS )
669
670
    add_subdirectory(Tests)
  endif()
berenger-bramas's avatar
berenger-bramas committed
671

672
673
674
675
  ##################################################################
  #              Build - Unitary and numerical Tests               #
  ##################################################################
  #
676
677
  message( STATUS "SCALFMM_BUILD_UTESTS         = ${SCALFMM_BUILD_UTESTS}" )
  if( SCALFMM_BUILD_UTESTS )
678
679
680
681
    include(CTest)
    enable_testing()
    add_subdirectory(UTests)
  endif()
berenger-bramas's avatar
berenger-bramas committed
682

683
684
685
  ##################################################################
  #                           Add - doc                            #
  ##################################################################
686
687
688
  if(SCALFMM_BUILD_DOC)
    add_subdirectory(Doc)
  endif()
689
690
691
692
  ##################################################################
  #                       Build - Addons                           #
  ##################################################################
  #
693
  if( SCALFMM_USE_ADDONS )
694
695
    file(GLOB all_addons ./Addons/*)
    # Options
696
    option( SCALFMM_ADDON_CKERNELAPI "Set to ON to build ScaFMM FMM API interface" OFF )
697

698
699
700
701
    foreach(addon_name ${all_addons})
      message(STATUS "Addons += ${addon_name}" )
      add_subdirectory(${addon_name})
    endforeach()
702
  endif()
703

704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
  # 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                  #
  #                                                                #
  ##################################################################
  #
719
720
721
  message(STATUS "SCALFMM_BINARY_DIR:          " ${SCALFMM_BINARY_DIR})
  configure_file(${SCALFMM_SOURCE_DIR}/ScalFMMConfig.cmake.in
    ${SCALFMM_BINARY_DIR}/ScalFMMConfig.cmake
722
723
724
    @ONLY IMMEDIATE
    )
  #
725
726
727
  install(FILES  ${SCALFMM_BINARY_DIR}/ScalFMMConfig.cmake  DESTINATION lib/  )
  if( SCALFMM_INSTALL_DATA )
    install(FILES  ${SCALFMM_SOURCE_DIR}/Data/test20k.fma  DESTINATION Data/   )
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
  endif()

  ##################################################################
  #                                                                #
  #              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")
  #
  set (CPACK_RESOURCE_FILE_LICENSE  "${CMAKE_CURRENT_SOURCE_DIR}/Licence.txt")
748
749
  set(CPACK_PACKAGE_VERSION_MAJOR "${SCALFMM_MAJOR_VERSION}")
  set(CPACK_PACKAGE_VERSION_MINOR "${SCALFMM_MINOR_VERSION}")
750
  #
751
  set(PACK_PACKAGE_VERSION "${SCALFMM_MAJOR_VERSION}.${SCALFMM_MINOR_VERSION}-${CPACK_PACKAGE_VERSION_PATCH}")
752
  set(CPACK_SOURCE_GENERATOR "TGZ")
753
  set(CPACK_SOURCE_PACKAGE_FILE_NAME  "SCALFMM-${SCALFMM_MAJOR_VERSION}.${SCALFMM_MINOR_VERSION}-${CPACK_PACKAGE_VERSION_PATCH}")
754
  set(CPACK_SOURCE_IGNORE_FILES "\\\\.git;.DS_Store;.*~;/*.aux;/*.idx;/*.log;/*.out;/*.toc;/*.ilg;scalfmm.pro*;org.eclipse.core.resources.prefs;.cproject;.project")
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
  list(APPEND CPACK_SOURCE_IGNORE_FILES  "${CMAKE_BINARY_DIR};${CMAKE_SOURCE_DIR}/Utils/;Notes;Deprecated;/Build*;/noDist/;/Bench;ToRemove;Olivier")
  # Uniform;GroupTree;Adaptive;testUnif*;/*Lagrange*")
  #list(APPEND CPACK_SOURCE_IGNORE_FILES  "Stages;Uniform;Adaptive;testUnif*;*Lagrange*" )
  #
  include(CPack)
  #
  #
  ##################################################################
  #                                                                #
  #                      PRINT messages                            #
  #                                                                #
  ##################################################################
  message(STATUS "CPACK_SOURCE_IGNORE_FILES = ${CPACK_SOURCE_IGNORE_FILES}")
  message(STATUS "CPACK_SOURCE_PACKAGE_FILE_NAME = ${CPACK_SOURCE_PACKAGE_FILE_NAME}")
  #
  #                    Use Mem stats
771
  message(STATUS "SCALFMM_USE_MEM_STATS        = ${SCALFMM_USE_MEM_STATS}" )
772
  #                    Use Log
773
  message(STATUS "SCALFMM_USE_LOG              = ${SCALFMM_USE_LOG}" )
774
  #                    Use Assert
775
  message(STATUS "SCALFMM_USE_ASSERT           = ${SCALFMM_USE_ASSERT}" )
776
777
  #
  #message(STATUS "CMAKE_CXX_FLAGS   =  ${CMAKE_CXX_FLAGS}")
778
  #set(CMAKE_CXX_FLAGS "${SCALFMM_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
COULAUD Olivier's avatar
??    
COULAUD Olivier committed
779
780
  message(STATUS "SCALFMM_USE_BLAS     =  ${SCALFMM_USE_BLAS}")
  message(STATUS "SCALFMM_USE_FFT       =  ${SCALFMM_USE_FFT}")
781
  message(STATUS "SCALFMM_USE_MKL      =   ${SCALFMM_USE_MKL}")
COULAUD Olivier's avatar
??    
COULAUD Olivier committed
782
# 
783
  message(STATUS "CMAKE_CXX_FLAGS     =  ${CMAKE_CXX_FLAGS}")
784
  message(STATUS "SCALFMM_CXX_FLAGS   =  ${SCALFMM_CXX_FLAGS}")
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
  message(STATUS "SCALFMM_LIBRARIES   =  ${SCALFMM_LIBRARIES}")
  message(STATUS "SCALFMM_INCLUDES    =  ${SCALFMM_INCLUDES}")
  ##################################################################
  #                               END                              #
  ##################################################################

else(MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_SOURCE_DIR}/CMakeModules/morse/")

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

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