CMakeLists.txt 38.4 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)
COULAUD Olivier's avatar
COULAUD Olivier committed
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
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules/)
23
set(SCALFMM_CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules)
COULAUD Olivier's avatar
COULAUD Olivier committed
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 37 38 39
# 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
40

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

43 44 45 46 47
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)
COULAUD Olivier's avatar
COULAUD Olivier committed
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
  elseif(EXISTS "${CMAKE_SOURCE_DIR}/CMakeModules/morse/")
COULAUD Olivier's avatar
COULAUD Olivier committed
52 53
    list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules/morse/)
    set(MORSE_CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules/morse )
54 55 56 57
  endif()
  include(MorseInit)
  #
  # Options
58 59 60 61 62 63 64
  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 )
65
  option( SCALFMM_BUILD_DOC            "Set to ON to build the Doxygen documentation " OFF )
66 67 68 69 70
  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 )
71
  option( SCALFMM_USE_SIGNALS          "Set to ON to catch various signal an print backtrace"  OFF )
72
  if( APPLE ) # to fix problem with  GCC and avx
COULAUD Olivier's avatar
COULAUD Olivier committed
73 74
    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  )
75
  else(APPLE)
COULAUD Olivier's avatar
COULAUD Olivier committed
76 77
    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  )
78
  endif(APPLE)
79
  CMAKE_DEPENDENT_OPTION( SCALFMM_USE_AVX2             "Set to ON to compile with AVX support (and use intrinsec AVXZ P2P)" ON "CPUOPTION_AVX2" OFF )
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 )
COULAUD Olivier's avatar
COULAUD Olivier committed
83
  option( SCALFMM_USE_EZTRACE          "Set to ON to compile with eztrace framwork" OFF )
84
  if( SCALFMM_ONLY_DEVEL )
85
    option( OPENMP_SUPPORT_COMMUTE   "Set to ON to let tasks commute (KSTAR/StarPU compiler only)" OFF )
86
    option( OPENMP_SUPPORT_PRIORITY  "Set to ON to enable tasks priority (KSTAR/StarPU compiler only)" OFF )
87 88
    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 )
BRAMAS Berenger's avatar
BRAMAS Berenger committed
89
    option( SCALFMM_DISABLE_NATIVE_OMP4 "Set to ON to disable the gcc/intel omp4"    OFF )
90
    option( SCALFMM_TIME_OMPTASKS "Set to ON to time omp4 tasks and generate output file"    OFF )
91 92 93
    option( SCALFMM_STARPU_USE_COMMUTE  "Set to ON to build SCALFMM with StarPU" ON )
    option( SCALFMM_STARPU_USE_REDUX  "Set to ON to build SCALFMM with StarPU" ON )
    option( SCALFMM_STARPU_USE_PRIO  "Set to ON to build SCALFMM with StarPU" ON )
94
  endif()
95
  message(STATUS "AVANT  ${CMAKE_CXX_COMPILER_ID}" )
96
  if( SCALFMM_USE_MPI )
97
    try_compile(COMPILE_INTEL ${CMAKE_CURRENT_BINARY_DIR}
COULAUD Olivier's avatar
COULAUD Olivier committed
98 99
      ${SCALFMM_CMAKE_MODULE_PATH}/compileTestIntel.cpp
      COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS}")
100 101 102 103 104 105 106
    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 "")
107
  set(SCALFMM_CXX_FLAGS "-std=c++11 -fpic -Wall")
108 109 110 111 112 113 114 115 116 117 118 119
  #
  #
  # 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)
120
  message(STATUS "SCALFMM_BUILD_DEBUG = ${SCALFMM_BUILD_DEBUG}" )
121 122
  #
  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
123
    set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -m64")
124 125 126 127 128 129 130 131 132
  endif()
  ##############################################################################
  #                           Compile options                                  #
  ##############################################################################
  #  -xHost -mfpmath=sse
  # -Wall Wnosign-conversion
  #
  if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
    # INTEL
133
    IF (APPLE)
