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

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

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

9 10 11 12 13
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)

#===========================================================================
# Project Declaration
#===========================================================================
14
project(SCALFMM C CXX)
COULAUD Olivier's avatar
COULAUD Olivier committed
15

16
# check if compiling into source directories
17
string(COMPARE EQUAL "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_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 23
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/)
set(SCALFMM_CMAKE_MODULE_PATH ${CMAKE_CURRENT_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
# SCALFMM version number.  An even minor number corresponds to releases.
set(SCALFMM_MAJOR_VERSION 1)
COULAUD Olivier's avatar
COULAUD Olivier committed
37
set(SCALFMM_MINOR_VERSION 5)
38 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)
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 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
  endif()
  include(MorseInit)
56 57 58 59 60 61 62 63 64 65
  # Set the RPATH config
  # --------------------
  # use, i.e. don't skip the full RPATH for the build tree
  set(CMAKE_SKIP_BUILD_RPATH  FALSE)
  # when building, don't use the install RPATH already
  # (but later on when installing)
  set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
  # the RPATH to be used when installing
  set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

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

70 71
  #
  # Options
72
  #
73 74 75 76 77 78 79
  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 )
80
  option( SCALFMM_BUILD_DOC            "Set to ON to build the Doxygen documentation " OFF )
81 82 83 84 85
  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 )
86
  option( SCALFMM_USE_SIGNALS          "Set to ON to catch various signal an print backtrace"  OFF )
87 88
  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  )
89
  option( SCALFMM_ONLY_DEVEL           "Set to ON to compile Development tools (only scalfmm team)" OFF )
90 91 92 93
  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 )

94 95 96
  #
  #  VECTORISATION
  #
97
  if( APPLE ) # to fix problem with  GCC and avx
COULAUD Olivier's avatar
COULAUD Olivier committed
98 99
    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  )
100
  else(APPLE)
COULAUD Olivier's avatar
COULAUD Olivier committed
101 102
    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  )
103
  endif(APPLE)
104 105
  CMAKE_DEPENDENT_OPTION( SCALFMM_USE_AVX2             "Set to ON to compile with AVX support (and use intrinsec AVX2 P2P)" ON "CPUOPTION_AVX2" OFF )

106
  if( SCALFMM_ONLY_DEVEL )
107
    # OPENMP 4/5 support 
108
    option( OPENMP_SUPPORT_COMMUTE   "Set to ON to let tasks commute (KSTAR/StarPU compiler only)" OFF )
109
    option( OPENMP_SUPPORT_PRIORITY  "Set to ON to enable tasks priority (KSTAR/StarPU compiler only)" OFF )
110
    option( OPENMP_SUPPORT_TASK_NAME "Set to ON to enable a taskname clause for tasks (KSTAR/StarPU compiler only)" OFF )
111 112 113 114 115
    if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
      option( SCALFMM_DISABLE_NATIVE_OMP4 "Set to ON to disable the gcc/intel omp4"    OFF )
    else()
      option( SCALFMM_DISABLE_NATIVE_OMP4 "Set to ON to disable the gcc/intel omp4"    ON )
    endif()
116
    option( SCALFMM_TIME_OMPTASKS "Set to ON to time omp4 tasks and generate output file"    OFF )
117
# SIMGRID and peformance models options
BRAMAS Berenger's avatar
BRAMAS Berenger committed
118
    option( SCALFMM_SIMGRID_NODATA "Set to ON to avoid the allocation of numerical parts in the group tree" OFF )
119
    option( STARPU_SIMGRID_MLR_MODELS "Set to ON to enable MLR models need for calibration and simulation" OFF )
120 121 122 123 124
# 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)
125
  endif()
126
  message(STATUS "AVANT  ${CMAKE_CXX_COMPILER_ID}" )
127 128 129
  #
  #  MPI
  #
130
  if( SCALFMM_USE_MPI )
131
    try_compile(COMPILE_INTEL ${CMAKE_CURRENT_BINARY_DIR}
COULAUD Olivier's avatar
COULAUD Olivier committed
132 133
      ${SCALFMM_CMAKE_MODULE_PATH}/compileTestIntel.cpp
      COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS}")
134 135 136 137 138 139 140
    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 "")
141
  set(SCALFMM_CXX_FLAGS "-std=c++11 -fpic -Wall")
142 143 144 145 146 147 148 149 150 151 152 153
  #
  #
  # 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)
154
  message(STATUS "SCALFMM_BUILD_DEBUG = ${SCALFMM_BUILD_DEBUG}" )
155 156
  #
  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
157
    set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -m64")
158 159 160 161 162 163 164 165 166
  endif()
  ##############################################################################
  #                           Compile options                                  #
  ##############################################################################
  #  -xHost -mfpmath=sse
  # -Wall Wnosign-conversion
  #
  if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
    # INTEL
167
    IF (APPLE)
COULAUD Olivier's avatar
COULAUD Olivier committed
168 169 170 171 172
      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)  
173
    else(APPLE)
COULAUD Olivier's avatar
COULAUD Olivier committed
174 175
      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
176
      set(SSE_FLAGS  "-axSSE4.2  -march=native")
177
    endif(APPLE)
178
    #-Wshadow -Wpointer-arith -Wcast-qual -Wconversion  -Wall -Wnosign-conversion ")
COULAUD Olivier's avatar
COULAUD Olivier committed
179 180 181
  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")
