CMakeLists.txt 39.2 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
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)
37
set(SCALFMM_MINOR_VERSION 4)
38 39
set(SCALFMM_PATCH_VERSION 0)
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
  elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/morse/")
    list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/morse/)
    set(MORSE_CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/morse )
54 55 56 57
  endif()
  include(MorseInit)
  #
  # Options
58
  #
59 60 61 62 63 64 65
  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 )
66
  option( SCALFMM_BUILD_DOC            "Set to ON to build the Doxygen documentation " OFF )
67 68 69 70 71
  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 )
72
  option( SCALFMM_USE_SIGNALS          "Set to ON to catch various signal an print backtrace"  OFF )
73 74 75 76 77 78 79 80 81 82
  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 )
  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 )

#
#  VECTORISATION
#
83
  if( APPLE ) # to fix problem with  GCC and avx
84 85
    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  )
86
  else(APPLE)
87 88
    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  )
89
  endif(APPLE)
90 91
  CMAKE_DEPENDENT_OPTION( SCALFMM_USE_AVX2             "Set to ON to compile with AVX support (and use intrinsec AVX2 P2P)" ON "CPUOPTION_AVX2" OFF )

92
  if( SCALFMM_ONLY_DEVEL )
93
# OPENMP 4/5 support 
94
    option( OPENMP_SUPPORT_COMMUTE   "Set to ON to let tasks commute (KSTAR/StarPU compiler only)" OFF )
95
    option( OPENMP_SUPPORT_PRIORITY  "Set to ON to enable tasks priority (KSTAR/StarPU compiler only)" OFF )
96
    option( OPENMP_SUPPORT_TASK_NAME "Set to ON to enable a taskname clause for tasks (KSTAR/StarPU compiler only)" OFF )
97
    option( SCALFMM_DISABLE_NATIVE_OMP4 "Set to ON to disable the gcc/intel omp4"    OFF )
98
    option( SCALFMM_TIME_OMPTASKS "Set to ON to time omp4 tasks and generate output file"    OFF )
99
    option( SCALFMM_SIMGRID_NODATA "Set to ON to avoid the allocation of numerical parts in the group tree" OFF )
100
    option( SCALFMM_SIMGRID_TASKNAMEPARAMS "Set to ON to have verbose information in the task name" OFF )
101 102 103 104 105
# 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)
106
  endif()
107
  message(STATUS "AVANT  ${CMAKE_CXX_COMPILER_ID}" )
108 109 110
#
#  MPI
#
111
  if( SCALFMM_USE_MPI )
112
    try_compile(COMPILE_INTEL ${CMAKE_CURRENT_BINARY_DIR}
113 114
      ${SCALFMM_CMAKE_MODULE_PATH}/compileTestIntel.cpp
      COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS}")
115 116 117 118 119 120 121
    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 "")
122
  set(SCALFMM_CXX_FLAGS "-std=c++11 -fpic -Wall")
123 124 125 126 127 128 129 130 131 132 133 134
  #
  #
  # 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)
135
  message(STATUS "SCALFMM_BUILD_DEBUG = ${SCALFMM_BUILD_DEBUG}" )
136 137
  #
  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
138
    set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -m64")
139 140 141 142 143 144 145 146 147
  endif()
  ##############################################################################
  #                           Compile options                                  #
  ##############################################################################
  #  -xHost -mfpmath=sse
  # -Wall Wnosign-conversion
  #
  if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
    # INTEL
148
    IF (APPLE)
149 150 151 152 153
      IF( CPUOPTION_SSE42 ) 
        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)  
154
    else(APPLE)
COULAUD Olivier's avatar
COULAUD Olivier committed
155 156
      set(AVX_FLAGS  "-march=native -axCORE-AVX2,CORE-AVX-I,AVX") #-mavx
      set(AVX2_FLAGS  "-march=native  -axCORE-AVX2,CORE-AVX-I") #-march=core-avx2
157
      set(SSE_FLAGS  "-axSSE4.2  -march=native")
158
    endif(APPLE)
159
    #-Wshadow -Wpointer-arith -Wcast-qual -Wconversion  -Wall -Wnosign-conversion ")
COULAUD Olivier's avatar
COULAUD Olivier committed
160 161 162
  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")
163
    # NOT      INTEL
164
    if(NOT SCALFMM_USE_MPI)
