CMakeLists.txt 12 KB
Newer Older
1
 cmake_minimum_required (VERSION 2.8.3 FATAL_ERROR)
2 3 4
if(CMAKE_MAJOR_VERSION GREATER 1 AND CMAKE_MINOR_VERSION GREATER 7 AND CMAKE_PATCH_VERSION GREATER 11)
  cmake_policy(SET CMP0022 OLD)
endif()
5
cmake_policy(SET CMP0004 OLD)
berenger-bramas's avatar
berenger-bramas committed
6 7
# check if compiling into source directories
STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" insource)
8
if(insource)
berenger-bramas's avatar
berenger-bramas committed
9
    MESSAGE(FATAL_ERROR "${PROJECT_NAME} requires an out of source build. Goto ./Build and tapes cmake ../")
10
endif(insource)
BRAMAS Berenger's avatar
BRAMAS Berenger committed
11 12 13 14 15

#
# MPI option has to be set before project, cannot be changed in the cache!
if( ScalFMM_USE_MPI )
	include(CMakeForceCompiler)
16
	CMAKE_FORCE_C_COMPILER(mpicc    "MPI C Compiler") 
BRAMAS Berenger's avatar
BRAMAS Berenger committed
17
    	CMAKE_FORCE_CXX_COMPILER(mpicxx "MPI C++ Compiler")
BRAMAS Berenger's avatar
BRAMAS Berenger committed
18
	set(ScalFMM_USE_MPI ON CACHE BOOL "ScalFmm use MPI")
BRAMAS Berenger's avatar
BRAMAS Berenger committed
19 20 21 22
else()
	MESSAGE(STATUS "Remove CMake cache and run cmake .. -DScalFMM_USE_MPI=ON to enable MPI" )
endif(ScalFMM_USE_MPI)

23
#
COULAUD Olivier's avatar
COULAUD Olivier committed
24 25 26 27 28 29 30 31
# Project Infos
project(ScalFMM)
#===========================================================================
# Version Number
#===========================================================================

# ScalFMM version number.  An even minor number corresponds to releases.
SET(ScalFMM_MAJOR_VERSION 1)
32
SET(ScalFMM_MINOR_VERSION 2)
33 34
SET(ScalFMM_PATCH_VERSION 1)
SET(ScalFMM_VERSION  "${ScalFMM_MAJOR_VERSION}.${ScalFMM_MINOR_VERSION}.${ScalFMM_PATCH_VERSION}" )
COULAUD Olivier's avatar
COULAUD Olivier committed
35 36

#
37 38 39
# Active language
# -----------------------
ENABLE_LANGUAGE(CXX )
40
MESSAGE(STATUS " CXX  ${CMAKE_CXX_COMPILER_ID}" )
BRAMAS Berenger's avatar
BRAMAS Berenger committed
41