182
    # NOT      INTEL
183
    if(NOT SCALFMM_USE_MPI)
184 185 186
      include(CheckCCompilerFlag)
      check_c_compiler_flag(-Wzero-as-null-pointer-constant HAS_WZERO_NULL_PTR_FLAG)
      if(HAS_WZERO_NULL_PTR_FLAG)
187
        set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -Wzero-as-null-pointer-constant")
188
      endif()
189
    else()
190 191 192
      include(CheckCCompilerFlag)
      check_c_compiler_flag(-Wno-literal-suffix HAS_NO_LITERAL_SUFFIX_FLAG)
      if(HAS_NO_LITERAL_SUFFIX_FLAG)
193
        set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -Wno-literal-suffix")
194
      endif()
195
    endif()
196
    IF (APPLE)
COULAUD Olivier's avatar
COULAUD Olivier committed
197 198 199 200 201 202
      #      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)
203 204
      set(AVX_FLAGS "-mtune=native -march=avx")
      set(AVX2_FLAGS "-mtune=native -march=native -mmic")
205
    else(APPLE)
206 207 208
      set(SSE_FLAGS  "-mtune=native -march=native")
      set(AVX_FLAGS "-mtune=native -march=native")
      set(AVX2_FLAGS "-mtune=native -march=native -mmic")
209 210
    endif(APPLE)
  endif()
211

212 213 214 215 216 217
  ##############################################################################
  #                           FUSE list                                        #
  ##############################################################################
  set(FUSE_LIST "")
  # then do list(APPEND FUSE_LIST "BLAS") to protect from FUSE_BLAS
  list(APPEND FUSE_LIST "MPI")
218

219 220 221 222
  ##############################################################################
  #                        Debug      flags                                    #
  ##############################################################################
  #
223
  if( SCALFMM_BUILD_DEBUG )
224 225 226 227 228 229
    #
    # Compile Debug flags
    #
    set(CMAKE_BUILD_TYPE Debug)
    ADD_DEFINITIONS(-O0)
    if( APPLE )
230
      set(SCALFMM_FLAGS_OPTI_DEBUG "-funroll-loops" CACHE STRING
231 232 233 234 235 236 237 238 239 240 241
        "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})
242
    set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} ${SCALFMM_FLAGS_OPTI_DEBUG}")
243 244 245 246 247 248
    set(CMAKE_CXX_FLAGS_TYPE "${CMAKE_CXX_FLAGS_DEBUG}")

  else()
    ##############################################################################
    #                          Release flags                                     #
    ##############################################################################
249

250 251 252
    set(CMAKE_BUILD_TYPE Release)
    set(CMAKE_CXX_FLAGS_TYPE  "${CMAKE_CXX_FLAGS_RELEASE}")
    # if compiler is intel add -ip
253

BRAMAS Berenger's avatar
BRAMAS Berenger committed
254
    if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
COULAUD Olivier's avatar
COULAUD Olivier committed
255
      set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -ipo  -fstrict-aliasing ")# -no-prec-div -no-prec-sqrt")
BRAMAS Berenger's avatar
BRAMAS Berenger committed
256
    endif()
257 258
    # Compile optimization
    if(APPLE)
259
      set(SCALFMM_FLAGS_OPTI_RELEASE "-funroll-loops" CACHE STRING
260 261 262
        "Set your optimization flags for release mode.")
    else(APPLE)
      # Not apple system - Check the compiler flags
COULAUD Olivier's avatar
COULAUD Olivier committed
263 264 265 266
      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.")
267 268
	# set(SCALFMM_FLAGS_OPTI_RELEASE "-funroll-loops -ftree-vectorize" CACHE STRING
	#   "Set your optimization flags for release mode.")
269 270 271 272 273 274
      else()
        set(SCALFMM_FLAGS_OPTI_RELEASE "-ffast-math -funroll-loops -ftree-vectorize" CACHE STRING
          "Set your optimization flags for release mode.")
      endif()
    endif(APPLE)
    #
275
    set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} ${SCALFMM_FLAGS_OPTI_RELEASE}")
276
  endif()
COULAUD Olivier's avatar
COULAUD Olivier committed
277 278
  MESSAGE(STATUS   " %%%%%%%%%% SCALFMM_CXX_FLAGS  ${SCALFMM_CXX_FLAGS} %%%%%%%%%%%%%")
  MESSAGE(STATUS   " %%%%%%%%%% CMAKE_CXX_FLAGS_RELEASE  ${CMAKE_CXX_FLAGS_RELEASE} %%%%%%%%%%%%%")
279

280 281 282 283
  #
  ##############################################################################
  #                Attach source code to exec                                  #
  ##############################################################################
284 285
  message(STATUS "SCALFMM_ATTACHE_SOURCE       = ${SCALFMM_ATTACHE_SOURCE}" )
  if( SCALFMM_ATTACHE_SOURCE )
286
    message(STATUS "Option -g is used, the code is attached to the binary." )
287 288
    set(SCALFMM_CXX_FLAGS  "${SCALFMM_CXX_FLAGS} -g")
  endif(SCALFMM_ATTACHE_SOURCE)
289 290 291 292 293
  #
  ##############################################################################
  #                                 find MPI                                   #
  ##############################################################################
  #
294
  if( SCALFMM_USE_MPI )
295 296 297 298 299

    # 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