165 166 167
      include(CheckCCompilerFlag)
      check_c_compiler_flag(-Wzero-as-null-pointer-constant HAS_WZERO_NULL_PTR_FLAG)
      if(HAS_WZERO_NULL_PTR_FLAG)
168
        set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -Wzero-as-null-pointer-constant")
169
      endif()
170
    else()
171 172 173
      include(CheckCCompilerFlag)
      check_c_compiler_flag(-Wno-literal-suffix HAS_NO_LITERAL_SUFFIX_FLAG)
      if(HAS_NO_LITERAL_SUFFIX_FLAG)
174
        set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -Wno-literal-suffix")
175
      endif()
176
    endif()
177
    IF (APPLE)
178 179 180 181 182 183
      #      set(SSE_FLAGS  "-msse4  -mfpmath=sse")   # -mtune=native -march=native
      IF( CPUOPTION_SSE42 ) 
        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)
184 185
      set(AVX_FLAGS "-mtune=native -march=avx")
      set(AVX2_FLAGS "-mtune=native -march=native -mmic")
186
    else(APPLE)
187 188 189
      set(SSE_FLAGS  "-mtune=native -march=native")
      set(AVX_FLAGS "-mtune=native -march=native")
      set(AVX2_FLAGS "-mtune=native -march=native -mmic")
190 191
    endif(APPLE)
  endif()
192

193 194 195 196 197 198
  ##############################################################################
  #                           FUSE list                                        #
  ##############################################################################
  set(FUSE_LIST "")
  # then do list(APPEND FUSE_LIST "BLAS") to protect from FUSE_BLAS
  list(APPEND FUSE_LIST "MPI")
199

200 201 202 203
  ##############################################################################
  #                        Debug      flags                                    #
  ##############################################################################
  #
204
  if( SCALFMM_BUILD_DEBUG )
205 206 207 208 209 210
    #
    # Compile Debug flags
    #
    set(CMAKE_BUILD_TYPE Debug)
    ADD_DEFINITIONS(-O0)
    if( APPLE )
211
      set(SCALFMM_FLAGS_OPTI_DEBUG "-funroll-loops" CACHE STRING
212 213 214 215 216 217 218 219 220 221 222
        "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})
223
    set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} ${SCALFMM_FLAGS_OPTI_DEBUG}")
224 225 226 227 228 229
    set(CMAKE_CXX_FLAGS_TYPE "${CMAKE_CXX_FLAGS_DEBUG}")

  else()
    ##############################################################################
    #                          Release flags                                     #
    ##############################################################################
230

231 232 233
    set(CMAKE_BUILD_TYPE Release)
    set(CMAKE_CXX_FLAGS_TYPE  "${CMAKE_CXX_FLAGS_RELEASE}")
    # if compiler is intel add -ip
234

BRAMAS Berenger's avatar
BRAMAS Berenger committed
235
    if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
COULAUD Olivier's avatar
COULAUD Olivier committed
236
      set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -ipo  -fstrict-aliasing ")# -no-prec-div -no-prec-sqrt")
BRAMAS Berenger's avatar
BRAMAS Berenger committed
237
    endif()
238 239
    # Compile optimization
    if(APPLE)
240
      set(SCALFMM_FLAGS_OPTI_RELEASE "-funroll-loops" CACHE STRING
241 242 243
        "Set your optimization flags for release mode.")
    else(APPLE)
      # Not apple system - Check the compiler flags
244 245 246 247
      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.")
248 249
  # set(SCALFMM_FLAGS_OPTI_RELEASE "-funroll-loops -ftree-vectorize" CACHE STRING
  #   "Set your optimization flags for release mode.")
250 251 252 253 254 255
      else()
        set(SCALFMM_FLAGS_OPTI_RELEASE "-ffast-math -funroll-loops -ftree-vectorize" CACHE STRING
          "Set your optimization flags for release mode.")
      endif()
    endif(APPLE)
    #
256
    set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} ${SCALFMM_FLAGS_OPTI_RELEASE}")
257
  endif()
258 259
  MESSAGE(STATUS   " %%%%%%%%%% SCALFMM_CXX_FLAGS  ${SCALFMM_CXX_FLAGS} %%%%%%%%%%%%%")
  MESSAGE(STATUS   " %%%%%%%%%% CMAKE_CXX_FLAGS_RELEASE  ${CMAKE_CXX_FLAGS_RELEASE} %%%%%%%%%%%%%")