COULAUD Olivier's avatar
COULAUD Olivier committed
134 135 136 137 138
      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)  
139
    else(APPLE)
COULAUD Olivier's avatar
COULAUD Olivier committed
140 141
      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
142
      set(SSE_FLAGS  "-axSSE4.2  -march=native")
143
    endif(APPLE)
Marc-Alexandre Espiaut's avatar
Marc-Alexandre Espiaut committed
144
    #-Wshadow -Wpointer-arith -Wcast-qual -Wconversion  -Wall -Wnosign-conversion ")
145
  else()
Marc-Alexandre Espiaut's avatar
Marc-Alexandre Espiaut committed
146
    # NOT      INTEL
147
    if(NOT SCALFMM_USE_MPI)
148 149 150
      include(CheckCCompilerFlag)
      check_c_compiler_flag(-Wzero-as-null-pointer-constant HAS_WZERO_NULL_PTR_FLAG)
      if(HAS_WZERO_NULL_PTR_FLAG)
151
        set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -Wzero-as-null-pointer-constant")
152
      endif()
153
    else()
154 155 156
      include(CheckCCompilerFlag)
      check_c_compiler_flag(-Wno-literal-suffix HAS_NO_LITERAL_SUFFIX_FLAG)
      if(HAS_NO_LITERAL_SUFFIX_FLAG)
157
        set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -Wno-literal-suffix")
158
      endif()
159
    endif()
160
    IF (APPLE)
COULAUD Olivier's avatar
COULAUD Olivier committed
161 162 163 164 165 166
      #      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)
167 168
      set(AVX_FLAGS "-mtune=native -march=avx")
      set(AVX2_FLAGS "-mtune=native -march=native -mmic")
169
    else(APPLE)
170 171 172
      set(SSE_FLAGS  "-mtune=native -march=native")
      set(AVX_FLAGS "-mtune=native -march=native")
      set(AVX2_FLAGS "-mtune=native -march=native -mmic")
173 174
    endif(APPLE)
  endif()
175

176 177 178 179 180 181
  ##############################################################################
  #                           FUSE list                                        #
  ##############################################################################
  set(FUSE_LIST "")
  # then do list(APPEND FUSE_LIST "BLAS") to protect from FUSE_BLAS
  list(APPEND FUSE_LIST "MPI")
182

183 184 185 186
  ##############################################################################
  #                        Debug      flags                                    #
  ##############################################################################
  #
187
  if( SCALFMM_BUILD_DEBUG )
188 189 190 191 192 193
    #
    # Compile Debug flags
    #
    set(CMAKE_BUILD_TYPE Debug)
    ADD_DEFINITIONS(-O0)
    if( APPLE )
194
      set(SCALFMM_FLAGS_OPTI_DEBUG "-funroll-loops" CACHE STRING
195 196 197 198 199 200 201 202 203 204 205
        "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})
206
    set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} ${SCALFMM_FLAGS_OPTI_DEBUG}")
207 208 209 210 211 212
    set(CMAKE_CXX_FLAGS_TYPE "${CMAKE_CXX_FLAGS_DEBUG}")

  else()
    ##############################################################################
    #                          Release flags                                     #
    ##############################################################################
213

214 215 216
    set(CMAKE_BUILD_TYPE Release)
    set(CMAKE_CXX_FLAGS_TYPE  "${CMAKE_CXX_FLAGS_RELEASE}")
    # if compiler is intel add -ip
217

BRAMAS Berenger's avatar
BRAMAS Berenger committed
218
    if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
COULAUD Olivier's avatar
COULAUD Olivier committed
219
      set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -ipo  -fstrict-aliasing ")# -no-prec-div -no-prec-sqrt")
BRAMAS Berenger's avatar
BRAMAS Berenger committed
220
    endif()
221 222
    # Compile optimization
    if(APPLE)
223
      set(SCALFMM_FLAGS_OPTI_RELEASE "-funroll-loops" CACHE STRING
224 225 226
        "Set your optimization flags for release mode.")
    else(APPLE)
      # Not apple system - Check the compiler flags