300
      set(MPI_C_COMPILER mpicc)
301 302
    endif()
    if(NOT MPI_CXX_COMPILER)
COULAUD Olivier's avatar
COULAUD Olivier committed
303
      set(MPI_CXX_COMPILER mpicxx)
304 305 306 307 308
    endif()

    find_package(MPI REQUIRED)

    if (MPI_CXX_INCLUDE_PATH)
COULAUD Olivier's avatar
COULAUD Olivier committed
309
      include_directories( ${MPI_CXX_INCLUDE_PATH} )
310 311
    endif()
    if (MPI_CXX_COMPILE_FLAGS)
COULAUD Olivier's avatar
COULAUD Olivier committed
312
      set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} ${MPI_CXX_COMPILE_FLAGS}")
313 314
    endif()
    if (MPI_CXX_INCLUDE_PATH)
COULAUD Olivier's avatar
COULAUD Olivier committed
315
      set(SCALFMM_INCLUDES  "${SCALFMM_INCLUDES}; ${MPI_CXX_INCLUDE_PATH}")
316 317
    endif()
    if (MPI_CXX_LINK_FLAGS)
COULAUD Olivier's avatar
COULAUD Olivier committed
318
      set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${MPI_CXX_LINK_FLAGS}")
319 320
    endif()
    if (MPI_CXX_LIBRARIES)
COULAUD Olivier's avatar
COULAUD Olivier committed
321
      set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${MPI_CXX_LIBRARIES}")
322 323 324 325 326 327 328 329
    endif()

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

339 340
    option( SCALFMM_USE_MKL_AS_BLAS  "Set to ON to use MKL BLAS/LAPACK" OFF )
    option( SCALFMM_USE_ESSL_AS_BLAS "Set to ON to use ESSL BLAS/LAPACK" OFF )
341

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

374
    if(BLAS_FOUND)
COULAUD Olivier's avatar
COULAUD Olivier committed
375
      set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${BLASLAPACK_LIBRARIES}")
376 377 378 379 380 381 382 383
      if(BLAS_LIBRARY_DIRS)
        # the RPATH to be used when installing
        list(APPEND CMAKE_INSTALL_RPATH "${BLAS_LIBRARY_DIRS}")
      endif()
      if(LAPACK_FOUND AND LAPACK_LIBRARY_DIRS)
        # the RPATH to be used when installing
        list(APPEND CMAKE_INSTALL_RPATH "${LAPACK_LIBRARY_DIRS}")
      endif()
384
      message (STATUS "check BLAS Fortran mangling")
385 386 387 388 389 390 391 392 393
      # add options to let the user be able to force a behavior
      option( SCALFMM_BLAS_ADD_     "Set to ON to force calls to BLAS Fortran symbols with _ (ex: dgemm_)"        OFF )
      option( SCALFMM_BLAS_UPCASE   "Set to ON to force calls to BLAS Fortran symbols in capital (ex: DGEMM)"     OFF )
      option( SCALFMM_BLAS_NOCHANGE "Set to ON to force calls to BLAS Fortran symbols with no change (ex: dgemm)" OFF )
      # if options not changed by user then auto-detection
      if (NOT SCALFMM_BLAS_ADD_ AND NOT SCALFMM_BLAS_UPCASE AND NOT SCALFMM_BLAS_NOCHANGE)
        # give blas libraries and check dgemm symbol
        set(CMAKE_REQUIRED_LIBRARIES "${BLAS_LIBRARIES}")
        check_function_exists(dgemv_ DGEMV_ADD_)
394
        check_function_exists(DGEMV  DGEMV_UPCASE)
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
        check_function_exists(dgemv  DGEMV_NOCHANGE)
        # here we consider that the first kind of symbol found will be the one used
        # current order is: ADD_, UPCASE, NOCHANGE
        if (DGEMV_ADD_)
          set (SCALFMM_BLAS_ADD_     ON)
          set (SCALFMM_BLAS_UPCASE   OFF)
          set (SCALFMM_BLAS_NOCHANGE OFF)
          message (STATUS "BLAS dgemv_ symbol found, SCALFMM_BLAS_ADD_ is ON")
        else (DGEMV_ADD_)
          if (DGEMV_UPCASE)
            set (SCALFMM_BLAS_ADD_     OFF)
            set (SCALFMM_BLAS_UPCASE   ON)
            set (SCALFMM_BLAS_NOCHANGE OFF)
            message (STATUS "BLAS DGEMV symbol found, SCALFMM_BLAS_UPCASE is ON")
          else (DGEMV_UPCASE)
            if (DGEMV_NOCHANGE)
              set (SCALFMM_BLAS_ADD_     OFF)
              set (SCALFMM_BLAS_UPCASE   OFF)
              set (SCALFMM_BLAS_NOCHANGE ON)
              message (STATUS "BLAS dgemv symbol found, SCALFMM_BLAS_NOCHANGE is ON")
            endif (DGEMV_NOCHANGE)
          endif (DGEMV_UPCASE)
        endif (DGEMV_ADD_)
        if ( (NOT DGEMV_ADD_) AND (NOT DGEMV_UPCASE) AND (NOT DGEMV_NOCHANGE) )
          message(FATAL_ERROR "BLAS Fortran mangling is not properly detected - please check your BLAS libraries")
        endif ()
      else  (NOT SCALFMM_BLAS_ADD_ AND NOT SCALFMM_BLAS_UPCASE AND NOT SCALFMM_BLAS_NOCHANGE)
        if (SCALFMM_BLAS_ADD_)
          message (STATUS "SCALFMM_BLAS_ADD_ is set to ON")
        endif()
        if (SCALFMM_BLAS_UPCASE)
          message (STATUS "SCALFMM_BLAS_UPCASE is set to ON")
        endif()
        if (SCALFMM_BLAS_NOCHANGE)
          message (STATUS "SCALFMM_BLAS_NOCHANGE is set to ON")
        endif()
      endif (NOT SCALFMM_BLAS_ADD_ AND NOT SCALFMM_BLAS_UPCASE AND NOT SCALFMM_BLAS_NOCHANGE)