260

261 262 263 264
  #
  ##############################################################################
  #                Attach source code to exec                                  #
  ##############################################################################
265 266
  message(STATUS "SCALFMM_ATTACHE_SOURCE       = ${SCALFMM_ATTACHE_SOURCE}" )
  if( SCALFMM_ATTACHE_SOURCE )
267
    message(STATUS "Option -g is used, the code is attached to the binary." )
268 269
    set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -g")
  endif(SCALFMM_ATTACHE_SOURCE)
270 271 272 273 274
  #
  ##############################################################################
  #                                 find MPI                                   #
  ##############################################################################
  #
275
  if( SCALFMM_USE_MPI )
276 277 278 279 280

    # 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)
281
      set(MPI_C_COMPILER mpicc)
282 283
    endif()
    if(NOT MPI_CXX_COMPILER)
284
      set(MPI_CXX_COMPILER mpicxx)
285 286 287 288 289
    endif()

    find_package(MPI REQUIRED)

    if (MPI_CXX_INCLUDE_PATH)
290
      include_directories( ${MPI_CXX_INCLUDE_PATH} )
291 292
    endif()
    if (MPI_CXX_COMPILE_FLAGS)
293
      set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} ${MPI_CXX_COMPILE_FLAGS}")
294 295
    endif()
    if (MPI_CXX_INCLUDE_PATH)
296
      set(SCALFMM_INCLUDES  "${SCALFMM_INCLUDES}; ${MPI_CXX_INCLUDE_PATH}")
297 298
    endif()
    if (MPI_CXX_LINK_FLAGS)
299
      set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${MPI_CXX_LINK_FLAGS}")
300 301
    endif()
    if (MPI_CXX_LIBRARIES)
302
      set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${MPI_CXX_LIBRARIES}")
303 304 305 306 307 308 309 310
    endif()

  endif()
  #
  ##############################################################################
  #                             Blas option                                    #
  ##############################################################################
  #
311
  if( SCALFMM_USE_BLAS )
312 313
    message(STATUS "CMAKE_CXX_COMPILER_ID STREQUAL  ${CMAKE_CXX_COMPILER_ID}")

314
    option( SCALFMM_USE_MKL_AS_BLAS "Set to ON to use MKL CBLAS" OFF )
315

316
    if( SCALFMM_USE_MKL_AS_BLAS )
317
      set(BLA_VENDOR "Intel10_64lp_seq")
318
      find_package(BLASEXT QUIET) # not REQUIRED
319

320
      if(BLAS_LIBRARY_DIRS)
321 322 323 324 325 326 327
        # 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()
328
    elseif(SCALFMM_USE_EXTERNAL_BLAS)
329
      message(STATUS "BLAS SET BY EXTERNAL PROGRAM = ${BLAS_LIBRARIES}")
330
    else()
331 332
      find_package(BLASEXT)  # not REQUIRED
      find_package(LAPACKEXT)  # not REQUIRED
333 334 335 336 337 338 339
      set(BLASLAPACK_LIBRARIES)
      if (LAPACK_LIBRARIES)
        set(BLASLAPACK_LIBRARIES "${LAPACK_LIBRARIES}")
      endif()
      if (BLAS_LIBRARIES)
        list(APPEND BLASLAPACK_LIBRARIES "${BLAS_LIBRARIES}")
      endif()
340
    endif()
341

342
    if(BLAS_FOUND)
343 344
      set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${BLASLAPACK_LIBRARIES}")
      #message(STATUS "SCALFMM_LIBRARIES          = ${SCALFMM_LIBRARIES}")
345
    else()
346 347 348
      message(WARNING "BLAS has not been found, SCALFMM will continue to compile but some applications will be disabled.")
      message(WARNING "If you have BLAS set BLAS_LIBDIR, BLAS_INCDIR or BLAS_DIR (CMake variables using -D or environment variables).")        
      set(SCALFMM_USE_BLAS OFF)
349
    endif()
350

351
  endif(SCALFMM_USE_BLAS)
352 353 354 355
  list(APPEND FUSE_LIST "BLAS")
  #
  # FFT option
  #
356
  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 )
357
  if( SCALFMM_USE_FFT )
358 359
    message(STATUS "SCALFMM USE FFT Configure:")

360
    if( SCALFMM_USE_MKL_AS_FFTW )
