CMakeLists.txt 29.5 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
14
15
16
17
18
19
20
21
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)

#===========================================================================
# Project Declaration
#===========================================================================
project(ScalFMM C CXX)

# directly make an error if in-source build
#if("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
#   message(FATAL_ERROR "In-source builds are not allowed.\n"
#   "Please create a build directory first and execute cmake configuration from "
#   "this directory. Example: mkdir build && cd build && cmake ..")
#endif()
BRAMAS Berenger's avatar
BRAMAS Berenger committed
22
#
23
24
25
26
27
28
29
30
31
# check if compiling into source directories
#string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" insource)
#if(insource)
#  message(FATAL_ERROR "${PROJECT_NAME} requires an out of source build. Goto ./Build and tapes cmake ../")
#endif(insource)

set(ScalFMM_CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules)


BRAMAS Berenger's avatar
BRAMAS Berenger committed
32
# MPI option has to be set before project, cannot be changed in the cache!
33
34
35
36
37
38
39
40
41
#if( ScalFMM_USE_MPI )
#  include(CMakeForceCompiler)
#  CMAKE_FORCE_C_COMPILER(mpicc      "MPI C Compiler")
#  CMAKE_FORCE_CXX_COMPILER(mpicxx   "MPI C++ Compiler")
#  set(ScalFMM_USE_MPI ON CACHE BOOL "ScalFMM use MPI")
#else()
#  message(STATUS "Remove CMake cache and run cmake .. -DScalFMM_USE_MPI=ON to enable MPI" )
#endif(ScalFMM_USE_MPI)

BRAMAS Berenger's avatar
BRAMAS Berenger committed
42

COULAUD Olivier's avatar
COULAUD Olivier committed
43
44
45
46
47
#===========================================================================
# Version Number
#===========================================================================

# ScalFMM version number.  An even minor number corresponds to releases.
48
49
50
51
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
52

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

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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)

  #
  # Active language
  # -----------------------
#  enable_language(CXX)
  #

  #
  # Options
  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"         OFF )
  option( ScalFMM_USE_FFT              "Set to ON to build ScaFMM with FFTW"         OFF )
  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_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_USE_DOUBLE_PRECISION "Set to ON to compile in double precision"    ON  )
  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"       ON  )
  option( ScalFMM_USE_AVX              "Set to ON to compile with AVX support"       OFF  )
  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_BUILD_ONLY_LIB       "Set to ON to compile only the lib (examples are not compiled) " OFF  )
  option( ScalFMM_ONLY_DEVEL           "Set to ON to compile Development tools (only scalfmm team)" ON )
  if( ScalFMM_ONLY_DEVEL )
    option( ScalFMM_USE_STARPU "Set to ON to build ScalFMM with StarPU" OFF )
  endif()
  if( ScalFMM_USE_MPI )
    try_compile(COMPILE_INTEL ${CMAKE_CURRENT_BINARY_DIR}
                ${ScalFMM_CMAKE_MODULE_PATH}/compileTestIntel.cpp
                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 "")
  set(ScalFMM_CXX_FLAGS "-std=c++11 -fpic -Wall")
  #
  #
  # 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)
  message(STATUS "ScalFMM_BUILD_DEBUG = ${ScalFMM_BUILD_DEBUG}" )
  #
  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
    set(ScalFMM_CXX_FLAGS  "${ScalFMM_CXX_FLAGS} -m64")
  endif()
  ##############################################################################
  #                           Compile options                                  #
  ##############################################################################
  #  -xHost -mfpmath=sse
  # -Wall Wnosign-conversion
  #
  if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
    # INTEL
134
    IF (APPLE)
135
136
137
138
139
      set(SSE_FLAGS  "-msse4  -mfpmath=sse")   # -mtune=native -march=native
    else(APPLE)
      set(AVX_FLAGS  "-mavx")
      set(SSE_FLAGS  "-axSSE4.2")
    endif(APPLE)
Marc-Alexandre Espiaut's avatar
Marc-Alexandre Espiaut committed
140
    #-Wshadow -Wpointer-arith -Wcast-qual -Wconversion  -Wall -Wnosign-conversion ")
141
  else()
Marc-Alexandre Espiaut's avatar
Marc-Alexandre Espiaut committed
142
    # NOT      INTEL