COULAUD Olivier's avatar
COULAUD Olivier committed
227 228 229 230 231 232
      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.")
	# set(SCALFMM_FLAGS_OPTI_RELEASE "-funroll-loops -ftree-vectorize" CACHE STRING
	#   "Set your optimization flags for release mode.")
233 234 235 236 237 238
      else()
        set(SCALFMM_FLAGS_OPTI_RELEASE "-ffast-math -funroll-loops -ftree-vectorize" CACHE STRING
          "Set your optimization flags for release mode.")
      endif()
    endif(APPLE)
    #
239
    set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} ${SCALFMM_FLAGS_OPTI_RELEASE}")
240
  endif()
COULAUD Olivier's avatar
COULAUD Olivier committed
241 242
  MESSAGE(STATUS   " %%%%%%%%%% SCALFMM_CXX_FLAGS  ${SCALFMM_CXX_FLAGS} %%%%%%%%%%%%%")
  MESSAGE(STATUS   " %%%%%%%%%% CMAKE_CXX_FLAGS_RELEASE  ${CMAKE_CXX_FLAGS_RELEASE} %%%%%%%%%%%%%")
243

244 245 246 247
  #
  ##############################################################################
  #                Attach source code to exec                                  #
  ##############################################################################
248 249
  message(STATUS "SCALFMM_ATTACHE_SOURCE       = ${SCALFMM_ATTACHE_SOURCE}" )
  if( SCALFMM_ATTACHE_SOURCE )
250
    message(STATUS "Option -g is used, the code is attached to the binary." )
251 252
    set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -g")
  endif(SCALFMM_ATTACHE_SOURCE)
253 254 255 256 257
  #
  ##############################################################################
  #                                 find MPI                                   #
  ##############################################################################
  #
258
  if( SCALFMM_USE_MPI )
259 260 261 262 263

    # 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)
COULAUD Olivier's avatar
COULAUD Olivier committed
264
      set(MPI_C_COMPILER mpicc)
265 266
    endif()
    if(NOT MPI_CXX_COMPILER)
COULAUD Olivier's avatar
COULAUD Olivier committed
267
      set(MPI_CXX_COMPILER mpicxx)
268 269 270 271 272
    endif()

    find_package(MPI REQUIRED)

    if (MPI_CXX_INCLUDE_PATH)
COULAUD Olivier's avatar
COULAUD Olivier committed
273
      include_directories( ${MPI_CXX_INCLUDE_PATH} )
274 275
    endif()
    if (MPI_CXX_COMPILE_FLAGS)
COULAUD Olivier's avatar
COULAUD Olivier committed
276
      set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} ${MPI_CXX_COMPILE_FLAGS}")
277 278
    endif()
    if (MPI_CXX_INCLUDE_PATH)
COULAUD Olivier's avatar
COULAUD Olivier committed
279
      set(SCALFMM_INCLUDES  "${SCALFMM_INCLUDES}; ${MPI_CXX_INCLUDE_PATH}")
280 281
    endif()
    if (MPI_CXX_LINK_FLAGS)
COULAUD Olivier's avatar
COULAUD Olivier committed
282
      set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${MPI_CXX_LINK_FLAGS}")
283 284
    endif()
    if (MPI_CXX_LIBRARIES)
COULAUD Olivier's avatar
COULAUD Olivier committed
285
      set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${MPI_CXX_LIBRARIES}")
286 287 288 289 290 291 292 293
    endif()

  endif()
  #
  ##############################################################################
  #                             Blas option                                    #
  ##############################################################################
  #
294
  if( SCALFMM_USE_BLAS )
295 296
    message(STATUS "CMAKE_CXX_COMPILER_ID STREQUAL  ${CMAKE_CXX_COMPILER_ID}")

297
    option( SCALFMM_USE_MKL_AS_BLAS "Set to ON to use MKL CBLAS" OFF )
298

299
    if( SCALFMM_USE_MKL_AS_BLAS )