432
    else()
COULAUD Olivier's avatar
COULAUD Olivier committed
433 434 435
      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)
436
    endif()
437

438
  endif(SCALFMM_USE_BLAS)
439 440 441 442
  list(APPEND FUSE_LIST "BLAS")
  #
  # FFT option
  #
443 444
  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 )
  CMAKE_DEPENDENT_OPTION(SCALFMM_USE_ESSL_AS_FFTW "Set to ON to use ESSL FFTW" ON  "SCALFMM_USE_FFT;SCALFMM_USE_ESSL_AS_BLAS" OFF )
445
  if( SCALFMM_USE_FFT )
446 447
    message(STATUS "SCALFMM USE FFT Configure:")

448 449 450
    # The package find_package(FFTW) can be used with the following COMPONENTS:
    # MKL, ESSL, THREADS|OMP and/or SIMPLE|LONG|QUAD
    # Default will find the real double precision fftw library version without THREADS|OMP
451
    if( SCALFMM_USE_MKL_AS_FFTW )
452 453 454
      message(STATUS "         SCALFMM USE FFT from MKL")
      find_package(FFTW COMPONENTS MKL)
    elseif (SCALFMM_USE_ESSL_AS_FFTW)
455 456 457
      message(STATUS "         SCALFMM USE FFT from ESSL ")
      find_package(FFTW COMPONENTS ESSL)
      add_definitions(-DSCALFMM_USE_ESSL_AS_FFTW)
458
    else()
459 460
      message(STATUS "         SCALFMM USE FFTW")
      find_package(FFTW COMPONENTS SIMPLE)
461
    endif()
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
      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")
        if (BLAS_FOUND)
          set(FFTW_FOUND ON)
        endif()

      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  COMPONENTS MKL) # not REQUIRED
        if (FFTW_LIBRARY_DIRS_DEP)
          set(FFT_LIBRARIES "-L${FFTW_LIBRARY_DIRS_DEP};" CACHE STRING "Set your MKL flags")
        endif()
        if (FFTW_LIBRARIES_DEP)
          foreach (fft_lib ${FFTW_LIBRARIES_DEP})
            set(FFT_LIBRARIES "${FFT_LIBRARIES};${fft_lib};")
          endforeach()
        endif()
        set(FFT_INCLUDES "${FFTW_INCLUDE_DIRS_DEP}" )
        if (FFT_LIBRARIES)
          set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${FFT_LIBRARIES}")
        endif()

      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 COMPONENTS SIMPLE) # not REQUIRED
	  #message(FATAL_ERROR ${FFTW_FOUND} ${FFTW_LIBRARY_DIRS_DEP} ${FFTW_LIBRARIES_DEP})
      if (FFTW_LIBRARY_DIRS_DEP)
        set(FFT_LIBRARIES "-L${FFTW_LIBRARY_DIRS_DEP};" CACHE STRING "Set your FFTW path")
      endif()
      if (FFTW_LIBRARIES_DEP)
        foreach (fft_lib ${FFTW_LIBRARIES_DEP})
          set(FFT_LIBRARIES "${FFT_LIBRARIES};${fft_lib};")
        endforeach()
      endif()
	  #message(FATAL_ERROR ${FFTW_INCLUDE_DIRS_DEP})
      set(FFT_INCLUDES "${FFTW_INCLUDE_DIRS_DEP}" )
      if (FFT_LIBRARIES)
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${FFT_LIBRARIES}")
      endif()
      if(FFTW_LIBRARY_DIRS)
        # the RPATH to be used when installing
        list(APPEND CMAKE_INSTALL_RPATH "${FFTW_LIBRARY_DIRS}")
      endif()
520

521 522 523 524
    set(FFT_INCLUDES "${FFTW_INCLUDE_DIRS_DEP}" )
    if (FFT_LIBRARIES)
      set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${FFT_LIBRARIES}")
    endif()
525

526 527 528 529
    if(FFTW_LIBRARY_DIRS)
      # the RPATH to be used when installing
      list(APPEND CMAKE_INSTALL_RPATH "${FFTW_LIBRARY_DIRS}")
    endif()
530
    if (FFT_INCLUDES)
COULAUD Olivier's avatar
COULAUD Olivier committed
531
      set(SCALFMM_INCLUDES "${SCALFMM_INCLUDES}; ${FFT_INCLUDES}")
532
    endif()
533

534
    if(NOT FFTW_FOUND)
COULAUD Olivier's avatar
COULAUD Olivier committed
535 536 537
      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)
538
    endif()
539

540
  endif(SCALFMM_USE_FFT)