143
144
    if(NOT ScalFMM_USE_MPI)
      set(ScalFMM_CXX_FLAGS  "${ScalFMM_CXX_FLAGS} -Wzero-as-null-pointer-constant")
145
    else()
146
147
148
149
150
      include(CheckCCompilerFlag)
      check_c_compiler_flag(-Wno-literal-suffix HAS_NO_LITERAL_SUFFIX_FLAG)
      if(HAS_NO_LITERAL_SUFFIX_FLAG)
        set(ScalFMM_CXX_FLAGS  "${ScalFMM_CXX_FLAGS} -Wno-literal-suffix")
      endif()
151
    endif()
152
153
154
155
156
157
158
    set(AVX_FLAGS "-mtune=native -march=native")
    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()
159

160
161
162
163
164
165
  ##############################################################################
  #                           FUSE list                                        #
  ##############################################################################
  set(FUSE_LIST "")
  # then do list(APPEND FUSE_LIST "BLAS") to protect from FUSE_BLAS
  list(APPEND FUSE_LIST "MPI")
166

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
  ##############################################################################
  #                        Debug      flags                                    #
  ##############################################################################
  #
  if( ScalFMM_BUILD_DEBUG )
    #
    # Compile Debug flags
    #
    set(CMAKE_BUILD_TYPE Debug)
    ADD_DEFINITIONS(-O0)
    if( APPLE )
      set(SCALFMM_FLAGS_OPTI_DEBUG "-m64  -funroll-loops" CACHE STRING
        "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})
    set(ScalFMM_CXX_FLAGS "${ScalFMM_CXX_FLAGS} ${SCALFMM_FLAGS_OPTI_DEBUG}")
    set(CMAKE_CXX_FLAGS_TYPE "${CMAKE_CXX_FLAGS_DEBUG}")

  else()
    ##############################################################################
    #                          Release flags                                     #
    ##############################################################################
    set(CMAKE_BUILD_TYPE Release)
    # force -O3 in release
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
    string(REPLACE "-O2" "-O3" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} )
    set(CMAKE_CXX_FLAGS_TYPE  "${CMAKE_CXX_FLAGS_RELEASE}")
    # if compiler is intel add -ip
BRAMAS Berenger's avatar
BRAMAS Berenger committed
203
    if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
204
205
      set(ScalFMM_CXX_FLAGS  "${ScalFMM_CXX_FLAGS} -ip")
      # set(ScalFMM_CXX_FLAGS  "${ScalFMM_CXX_FLAGS} -ip -no-prec-div -no-prec-sqrt")
BRAMAS Berenger's avatar
BRAMAS Berenger committed
206
    endif()
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
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
    # Compile optimization
    if(APPLE)
      set(SCALFMM_FLAGS_OPTI_RELEASE "-m64  -funroll-loops" CACHE STRING
        "Set your optimization flags for release mode.")
    else(APPLE)
      # Not apple system - Check the compiler flags
      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 " " CACHE STRING
          "Set your optimization flags for release mode.")
      else()
        set(SCALFMM_FLAGS_OPTI_RELEASE "-ffast-math -funroll-loops -ftree-vectorize" CACHE STRING
          "Set your optimization flags for release mode.")
      endif()
    endif(APPLE)
    #
    set(ScalFMM_CXX_FLAGS  "${ScalFMM_CXX_FLAGS} ${SCALFMM_FLAGS_OPTI_RELEASE}")
  endif()
  #
  ##############################################################################
  #                Attach source code to exec                                  #
  ##############################################################################
  message(STATUS "ScalFMM_ATTACHE_SOURCE       = ${ScalFMM_ATTACHE_SOURCE}" )
  if( ScalFMM_ATTACHE_SOURCE )
    message(STATUS "Option -g is used, the code is attached to the binary." )
    set(ScalFMM_CXX_FLAGS  "${ScalFMM_CXX_FLAGS} -g")
  endif(ScalFMM_ATTACHE_SOURCE)
  #
  ##############################################################################
  #                                 find MPI                                   #
  ##############################################################################
  #
  if( ScalFMM_USE_MPI )

    # 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)
        set(ScalFMM_CXX_FLAGS "${ScalFMM_CXX_FLAGS} ${MPI_CXX_COMPILE_FLAGS}")
    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                                    #
  ##############################################################################
  #
  if( ScalFMM_USE_BLAS )
    message(STATUS "CMAKE_CXX_COMPILER_ID STREQUAL  ${CMAKE_CXX_COMPILER_ID}")

    option( ScalFMM_USE_MKL_AS_BLAS "Set to ON to use MKL CBLAS" OFF )

    if( ScalFMM_USE_MKL_AS_BLAS )

      set(BLA_VENDOR "Intel10_64lp_seq")
      find_package(BLASEXT REQUIRED)

      if(BLAS_FOUND AND BLAS_LIBRARY_DIRS)
        # the RPATH to be used when installing
        list(APPEND CMAKE_INSTALL_RPATH "${BLAS_LIBRARY_DIRS}")
      else()
        message(FATAL_ERROR "A BLAS library is required but has not been found")
      endif()
      unset(LAPACK_LIBRARIES)
      if (BLAS_LIBRARIES)
        set(BLASLAPACK_LIBRARIES ${BLAS_LIBRARIES})
      endif()

    elseif(ScalFMM_USE_EXTERNAL_BLAS)

      message(STATUS "BLAS SET BY EXTERNAL PROGRAM = ${BLAS_LIBRARIES}")