300
      set(BLA_VENDOR "Intel10_64lp_seq")
COULAUD Olivier's avatar
COULAUD Olivier committed
301
      find_package(BLASEXT QUIET) # not REQUIRED
302

303
      if(BLAS_LIBRARY_DIRS)
304 305 306 307 308 309 310
        # 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()
311
    elseif(SCALFMM_USE_EXTERNAL_BLAS)
312
      message(STATUS "BLAS SET BY EXTERNAL PROGRAM = ${BLAS_LIBRARIES}")
313
    else()
314 315
      find_package(BLASEXT)  # not REQUIRED
      find_package(LAPACKEXT)  # not REQUIRED
316 317 318 319 320 321 322
      set(BLASLAPACK_LIBRARIES)
      if (LAPACK_LIBRARIES)
        set(BLASLAPACK_LIBRARIES "${LAPACK_LIBRARIES}")
      endif()
      if (BLAS_LIBRARIES)
        list(APPEND BLASLAPACK_LIBRARIES "${BLAS_LIBRARIES}")
      endif()
323
    endif()
324

325
    if(BLAS_FOUND)
COULAUD Olivier's avatar
COULAUD Olivier committed
326 327
      set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${BLASLAPACK_LIBRARIES}")
      #message(STATUS "SCALFMM_LIBRARIES          = ${SCALFMM_LIBRARIES}")
328
    else()
COULAUD Olivier's avatar
COULAUD Olivier committed
329 330 331
      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)
332
    endif()
333

334
  endif(SCALFMM_USE_BLAS)
335 336 337 338
  list(APPEND FUSE_LIST "BLAS")
  #
  # FFT option
  #
339
  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 )
340
  if( SCALFMM_USE_FFT )
341 342
    message(STATUS "SCALFMM USE FFT Configure:")

343
    if( SCALFMM_USE_MKL_AS_FFTW )
344 345 346

      message(STATUS "         SCALFMM USE MKL ")

347
      if( SCALFMM_USE_MKL_AS_BLAS )
348 349 350 351

        unset(FFT_LIBRARIES CACHE)
        message(STATUS "         SCALFMM USE MKL already defined")
        set(FFT_INCLUDES "$ENV{MKLROOT}/include/fftw" CACHE STRING "Set your MKL flags")
352
        if (BLAS_FOUND)
COULAUD Olivier's avatar
COULAUD Olivier committed
353
          set(FFTW_FOUND ON)
354
        endif()
355

356
      else(SCALFMM_USE_MKL_AS_BLAS)
357 358 359 360

        # 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
361
        find_package(FFTW  COMPONENTS MKL) # not REQUIRED
362
        if (FFTW_LIBRARY_DIRS_DEP)
COULAUD Olivier's avatar
COULAUD Olivier committed
363
          set(FFT_LIBRARIES "-L${FFTW_LIBRARY_DIRS_DEP};" CACHE STRING "Set your MKL flags")
364 365
        endif()
        if (FFTW_LIBRARIES_DEP)
COULAUD Olivier's avatar
COULAUD Olivier committed
366 367 368
          foreach (fft_lib ${FFTW_LIBRARIES_DEP})
            set(FFT_LIBRARIES "${FFT_LIBRARIES};${fft_lib};")
          endforeach()
369
        endif()
370
        set(FFT_INCLUDES "${FFTW_INCLUDE_DIRS_DEP}" )
371
        if (FFT_LIBRARIES)
COULAUD Olivier's avatar
COULAUD Olivier committed
372
          set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${FFT_LIBRARIES}")
373
        endif()
374

375
      endif(SCALFMM_USE_MKL_AS_BLAS)
376

377
    else(SCALFMM_USE_MKL_AS_FFTW)
378 379 380 381 382

      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
383
      find_package(FFTW COMPONENTS SIMPLE) # not REQUIRED
384 385 386 387 388
      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})
389
          set(FFT_LIBRARIES "${FFT_LIBRARIES};${fft_lib};")