541
  list(APPEND FUSE_LIST "FFT")
COULAUD Olivier's avatar
??  
COULAUD Olivier committed
542
  message(STATUS "SCALFMM_USE_FFT       =  ${SCALFMM_USE_FFT}")
543 544 545 546 547 548
  if (SCALFMM_INCLUDES)
    list(REMOVE_DUPLICATES SCALFMM_INCLUDES)
  endif()
  if (SCALFMM_LIBRARIES)
    list(REMOVE_DUPLICATES SCALFMM_LIBRARIES)
  endif()
549 550 551 552 553 554 555

  #
  # 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}")
556
    set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} -Wall")
557 558
  else()
    # Compile option valid on GCC/G++
559
    set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wconversion -Wcast-qual -Wcast-align -Woverloaded-virtual")
560
  endif()
561 562
  #
  ##################################################################
COULAUD Olivier's avatar
??  
COULAUD Olivier committed
563
  #              STARPU Section
564 565
  ##################################################################
  #
566 567
  message( STATUS "SCALFMM_USE_STARPU             = ${SCALFMM_USE_STARPU}" )
  if( SCALFMM_USE_STARPU )
568
    # CUDA could be used with StarPU enabled
569 570 571
    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
572 573 574 575 576
      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)
577 578
        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")
COULAUD Olivier's avatar
COULAUD Olivier committed
579 580 581 582
      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}" )
583

COULAUD Olivier's avatar
COULAUD Olivier committed
584
      find_package(CUDA REQUIRED)
585

COULAUD Olivier's avatar
COULAUD Olivier committed
586 587 588 589 590 591
      if (CUDA_INCLUDE_DIRS)
        include_directories(${CUDA_INCLUDE_DIRS})
      endif()
      if (CUDA_LIBRARIES)
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${CUDA_LIBRARIES}")
      endif()
592

593
      set(CUDA_NEEDED_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/Src)
594 595 596
    endif()

    # Find StarPU with a list of optional components
597
    set(SCALFMM_STARPU_VERSION "1.1" CACHE STRING "oldest STARPU version desired")
598 599
    # create list of components in order to make a single call to find_package(starpu...)
    set(STARPU_COMPONENT_LIST "HWLOC")
600
    if(SCALFMM_USE_MPI)
COULAUD Olivier's avatar
COULAUD Olivier committed
601
      list(APPEND STARPU_COMPONENT_LIST "MPI")
602
    endif()
603
    if(SCALFMM_USE_CUDA)
COULAUD Olivier's avatar
COULAUD Olivier committed
604
      list(APPEND STARPU_COMPONENT_LIST "CUDA")
605
    endif()
606

607
    find_package(STARPU ${SCALFMM_STARPU_VERSION} REQUIRED
COULAUD Olivier's avatar
COULAUD Olivier committed
608
      COMPONENTS ${STARPU_COMPONENT_LIST})
609

610 611 612 613 614 615 616 617 618 619 620 621 622
    if(HWLOC_FOUND AND HWLOC_LIBRARY_DIRS)
      # the RPATH to be used when installing
      list(APPEND CMAKE_INSTALL_RPATH "${HWLOC_LIBRARY_DIRS}")
    endif()
    if(FXT_FOUND AND FXT_LIBRARY_DIRS)
      # the RPATH to be used when installing
      list(APPEND CMAKE_INSTALL_RPATH "${FXT_LIBRARY_DIRS}")
    endif()
    if(STARPU_FOUND AND STARPU_LIBRARY_DIRS)
      # the RPATH to be used when installing
      list(APPEND CMAKE_INSTALL_RPATH "${STARPU_LIBRARY_DIRS}")
    endif()

623
    # Append list of libraries and include dirs
624 625 626
    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
627
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${starpu_libdir}")
628
      else()
COULAUD Olivier's avatar
COULAUD Olivier committed
629
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};-L${starpu_libdir}")
630 631 632 633
      endif()
    endforeach()
    foreach (starpu_lib ${STARPU_LIBRARIES_DEP})
      if (EXISTS ${starpu_lib} OR ${starpu_lib} MATCHES "^ *-")
COULAUD Olivier's avatar
COULAUD Olivier committed
634
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${starpu_lib}")
635
      else()
COULAUD Olivier's avatar
COULAUD Olivier committed
636
        set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};-l${starpu_lib}")
637 638
      endif()
    endforeach()
639

640
    # TODO: is this very useful? CUDA is already a component of find starpu
641
    if (CUDA_LIBRARIES)