361 362 363

      message(STATUS "         SCALFMM USE MKL ")

364
      if( SCALFMM_USE_MKL_AS_BLAS )
365 366 367 368

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

373
      else(SCALFMM_USE_MKL_AS_BLAS)
374 375 376 377

        # 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
378
        find_package(FFTW  COMPONENTS MKL) # not REQUIRED
379
        if (FFTW_LIBRARY_DIRS_DEP)
380
          set(FFT_LIBRARIES "-L${FFTW_LIBRARY_DIRS_DEP};" CACHE STRING "Set your MKL flags")
381 382
        endif()
        if (FFTW_LIBRARIES_DEP)
383 384 385
          foreach (fft_lib ${FFTW_LIBRARIES_DEP})
            set(FFT_LIBRARIES "${FFT_LIBRARIES};${fft_lib};")
          endforeach()
386
        endif()
387
        set(FFT_INCLUDES "${FFTW_INCLUDE_DIRS_DEP}" )
388
        if (FFT_LIBRARIES)
389
          set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${FFT_LIBRARIES}")
390
        endif()
391

392
      endif(SCALFMM_USE_MKL_AS_BLAS)
393

394
    else(SCALFMM_USE_MKL_AS_FFTW)
395 396 397 398 399

      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
400
      find_package(FFTW COMPONENTS SIMPLE) # not REQUIRED
401
      if (FFTW_LIBRARY_DIRS_DEP)
402
        set(FFT_LIBRARIES "-L${FFTW_LIBRARY_DIRS_DEP};" CACHE STRING "Set your FFTW path")
403 404 405
      endif()
      if (FFTW_LIBRARIES_DEP)
        foreach (fft_lib ${FFTW_LIBRARIES_DEP})
406
          set(FFT_LIBRARIES "${FFT_LIBRARIES};${fft_lib};")
407 408
        endforeach()
      endif()
409
      set(FFT_INCLUDES "${FFTW_INCLUDE_DIRS_DEP}" )
410
      if (FFT_LIBRARIES)
411
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${FFT_LIBRARIES}")
412
      endif()
413

414
    endif(SCALFMM_USE_MKL_AS_FFTW)
415 416

    if (FFT_INCLUDES)
417
      set(SCALFMM_INCLUDES "${SCALFMM_INCLUDES}; ${FFT_INCLUDES}")
418
    endif()
419

420
    if(FFTW_FOUND)
421 422
      message(STATUS "         SCALFMM_LIBRARIES          = ${SCALFMM_LIBRARIES}")
      message(STATUS "         SCALFMM_INCLUDES          = ${SCALFMM_INCLUDES}")
423
    else()
424 425 426
      message(WARNING "FFTW has not been found, SCALFMM will continue to compile but some applications will be disabled.")
      message(WARNING "If you have FFTW set FFTW_LIBDIR, FFTW_INCDIR or FFTW_DIR (CMake variables using -D or environment variables).")        
      set(SCALFMM_USE_FFT OFF)
427
    endif()
428
  endif(SCALFMM_USE_FFT)
429
  list(APPEND FUSE_LIST "FFT")
430 431
  message(STATUS "         SCALFMM_LIBRARIES          = ${SCALFMM_LIBRARIES}")
  message(STATUS "         SCALFMM_INCLUDES          = ${SCALFMM_INCLUDES}")
432
  
COULAUD Olivier's avatar
COULAUD Olivier committed
433
  message(STATUS "SCALFMM_USE_FFT       =  ${SCALFMM_USE_FFT}")
434 435 436 437 438 439 440

  #
  # 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}")
441
    set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} -Wall")
442 443
  else()
    # Compile option valid on GCC/G++
444
    set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wconversion -Wcast-qual -Wcast-align -Woverloaded-virtual")
445
  endif()
446 447
  #
  ##################################################################
COULAUD Olivier's avatar
COULAUD Olivier committed
448
  #              STARPU Section
449 450
  ##################################################################
  #
451 452
  message( STATUS "SCALFMM_USE_STARPU             = ${SCALFMM_USE_STARPU}" )
  if( SCALFMM_USE_STARPU )
453
    # CUDA could be used with StarPU enabled
454 455 456
    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)
457 458 459 460 461
      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)
462 463
        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")
464 465 466 467
      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}" )
468

469
      find_package(CUDA REQUIRED)