390 391
        endforeach()
      endif()
392
      set(FFT_INCLUDES "${FFTW_INCLUDE_DIRS_DEP}" )
393
      if (FFT_LIBRARIES)
394
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${FFT_LIBRARIES}")
395
      endif()
396

397
    endif(SCALFMM_USE_MKL_AS_FFTW)
398 399

    if (FFT_INCLUDES)
COULAUD Olivier's avatar
COULAUD Olivier committed
400
      set(SCALFMM_INCLUDES "${SCALFMM_INCLUDES}; ${FFT_INCLUDES}")
401
    endif()
402

403
    if(FFTW_FOUND)
COULAUD Olivier's avatar
COULAUD Olivier committed
404 405
      message(STATUS "         SCALFMM_LIBRARIES          = ${SCALFMM_LIBRARIES}")
      message(STATUS "         SCALFMM_INCLUDES          = ${SCALFMM_INCLUDES}")
406
    else()
COULAUD Olivier's avatar
COULAUD Olivier committed
407 408 409
      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)
410
    endif()
411
  endif(SCALFMM_USE_FFT)
412
  list(APPEND FUSE_LIST "FFT")
COULAUD Olivier's avatar
COULAUD Olivier committed
413 414
  message(STATUS "         SCALFMM_LIBRARIES          = ${SCALFMM_LIBRARIES}")
  message(STATUS "         SCALFMM_INCLUDES          = ${SCALFMM_INCLUDES}")
415
  
COULAUD Olivier's avatar
??  
COULAUD Olivier committed
416
  message(STATUS "SCALFMM_USE_FFT       =  ${SCALFMM_USE_FFT}")
417 418 419 420 421 422 423

  #
  # 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}")
424
    set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} -Wall")
425 426
  else()
    # Compile option valid on GCC/G++
427
    set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wconversion -Wcast-qual -Wcast-align -Woverloaded-virtual")
428
  endif()
429 430
  #
  ##################################################################
COULAUD Olivier's avatar
??  
COULAUD Olivier committed
431
  #              STARPU Section
432 433
  ##################################################################
  #
434 435
  message( STATUS "SCALFMM_USE_STARPU             = ${SCALFMM_USE_STARPU}" )
  if( SCALFMM_USE_STARPU )
436
    # No fast math with starpu
437
    if(SCALFMM_CXX_FLAGS)
COULAUD Olivier's avatar
COULAUD Olivier committed
438
      string(REPLACE "-ffast-math" " " SCALFMM_CXX_FLAGS ${SCALFMM_CXX_FLAGS})
439 440
    endif()
    if(SCALFMM_FLAGS_OPTI_RELEASE)
COULAUD Olivier's avatar
COULAUD Olivier committed
441
      string(REPLACE "-ffast-math" " " SCALFMM_FLAGS_OPTI_RELEASE ${SCALFMM_FLAGS_OPTI_RELEASE})     
442
    endif()
443

444
    # CUDA could be used with StarPU enabled
445 446 447
    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)
COULAUD Olivier's avatar
COULAUD Olivier committed
448 449 450 451 452 453 454 455 456 457 458
      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}" )
459

COULAUD Olivier's avatar
COULAUD Olivier committed
460
      find_package(CUDA REQUIRED)
461

COULAUD Olivier's avatar
COULAUD Olivier committed
462 463 464 465 466 467 468 469
      if (CUDA_INCLUDE_DIRS)
        include_directories(${CUDA_INCLUDE_DIRS})
      endif()
      if (CUDA_LIBRARIES)
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${CUDA_LIBRARIES}")
      endif()
      
      set(CUDA_NEEDED_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/Src)
470 471 472
    endif()

    # Find StarPU with a list of optional components
473
    set(SCALFMM_STARPU_VERSION "1.1" CACHE STRING "oldest STARPU version desired")
474 475
    # create list of components in order to make a single call to find_package(starpu...)
    set(STARPU_COMPONENT_LIST "HWLOC")
476
    if(SCALFMM_USE_MPI)