COULAUD Olivier's avatar
COULAUD Olivier committed
642
      set(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${CUDA_LIBRARIES}")
643
    endif()
Florent Pruvost's avatar
Florent Pruvost committed
644

645
    # Message
646 647
    message(STATUS "         STARPU_LIBRARIES          = ${STARPU_LIBRARIES}")
    if (STARPU_INCLUDE_DIRS)
COULAUD Olivier's avatar
COULAUD Olivier committed
648
      message(STATUS "         STARPU_INCLUDES           = ${STARPU_INCLUDE_DIRS}")
649
      set(SCALFMM_INCLUDES  "${SCALFMM_INCLUDES}; ${STARPU_INCLUDE_DIRS}")
650
    endif()
651

652 653 654 655
    # Adding SimGrid includes
    set(SCALFMM_INCLUDES "${SCALFMM_INCLUDES};$ENV{SIMGRID_INCLUDE}")
    message(STATUS "         Adding SIMGRID           = $ENV{SIMGRID_INCLUDE}")

656
    # TODO: replace this by a component of find starpu
657 658 659
    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
660 661
      include_directories($ENV{OPENCL_INC})
      SET(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};-L$ENV{OPENCL_LIB};-lOpenCL")
BRAMAS Berenger's avatar
BRAMAS Berenger committed
662
    endif()
663
  endif(SCALFMM_USE_STARPU)
664
  list(APPEND FUSE_LIST "STARPU")
Florent Pruvost's avatar
Florent Pruvost committed
665
  list(APPEND FUSE_LIST "CUDA")
BRAMAS Berenger's avatar
BRAMAS Berenger committed
666
  list(APPEND FUSE_LIST "OPENCL")
Florent Pruvost's avatar
Florent Pruvost committed
667

668 669 670 671
  ##################################################################
  #                         Use SSE                                #
  ##################################################################

672 673 674 675
  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)" )
676 677 678
    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
679 680 681
      ${SCALFMM_CMAKE_MODULE_PATH}/compileTestSse.cpp
      COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${SSE_FLAGS}"
      OUTPUT_VARIABLE COMPILE_SSE_OUTPUT)
682 683

    if(${COMPILE_SSE})
684
      set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} ${SSE_FLAGS}")
685 686

      try_compile(COMPILE_RESULT_VAR ${CMAKE_CURRENT_BINARY_DIR}
COULAUD Olivier's avatar
COULAUD Olivier committed
687 688
        ${SCALFMM_CMAKE_MODULE_PATH}/checkSSEpe.cpp
        COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${SSE_FLAGS}")
689 690 691
      if( NOT ${COMPILE_RESULT_VAR})
        set(__SSEPE_INTEL_COMPILER ON)
      endif()
692
      #set(SCALFMM_USE_AVX OFF)
693
    else(${COMPILE_SSE})
694
      message(FATAL_ERROR "SSE NOT SUPPORTED ; Set SCALFMM_USE_SSE  to OFF \n Output from test is : ${COMPILE_SSE_OUTPUT}")
695 696 697
    endif(${COMPILE_SSE})
  endif()
  list(APPEND FUSE_LIST "SSE")
698

699 700 701 702
  ##################################################################
  #                           Use AVX                              #
  ##################################################################

703 704 705 706
  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)" )
707 708 709
    endif()

    try_compile(COMPILE_AVX ${CMAKE_CURRENT_BINARY_DIR}
COULAUD Olivier's avatar
COULAUD Olivier committed
710 711 712 713 714
      ${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}")
715

716
      set(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS}   ${AVX_FLAGS}")
COULAUD Olivier's avatar
COULAUD Olivier committed
717 718
      message(STATUS "%%%%%%%%%%%% SCALFMM_CXX_FLAGS               = ${SCALFMM_CXX_FLAGS}")
      #set( SCALFMM_USE_SSE   OFF   FORCE) # ne marche pas
719
      try_compile(COMPILE_RESULT_AVSPE ${CMAKE_CURRENT_BINARY_DIR}
COULAUD Olivier's avatar
COULAUD Olivier committed
720 721 722
        ${SCALFMM_CMAKE_MODULE_PATH}/checkAVXpe.cpp
        COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${AVX_FLAGS}")
      if( NOT ${COMPILE_RESULT_AVSPE})
723 724


725
        set(__AVXPE_INTEL_COMPILER ON)
COULAUD Olivier's avatar
COULAUD Olivier committed
726
      endif()
727 728 729

      message(STATUS ${CMAKE_CXX_FLAGS} )
    else(${COMPILE_AVX})
730
      message(FATAL_ERROR "AVX NOT SUPPORTED ; Set SCALFMM_USE_AVX  to OFF \n Output from test is : ${COMPILE_AVX_OUTPUT} ")
731
    endif(${COMPILE_AVX})
732
  endif(SCALFMM_USE_AVX)
733 734
  list(APPEND FUSE_LIST "AVX")
  #
735
  # Error if both SCALFMM_USE_AVX AND SCALFMM_USE_SSE are set
736
  #
737 738 739
  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)
740
  ##################################################################
741 742 743 744 745 746 747 748 749 750
  #                           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
751 752 753
      ${SCALFMM_CMAKE_MODULE_PATH}/compileTestAvx2.cpp
      COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${AVX2_FLAGS}"
      OUTPUT_VARIABLE COMPILE_AVX2_OUTPUT)
754 755 756 757
    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
758 759
        ${SCALFMM_CMAKE_MODULE_PATH}/checkAVX2pe.cpp
        COMPILE_DEFINITIONS "${CMAKE_CXX_FLAGS} ${AVX2_FLAGS}")
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
      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)
  ##################################################################
777 778
  #                     Use  native MIC compilation                #
  ##################################################################
779
  if( SCALFMM_USE_MIC_NATIVE )
780 781
    include(CheckCCompilerFlag)
    check_c_compiler_flag(-mmic HAS_MMIC_FLAG)
782
    if(NOT HAS_MMIC_FLAG)
783
      message(FATAL_ERROR "MIC NOT SUPPORTED ; Set SCALFMM_USE_MIC_NATIVE to OFF")
784 785 786
    endif()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmic")
  else()
787
    #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xhost")