470

471 472 473 474 475 476 477
      if (CUDA_INCLUDE_DIRS)
        include_directories(${CUDA_INCLUDE_DIRS})
      endif()
      if (CUDA_LIBRARIES)
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${CUDA_LIBRARIES}")
      endif()
      
478
      set(CUDA_NEEDED_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/Src)
479 480 481
    endif()

    # Find StarPU with a list of optional components
482
    set(SCALFMM_STARPU_VERSION "1.1" CACHE STRING "oldest STARPU version desired")
483 484
    # create list of components in order to make a single call to find_package(starpu...)
    set(STARPU_COMPONENT_LIST "HWLOC")
485
    if(SCALFMM_USE_MPI)
486
      list(APPEND STARPU_COMPONENT_LIST "MPI")
487
    endif()
488
    if(SCALFMM_USE_CUDA)
489
      list(APPEND STARPU_COMPONENT_LIST "CUDA")
490
    endif()
491

492
    find_package(STARPU ${SCALFMM_STARPU_VERSION} REQUIRED
493
      COMPONENTS ${STARPU_COMPONENT_LIST})
494

495
    # Append list of libraries and include dirs
496 497 498
    include_directories(${STARPU_INCLUDE_DIRS_DEP})
    foreach (starpu_libdir ${STARPU_LIBRARY_DIRS_DEP})
      if (${starpu_libdir} MATCHES "^ *-L")
499
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${starpu_libdir}")
500
      else()
501
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};-L${starpu_libdir}")
502 503 504 505
      endif()
    endforeach()
    foreach (starpu_lib ${STARPU_LIBRARIES_DEP})
      if (EXISTS ${starpu_lib} OR ${starpu_lib} MATCHES "^ *-")
506
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${starpu_lib}")
507
      else()
508
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};-l${starpu_lib}")
509 510
      endif()
    endforeach()
511

512
    # TODO: is this very useful? CUDA is already a component of find starpu
513
    if (CUDA_LIBRARIES)
514
      set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${CUDA_LIBRARIES}")
515
    endif()
516

517
    # Message
518 519
    message(STATUS "         STARPU_LIBRARIES          = ${STARPU_LIBRARIES}")
    if (STARPU_INCLUDE_DIRS)
520 521
      message(STATUS "         STARPU_INCLUDES           = ${STARPU_INCLUDE_DIRS}")
      set(SCALFMM_INCLUDES  "${SCALFMM_INCLUDES}; ${STARPU_INCLUDE_DIRS}")
522
    endif()
523

524
    # TODO: replace this by a component of find starpu
525 526 527
    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)
528 529
      include_directories($ENV{OPENCL_INC})
      SET(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};-L$ENV{OPENCL_LIB};-lOpenCL")
530
    endif()
531
  endif(SCALFMM_USE_STARPU)
532
  list(APPEND FUSE_LIST "STARPU")
533
  list(APPEND FUSE_LIST "CUDA")
534
  list(APPEND FUSE_LIST "OPENCL")
535

536 537 538 539
  ##################################################################
  #                         Use SSE                                #
  ##################################################################

540 541 542 543
  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)" )
544 545 546
    endif()
    message( STATUS "SSE_FLAGS ${SSE_FLAGS}  -- ${CMAKE_CXX_FLAGS}  ")
    try_compile(COMPILE_SSE  ${CMAKE_CURRENT_BINARY_DIR}
547 548 549
      ${SCALFMM_CMAKE_MODULE_PATH}/compileTestSse.cpp
      COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${SSE_FLAGS}"
      OUTPUT_VARIABLE COMPILE_SSE_OUTPUT)
550 551

    if(${COMPILE_SSE})
552
      set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} ${SSE_FLAGS}")
553 554

      try_compile(COMPILE_RESULT_VAR ${CMAKE_CURRENT_BINARY_DIR}
555 556
        ${SCALFMM_CMAKE_MODULE_PATH}/checkSSEpe.cpp
        COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${SSE_FLAGS}")
557 558 559
      if( NOT ${COMPILE_RESULT_VAR})
        set(__SSEPE_INTEL_COMPILER ON)
      endif()
560
      #set(SCALFMM_USE_AVX OFF)
561
    else(${COMPILE_SSE})
562
      message(FATAL_ERROR "SSE NOT SUPPORTED ; Set SCALFMM_USE_SSE  to OFF \n Output from test is : ${COMPILE_SSE_OUTPUT}")
563 564 565
    endif(${COMPILE_SSE})
  endif()
  list(APPEND FUSE_LIST "SSE")
566

567 568 569 570
  ##################################################################
  #                           Use AVX                              #
  ##################################################################

571 572 573 574
  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)" )