301
    else()
302
303
304
305
306
307
308
309
310
311
312

      find_package(BLASEXT REQUIRED)
      find_package(LAPACKEXT REQUIRED)
      set(BLASLAPACK_LIBRARIES)
      if (LAPACK_LIBRARIES)
        set(BLASLAPACK_LIBRARIES "${LAPACK_LIBRARIES}")
      endif()
      if (BLAS_LIBRARIES)
        list(APPEND BLASLAPACK_LIBRARIES "${BLAS_LIBRARIES}")
      endif()

313
    endif()
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
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

    set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES}; ${BLASLAPACK_LIBRARIES}")
    #message(STATUS "SCALFMM_LIBRARIES          = ${SCALFMM_LIBRARIES}")

  endif(ScalFMM_USE_BLAS)
  list(APPEND FUSE_LIST "BLAS")
  #
  # FFT option
  #
  if( ScalFMM_USE_FFT )

    option( ScalFMM_USE_MKL_AS_FFTW "Set to ON to use MKL FFTW" OFF )

    message(STATUS "SCALFMM USE FFT Configure:")

    if( ScalFMM_USE_MKL_AS_FFTW )

      message(STATUS "         SCALFMM USE MKL ")

      if( ScalFMM_USE_MKL_AS_BLAS )

        unset(FFT_LIBRARIES CACHE)
        message(STATUS "         SCALFMM USE MKL already defined")
        set(FFT_INCLUDES "$ENV{MKLROOT}/include/fftw" CACHE STRING "Set your MKL flags")

      else(ScalFMM_USE_MKL_AS_BLAS)

        # 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
        find_package(FFTW REQUIRED COMPONENTS MKL)
        if(FFTW_LIBRARY_DIRS)
          set(FFT_LIBRARIES "-L${FFTW_LIBRARY_DIRS};" CACHE STRING "Set your MKL flags")
        endif()
        foreach (fft_lib ${FFTW_LIBRARIES})
            set(FFT_LIBRARIES "${FFT_LIBRARIES} ${fft_lib};")
        endforeach()
        if (FFTW_INCLUDE_DIRS)
            set(FFT_INCLUDES "${FFTW_INCLUDE_DIRS}" )
        endif()
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES}; ${FFT_LIBRARIES}")

      endif(ScalFMM_USE_MKL_AS_BLAS)

    else(ScalFMM_USE_MKL_AS_FFTW)

      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
      find_package(FFTW REQUIRED)

      if(FFTW_LIBRARY_DIRS)
        set(FFT_LIBRARIES "-L${FFTW_LIBRARY_DIRS};" CACHE STRING "Set your MKL flags")
      endif()
      foreach (fft_lib ${FFTW_LIBRARIES})
        set(FFT_LIBRARIES "${FFT_LIBRARIES} ${fft_lib};")
      endforeach()
      if (FFTW_INCLUDE_DIRS)
        set(FFT_INCLUDES "${FFTW_INCLUDE_DIRS}" )
      endif()
      set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES}; ${FFT_LIBRARIES}")

    endif(ScalFMM_USE_MKL_AS_FFTW)

    if (FFT_INCLUDES)
        set(SCALFMM_INCLUDES "${SCALFMM_INCLUDES}; ${FFT_INCLUDES}")
    endif()
    message(STATUS "         SCALFMM_LIBRARIES          = ${SCALFMM_LIBRARIES}")
    message(STATUS "         SCALFMM_INCLUDES          = ${SCALFMM_INCLUDES}")

  endif(ScalFMM_USE_FFT)
  list(APPEND FUSE_LIST "FFT")

  # Compile option
  #ADD_DEFINITIONS(-Wall -Wshadow -Wpointer-arith -Wcast-qual -Wconversion -fpic )
  #
  # 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}")
    if(APPLE)
      string(FIND ${CMAKE_CXX_COMPILER}  "icl++" NAME)
      if( ${NAME} GREATER  0)
        if(  ${INTEL_VERSION} EQUAL 15. OR  ${INTEL_VERSION} GREATER 15.0.0)
  	message( STATUS "  Intel compiler is icl++ ( version >= 15.0.0)")
  	set(INTEL_ICL_COMPILER "ON")