COULAUD Olivier's avatar
COULAUD Olivier committed
477
      list(APPEND STARPU_COMPONENT_LIST "MPI")
478
    endif()
479
    if(SCALFMM_USE_CUDA)
COULAUD Olivier's avatar
COULAUD Olivier committed
480
      list(APPEND STARPU_COMPONENT_LIST "CUDA")
481
    endif()
482

483
    find_package(STARPU ${SCALFMM_STARPU_VERSION} REQUIRED
COULAUD Olivier's avatar
COULAUD Olivier committed
484
      COMPONENTS ${STARPU_COMPONENT_LIST})
485

486
    # Append list of libraries and include dirs
487 488 489
    include_directories(${STARPU_INCLUDE_DIRS_DEP})
    foreach (starpu_libdir ${STARPU_LIBRARY_DIRS_DEP})
      if (${starpu_libdir} MATCHES "^ *-L")
COULAUD Olivier's avatar
COULAUD Olivier committed
490
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${starpu_libdir}")
491
      else()
COULAUD Olivier's avatar
COULAUD Olivier committed
492
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};-L${starpu_libdir}")
493 494 495 496
      endif()
    endforeach()
    foreach (starpu_lib ${STARPU_LIBRARIES_DEP})
      if (EXISTS ${starpu_lib} OR ${starpu_lib} MATCHES "^ *-")
COULAUD Olivier's avatar
COULAUD Olivier committed
497
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${starpu_lib}")
498
      else()
COULAUD Olivier's avatar
COULAUD Olivier committed
499
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};-l${starpu_lib}")
500 501
      endif()
    endforeach()
502

503
    # TODO: is this very useful? CUDA is already a component of find starpu
504
    if (CUDA_LIBRARIES)
COULAUD Olivier's avatar
COULAUD Olivier committed
505
      set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${CUDA_LIBRARIES}")
506
    endif()
Florent Pruvost's avatar
Florent Pruvost committed
507

508
    # Message
509 510
    message(STATUS "         STARPU_LIBRARIES          = ${STARPU_LIBRARIES}")
    if (STARPU_INCLUDE_DIRS)
COULAUD Olivier's avatar
COULAUD Olivier committed
511 512
      message(STATUS "         STARPU_INCLUDES           = ${STARPU_INCLUDE_DIRS}")
      set(SCALFMM_INCLUDES  "${SCALFMM_INCLUDES}; ${STARPU_INCLUDE_DIRS}")
513
    endif()
514

515
    # TODO: replace this by a component of find starpu
516 517 518
    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)
COULAUD Olivier's avatar
COULAUD Olivier committed
519 520
      include_directories($ENV{OPENCL_INC})
      SET(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};-L$ENV{OPENCL_LIB};-lOpenCL")
BRAMAS Berenger's avatar
BRAMAS Berenger committed
521
    endif()
522
  endif(SCALFMM_USE_STARPU)
523
  list(APPEND FUSE_LIST "STARPU")
Florent Pruvost's avatar
Florent Pruvost committed
524
  list(APPEND FUSE_LIST "CUDA")
BRAMAS Berenger's avatar
BRAMAS Berenger committed
525
  list(APPEND FUSE_LIST "OPENCL")
Florent Pruvost's avatar
Florent Pruvost committed
526

527 528 529 530
  ##################################################################
  #                         Use SSE                                #
  ##################################################################

531 532 533 534
  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)" )
535 536 537
    endif()
    message( STATUS "SSE_FLAGS ${SSE_FLAGS}  -- ${CMAKE_CXX_FLAGS}  ")
    try_compile(COMPILE_SSE  ${CMAKE_CURRENT_BINARY_DIR}
COULAUD Olivier's avatar
COULAUD Olivier committed
538 539 540
      ${SCALFMM_CMAKE_MODULE_PATH}/compileTestSse.cpp
      COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${SSE_FLAGS}"
      OUTPUT_VARIABLE COMPILE_SSE_OUTPUT)