575 576 577
    endif()

    try_compile(COMPILE_AVX ${CMAKE_CURRENT_BINARY_DIR}
578 579 580 581 582 583
      ${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}")
      
584
      set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS}   ${AVX_FLAGS}")
585 586
      message(STATUS "%%%%%%%%%%%% SCALFMM_CXX_FLAGS               = ${SCALFMM_CXX_FLAGS}")
      #set( SCALFMM_USE_SSE   OFF   FORCE) # ne marche pas
587
      try_compile(COMPILE_RESULT_AVSPE ${CMAKE_CURRENT_BINARY_DIR}
588 589 590
        ${SCALFMM_CMAKE_MODULE_PATH}/checkAVXpe.cpp
        COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${AVX_FLAGS}")
      if( NOT ${COMPILE_RESULT_AVSPE})
591 592


593
        set(__AVXPE_INTEL_COMPILER ON)
594
      endif()
595 596 597

      message(STATUS ${CMAKE_CXX_FLAGS} )
    else(${COMPILE_AVX})
598
      message(FATAL_ERROR "AVX NOT SUPPORTED ; Set SCALFMM_USE_AVX  to OFF \n Output from test is : ${COMPILE_AVX_OUTPUT} ")
599
    endif(${COMPILE_AVX})
600
  endif(SCALFMM_USE_AVX)
601 602
  list(APPEND FUSE_LIST "AVX")
  #
603
  # Error if both SCALFMM_USE_AVX AND SCALFMM_USE_SSE are set
604
  #
605 606 607
  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)
608
  ##################################################################
609 610 611 612 613 614 615 616 617 618
  #                           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}
619 620 621
      ${SCALFMM_CMAKE_MODULE_PATH}/compileTestAvx2.cpp
      COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${AVX2_FLAGS}"
      OUTPUT_VARIABLE COMPILE_AVX2_OUTPUT)
622 623 624 625
    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}
626 627
        ${SCALFMM_CMAKE_MODULE_PATH}/checkAVX2pe.cpp
        COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${AVX2_FLAGS}")
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
      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)
  ##################################################################
645 646
  #                     Use  native MIC compilation                #
  ##################################################################
647
  if( SCALFMM_USE_MIC_NATIVE )
648 649
    include(CheckCCompilerFlag)
    check_c_compiler_flag(-mmic HAS_MMIC_FLAG)
650
    if(NOT HAS_MMIC_FLAG)
651
      message(FATAL_ERROR "MIC NOT SUPPORTED ; Set SCALFMM_USE_MIC_NATIVE to OFF")
652 653 654
    endif()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmic")
  else()
655
    #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xhost")
656 657 658 659
  endif()
  list(APPEND FUSE_LIST "MIC")
  ##################################################################
  #
COULAUD Olivier's avatar
COULAUD Olivier committed
660 661
  #   Set EZTRACE
  #
662
  ##################################################################
COULAUD Olivier's avatar
COULAUD Olivier committed
663 664 665 666
  If(SCALFMM_USE_EZTRACE)
    find_package (PkgConfig)
    if(PKG_CONFIG_FOUND)
      set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH "ON")
667
      pkg_search_module( EZTrace REQUIRED eztrace)
COULAUD Olivier's avatar
COULAUD Olivier committed
668
      if(EZTrace_FOUND)
669 670 671
        link_directories(${EZTrace_LIBRARY_DIRS})
        link_libraries( ${EZTrace_LIBRARIES})
        IF( SCALFMM_USE_MPI )
COULAUD Olivier's avatar
COULAUD Olivier committed
672
          link_libraries(-leztrace-autostart-mpi)
673 674 675 676 677 678 679 680 681
  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 )
682
      else(EZTrace_FOUND)
683 684
  MESSAGE(WARNING "Eztrace not found - EZTRACE Is set to OFF")
  set(SCALFMM_USE_EZTRACE OFF)  
685
      endif(EZTrace_FOUND)
COULAUD Olivier's avatar
COULAUD Olivier committed
686
    else(PKG_CONFIG_FOUND)