402
        else()
403
  	message(FATAL_ERROR  "  Intel compiler should be icl++ ( version >= 15.0.0)")
404
        endif()
405
      else()
406
        message(FATAL_ERROR  "  Intel compiler should be icl++ ( version >= 15.0.0)")
Olivier Coulaud's avatar
Olivier Coulaud committed
407
      endif()
408
    endif()
409
  endif()
410
411
412
413
414
  #
  ##################################################################
  ##################################################################
  #
  if( ScalFMM_USE_STARPU )
415

416
417
418
    set(ScalFMM_STARPU_VERSION "1.1" CACHE STRING "oldest STARPU version desired")
    # create list of components in order to make a single call to find_package(starpu...)
    set(STARPU_COMPONENT_LIST "HWLOC")
419
    if(ScalFMM_USE_MPI)
420
        list(APPEND STARPU_COMPONENT_LIST "MPI")
421
    endif()
422

423
424
    find_package(STARPU ${ScalFMM_STARPU_VERSION} REQUIRED
                 COMPONENTS ${STARPU_COMPONENT_LIST})
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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
    set(STARPU_LIBRARIES_CPY "${STARPU_LIBRARIES}")
    set(STARPU_LIBRARIES "")
    foreach (starpu_lib ${STARPU_LIBRARIES_CPY})
      if (EXISTS ${starpu_lib} OR ${starpu_lib} MATCHES "^-")
          set(STARPU_LIBRARIES "${STARPU_LIBRARIES} ${starpu_lib}")
      else()
          set(STARPU_LIBRARIES "${STARPU_LIBRARIES} -l${starpu_lib}")
      endif()
    endforeach()
    if (STARPU_LIBRARY_DIRS)
        set(STARPU_LIBRARIES"-L${STARPU_LIBRARY_DIRS} ${STARPU_LIBRARIES}")
    endif()
    set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES}; ${STARPU_LIBRARIES}")
    if (STARPU_INCLUDE_DIRS)
        set(STARPU_INCLUDES "${STARPU_INCLUDE_DIRS}")
        include_directories(${STARPU_INCLUDES})
    endif()

    message(STATUS "         STARPU_LIBRARIES          = ${STARPU_LIBRARIES}")
    if (STARPU_INCLUDE_DIRS)
        message(STATUS "         STARPU_INCLUDES           = ${STARPU_INCLUDES}")
    endif()

  endif(ScalFMM_USE_STARPU)
  list(APPEND FUSE_LIST "STARPU")
  #
  ##################################################################
  #                         Use SSE                                #
  ##################################################################

  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)" )
    endif()
    message( STATUS "SSE_FLAGS ${SSE_FLAGS}  -- ${CMAKE_CXX_FLAGS}  ")
    try_compile(COMPILE_SSE  ${CMAKE_CURRENT_BINARY_DIR}
                ${ScalFMM_CMAKE_MODULE_PATH}/compileTestSse.cpp
                COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${SSE_FLAGS}"
                OUTPUT_VARIABLE COMPILE_SSE_OUTPUT)

    if(${COMPILE_SSE})
      set(ScalFMM_CXX_FLAGS "${ScalFMM_CXX_FLAGS} ${SSE_FLAGS}")

      try_compile(COMPILE_RESULT_VAR ${CMAKE_CURRENT_BINARY_DIR}
                  ${ScalFMM_CMAKE_MODULE_PATH}/checkSSEpe.cpp
                  COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${SSE_FLAGS}")
      if( NOT ${COMPILE_RESULT_VAR})
        set(__SSEPE_INTEL_COMPILER ON)
      endif()
      #		set(ScalFMM_USE_AVX OFF)
    else(${COMPILE_SSE})
      message(FATAL_ERROR "SSE NOT SUPPORTED ; Set ScalFMM_USE_SSE  to OFF \n Output from test is : ${COMPILE_SSE_OUTPUT}")
    endif(${COMPILE_SSE})
  endif()
  list(APPEND FUSE_LIST "SSE")
  ##################################################################
  #                           Use AVX                              #
  ##################################################################

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

    try_compile(COMPILE_AVX ${CMAKE_CURRENT_BINARY_DIR}
                ${ScalFMM_CMAKE_MODULE_PATH}/compileTestAvx.cpp
                COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${AVX_FLAGS}"
                OUTPUT_VARIABLE COMPILE_AVX_OUTPUT)
    if(${COMPILE_AVX})
      set(ScalFMM_CXX_FLAGS "${ScalFMM_CXX_FLAGS}   ${AVX_FLAGS}")
      #             set( ScalFMM_USE_SSE   OFF   FORCE) # ne marche pas
      try_compile(COMPILE_RESULT_AVSPE ${CMAKE_CURRENT_BINARY_DIR}
                  ${ScalFMM_CMAKE_MODULE_PATH}/checkAVXpe.cpp
                  COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${AVX_FLAGS}")
      if( NOT ${COMPILE_RESULT_AVSPE})
        set(__AVXPE_INTEL_COMPILER ON)
      endif()

      message(STATUS ${CMAKE_CXX_FLAGS} )
    else(${COMPILE_AVX})
      message(FATAL_ERROR "AVX NOT SUPPORTED ; Set ScalFMM_USE_AVX  to OFF \n Output from test is : ${COMPILE_AVX_OUTPUT} ")
    endif(${COMPILE_AVX})
  endif(ScalFMM_USE_AVX)
  list(APPEND FUSE_LIST "AVX")
  #
  # Error if both ScalFMM_USE_AVX AND ScalFMM_USE_SSE are set
  #
  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)
  ##################################################################
  #                     Use  native MIC compilation                #
  ##################################################################
  if( ScalFMM_USE_MIC_NATIVE )
522
523
    include(CheckCCompilerFlag)
    check_c_compiler_flag(-mmic HAS_MMIC_FLAG)
524
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
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
    if(NOT HAS_MMIC_FLAG)
      message(FATAL_ERROR "MIC NOT SUPPORTED ; Set ScalFMM_USE_MIC_NATIVE to OFF")
    endif()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmic")
  else()
    # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xhost")
  endif()
  list(APPEND FUSE_LIST "MIC")
  ##################################################################
  #
  ##################################################################
  #
  # Add CBLAS
  #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}  ${CBLAS_LIBRARIES}")
  # SI CBLAS necessaire utiliser la ligne cidessous
  #set(SCALFMM_LIBRARIES   "${CBLAS_LIBRARIES}; ${SCALFMM_LIBRARIES} ")
  #
  ##################################################################
  #                                                                #
  #                     END SETTING VARIABLES                      #
  #                                                                #
  ##################################################################
  #
  # Generate  ScalFmmConfig.h
  #
  set(ScalFMM_COMPILE_FLAGS "${ScalFMM_CXX_FLAGS} ${CMAKE_CXX_FLAGS_TYPE} ${CMAKE_CXX_FLAGS}")
  set(CMAKE_CXX_FLAGS "${ScalFMM_COMPILE_FLAGS} ${CMAKE_CXX_FLAGS_TYPE} ${CMAKE_CXX_FLAGS}")
  set(ScalFMM_COMPILE_LIBS   "${SCALFMM_LIBRARIES}")
  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                  #
  ##################################################################
  if( NOT ScalFMM_BUILD_ONLY_LIB )
    # Build - Examples and drivers
    add_subdirectory(Examples)
  endif()
  ##################################################################
  #           Build tools (Internal use)                           #
  ##################################################################
  # Build - UTILs
  if( ScalFMM_ONLY_DEVEL )
    #if( NOT ScalFMM_BUILD_ONLY_LIB )
576
    add_subdirectory(Utils)
577
  endif()
578

579
580
581
582
583
584
585
586
  ##################################################################
  #                Build -Tests to see examples                    #
  ##################################################################
  # Build - Tests
  message( STATUS "ScalFMM_BUILD_TESTS          = ${ScalFMM_BUILD_TESTS}" )
  if( ScalFMM_BUILD_TESTS )
    add_subdirectory(Tests)
  endif()
berenger-bramas's avatar
berenger-bramas committed
587

588
589
590
591
592
593
594
595
596
597
  ##################################################################
  #              Build - Unitary and numerical Tests               #
  ##################################################################
  #
  message( STATUS "ScalFMM_BUILD_UTESTS         = ${ScalFMM_BUILD_UTESTS}" )
  if( ScalFMM_BUILD_UTESTS )
    include(CTest)
    enable_testing()
    add_subdirectory(UTests)
  endif()
berenger-bramas's avatar
berenger-bramas committed
598

599
600
601
602
603
604
605
606
607
608
609
610
611
  ##################################################################
  #                           Add - doc                            #
  ##################################################################
  #
  add_subdirectory(Doc)
  ##################################################################
  #                       Build - Addons                           #
  ##################################################################
  #
  if( ScalFMM_USE_ADDONS )
    file(GLOB all_addons ./Addons/*)
    # Options
    option( ScalFMM_ADDON_CKERNELAPI "Set to ON to build ScaFMM FMM API interface" OFF )
612

613
614
615
616
    foreach(addon_name ${all_addons})
      message(STATUS "Addons += ${addon_name}" )
      add_subdirectory(${addon_name})
    endforeach()
617
  endif()
618

619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
  # 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                  #
  #                                                                #
  ##################################################################
  #
  message(STATUS "ScalFMM_BINARY_DIR:          " ${ScalFMM_BINARY_DIR})
  configure_file(${ScalFMM_SOURCE_DIR}/ScalFMMConfig.cmake.in
    ${ScalFMM_BINARY_DIR}/ScalFMMConfig.cmake
    @ONLY IMMEDIATE
    )
  #
  install(FILES
    ${ScalFMM_BINARY_DIR}/ScalFMMConfig.cmake
    DESTINATION lib/
    )
  if( NOT ScalFMM_BUILD_ONLY_LIB)
    install(FILES
      ${ScalFMM_SOURCE_DIR}/Data/test20k.fma
      DESTINATION Data/
      )
  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")
  set(CPACK_PACKAGE_VERSION_MAJOR "${ScalFMM_MAJOR_VERSION}")
  set(CPACK_PACKAGE_VERSION_MINOR "${ScalFMM_MINOR_VERSION}")
  #
  set(PACK_PACKAGE_VERSION "${ScalFMM_MAJOR_VERSION}.${ScalFMM_MINOR_VERSION}-${CPACK_PACKAGE_VERSION_PATCH}")
  set(CPACK_SOURCE_GENERATOR "TGZ")
  set(CPACK_SOURCE_PACKAGE_FILE_NAME  "ScalFMM-${ScalFMM_MAJOR_VERSION}.${ScalFMM_MINOR_VERSION}-${CPACK_PACKAGE_VERSION_PATCH}")
  set(CPACK_SOURCE_IGNORE_FILES "\\\\.git;.DS_Store;.*~;/*.aux;/*.idx;/*.log;/*.out;/*.toc;/*.ilg;/*.ind;scalfmm.pro*;org.eclipse.core.resources.prefs;.cproject;.project")
  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
  message(STATUS "ScalFMM_USE_MEM_STATS        = ${ScalFMM_USE_MEM_STATS}" )
  #                    Use Log
  message(STATUS "ScalFMM_USE_LOG              = ${ScalFMM_USE_LOG}" )
  #                    Use Assert
  message(STATUS "ScalFMM_USE_ASSERT           = ${ScalFMM_USE_ASSERT}" )
  #
  #message(STATUS "CMAKE_CXX_FLAGS   =  ${CMAKE_CXX_FLAGS}")
  #set(CMAKE_CXX_FLAGS "${ScalFMM_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")

  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}")
  ##################################################################
  #                               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/")