788 789 790 791
  endif()
  list(APPEND FUSE_LIST "MIC")
  ##################################################################
  #
COULAUD Olivier's avatar
COULAUD Olivier committed
792 793
  #   Set EZTRACE
  #
794
  ##################################################################
COULAUD Olivier's avatar
COULAUD Olivier committed
795 796 797 798
  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
799
      pkg_search_module( EZTrace REQUIRED eztrace)
COULAUD Olivier's avatar
COULAUD Olivier committed
800
      if(EZTrace_FOUND)
COULAUD Olivier's avatar
COULAUD Olivier committed
801 802
        link_directories(${EZTrace_LIBRARY_DIRS})
        link_libraries( ${EZTrace_LIBRARIES})
803 804 805 806
        if (EZTrace_LIBRARY_DIRS)
          # the RPATH to be used when installing
          list(APPEND CMAKE_INSTALL_RPATH "${EZTrace_LIBRARY_DIRS}")
        endif()
COULAUD Olivier's avatar
COULAUD Olivier committed
807
        IF( SCALFMM_USE_MPI )
COULAUD Olivier's avatar
COULAUD Olivier committed
808
          link_libraries(-leztrace-autostart-mpi)
809 810 811 812 813 814 815 816 817
	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 )
COULAUD Olivier's avatar
COULAUD Olivier committed
818
      else(EZTrace_FOUND)
819 820
	MESSAGE(WARNING "Eztrace not found - EZTRACE Is set to OFF")
	set(SCALFMM_USE_EZTRACE OFF)  
COULAUD Olivier's avatar
COULAUD Olivier committed
821
      endif(EZTrace_FOUND)
COULAUD Olivier's avatar
COULAUD Olivier committed
822
    else(PKG_CONFIG_FOUND)
COULAUD Olivier's avatar
COULAUD Olivier committed
823
      MESSAGE(WARNING "PKG-CONFIG not found - EZTRACE Is set to OFF")
COULAUD Olivier's avatar
COULAUD Olivier committed
824 825 826 827
      set(SCALFMM_USE_EZTRACE OFF)
    endif(PKG_CONFIG_FOUND)

  endif(SCALFMM_USE_EZTRACE)
828

829 830 831 832 833
  ##################################################################
  #
  #   To catch signals
  #
  ##################################################################  
834 835 836 837 838 839 840 841
  if((WIN32 OR (${CMAKE_SYSTEM_NAME} MATCHES "Windows")) AND SCALFMM_USE_SIGNALS)
    # We are on Windows and we cannot catch signals
    message( FATAL_ERROR "Catching the signals requieres an UNIX system." )
  else()
    IF( NOT APPLE)
      SET(SCALFMM_CXX_FLAGS "${SCALFMM_CXX_FLAGS} -rdynamic")
    ENDIF()
  endif()
842 843 844 845 846 847 848 849
  ##################################################################
  #                                                                #
  #                     END SETTING VARIABLES                      #
  #                                                                #
  ##################################################################
  #
  # Generate  ScalFmmConfig.h
  #
850
  set(SCALFMM_COMPILE_FLAGS "${SCALFMM_CXX_FLAGS} ${CMAKE_CXX_FLAGS_TYPE} ${CMAKE_CXX_FLAGS}")
851
  set(CMAKE_CXX_FLAGS "${SCALFMM_COMPILE_FLAGS}")
852 853 854
  # 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
855
    string(STRIP ${lib_var} lib_var)
856
    LIST(APPEND SCALFMM_COMPILE_LIBS   ${lib_var})
857
  endforeach()
858
  configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/Src/ScalFmmConfig.h.cmake
859
    ${CMAKE_CURRENT_BINARY_DIR}/Src/ScalFmmConfig.h  )
860 861 862 863 864 865 866 867 868 869 870 871
  #
  ##################################################################
  #                      Build - lib                               #
  ##################################################################
  #
  add_subdirectory(Src)
  # Link with scalfmm lib
  set(scalfmm_lib scalfmm)
  #
  ##################################################################
  #            Remove compilation  of the drivers                  #
  ##################################################################
872
  message(STATUS "SCALFMM_BUILD_EXAMPLES  =  ${SCALFMM_BUILD_EXAMPLES}" ) 
873
  if( SCALFMM_BUILD_EXAMPLES )
874 875 876 877 878 879 880
    # Build - Examples and drivers
    add_subdirectory(Examples)
  endif()
  ##################################################################
  #           Build tools (Internal use)                           #
  ##################################################################
  # Build - UTILs
881
  if( SCALFMM_ONLY_DEVEL AND SCALFMM_BUILD_UTILS)
882
    add_subdirectory(Utils)
883
  endif()
884

885 886 887 888
  ##################################################################
  #                Build -Tests to see examples                    #
  ##################################################################
  # Build - Tests
889 890
  message( STATUS "SCALFMM_BUILD_TESTS          = ${SCALFMM_BUILD_TESTS}" )
  if( SCALFMM_BUILD_TESTS )
891 892
    add_subdirectory(Tests)
  endif()
berenger-bramas's avatar
berenger-bramas committed
893

894 895 896 897
  ##################################################################
  #              Build - Unitary and numerical Tests               #
  ##################################################################
  #
898 899
  message( STATUS "SCALFMM_BUILD_UTESTS         = ${SCALFMM_BUILD_UTESTS}" )
  if( SCALFMM_BUILD_UTESTS )