687
      MESSAGE(WARNING "PKG-CONFIG not found - EZTRACE Is set to OFF")
COULAUD Olivier's avatar
COULAUD Olivier committed
688 689 690 691
      set(SCALFMM_USE_EZTRACE OFF)
    endif(PKG_CONFIG_FOUND)

  endif(SCALFMM_USE_EZTRACE)
692 693 694 695 696 697 698
  
  ##################################################################
  #
  #   To catch signals
  #
  ##################################################################  
    if((WIN32 OR (${CMAKE_SYSTEM_NAME} MATCHES "Windows")) AND SCALFMM_USE_SIGNALS)
699 700
      # We are on Windows and we cannot catch signals
      message( FATAL_ERROR "Catching the signals requieres an UNIX system." )
701
    else()
COULAUD Olivier's avatar
COULAUD Olivier committed
702
        IF( NOT APPLE)
703 704 705
        SET(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} -rdynamic")
        ENDIF()
        
706
    endif()
707 708 709 710 711 712 713 714
  ##################################################################
  #                                                                #
  #                     END SETTING VARIABLES                      #
  #                                                                #
  ##################################################################
  #
  # Generate  ScalFmmConfig.h
  #
715
  set(SCALFMM_COMPILE_FLAGS "${SCALFMM_CXX_FLAGS} ${CMAKE_CXX_FLAGS_TYPE} ${CMAKE_CXX_FLAGS}")
716
  set(CMAKE_CXX_FLAGS "${SCALFMM_COMPILE_FLAGS}")
717 718 719
  # We need the libraries without spaces (inside the config file)
  set(SCALFMM_COMPILE_LIBS   "")
  foreach(lib_var ${SCALFMM_LIBRARIES})
720 721
    string(STRIP ${lib_var} lib_var)
    LIST(APPEND SCALFMM_COMPILE_LIBS   ${lib_var})        
722
  endforeach()
723
  configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/Src/ScalFmmConfig.h.cmake
724
    ${CMAKE_CURRENT_BINARY_DIR}/Src/ScalFmmConfig.h  )
725 726 727 728 729 730 731 732 733 734 735 736
  #
  ##################################################################
  #                      Build - lib                               #
  ##################################################################
  #
  add_subdirectory(Src)
  # Link with scalfmm lib
  set(scalfmm_lib scalfmm)
  #
  ##################################################################
  #            Remove compilation  of the drivers                  #
  ##################################################################
COULAUD Olivier's avatar
COULAUD Olivier committed
737
   message(STATUS "SCALFMM_BUILD_EXAMPLES  =  ${SCALFMM_BUILD_EXAMPLES}" ) 
738
  if( SCALFMM_BUILD_EXAMPLES )
739 740 741 742 743 744 745
    # Build - Examples and drivers
    add_subdirectory(Examples)
  endif()
  ##################################################################
  #           Build tools (Internal use)                           #
  ##################################################################
  # Build - UTILs
746
  if( SCALFMM_ONLY_DEVEL AND SCALFMM_BUILD_UTILS)
747
    add_subdirectory(Utils)
748
  endif()
749

750 751 752 753
  ##################################################################
  #                Build -Tests to see examples                    #
  ##################################################################
  # Build - Tests
754 755
  message( STATUS "SCALFMM_BUILD_TESTS          = ${SCALFMM_BUILD_TESTS}" )
  if( SCALFMM_BUILD_TESTS )
756 757
    add_subdirectory(Tests)
  endif()
berenger-bramas's avatar
berenger-bramas committed
758

759 760 761 762
  ##################################################################
  #              Build - Unitary and numerical Tests               #
  ##################################################################
  #
763 764
  message( STATUS "SCALFMM_BUILD_UTESTS         = ${SCALFMM_BUILD_UTESTS}" )
  if( SCALFMM_BUILD_UTESTS )
765 766 767 768
    include(CTest)
    enable_testing()
    add_subdirectory(UTests)
  endif()
berenger-bramas's avatar
berenger-bramas committed
769

770 771 772
  ##################################################################
  #                           Add - doc                            #
  ##################################################################
773 774 775
  if(SCALFMM_BUILD_DOC)
    add_subdirectory(Doc)
  endif()
776 777 778 779
  ##################################################################
  #                       Build - Addons                           #
  ##################################################################
  #