541 542

    if(${COMPILE_SSE})
543
      set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} ${SSE_FLAGS}")
544 545

      try_compile(COMPILE_RESULT_VAR ${CMAKE_CURRENT_BINARY_DIR}
COULAUD Olivier's avatar
COULAUD Olivier committed
546 547
        ${SCALFMM_CMAKE_MODULE_PATH}/checkSSEpe.cpp
        COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${SSE_FLAGS}")
548 549 550
      if( NOT ${COMPILE_RESULT_VAR})
        set(__SSEPE_INTEL_COMPILER ON)
      endif()
551
      #set(SCALFMM_USE_AVX OFF)
552
    else(${COMPILE_SSE})
553
      message(FATAL_ERROR "SSE NOT SUPPORTED ; Set SCALFMM_USE_SSE  to OFF \n Output from test is : ${COMPILE_SSE_OUTPUT}")
554 555 556
    endif(${COMPILE_SSE})
  endif()
  list(APPEND FUSE_LIST "SSE")
557

558 559 560 561
  ##################################################################
  #                           Use AVX                              #
  ##################################################################

562 563 564 565
  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)" )
566 567 568
    endif()

    try_compile(COMPILE_AVX ${CMAKE_CURRENT_BINARY_DIR}
COULAUD Olivier's avatar
COULAUD Olivier committed
569 570 571 572 573 574
      ${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}")
      
575
      set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS}   ${AVX_FLAGS}")
COULAUD Olivier's avatar
COULAUD Olivier committed
576 577
      message(STATUS "%%%%%%%%%%%% SCALFMM_CXX_FLAGS               = ${SCALFMM_CXX_FLAGS}")
      #set( SCALFMM_USE_SSE   OFF   FORCE) # ne marche pas
578
      try_compile(COMPILE_RESULT_AVSPE ${CMAKE_CURRENT_BINARY_DIR}
COULAUD Olivier's avatar
COULAUD Olivier committed
579 580 581
        ${SCALFMM_CMAKE_MODULE_PATH}/checkAVXpe.cpp
        COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${AVX_FLAGS}")
      if( NOT ${COMPILE_RESULT_AVSPE})
582 583


584
        set(__AVXPE_INTEL_COMPILER ON)
COULAUD Olivier's avatar
COULAUD Olivier committed
585
      endif()
586 587 588

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

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

737 738 739 740
  ##################################################################
  #                Build -Tests to see examples                    #
  ##################################################################
  # Build - Tests
741 742
  message( STATUS "SCALFMM_BUILD_TESTS          = ${SCALFMM_BUILD_TESTS}" )
  if( SCALFMM_BUILD_TESTS )
743 744
    add_subdirectory(Tests)
  endif()
berenger-bramas's avatar
berenger-bramas committed
745

746 747 748 749
  ##################################################################
  #              Build - Unitary and numerical Tests               #
  ##################################################################
  #
750 751
  message( STATUS "SCALFMM_BUILD_UTESTS         = ${SCALFMM_BUILD_UTESTS}" )
  if( SCALFMM_BUILD_UTESTS )
752 753 754 755
    include(CTest)
    enable_testing()
    add_subdirectory(UTests)
  endif()
berenger-bramas's avatar
berenger-bramas committed
756

757 758 759
  ##################################################################
  #                           Add - doc                            #
  ##################################################################
760 761 762
  if(SCALFMM_BUILD_DOC)
    add_subdirectory(Doc)
  endif()
763 764 765 766
  ##################################################################
  #                       Build - Addons                           #
  ##################################################################
  #
767
  if( SCALFMM_USE_ADDONS )
768 769
    file(GLOB all_addons ./Addons/*)
    # Options
770
    option( SCALFMM_ADDON_CKERNELAPI "Set to ON to build ScaFMM FMM API interface" OFF )
771

772 773 774 775
    foreach(addon_name ${all_addons})
      message(STATUS "Addons += ${addon_name}" )
      add_subdirectory(${addon_name})
    endforeach()
776
  endif()
777

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