900 901 902 903
    include(CTest)
    enable_testing()
    add_subdirectory(UTests)
  endif()
904
  #
905 906 907
  ##################################################################
  #                           Add - doc                            #
  ##################################################################
908
  #
COULAUD Olivier's avatar
COULAUD Olivier committed
909
  message(STATUS "SCALFMM_BUILD_DOC           =  ${SCALFMM_BUILD_DOC}" ) 
910 911 912
  if(SCALFMM_BUILD_DOC)
    add_subdirectory(Doc)
  endif()
913
  #
914 915 916 917
  ##################################################################
  #                       Build - Addons                           #
  ##################################################################
  #
918
  if( SCALFMM_USE_ADDONS )
919 920
    file(GLOB all_addons ./Addons/*)
    # Options
921
    option( SCALFMM_ADDON_CKERNELAPI "Set to ON to build ScaFMM FMM API interface" OFF )
922

923 924 925 926
    foreach(addon_name ${all_addons})
      message(STATUS "Addons += ${addon_name}" )
      add_subdirectory(${addon_name})
    endforeach()
927
  endif()
928

929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
  # 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                  #
  #                                                                #
  ##################################################################
  #
944 945 946
  message(STATUS "SCALFMM_BINARY_DIR:          " ${SCALFMM_BINARY_DIR})
  configure_file(${SCALFMM_SOURCE_DIR}/ScalFMMConfig.cmake.in
    ${SCALFMM_BINARY_DIR}/ScalFMMConfig.cmake
947 948 949
    @ONLY IMMEDIATE
    )
  #
950 951 952
  install(FILES  ${SCALFMM_BINARY_DIR}/ScalFMMConfig.cmake  DESTINATION lib/  )
  if( SCALFMM_INSTALL_DATA )
    install(FILES  ${SCALFMM_SOURCE_DIR}/Data/test20k.fma  DESTINATION Data/   )
953
  endif()
954
  #
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972
  ##################################################################
  #                                                                #
  #              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")
973 974
  set(CPACK_PACKAGE_VERSION_MAJOR "${SCALFMM_MAJOR_VERSION}")
  set(CPACK_PACKAGE_VERSION_MINOR "${SCALFMM_MINOR_VERSION}")
975
  #
976
  set(PACK_PACKAGE_VERSION "${SCALFMM_MAJOR_VERSION}.${SCALFMM_MINOR_VERSION}-${CPACK_PACKAGE_VERSION_PATCH}")
977
  set(CPACK_SOURCE_GENERATOR "TGZ")
978
  set(CPACK_SOURCE_PACKAGE_FILE_NAME  "SCALFMM-${SCALFMM_MAJOR_VERSION}.${SCALFMM_MINOR_VERSION}-${CPACK_PACKAGE_VERSION_PATCH}")
979 980
  set(CPACK_SOURCE_IGNORE_FILES "\\\\.git;.DS_Store;.*~;/*.aux;/*.idx;/*.log;/*.out;/*.toc;/*.ilg;scalfmm.pro*;org.eclipse.core.resources.prefs;.cproject;.project;/.settings/,/FmmApi/")
  list(APPEND CPACK_SOURCE_IGNORE_FILES  "${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}/Utils/;Notes;Deprecated;/Build*;/noDist/;/Bench/;/Obsolete/;ToRemove;Olivier;Addons/HMat")
981
  # Uniform;GroupTree;Adaptive;testUnif*;/*Lagrange*")
982
  #list(APPEND CPACK_SOURCE_IGNORE_FILES  "Stages;Uniform;O;testUnif*;*Lagrange*" )
983 984 985 986 987 988 989 990 991
  #
  include(CPack)
  #
  #
  ##################################################################
  #                                                                #
  #                      PRINT messages                            #
  #                                                                #
  ##################################################################
992
  message(STATUS "CPACK_SOURCE_IGNORE_FILES      = ${CPACK_SOURCE_IGNORE_FILES}")
993 994 995
  message(STATUS "CPACK_SOURCE_PACKAGE_FILE_NAME = ${CPACK_SOURCE_PACKAGE_FILE_NAME}")
  #
  #                    Use Mem stats
996
  message(STATUS "SCALFMM_USE_MEM_STATS = ${SCALFMM_USE_MEM_STATS}" )
997
  #                    Use Log
998
  message(STATUS "SCALFMM_USE_LOG       = ${SCALFMM_USE_LOG}" )
999
  #                    Use Assert
1000
  message(STATUS "SCALFMM_USE_ASSERT    = ${SCALFMM_USE_ASSERT}" )
1001
  #
1002
  message(STATUS "SCALFMM_USE_BLAS      =  ${SCALFMM_USE_BLAS}")
COULAUD Olivier's avatar
??  
COULAUD Olivier committed
1003
  message(STATUS "SCALFMM_USE_FFT       =  ${SCALFMM_USE_FFT}")
1004
  message(STATUS "SCALFMM_USE_MKL       =   ${SCALFMM_USE_MKL}")
COULAUD Olivier's avatar
COULAUD Olivier committed
1005
  # 
1006 1007 1008 1009 1010
  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}")
  #
1011 1012 1013
  ##################################################################
  #                               END                              #
  ##################################################################
1014
  #
1015
else(MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/morse/")
1016 1017 1018 1019 1020 1021 1022

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

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