780
  if( SCALFMM_USE_ADDONS )
781 782
    file(GLOB all_addons ./Addons/*)
    # Options
783
    option( SCALFMM_ADDON_CKERNELAPI "Set to ON to build ScaFMM FMM API interface" OFF )
784

785 786 787 788
    foreach(addon_name ${all_addons})
      message(STATUS "Addons += ${addon_name}" )
      add_subdirectory(${addon_name})
    endforeach()
789
  endif()
790

791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
  # 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                  #
  #                                                                #
  ##################################################################
  #
806 807 808
  message(STATUS "SCALFMM_BINARY_DIR:          " ${SCALFMM_BINARY_DIR})
  configure_file(${SCALFMM_SOURCE_DIR}/ScalFMMConfig.cmake.in
    ${SCALFMM_BINARY_DIR}/ScalFMMConfig.cmake
809 810 811
    @ONLY IMMEDIATE
    )
  #
812 813 814
  install(FILES  ${SCALFMM_BINARY_DIR}/ScalFMMConfig.cmake  DESTINATION lib/  )
  if( SCALFMM_INSTALL_DATA )
    install(FILES  ${SCALFMM_SOURCE_DIR}/Data/test20k.fma  DESTINATION Data/   )
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
  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")
835 836
  set(CPACK_PACKAGE_VERSION_MAJOR "${SCALFMM_MAJOR_VERSION}")
  set(CPACK_PACKAGE_VERSION_MINOR "${SCALFMM_MINOR_VERSION}")
837
  #
838
  set(PACK_PACKAGE_VERSION "${SCALFMM_MAJOR_VERSION}.${SCALFMM_MINOR_VERSION}-${CPACK_PACKAGE_VERSION_PATCH}")
839
  set(CPACK_SOURCE_GENERATOR "TGZ")
840
  set(CPACK_SOURCE_PACKAGE_FILE_NAME  "SCALFMM-${SCALFMM_MAJOR_VERSION}.${SCALFMM_MINOR_VERSION}-${CPACK_PACKAGE_VERSION_PATCH}")
841
  set(CPACK_SOURCE_IGNORE_FILES "\\\\.git;.DS_Store;.*~;/*.aux;/*.idx;/*.log;/*.out;/*.toc;/*.ilg;scalfmm.pro*;org.eclipse.core.resources.prefs;.cproject;.project")
842
  list(APPEND CPACK_SOURCE_IGNORE_FILES  "${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}/Utils/;Notes;Deprecated;/Build*;/noDist/;/Bench;ToRemove;Olivier;Addons/HMat")
843 844 845 846 847 848 849 850 851 852 853 854 855 856 857
  # 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
858
  message(STATUS "SCALFMM_USE_MEM_STATS        = ${SCALFMM_USE_MEM_STATS}" )
859
  #                    Use Log
860
  message(STATUS "SCALFMM_USE_LOG              = ${SCALFMM_USE_LOG}" )
861
  #                    Use Assert
862
  message(STATUS "SCALFMM_USE_ASSERT           = ${SCALFMM_USE_ASSERT}" )
863 864
  #
  #message(STATUS "CMAKE_CXX_FLAGS   =  ${CMAKE_CXX_FLAGS}")
865
  #set(CMAKE_CXX_FLAGS "${SCALFMM_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
COULAUD Olivier's avatar
COULAUD Olivier committed
866 867
  message(STATUS "SCALFMM_USE_BLAS     =  ${SCALFMM_USE_BLAS}")
  message(STATUS "SCALFMM_USE_FFT       =  ${SCALFMM_USE_FFT}")
868
  message(STATUS "SCALFMM_USE_MKL      =   ${SCALFMM_USE_MKL}")
869
  # 
870
  message(STATUS "CMAKE_CXX_FLAGS     =  ${CMAKE_CXX_FLAGS}")
871
  message(STATUS "SCALFMM_CXX_FLAGS   =  ${SCALFMM_CXX_FLAGS}")
872 873 874 875 876 877
  message(STATUS "SCALFMM_LIBRARIES   =  ${SCALFMM_LIBRARIES}")
  message(STATUS "SCALFMM_INCLUDES    =  ${SCALFMM_INCLUDES}")
  ##################################################################
  #                               END                              #
  ##################################################################

878
else(MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/morse/")
879 880 881 882 883 884 885

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

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