42
#
berenger-bramas's avatar
berenger-bramas committed
43
# Options
BRAMAS Berenger's avatar
BRAMAS Berenger committed
44
OPTION( ScalFMM_USE_BLAS 		"Set to ON to build ScaFMM with BLAS" OFF )
45
OPTION( ScalFMM_USE_FFT  		"Set to ON to build ScaFMM with FFTW" OFF )
BRAMAS Berenger's avatar
BRAMAS Berenger committed
46
OPTION( ScalFMM_USE_TRACE 		"Set to ON to print trace or use itac trace" OFF )
47
OPTION( ScalFMM_BUILD_TESTS 		"Set to ON to build functionalities Tests" OFF )
BRAMAS Berenger's avatar
BRAMAS Berenger committed
48
OPTION( ScalFMM_BUILD_UTESTS 		"Set to ON to build UTests" OFF )
49 50 51 52 53 54
OPTION( ScalFMM_BUILD_DEBUG          "Set to ON to build in Debug"                 OFF )
OPTION( ScalFMM_USE_LOG              "Set to ON to print output debug information" OFF )
OPTION( ScalFMM_USE_MEM_STATS        "Set to ON to profile memory"                 OFF )
OPTION( ScalFMM_USE_DOUBLE_PRECISION "Set to ON to compile in double precision"    ON  )
OPTION( ScalFMM_ATTACHE_SOURCE       "Set to ON to compile with -g"                OFF )
OPTION( ScalFMM_USE_ADDONS           "Set to ON to compile add ons"                OFF )
55
OPTION( ScalFMM_USE_SSE              "Set to ON to compile with SSE support"       ON  )
56
OPTION( ScalFMM_USE_AVX              "Set to ON to compile with AVX support"       OFF  )
BRAMAS Berenger's avatar
BRAMAS Berenger committed
57
OPTION( ScalFMM_USE_ASSERT           "Set to ON to enable safe tests during execution" ON  )
58
OPTION( ScalFMM_USE_MIC_NATIVE       "Set to ON to compile in native mode for MIC" OFF  )
59
# Set scalfmm to default libraries
60
SET(SCALFMM_LIBRARIES "")
61 62 63 64 65
#
# Compile option
#
SET(ScaLFMM_CXX_FLAGS "-std=c++11 -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wconversion -fpic")
#
66
# Test if openmp is here
67
#
68 69
find_package (OpenMP) 
if(OPENMP_FOUND)
COULAUD Olivier's avatar
COULAUD Olivier committed
70
	set(CMAKE_C_FLAGS            "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
71
	set(CMAKE_CXX_FLAGS          "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
COULAUD Olivier's avatar
COULAUD Olivier committed
72
	set(CMAKE_EXE_LINKER_FLAGS   "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
73 74
endif(OPENMP_FOUND)
MESSAGE(STATUS "ScalFMM_BUILD_DEBUG          = ${ScalFMM_BUILD_DEBUG}" )
75 76 77 78 79 80
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  SET(FLAGS_64bits "-m64")
else()
  SET(FLAGS_64bits "")
endif()
#
berenger-bramas's avatar
berenger-bramas committed
81
# Debug
82
#
83
if( ScalFMM_BUILD_DEBUG )
84 85 86
#
# Compile Debug flags
#
berenger-bramas's avatar
berenger-bramas committed
87
  SET(CMAKE_BUILD_TYPE Debug)
88
  ADD_DEFINITIONS(-O0)
89
  IF( APPLE ) 
90
    SET(SCALFMM_FLAGS_OPTI_DEBUG "-m64  -funroll-loops" CACHE STRING "Set your optimization flags for debug mode.")
91
  ELSE(APPLE)
92
    SET(SCALFMM_FLAGS_OPTI_DEBUG "${FLAGS_64bits} -fp-model strict  -funroll-loops" CACHE STRING "Set your optimization flags for debug mode.")
93 94 95
  ENDIF(APPLE)
#  ADD_DEFINITIONS(${SCALFMM_FLAGS_OPTI_DEBUG})
  SET(ScaLFMM_CXX_FLAGS  "${ScaLFMM_CXX_FLAGS} ${SCALFMM_FLAGS_OPTI_DEBUG}")
96
else()
97 98 99
#
# Compile Release flags
#
100
  SET(CMAKE_BUILD_TYPE Release)
BRAMAS Berenger's avatar
BRAMAS Berenger committed
101 102 103
  # force -O3 in release
  SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
  STRING(REPLACE "-O2" "" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} )
104
  # if compiler is intel add -ip
105
  IF(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
106
    SET(ScaLFMM_CXX_FLAGS  "${ScaLFMM_CXX_FLAGS} -ip -no-prec-div -no-prec-sqrt")
107
  ENDIF()
108 109 110

  # Compile optimization
  IF( APPLE ) 
111 112
    SET(SCALFMM_FLAGS_OPTI_RELEASE "-m64  -funroll-loops" CACHE STRING "Set your optimization flags for release mode.")
  ELSE(APPLE)
113 114
    # Not apple system - Check the compilater flags 
    if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
115
      SET(SCALFMM_FLAGS_OPTI_RELEASE "${FLAGS_64bits} -march=native -fp-model precise -fp-model source -fimf-precision=low  -funroll-loops -ftree-vectorize" CACHE STRING "Set your optimization flags for release mode.")
116
    else()
117
      SET(SCALFMM_FLAGS_OPTI_RELEASE "${FLAGS_64bits} -ffast-math -flto -funroll-loops -ftree-vectorize" CACHE STRING "Set your optimization flags for release mode.")
118
    endif()
119
  ENDIF(APPLE)
120
#
121
  SET(ScaLFMM_CXX_FLAGS  "${ScaLFMM_CXX_FLAGS} ${SCALFMM_FLAGS_OPTI_RELEASE}")
berenger-bramas's avatar
berenger-bramas committed
122
endif()
123
#
124
# Attach source code to exec
125 126
MESSAGE(STATUS "ScalFMM_ATTACHE_SOURCE       = ${ScalFMM_ATTACHE_SOURCE}" )
if( ScalFMM_ATTACHE_SOURCE )
127
  MESSAGE( STATUS "Option -g is used, the code is attached to the binary." )
128 129 130
#  ADD_DEFINITIONS(-g)
    SET(ScaLFMM_CXX_FLAGS  "${ScaLFMM_CXX_FLAGS} -g")

131 132
endif()

133
# Trace
134 135 136 137
MESSAGE( STATUS "ScalFMM_USE_TRACE            = ${ScalFMM_USE_TRACE}" )
if( ScalFMM_USE_TRACE )
  OPTION( ScalFMM_USE_ITAC "Set to ON to use itac trace" OFF )
  if( ScaLFMM_USE_ITAC )
138 139
    ADD_DEFINITIONS(-I$VT_ROOT/include -trace)
  endif()
140 141
endif()

142
# Blas option
143 144 145
if( ScalFMM_USE_BLAS )
  OPTION( ScalFMM_USE_MKL_AS_BLAS "Set to ON to use MKL CBLAS" OFF )
  if( ScalFMM_USE_MKL_AS_BLAS )
146 147
     SET(BLAS_LIBRARIES
  "-L$ENV{MKLROOT}/lib;-lmkl_intel_lp64;-lmkl_sequential;-lmkl_core" CACHE STRING "Set your MKL flags")
148
     SET(LAPACK_LIBRARIES "")
149 150
  elseif(ScalFMM_USE_EXTERNAL_BLAS) 
         MESSAGE(STATUS "BLAS SET BY EXTERNAL PROGRAM = ${BLAS_LIBRARIES}")
151
  else()
BRAMAS Berenger's avatar
BRAMAS Berenger committed
152 153
	INCLUDE(FindBLAS)
	INCLUDE(FindLAPACK)
154
  endif()
155 156
  SET(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES};${BLAS_LIBRARIES};${LAPACK_LIBRARIES}")
  MESSAGE(STATUS "SCALFMM_LIBRARIES          = ${SCALFMM_LIBRARIES}")
157
endif(ScalFMM_USE_BLAS)
158

159 160
# FFT option
if( ScalFMM_USE_FFT )
161 162
  OPTION( ScalFMM_USE_MKL_AS_FFTW "Set to ON to use MKL FFTW" ON )
  if( ScalFMM_USE_MKL_AS_FFTW )
163 164
    SET(FFT_LIBRARIES "-L$ENV{MKLROOT}/lib; -lmkl_intel_lp64; -lmkl_sequential; -lmkl_core; -lpthread; -lm" CACHE STRING "Set your MKL flags")
    SET(FFT_INCLUDES "$ENV{MKLROOT}/include/fftw" CACHE STRING "Set your MKL flags")
165
  else()
166
    SET(FFT_LIBRARIES "-lfftw3" CACHE STRING "Use LIBFFTW")
167
  endif()
168
  SET(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES}; ${FFT_LIBRARIES}")
169
  SET(SCALFMM_INCLUDES "${SCALFMM_INCLUDES}; ${FFT_INCLUDES}")
170
  MESSAGE(STATUS "SCALFMM_LIBRARIES          = ${SCALFMM_LIBRARIES}")
171
  MESSAGE(STATUS "SCALFMM_INCLUDES          = ${SCALFMM_INCLUDES}")
172
endif(ScalFMM_USE_FFT)
173

174
# Compile option
175
#ADD_DEFINITIONS(-Wall -Wshadow -Wpointer-arith -Wcast-qual -Wconversion -fpic )
176 177
# 
# C++ 2011
178
#ADD_DEFINITIONS(-std=c++11)
179
IF(CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND APPLE)
180 181 182 183 184 185 186
  execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE INTEL_VERSION)
#  MESSAGE( "CMAKE_SYSTEM:   ${CMAKE_SYSTEM}  ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION}")
#  MESSAGE( "Intel:   ${INTEL_VERSION}")
  if( ${CMAKE_SYSTEM_VERSION} EQUAL 13 AND  ${INTEL_VERSION} GREATER 13.0 )
    SET(SCALFMM_LIBRARIES "${SCALFMM_LIBRARIES} -stdlib=libc++")
    SET(ScaLFMM_CXX_FLAGS "${ScaLFMM_CXX_FLAGS} -stdlib=libc++")
  endif()
187
endif()
berenger-bramas's avatar
berenger-bramas committed
188

Arnaud's avatar
Arnaud committed
189
CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/Src/ScalFmmConfig.h.cmake 
190
		${CMAKE_BINARY_DIR}/Src/ScalFmmConfig.h  )
191

192 193 194 195 196 197
##################################################################
#                     Use  native MIC compilation                #
##################################################################
if( ScalFMM_USE_MIC_NATIVE ) 
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmic")
else()
198
 # SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xhost")
199 200 201 202
ENDIF()
##################################################################
#                             Use SSE                            #
##################################################################
203

204 205
MESSAGE( STATUS "ScalFMM_USE_SSE              = ${ScalFMM_USE_SSE}" )
if( ScalFMM_USE_SSE )
206
  IF(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
207
#    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -vec -axSSE4.2")
208 209 210
  ELSE()
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse -msse2 -msse3 -mfpmath=sse")
  ENDIF()
211
endif()
212 213 214
##################################################################
#                             Use AVX                            #
##################################################################
215 216 217 218

MESSAGE(STATUS "ScalFMM_USE_AVX               = ${ScalFMM_USE_AVX}")
if(ScalFMM_USE_AVX)
  IF(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
219
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
220 221 222
  ELSE()
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse -msse2 -msse3 -mfpmath=sse -mavx")
  ENDIF()
223
MESSAGE(STATUS ${CMAKE_CXX_FLAGS} )
224 225 226 227
endif()



228 229
if( ScalFMM_USE_MIC_NATIVE ) 
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmic")
230

231
ENDIF()
232
# Use Mem stats
233
MESSAGE( STATUS "ScalFMM_USE_MEM_STATS        = ${ScalFMM_USE_MEM_STATS}" )
234

BRAMAS Berenger's avatar
BRAMAS Berenger committed
235 236 237 238 239 240
# Use Log
MESSAGE( STATUS "ScalFMM_USE_LOG              = ${ScalFMM_USE_LOG}" )

# Use Assert
MESSAGE( STATUS "ScalFMM_USE_ASSERT           = ${ScalFMM_USE_ASSERT}" )

241 242 243
# Add CBLAS
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}  ${CBLAS_LIBRARIES}")

berenger-bramas's avatar
berenger-bramas committed
244
# Build - lib
245
add_subdirectory(Src)
berenger-bramas's avatar
berenger-bramas committed
246

247 248 249
# Link with scalfmm lib
set(scalfmm_lib scalfmm)

250 251 252 253
# Build - Examples and drivers
add_subdirectory(Examples)


berenger-bramas's avatar
berenger-bramas committed
254
# Build - Tests
255 256
MESSAGE( STATUS "ScalFMM_BUILD_TESTS          = ${ScalFMM_BUILD_TESTS}" )
if( ScalFMM_BUILD_TESTS )
berenger-bramas's avatar
berenger-bramas committed
257 258 259 260
	add_subdirectory(Tests)
endif()

# Build - UTests
261 262
MESSAGE( STATUS "ScalFMM_BUILD_UTESTS         = ${ScalFMM_BUILD_UTESTS}" )
if( ScalFMM_BUILD_UTESTS )
berenger-bramas's avatar
berenger-bramas committed
263
	ENABLE_TESTING()
berenger-bramas's avatar
berenger-bramas committed
264 265
	add_subdirectory(UTests)
endif()
berenger-bramas's avatar
berenger-bramas committed
266 267 268

# Build - doc
add_subdirectory(Doc)
269

270
# Build - Addons
271
if( ScalFMM_USE_ADDONS )
272 273 274 275 276 277 278 279
	file(GLOB all_addons ./Addons/*)

	foreach(addon_name ${all_addons}) 
		MESSAGE(STATUS "Addons += ${addon_name}" )
		add_subdirectory(${addon_name})
	endforeach()
endif()

280 281 282
# Add custom clean command
if("${CMAKE_GENERATOR}" MATCHES "Make")
	ADD_CUSTOM_TARGET(reset
283
		COMMAND ${CMAKE_MAKE_PROGRAM} clean && rm -r ./CMake* && cmake ..
284 285 286 287
		WORKING_DIRECTORY ${CMAKE_CURRENT_DIR}
		COMMENT "Cleaning Build dir and CMake cache, then do cmake.."
		)
endif()
COULAUD Olivier's avatar
COULAUD Olivier committed
288 289 290 291 292 293
#
#
#===========================================================================
#    Build and export cmake files 
#===========================================================================
#
294
MESSAGE(STATUS "ScalFMM_BINARY_DIR:          " ${ScalFMM_BINARY_DIR})
COULAUD Olivier's avatar
COULAUD Olivier committed
295 296 297 298 299 300 301
CONFIGURE_FILE(${ScalFMM_SOURCE_DIR}/ScalFMMConfig.cmake.in
               ${ScalFMM_BINARY_DIR}/ScalFMMConfig.cmake 
               @ONLY IMMEDIATE
               )
INSTALL(FILES 
  ${ScalFMM_BINARY_DIR}/ScalFMMConfig.cmake
  DESTINATION lib/
COULAUD Olivier's avatar
s  
COULAUD Olivier committed
302
  )
303 304 305 306 307 308 309 310 311
#
# Add CPACK Module
# ----------------
#
# build a CPack driven installer package
set (CPACK_RESOURCE_FILE_LICENSE  
     "${CMAKE_CURRENT_SOURCE_DIR}/Licence.txt")
SET(CPACK_PACKAGE_VERSION_MAJOR "${ScalFMM_MAJOR_VERSION}")
SET(CPACK_PACKAGE_VERSION_NINOR "${ScalFMM_MINOR_VERSION}")
312 313 314 315 316 317 318 319
#
# Use git commit number as   CPACK_PACKAGE_VERSION_PATCH
execute_process(
        COMMAND git rev-list HEAD --count
        OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
        RESULT_VARIABLE RET
        ERROR_QUIET
  )
320 321 322 323 324 325 326
SET(CPACK_INCLUDE_TOPLEVEL_DIRECTORY "ON")
#
SET(CPACK_SOURCE_GENERATOR "TGZ")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME  "ScalFMM-${ScalFMM_VERSION}") 
SET(CPACK_SOURCE_IGNORE_FILES "\\\\.git;.DS_Store;.*~;/*.aux;/*.idx;/*.log;/*.out;/*.toc;/*.ilg;/*.ind;scalfmm.pro*")
LIST(APPEND CPACK_SOURCE_IGNORE_FILES "${CMAKE_BINARY_DIR}")
#
BRAMAS Berenger's avatar
BRAMAS Berenger committed
327
INCLUDE(CPack)
328 329 330
#
# OUTPUT
#
331
MESSAGE(STATUS "CMAKE_CXX_FLAGS   =  ${CMAKE_CXX_FLAGS}")
332 333
MESSAGE(STATUS "ScaLFMM_CXX_FLAGS   =  ${ScaLFMM_CXX_FLAGS}")
MESSAGE(STATUS "SCALFMM_LIBRARIES   =  ${SCALFMM_LIBRARIES}")
334
MESSAGE(STATUS "SCALFMM_INCLUDES   =  ${SCALFMM_INCLUDES}")