CMakeLists.txt 61.8 KB
Newer Older
1
# The YADE has the following parameters to configure:
2
#  CMAKE_INSTALL_PREFIX: path, where Yade will be installed (/usr/local by default)
3 4
#  LIBRARY_OUTPUT_PATH: path to install libraries (lib by default)
#  DEBUG: compile in debug-mode (OFF by default)
Janek Kozicki's avatar
Janek Kozicki committed
5
#  ENABLE_LOGGER: use boost::log library for logging (ON by default)
6
#  MAX_LOG_LEVEL: set maximum level for LOG_* macros compiled with ENABLE_LOGGER. For production build use MAX_LOG_LEVEL<=5, to avoid filter integer comparison on each call to LOG_TRACE(…)
7
#  ENABLE_USEFUL_ERRORS: enable useful compiler errors which help a lot in error-free development.
8 9 10 11 12 13 14 15
#  CMAKE_VERBOSE_MAKEFILE: output additional information during compiling (OFF by default)
#  SUFFIX: suffix, added after binary-names (version number by default)
#  NOSUFFIX: do not add a suffix after binary-name (OFF by default)
#  YADE_VERSION: explicitely set version number (is defined from git-directory by default)
#  ENABLE_GUI: enable GUI option (ON by default)
#  ENABLE_CGAL: enable CGAL option (ON by default)
#  ENABLE_VTK: enable VTK-export option (ON by default)
#  ENABLE_OPENMP: enable OpenMP-parallelizing option (ON by default)
16
#  ENABLE_MPI : Enable MPI communications in Yade. Used for Yade-OpenFOAM coupling.
17 18
#  ENABLE_GTS: enable GTS-option (ON by default)
#  ENABLE_GL2PS: enable GL2PS-option (ON by default)
19 20
#  ENABLE_LINSOLV: enable LINSOLV-option (ON by default)
#  ENABLE_PFVFLOW: enable PFVFLOW-option, FlowEngine (ON by default)
bchareyre's avatar
bchareyre committed
21
#  ENABLE_TWOPHASEFLOW: enable TWOPHASEFLOW-option, TwoPhaseFlowEngine (ON by default)
Anton Gladky's avatar
Anton Gladky committed
22
#  ENABLE_LBMFLOW: enable LBMFLOW-option, LBM_ENGINE (ON by default)
23
#  ENABLE_SPH: enable SPH-option, Smoothed Particle Hydrodynamics (OFF by default)
24
#  ENABLE_LIQMIGRATION: enable LIQMIGRATION-option, see [Mani2013] for details (OFF by default)
25
#  ENABLE_MASK_ARBITRARY: enable MASK_ARBITRARY option (OFF by default)
Anton Gladky's avatar
Anton Gladky committed
26
#  ENABLE_PROFILING: enable profiling, e.g. shows some more metrics, which can define bottlenecks of the code (OFF by default)
Vasileios Angelidakis's avatar
Vasileios Angelidakis committed
27 28
#  ENABLE_POTENTIAL_BLOCKS: enable potential blocks option (ON by default)
#  ENABLE_POTENTIAL_PARTICLES: enable potential particles option (ON by default)
29
#  ENABLE_DEFORM: enable constant volume deformation engine (OFF by default)
30
#  ENABLE_FEMLIKE: enable meshed solids (FEM-like)
William Chèvremont's avatar
William Chèvremont committed
31
#  ENABLE_OAR: generate a script for oar-based task scheduler (OFF by default)
32
#  ENABLE_ASAN: AddressSanitizer build, please see documentation (OFF by default)
33
#  ENABLE_MPFR: use https://www.mpfr.org/ library, can be used for higher precision calculations or for CGAL exact predicates (OFF by default)
Robert Caulk's avatar
Robert Caulk committed
34
#  ENABLE_PARTIALSAT: enable the partially saturated clay engine, under construction (OFF by default)
35
#  REAL_PRECISION_BITS , REAL_DECIMAL_PLACES: specify either of them to use a custom calculation precision. By default double (64 bits, 15 decimal places) precision is used.
36
#  runtimePREFIX: used for packaging, when install directory is not the same is runtime directory (/usr/local by default)
37
#  CHUNKSIZE: set >1, if you want several sources to be compiled at once. Increases compilation speed and RAM-consumption during it (1 by default)
38
#  VECTORIZE: enables vectorization and alignment in Eigen3 library, experimental (OFF by default)
Anton Gladky's avatar
Anton Gladky committed
39
#  USE_QT5: use QT5 for GUI (ON by default)
40
#  CHOLMOD_GPU link Yade to custom SuiteSparse installation and activate GPU accelerated PFV (OFF by default)
41
#  SUITESPARSEPATH: define this variable with the path to a custom suitesparse install
42
#  PYTHON_VERSION: force python version to the given one, set -1 to automatically use the last version on the system. (-1 by default)
43

44
project(Yade C CXX)
45
cmake_minimum_required(VERSION 3.5.0)
46 47 48 49 50
IF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0)
  set (CMAKE_CXX_STANDARD 14)
ELSE()
  set (CMAKE_CXX_STANDARD 17)
ENDIF()
51
set (CMAKE_CXX_STANDARD_REQUIRED ON)
52

53
# https://misc.flogisoft.com/bash/tip_colors_and_formatting
54 55 56
# https://stackoverflow.com/questions/18968979/how-to-get-colorized-output-with-cmake , use ${Esc} for printing colors
string(ASCII 27 Esc)
# To have a cmake option with multiple values I used https://cmake.org/pipermail/cmake/2016-October/064342.html
57 58
# set maximum level for LOG_* macros compiled with ENABLE_LOGGER. For production build use MAX_LOG_LEVEL below 5, to avoid filter integer comparison on each call to LOG_TRACE(…)
set(MAX_LOG_LEVEL "5" CACHE STRING "default MAX_LOG_LEVEL")
59 60
set_property(CACHE MAX_LOG_LEVEL PROPERTY STRINGS "0" "1" "2" "3" "4" "5" "6")  # define list of values GUI will offer for the variable

61 62 63 64 65 66 67

#===========================================================
SET(DEFAULT ON CACHE INTERNAL "Default value for enabled by default options")
SET(LINKLIBS "")
SET(CONFIGURED_FEATS "")
SET(DISABLED_FEATS "")

Janek Kozicki's avatar
Janek Kozicki committed
68
OPTION(ENABLE_LOGGER "use boost::log library for logging (ON by default)" ON)
69
OPTION(ENABLE_USEFUL_ERRORS "enable useful compiler errors which help a lot in error-free development." ON)
70 71
OPTION(ENABLE_VTK "Enable VTK" ${DEFAULT})
OPTION(ENABLE_OPENMP "Enable OpenMP" ${DEFAULT})
72
OPTION(ENABLE_MPI "Enable MPI environement and communications, required for coupling Yade with OpenFOAM  " ON)
73 74 75 76 77 78 79 80 81 82 83 84
OPTION(ENABLE_GTS "Enable GTS" ${DEFAULT})
OPTION(ENABLE_GUI "Enable GUI" ${DEFAULT})
OPTION(ENABLE_CGAL "Enable CGAL" ${DEFAULT})
OPTION(ENABLE_GL2PS "Enable GL2PS" ${DEFAULT})
OPTION(ENABLE_LINSOLV "Enable direct solver for the flow engines (experimental)" ${DEFAULT})
OPTION(ENABLE_PFVFLOW "Enable one-phase flow engines" ${DEFAULT})
OPTION(ENABLE_TWOPHASEFLOW "Enable two-phase flow engines" ${DEFAULT})
OPTION(ENABLE_SPH "Enable SPH" OFF)
OPTION(ENABLE_LBMFLOW "Enable LBM engine (very experimental)" ON)
OPTION(ENABLE_LIQMIGRATION "Enable liquid control (very experimental), see [Mani2013] for details" OFF)
OPTION(ENABLE_MASK_ARBITRARY "Enable arbitrary precision of bitmask variables (only Body::groupMask yet implemented) (experimental). Use -DMASK_ARBITRARY_SIZE=int to set number of used bits (256 by default)" OFF)
OPTION(ENABLE_PROFILING "Enable profiling, e.g. shows some more metrics, which can define bottlenecks of the code (OFF by default)" OFF)
85
OPTION(ENABLE_POTENTIAL_PARTICLES "Enable potential particles" ON)
86
OPTION(ENABLE_OAR "Generate script for oar-based task scheduler" OFF)
87
OPTION(ENABLE_MPFR "Use mpfr library (higher precision calculations or CGAL exact predicates)" OFF)
88
OPTION(USE_QT5 "USE Qt5 for GUI" ON)
89
OPTION(ENABLE_POTENTIAL_BLOCKS "Enable PotentialBlocks" ON)
90
OPTION(ENABLE_DEFORM "Enable Deformation Engine" OFF)
91
OPTION(ENABLE_FEMLIKE "Enable deformable solids" ON)
92
OPTION(CHOLMOD_GPU "Enable GPU acceleration flow engine direct solver" OFF)
93
OPTION(ENABLE_THERMAL "Enable thermal engine (experimental)" ON)
94
OPTION(ENABLE_ASAN "Enable AddressSanitizer build, please see documentation" OFF)
Robert Caulk's avatar
Robert Caulk committed
95
OPTION(ENABLE_PARTIALSAT "Enable the partially saturated clay engine" OFF)
96
#Set -DPYTHON_VERSION numeric option below:
97
set(PYTHON_VERSION -1 CACHE STRING "Force python version to the given one. Defaults to -DPYTHON_VERSION=-1 which automatically uses the newest available python version on the system.")
98 99
#===========================================================

Anton Gladky's avatar
Anton Gladky committed
100

101 102

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cMake")
103

104 105 106
INCLUDE(GetVersion)
INCLUDE(GNUInstallDirs)

107 108
INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR})

109
#===========================================================
110
# HACK!!! If the version of gcc is 4.8 or greater, we add -ftrack-macro-expansion=0
111
# and -save-temps into compiler to reduce the memory consumption during compilation.
112 113 114
# See http://bugs.debian.org/726009 for more information
# Can be removed later, if gcc fixes its regression
# Taken from http://stackoverflow.com/questions/4058565/check-gcc-minor-in-cmake
115

116 117 118
# this line was trying to get the g++ version. But it does not work with ccache.
# But we already have CMAKE_CXX_COMPILER_VERSION, so we don't need this line!
#EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
Anton Gladky's avatar
Anton Gladky committed
119 120

IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")  # Check whether we compile with GCC
Anton Gladky's avatar
Anton Gladky committed
121
  IF (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.8)
Anton Gladky's avatar
Anton Gladky committed
122 123 124 125 126
    MESSAGE(STATUS "GCC Version >= 4.8. Adding -ftrack-macro-expansion=0")
    ADD_DEFINITIONS("-ftrack-macro-expansion=0")
  ELSE()
    MESSAGE(STATUS "GCC Version < 4.8. will not use -ftrack-macro-expansion=0")
  ENDIF()
127 128 129
ENDIF()

# -save-temps is not supported with ccache
130
IF ((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.8) AND ( NOT "${CMAKE_CXX_COMPILER_LAUNCHER}" MATCHES ".*ccache" AND NOT "${CMAKE_CXX_COMPILER}" MATCHES ".*ccache.*" AND NOT DISABLE_SAVE_TEMPS))
131 132
  MESSAGE(STATUS "GCC Version >= 4.8. Adding -save-temps")
  ADD_DEFINITIONS("-save-temps")
133 134 135 136 137 138
ELSE()
  IF ( "${CMAKE_CXX_COMPILER_LAUNCHER}" MATCHES ".*ccache" OR "${CMAKE_CXX_COMPILER}" MATCHES ".*ccache.*" )
    MESSAGE(STATUS "ccache detected, will not use -save-temps")
# on ubuntu 18.04 and 18.10 when ccache is used we need to fix some bug, see https://gitlab.kitware.com/cmake/cmake/issues/17275
# but we can't do this on ubuntu 16.04 with cmake version 3.5.1, because that produces error: "list does not recognize sub-command FILTER".
# So we must be above version 3.6, because https://cmake.org/cmake/help/v3.6/release/3.6.html?highlight=filter
Janek Kozicki's avatar
Janek Kozicki committed
139
# Later maybe on some higher cmake version this will become unnecessary.
140 141 142 143 144 145 146 147 148
    IF(CMAKE_VERSION VERSION_GREATER 3.6 OR CMAKE_VERSION VERSION_EQUAL 3.6)
        string (STRIP "${CMAKE_CXX_COMPILER_ARG1}" __CXX_COMPILER_ARG1)
        set(CMAKE_CXX_COMPILER_PREDEFINES_COMMAND "${CMAKE_CXX_COMPILER}" "${__CXX_COMPILER_ARG1}" "-dM" "-E" "-c" "${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp")
        list(FILTER CMAKE_CXX_COMPILER_PREDEFINES_COMMAND EXCLUDE REGEX "^$")
        unset(__CXX_COMPILER_ARG1)
    ENDIF()
  ELSE()
    MESSAGE(STATUS "GCC Version < 4.8 or DISABLE_SAVE_TEMPS. will not use -save-temps")
  ENDIF()
149 150 151
ENDIF()

#===========================================================
152

153
FIND_PACKAGE(Eigen3 REQUIRED)
154

155 156 157 158 159 160 161 162 163 164
#===========================================================
# AddressSanitizer build
IF(ENABLE_ASAN)
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1 -g -fsanitize=address -fno-omit-frame-pointer")
  SET(CMAKE_BUILD_TYPE Debug)
  SET(CMAKE_VERBOSE_MAKEFILE 1)
ENDIF(ENABLE_ASAN)
#===========================================================

IF(DEBUG)
165 166
  SET(CMAKE_VERBOSE_MAKEFILE 1)
  SET(CMAKE_BUILD_TYPE Debug)
167
  ADD_DEFINITIONS("-DYADE_DEBUG")
168
ELSE (DEBUG)
169 170 171 172
  IF (NOT(CMAKE_BUILD_TYPE))
    # If no build_type set, we use Release profile
    SET(CMAKE_BUILD_TYPE Release)
  ENDIF (NOT(CMAKE_BUILD_TYPE))
173
ENDIF (DEBUG)
174

175
IF(ENABLE_LOGGER)
176
  MESSAGE(STATUS "${Esc}[36mLog filtering: enabled${Esc}[0m")
177
  SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} BoostLog")
178 179
  ADD_DEFINITIONS("-DYADE_BOOST_LOG")
  ADD_DEFINITIONS("-DBOOST_LOG_DYN_LINK")
180
  IF (DEBUG)
Janek Kozicki's avatar
Janek Kozicki committed
181
    MESSAGE(STATUS "Enabling boost::log library and DEBUG=ON. Files will be very large with full debug info inside.")
182
    IF(${MAX_LOG_LEVEL} LESS 6)
183
      MESSAGE(STATUS "${Esc}[33mWarning: using DEBUG=ON with MAX_LOG_LEVEL=${MAX_LOG_LEVEL} (less than 6, the maximum log level) rarely makes sense, use cmake option MAX_LOG_LEVEL=6 to fix this.${Esc}[0m")
184
    ENDIF()
185
  ELSE (DEBUG)
Janek Kozicki's avatar
Janek Kozicki committed
186
    MESSAGE(STATUS "Enabling boost::log library and DEBUG=OFF. Logging will work nicely, backtraces will not have debug info, files will be small.")
187
  ENDIF (DEBUG)
188
ELSE(ENABLE_LOGGER)
189
  MESSAGE(STATUS "${Esc}[36mLog filtering: disabled${Esc}[0m")
Janek Kozicki's avatar
Janek Kozicki committed
190 191 192 193 194
  IF (DEBUG)
    MESSAGE(STATUS "Disabling boost::log library (only rudimentary LOG_* macros will work) and DEBUG=ON. Files will be very large with full debug info inside.")
  ELSE (DEBUG)
    MESSAGE(STATUS "Disabling boost::log library (only rudimentary LOG_* macros will work, and only up to LOG_WARN) and DEBUG=OFF. Backtraces will not have debug info, files will be small.")
  ENDIF (DEBUG)
195
ENDIF(ENABLE_LOGGER)
196

197 198
ADD_DEFINITIONS("-DMAX_LOG_LEVEL=${MAX_LOG_LEVEL}")

199 200 201 202 203 204 205
#==================================
#====== *** PYTHON/BOOST *** ======
#==================================
INCLUDE(YadePythonHelpers)

SET(PY3_VERSIONS 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0) #append newer python versions at the beginning here.
SET(PY2_VERSIONS 2.7 2.6)
206 207 208 209

IF (DEFINED PYTHON_EXECUTABLE)
	SET(USER_DEFINED_PYTHON_EX ${PYTHON_EXECUTABLE})
ENDIF()
210 211 212 213 214 215 216 217
IF(${PYTHON_VERSION} EQUAL -1)
	SET(PY_VERSIONS_CHECK "${PY3_VERSIONS};${PY2_VERSIONS}")
ELSEIF(${PYTHON_VERSION} EQUAL 2)
	SET(PY_VERSIONS_CHECK "${PY2_VERSIONS}")
ELSEIF(${PYTHON_VERSION} EQUAL 3)
	SET(PY_VERSIONS_CHECK "${PY3_VERSIONS}")
ELSE()
	SET(PY_VERSIONS_CHECK "${PYTHON_VERSION}")
218 219
ENDIF()

220 221 222 223 224 225 226 227 228
MESSAGE("Loop on the following python versions and check available dependencies:${PY_VERSIONS_CHECK}" )
FOREACH(py_version ${PY_VERSIONS_CHECK})
	#Set desired python version
	set(Python_ADDITIONAL_VERSIONS ${py_version})
	#Find python
	FIND_PACKAGE(PythonInterp)
	IF(NOT PythonInterp_FOUND)
		MESSAGE(FATAL_ERROR "No python version could be found in your system.")
	ENDIF()
229 230 231 232 233
	IF (DEFINED USER_DEFINED_PYTHON_EX)
        	MESSAGE("Using user defined PYTHON_EXECUTABLE: ${USER_DEFINED_PYTHON_EX}")
        	SET(PYTHON_EXECUTABLE ${USER_DEFINED_PYTHON_EX} CACHE FILEPATH "user defined python executable" FORCE)
	ENDIF()

234 235 236
	#FindPythonInterp will try to fallback in older Python version, we have to check manually if it found the version we wish
	PYTHON_VERSION_MATCHES(${py_version})
	IF(NOT ${PYTHON_VERSION_MATCH})
Bruno Chareyre's avatar
Bruno Chareyre committed
237 238 239
	    #Reset variables to be able to use finpythoninterp multiple times
		unset(PYTHON_EXECUTABLE CACHE)
		unset(PYTHONINTERP_FOUND CACHE)
240 241 242 243 244 245 246
		CONTINUE()
	ENDIF()
	MESSAGE("Python version ${PYTHON_VERSION_STRING} found, try to import dependencies...")
	FIND_PYTHON_PACKAGES()
	IF(ALL_PYTHON_DEPENDENCIES_FOUND)
		MESSAGE("Found all python dependencies with version ${PYTHON_VERSION_STRING}, will compile yade with that.")
		BREAK()
247
	ELSE()
Bruno Chareyre's avatar
Bruno Chareyre committed
248
	    #Reset variables to be able to use finpythoninterp multiple times
249 250
		unset(PYTHON_EXECUTABLE CACHE)
		unset(PYTHONINTERP_FOUND CACHE)
251 252
	ENDIF()
ENDFOREACH()
253

254 255 256 257
#After the loop on all python versions, having ALL_PYTHON_DEPENDENCIES_FOUND==FALSE must trigger an error:
IF(NOT ALL_PYTHON_DEPENDENCIES_FOUND)
	MESSAGE(FATAL_ERROR "No python version with all dependencies was found.")
ENDIF()
Anton Gladky's avatar
Anton Gladky committed
258

259 260 261
#======================================
#====== *** END PYTHON/BOOST *** ======
#======================================
Anton Gladky's avatar
Anton Gladky committed
262

263 264 265
#======================================
#====== **** Compiler flags **** ======
#======================================
266 267
if(ENABLE_USEFUL_ERRORS)
  # Enable as many warnings as possible, and treat them as errors (using -Werror flag).
268 269
  # Four warnings are impossible to fix, because they are in external libraries:
  #   (1) libeigen: -Wmaybe-uninitialized, -Wcomment, -Wdeprecated-copy ; and only in g++ 7 or 8: -Wint-in-bool-context
270
  #   (2) open mpi: -Wcast-function-type
271 272
  # Three warnings are impossible to fix, because they are in older compiler, or in older library version
  #   (1) libeigen ver. <=3.3.4 : -Wshadow=compatible-local -Wno-error=float-conversion
273
  #   (2) numpy    ver. < 1.13  : -Wunused-function
274
  # These impossible to fix warnings are in ${WORKAROUND_LIBRARY_WARNINGS}
275 276
  # So depending on compiler version I need to turn these errors off.
  # They will be still printed as warnings. But they will not be an error due to -Werror flag.
277 278 279 280

  # Notes:
  #  -Wfloat-conversion warning: you have to select the int(…) conversion policy: std::floor(…), std::ceil(…), std::round(…), e.g. with int(std::ceil(11.9999999999999993))

Janek Kozicki's avatar
Janek Kozicki committed
281
  # g++ ver < 10 ; all workarounds are for g++ < ver.10; When version 10 appears I hope that there will be fewer warnigs to disable. This 'IF' is to trigger the re-evealuation when g++ v.10 appears.
282
  IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.0 )
283
    SET(WORKAROUND_LIBRARY_WARNINGS " -Wno-error=maybe-uninitialized -Wno-comment")
284 285 286 287
    # g++ ver == 10
    IF (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 10.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 10.0)
      SET(WORKAROUND_LIBRARY_WARNINGS "${WORKAROUND_LIBRARY_WARNINGS} -Wno-cast-function-type")
    ENDif()
Janek Kozicki's avatar
Janek Kozicki committed
288 289
    # g++ ver >= 8
    IF (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 8.0)
290
      SET(WORKAROUND_LIBRARY_WARNINGS "${WORKAROUND_LIBRARY_WARNINGS} -Wno-cast-function-type")
Janek Kozicki's avatar
Janek Kozicki committed
291 292
      # g++ ver >= 9
      IF (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 9.0)
293
        SET(WORKAROUND_LIBRARY_WARNINGS "${WORKAROUND_LIBRARY_WARNINGS} -Wno-deprecated-copy")
Janek Kozicki's avatar
Janek Kozicki committed
294
      ENDIF()
295
    ENDIF()
Janek Kozicki's avatar
Janek Kozicki committed
296 297 298 299
    # g++ ver >= 7
    IF (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 7.0)
      # g++ ver < 8
      IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
300
        SET(WORKAROUND_LIBRARY_WARNINGS "${WORKAROUND_LIBRARY_WARNINGS} -Wno-int-in-bool-context")
Janek Kozicki's avatar
Janek Kozicki committed
301 302 303 304 305 306
      ENDIF()
      # g++ ver >= 7 and eigen > 3.3.4
      IF(NOT ((${EIGEN3_MAJOR_VERSION} EQUAL 3) AND ( (${EIGEN3_MINOR_VERSION} LESS 4) OR (${EIGEN3_MINOR_VERSION} EQUAL 4))))
        # eigen > 3.3.4, (newer than ubuntu 16.04 xenial or 18.04 bionic)
        SET(WORKAROUND_LIBRARY_WARNINGS "${WORKAROUND_LIBRARY_WARNINGS} -Wshadow=compatible-local")
      ENDIF()
307 308
    ENDIF()
  ENDIF()
309

310 311
  IF((${EIGEN3_MAJOR_VERSION} LESS 2) OR (${EIGEN3_MAJOR_VERSION} EQUAL 2))
    # eigen <= 3.2, ubuntu 16.04 xenial
312
    SET(WORKAROUND_LIBRARY_WARNINGS "${WORKAROUND_LIBRARY_WARNINGS} -Wno-error=float-conversion")
313
  ENDIF()
314 315
  IF((${NUMPY_VERSION_MAJOR} EQUAL 1) AND (${NUMPY_VERSION_MINOR} LESS 13))
    # numpy 1.11.0 has unused-function, 1.13 does not. So we have to print warning only when it appears.
316
    SET(WORKAROUND_LIBRARY_WARNINGS "${WORKAROUND_LIBRARY_WARNINGS} -Wno-unused-function")
317
  ENDIF()
318
  SET(ALL_ENABLED_USEFUL_ERRORS " -Werror -Wformat -Wformat-security -Wformat-nonliteral -Wall -Wextra -Wnarrowing -Wreturn-type -Wuninitialized -Wfloat-conversion -Wcast-align -Wdisabled-optimization -Wtrampolines -Wpointer-arith -Wswitch-bool -Wwrite-strings -Wnon-virtual-dtor -Wreturn-local-addr")
319
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ALL_ENABLED_USEFUL_ERRORS} ${WORKAROUND_LIBRARY_WARNINGS} -Wno-error=cpp -fdce -fstack-protector-strong")
320

321 322 323 324 325 326 327 328 329
#  -Wcast-qual      is useful, but too many warnings in libeigen
#  -Wlogical-op     (1 unfixable warning in /usr/include/vtk-6.3/vtkVariantInlineOperators.h: logical ‘or’ of equal expressions )
#  -Wswitch-default (1 unfixable warning in /usr/include/coin/CoinHelperFunctions.hpp )
#  -Wswitch-enum    is not useful.
# Also see: https://stackoverflow.com/questions/5088460/flags-to-enable-thorough-and-verbose-g-warnings
# Below is the list of all still not fixed warnings `| sort | uniq`, maybe some of them are not much useful:
# -Weffc++              (4465) -Wsign-conversion  (4176) -Wpedantic    (1744) -Wconversion         ( 755) -Wshadow         ( 527)
# -Wfloat-equal         ( 486) -Wvla              ( 119) -Wswitch-enum (  36) -Wcast-qual          (  34) -Wswitch-default (  16)
# -Wmaybe-uninitialized (  10) -Wcomment          (   3) -Wcpp         (   2) -Wcast-function-type (   2) -Wlogical-op     (   1)
330 331

ELSE(ENABLE_USEFUL_ERRORS)
332
  SET(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -Wformat -Wformat-security -Werror=format-security -Wall -fstack-protector-strong")
333 334
ENDIF(ENABLE_USEFUL_ERRORS)
#===========================================================
335 336 337 338
MESSAGE(STATUS   "${Esc}[36mChosen compiler flags are: CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS} ${Esc}[0m")
#======================================
#====== ** END Compiler flags ** ======
#======================================
339

340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
#======================================
#====== **** Real precision **** ======
#======================================
#
# This section accepts either one of these two input parameters:
#  * REAL_PRECISION_BITS
#  * REAL_DECIMAL_PLACES
# Additionally:
#  * ENABLE_MPFR - optional: if more precision than float128 is required then either MPFR or boost::multiprecision::cpp_bin_float type is used.
#
# A hardware-accelerated numerical type is used when available, otherwise mpfr library (or boost cpp_bin_float.hpp) is used for arbitrary precision. The supported types are following:
#     type                   bits     decimal places
#     float,float32_t        32       6                      hardware accelerated
#     double,float64_t       64       15                     hardware accelerated
#     long double,float80_t  80       18                     hardware accelerated
#     float128_t             128      33                     depending on processor type it can be hardware accelerated
#     mpfr                   Nbit     Nbit/(log(2)/log(10))
#     boost::cpp_bin_float   Nbit     Nbit/(log(2)/log(10))
#
# This section does following things:
#  * set REAL_PRECISION_BITS as one of: 32,64,80,128 or higher
#  * set REAL_DECIMAL_PLACES as one of:  6,15,18, 33 or higher
#  * set REAL_USE_ARBITRARY  as one of: --- "OFF" -- or "MPFR" or "BOOST_BIN_FLOAT"
363 364 365
#  * set REAL_USE_MPMATH     as one of: -OFF-,------ON--------
#  * set REAL_PREC_NAME      as one of: "PrecisionFloat" "PrecisionDouble", "PrecisionLongDouble", "PrecisionFloat128", "PrecisionMpfr" or "PrecisionBoostBinFloat"
#  * set CONFIGURED_FEATS    ${REAL_PREC_NAME} ${REAL_USE_MPMATH}
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
#  * #define YADE_REAL_BIT  REAL_PRECISION_BITS
#  * #define YADE_REAL_DEC  REAL_DECIMAL_PLACES
#  * #define YADE_REAL_MPFR    // defined when Real is expressed using mpfr (requires mpfr)
#  * #define YADE_REAL_BBFLOAT // defined when Real is expressed using boost::multiprecision::cpp_bin_float
#  * #define YADE_MPFR         // defined when yade links with optional mpfr library, for example to use with CGAL exact predicates. Unrelated about whether Real uses arbitrary precision.
#
# Some useful links:
# https://www.boost.org/doc/libs/1_71_0/libs/multiprecision/doc/html/boost_multiprecision/tut/floats/float128.html
# https://www.boost.org/doc/libs/1_71_0/libs/multiprecision/doc/html/boost_multiprecision/intro.html
# https://www.boost.org/doc/libs/1_71_0/libs/multiprecision/doc/html/boost_multiprecision/tut/floats/mpfr_float.html
# http://charette.no-ip.com:81/programming/doxygen/boost/classstd_1_1numeric__limits_3_01boost_1_1multiprecision_1_1number_3_01boost_1_1multiprecision_1_1aef0fd61e32c5f58e49aeed0766e135.html
# http://christian-seiler.de/projekte/fpmath/

MESSAGE(STATUS "Determining preferred precision of Real numbers")

SET(REAL_USE_ARBITRARY "OFF") # this line later might need some extra IF() if someone will want to use CGAL exact predicates, see lib/base/AliasCGAL.hpp 'CGAL definitions - does not work with another kernel'

IF( (    REAL_DECIMAL_PLACES) AND (    REAL_PRECISION_BITS))
  MESSAGE(FATAL_ERROR "Cannot specify both REAL_DECIMAL_PLACES and REAL_PRECISION_BITS")
ENDIF()

IF( (NOT REAL_DECIMAL_PLACES) AND (NOT REAL_PRECISION_BITS))
  SET(REAL_PRECISION_BITS "64")
  SET(REAL_DECIMAL_PLACES "15")
390
  SET(REAL_PREC_NAME "PrecisionDouble")
391 392 393 394 395 396 397 398 399 400 401 402
ENDIF()

function(floatexprToInt expr output)
    # If "%f" was instead of "%i" in this place  ↓↓ then it would return a floating point value
    execute_process(COMMAND awk "BEGIN {printf \"%i\",${expr}}" OUTPUT_VARIABLE __output)
    set(${output} ${__output} PARENT_SCOPE)
endfunction()

IF( (    REAL_DECIMAL_PLACES) AND (NOT REAL_PRECISION_BITS))
  IF(${REAL_DECIMAL_PLACES} LESS 7)
    SET(REAL_PRECISION_BITS "32")
    SET(REAL_DECIMAL_PLACES "6")
403
    SET(REAL_PREC_NAME "PrecisionFloat")
404 405 406
  ELSEIF(${REAL_DECIMAL_PLACES} LESS 16)
    SET(REAL_PRECISION_BITS "64")
    SET(REAL_DECIMAL_PLACES "15")
407
    SET(REAL_PREC_NAME "PrecisionDouble")
408 409 410
  ELSEIF(${REAL_DECIMAL_PLACES} LESS 19)
    SET(REAL_PRECISION_BITS "80")
    SET(REAL_DECIMAL_PLACES "18")
411 412
    SET(REAL_PREC_NAME "PrecisionLongDouble")
    SET(REAL_USE_MPMATH "ON")
413 414 415
  ELSEIF(${REAL_DECIMAL_PLACES} LESS 34)
    SET(REAL_PRECISION_BITS "128")
    SET(REAL_DECIMAL_PLACES "33")
416 417
    SET(REAL_PREC_NAME "PrecisionFloat128")
    SET(REAL_USE_MPMATH "ON")
418 419 420 421
  ELSEIF(${REAL_DECIMAL_PLACES} LESS 39)
    MESSAGE(STATUS "${Esc}[36mNote: decimal places between 34 and 39 make it unclear if you want mpfr or float128, defaulting to float128. It is because some bits are used by the exponent.${Esc}[0m")
    SET(REAL_PRECISION_BITS "128")
    SET(REAL_DECIMAL_PLACES "33")
422 423
    SET(REAL_PREC_NAME "PrecisionFloat128")
    SET(REAL_USE_MPMATH "ON")
424 425 426 427 428
  ELSE()
    # calculate Nbits as Ndecimal/((log(2)/log(10)))
    floatexprToInt("(${REAL_DECIMAL_PLACES}/0.30102999566398119521)" REAL_PRECISION_BITS)
    #MATH(EXPR REAL_PRECISION_BITS "(${REAL_DECIMAL_PLACES}/0.30102999566398119521)") # ← doesn't work with floats
    SET(REAL_USE_ARBITRARY "ON") # we know it has to be arbitrary, but we don't know yet if mpfr is available
429
    SET(REAL_USE_MPMATH "ON")
430 431 432 433 434 435 436
  ENDIF()
ENDIF()

IF( (NOT REAL_DECIMAL_PLACES) AND (    REAL_PRECISION_BITS))
  IF(${REAL_PRECISION_BITS} LESS 33)
    SET(REAL_PRECISION_BITS "32")
    SET(REAL_DECIMAL_PLACES "6")
437
    SET(REAL_PREC_NAME "PrecisionFloat")
438 439 440
  ELSEIF(${REAL_PRECISION_BITS} LESS 65)
    SET(REAL_PRECISION_BITS "64")
    SET(REAL_DECIMAL_PLACES "15")
441
    SET(REAL_PREC_NAME "PrecisionDouble")
442 443 444
  ELSEIF(${REAL_PRECISION_BITS} LESS 81)
    SET(REAL_PRECISION_BITS "80")
    SET(REAL_DECIMAL_PLACES "18")
445 446
    SET(REAL_PREC_NAME "PrecisionLongDouble")
    SET(REAL_USE_MPMATH "ON")
447 448 449
  ELSEIF(${REAL_PRECISION_BITS} LESS 129)
    SET(REAL_PRECISION_BITS "128")
    SET(REAL_DECIMAL_PLACES "33")
450 451
    SET(REAL_PREC_NAME "PrecisionFloat128")
    SET(REAL_USE_MPMATH "ON")
452 453 454 455
  ELSE()
    # calculate Ndecimal as Nbits*((log(2)/log(10)))
    floatexprToInt("(${REAL_PRECISION_BITS}*0.30102999566398119521)" REAL_DECIMAL_PLACES)
    SET(REAL_USE_ARBITRARY "ON") # we know it has to be arbitrary, but we don't know yet if mpfr is available
456
    SET(REAL_USE_MPMATH "ON")
457 458 459 460 461
  ENDIF()
ENDIF()

IF(REAL_USE_ARBITRARY)
  IF(NOT ENABLE_MPFR)
462
    SET(REAL_PREC_NAME "PrecisionBoostBinFloat${REAL_DECIMAL_PLACES}")
463
    SET(REAL_USE_ARBITRARY "BOOST_BIN_FLOAT")
464 465
    ADD_DEFINITIONS("-DYADE_REAL_BBFLOAT")
    MESSAGE(STATUS "To use faster higher precision use -DENABLE_MPFR=ON cmake option. Currently a simple type boost::multiprecision::cpp_bin_float will be used.")
466
  ELSE()
467
    SET(REAL_PREC_NAME "PrecisionMpfr${REAL_DECIMAL_PLACES}")
468
    SET(REAL_USE_ARBITRARY "MPFR")
469
    ADD_DEFINITIONS("-DYADE_REAL_MPFR")
470 471
    MESSAGE(STATUS "Real type will use mpfr precision.")
  ENDIF()
472 473 474
ENDIF()

IF(REAL_USE_MPMATH)
475 476 477
  FIND_PACKAGE(Mpmath REQUIRED)
  IF(MPMATH_FOUND)
    MESSAGE(STATUS "python-mpmath found, version: ${MPMATH_VERSION}")
478 479
    SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} mpmath")
    SET(MPMATH_IS_USED "True")
480
  ELSE()
481
    MESSAGE(FATAL_ERROR "Cannot find python-mpmath or python3-mpmath package http://mpmath.org to use high precision in python, but it is necessary for selected Real precision.")
482 483 484
  ENDIF()
ELSE()
  SET(DISABLED_FEATS "${DISABLED_FEATS} mpmath")
485
  SET(MPMATH_IS_USED "False")
486 487
ENDIF()

488 489 490
IF(NOT ((${REAL_PRECISION_BITS} EQUAL 64)))
# This means that new high-precision capabilities will be used. To make this work we need a patched version of /usr/include/miniegen
  MESSAGE(STATUS "Checking compiler version for ${REAL_PREC_NAME}")
491 492 493
  IF(NOT ALLOW_CRASHES)
    IF(REAL_USE_ARBITRARY AND ENABLE_MPFR)
      IF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.3.0 )
494
        MESSAGE(FATAL_ERROR "MPFR works since g++ version around 8.3.0. For possible supported platforms see https://gitlab.com/cosurgi/minieigen-real/pipelines/104924921 you can use -DALLOW_CRASHES=ON to override.")
495 496 497
      ENDIF()
    ELSE()
      IF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.2.1 )
498
        MESSAGE(FATAL_ERROR "High precision '${REAL_PREC_NAME}' works since g++ version around 9.2.1. For possible supported platforms see https://gitlab.com/cosurgi/minieigen-real/pipelines/104924921 you can use -DALLOW_CRASHES=ON to override.")
499
      ENDIF()
500 501
    ENDIF()
  ELSE()
502
    MESSAGE(STATUS "${Esc}[31mSkipping this check, ALLOW_CRASHES=ON${Esc}[0m")
503 504 505
  ENDIF()
ENDIF()

506 507
ADD_DEFINITIONS("-DYADE_REAL_BIT=${REAL_PRECISION_BITS}")
ADD_DEFINITIONS("-DYADE_REAL_DEC=${REAL_DECIMAL_PLACES}")
508 509 510 511 512

SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} ${REAL_PREC_NAME}")

IF(ENABLE_MPFR)
  FIND_PACKAGE(MPFR REQUIRED)
513 514
  FIND_PACKAGE(MPFRCPP REQUIRED)
  IF(MPFR_FOUND AND MPFRCPP_FOUND)
515 516
    SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} MPFR")
    MESSAGE(STATUS "MPFR enabled, version: ${MPFR_VERSION}, linking with ${MPFR_LIBRARIES}")
517
    ADD_DEFINITIONS("-DYADE_MPFR")
518
  ELSE()
519
    MESSAGE(FATAL_ERROR "Cannot find MPFR library https://www.mpfr.org, two debian packages libmpfr-dev libmpfrc++-dev")
520 521 522 523 524 525 526
  ENDIF()
ELSE()
  SET(DISABLED_FEATS "${DISABLED_FEATS} MPFR")
  MESSAGE(STATUS "mpfr disabled")
ENDIF()

IF(REAL_USE_ARBITRARY EQUAL "ON")
527
  MESSAGE(FATAL_ERROR " there's an error in CMakeLists.txt, REAL_USE_ARBITRARY == ${REAL_USE_ARBITRARY}, but should be OFF,MPFR,BOOST_BIN_FLOAT")
528 529
ENDIF()

530
MESSAGE(STATUS "Will use ${Esc}[93m${REAL_PREC_NAME}${Esc}[0m as Real type with ${Esc}[36m${REAL_DECIMAL_PLACES}${Esc}[0m decimal places precision and use ${Esc}[36m${REAL_PRECISION_BITS}${Esc}[0m bits of storage.")
531
#======================================
532
#====== * Unsupported features * ======
533
#======================================
534 535 536 537 538 539 540
# non-double Real precision does not work with extarnal library cholmod.
IF(NOT (${REAL_PRECISION_BITS} EQUAL 64))
  IF(ENABLE_TWOPHASEFLOW OR ENABLE_LINSOLV OR ENABLE_PFVFLOW)
     MESSAGE(STATUS "ENABLE_TWOPHASEFLOW OR ENABLE_LINSOLV OR ENABLE_PFVFLOW were disabled automatically because they use double precision external library: cholesky linear solver. It can be replaced with native Eigen solvers, then it will work.")
     SET(ENABLE_TWOPHASEFLOW OFF)
     SET(ENABLE_LINSOLV OFF)
     SET(ENABLE_PFVFLOW OFF)
541
  ENDIF(ENABLE_TWOPHASEFLOW OR ENABLE_LINSOLV OR ENABLE_PFVFLOW)
542 543 544
  IF(ENABLE_TWOPHASEFLOW OR ENABLE_LINSOLV OR ENABLE_PFVFLOW)
    MESSAGE(FATAL_ERROR "Cannot (yet) use ENABLE_TWOPHASEFLOW OR ENABLE_LINSOLV OR ENABLE_PFVFLOW with high precision.")
  ENDIF(ENABLE_TWOPHASEFLOW OR ENABLE_LINSOLV OR ENABLE_PFVFLOW)
Janek Kozicki's avatar
Janek Kozicki committed
545 546 547 548 549 550 551
  IF(ENABLE_POTENTIAL_BLOCKS)
     MESSAGE(STATUS "ENABLE_POTENTIAL_BLOCKS was disabled because external library coinor can only work with double type.")
     SET(ENABLE_POTENTIAL_BLOCKS OFF)
  ENDIF(ENABLE_POTENTIAL_BLOCKS)
  IF(ENABLE_POTENTIAL_BLOCKS)
    MESSAGE(FATAL_ERROR "Cannot (yet) use ENABLE_POTENTIAL_BLOCKS with high precision.")
  ENDIF(ENABLE_POTENTIAL_BLOCKS)
552 553 554 555 556 557 558
  IF(ENABLE_MPI)
     MESSAGE(STATUS "ENABLE_MPI was disabled because it hasn't been tested. It is possible that a pure python-only library will correctly send mpmath.mpf(…) high precision Real type over network, but this was not tested.")
     SET(ENABLE_MPI OFF)
  ENDIF(ENABLE_MPI)
  IF(ENABLE_MPI)
    MESSAGE(FATAL_ERROR "Cannot (yet) use ENABLE_MPI with high precision.")
  ENDIF(ENABLE_MPI)
559 560
ENDIF(NOT (${REAL_PRECISION_BITS} EQUAL 64))

561 562 563 564
# This is for testing compilation with Real as float. Only useful to have wider testing coverage, not for real world use.
IF(${REAL_PRECISION_BITS} EQUAL 32)
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=float-conversion -Wno-error=narrowing")
ENDIF()
565

566 567 568 569
#======================================
#====== ** END Real precision ** ======
#======================================

570
#===========================================================
Anton Gladky's avatar
Anton Gladky committed
571

Anton Gladky's avatar
Anton Gladky committed
572
FIND_PACKAGE(BZip2 REQUIRED)
Anton Gladky's avatar
Anton Gladky committed
573
FIND_PACKAGE(ZLIB REQUIRED)
574 575
#===========================================================

Anton Gladky's avatar
Anton Gladky committed
576 577 578
# Use Eigen3 by default
IF (EIGEN3_FOUND)
  INCLUDE_DIRECTORIES(${EIGEN3_INCLUDE_DIR})
579
  MESSAGE(STATUS "Found Eigen3, version: ${EIGEN3_VERSION}")
580

581
  # Minimal required version 3.2.1
582
  IF ((${EIGEN3_MAJOR_VERSION} LESS 2) OR ((${EIGEN3_MAJOR_VERSION} EQUAL 2) AND (${EIGEN3_MINOR_VERSION} LESS 1)))
583
    MESSAGE(FATAL_ERROR "Minimal required Eigen3 version is 3.2.1, please update Eigen3!")
584 585
  ENDIF ((${EIGEN3_MAJOR_VERSION} LESS 2) OR ((${EIGEN3_MAJOR_VERSION} EQUAL 2) AND (${EIGEN3_MINOR_VERSION} LESS 1)))

586
  IF (NOT VECTORIZE)
Anton Gladky's avatar
Anton Gladky committed
587 588
    MESSAGE(STATUS "Disable vectorization")
    ADD_DEFINITIONS("-DEIGEN_DONT_VECTORIZE -DEIGEN_DONT_ALIGN -DEIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT")
589
  ELSE (NOT VECTORIZE)
590 591 592
    IF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.2.1 )
      MESSAGE(FATAL_ERROR "SSE vectorization works since g++ version around 9.2.1.")
    ENDIF()
593
    MESSAGE(STATUS "Enable vectorization")
594
    SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} VECTORIZE")
595
  ENDIF (NOT VECTORIZE)
596

597
ENDIF(EIGEN3_FOUND)
Anton Gladky's avatar
Anton Gladky committed
598
#===========================================================
Anton Gladky's avatar
Anton Gladky committed
599
INCLUDE_DIRECTORIES(${BZIP2_INCLUDE_DIR})
Anton Gladky's avatar
Anton Gladky committed
600 601
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS})
SET(LINKLIBS  "${LINKLIBS};${BZIP2_LIBRARIES};${ZLIB_LIBRARIES};")
Anton Gladky's avatar
Anton Gladky committed
602
#===========================================================
Anton Gladky's avatar
Anton Gladky committed
603 604 605 606 607 608 609 610 611 612 613
IF((Boost_MAJOR_VERSION EQUAL 1) OR (Boost_MAJOR_VERSION GREATER 1) AND
  ((Boost_MINOR_VERSION EQUAL 53) OR (Boost_MINOR_VERSION GREATER 53)))
  SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} Odeint")
  ADD_DEFINITIONS("-DYADE_ODEINT")
ELSE((Boost_MAJOR_VERSION EQUAL 1) OR (Boost_MAJOR_VERSION GREATER 1) AND
    ((Boost_MINOR_VERSION EQUAL 53) OR (Boost_MINOR_VERSION GREATER 53)))
  SET(DISABLED_FEATS "${DISABLED_FEATS} Odeint")
  MESSAGE(STATUS "Boost Odeint can be enabled, only if Boost>=1.53 is used")
ENDIF((Boost_MAJOR_VERSION EQUAL 1) OR (Boost_MAJOR_VERSION GREATER 1) AND
     ((Boost_MINOR_VERSION EQUAL 53) OR (Boost_MINOR_VERSION GREATER 53)))
#===========================================================
614
IF(ENABLE_VTK)
615
  FIND_PACKAGE(VTK COMPONENTS vtkIOParallelXML vtkCommonCore vtkIOImage vtkIOXML vtkFiltersCore vtkImagingCore vtkRenderingCore vtkImagingGeneral vtkImagingHybrid)
616 617 618 619 620 621 622 623
  IF(VTK_FOUND)
    INCLUDE_DIRECTORIES(${VTK_INCLUDE_DIRS})
    LINK_DIRECTORIES( ${VTK_LIBRARY_DIRS} )
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DYADE_VTK")
    MESSAGE(STATUS "Found VTK")
    SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} VTK")
  ELSE(VTK_FOUND)
    MESSAGE(STATUS "VTK NOT found")
Anton Gladky's avatar
Anton Gladky committed
624
    SET(ENABLE_VTK OFF)
625
    SET(DISABLED_FEATS "${DISABLED_FEATS} VTK")
626
  ENDIF(VTK_FOUND)
627 628
ELSE(ENABLE_VTK)
  SET(DISABLED_FEATS "${DISABLED_FEATS} VTK")
629 630 631 632
ENDIF(ENABLE_VTK)
#===========================================================
IF(ENABLE_OPENMP)
  FIND_PACKAGE(OpenMP)
633
  IF(OPENMP_FOUND)
634
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DYADE_OPENMP ${OpenMP_CXX_FLAGS}")
635 636
    MESSAGE(STATUS "Found OpenMP")
    SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} OpenMP")
637
  ELSE(OPENMP_FOUND)
638
    MESSAGE(STATUS "OpenMP NOT found")
Anton Gladky's avatar
Anton Gladky committed
639
    SET(ENABLE_OPENMP OFF)
640
    SET(DISABLED_FEATS "${DISABLED_FEATS} OPENMP")
641
  ENDIF(OPENMP_FOUND)
642 643
ELSE(ENABLE_OPENMP)
  SET(DISABLED_FEATS "${DISABLED_FEATS} OPENMP")
644 645 646 647
ENDIF(ENABLE_OPENMP)
#===========================================================
IF(ENABLE_GTS)
  FIND_PACKAGE(GTS)
648 649
  FIND_PACKAGE(glib2)
  IF(GTS_FOUND AND GLIB2_FOUND)
650 651 652
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DYADE_GTS ${CMAKE_GTS_CXX_FLAGS}")
    SET(CMAKE_LD_FLAGS  "${CMAKE_LD_FLAGS} ${GTS_LIBRARIES}")
    INCLUDE_DIRECTORIES(${GTS_INCLUDE_DIR})
653
    INCLUDE_DIRECTORIES(${GLIB2_INCLUDE_DIRS})
654 655
    MESSAGE(STATUS "Found GTS")
    SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} GTS")
656
  ELSE(GTS_FOUND AND GLIB2_FOUND)
657
    MESSAGE(STATUS "GTS NOT found")
658
    SET(DISABLED_FEATS "${DISABLED_FEATS} GTS")
Anton Gladky's avatar
Anton Gladky committed
659
    SET(ENABLE_GTS OFF)
660
  ENDIF(GTS_FOUND AND GLIB2_FOUND)
661 662
ELSE(ENABLE_GTS)
  SET(DISABLED_FEATS "${DISABLED_FEATS} GTS")
663 664 665 666 667 668
ENDIF(ENABLE_GTS)
#===========================================================
IF(ENABLE_GUI)
  FIND_PACKAGE(OpenGL)
  FIND_PACKAGE(GLUT)
  FIND_PACKAGE(glib2)
669

Anton Gladky's avatar
Anton Gladky committed
670
  IF(USE_QT5)
671
    MESSAGE(STATUS "USE QT5")
672
    FIND_PACKAGE(QGLVIEWER-qt5 REQUIRED)
Anton Gladky's avatar
Anton Gladky committed
673
    FIND_PACKAGE(Qt5 CONFIG REQUIRED Widgets Xml OpenGL)
Anton Gladky's avatar
Anton Gladky committed
674
    FIND_PACKAGE(Qt5Widgets)
Anton Gladky's avatar
Anton Gladky committed
675 676 677
    IF(Qt5Widgets_FOUND AND OPENGL_FOUND AND GLUT_FOUND AND GLIB2_FOUND AND QGLVIEWER_FOUND)
      SET(GUI_LIBS ${GLUT_LIBRARY} ${QGLVIEWER_LIBRARIES})
      SET(GUI_SRC_LIB "lib/opengl/GLUtils.cpp")
678
      SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DYADE_OPENGL -DYADE_QT5")
679 680 681
      SET(Used_QT_VERSION_MAJOR ${QT5_VERSION_MAJOR})
      SET(Used_QT_VERSION_MINOR ${QT5_VERSION_MINOR})
      SET(Used_QT_VERSION_PATCH ${QT5_VERSION_PATCH})
Anton Gladky's avatar
Anton Gladky committed
682 683 684 685 686 687 688 689
      MESSAGE(STATUS "Found GUI-Qt5-LIBS")
      SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} GUI-Qt5")
    ELSE(Qt5Widgets_FOUND AND OPENGL_FOUND AND GLUT_FOUND AND GLIB2_FOUND AND QGLVIEWER_FOUND)
      MESSAGE(STATUS "GUI-Qt5-LIBS NOT found")
      SET(DISABLED_FEATS "${DISABLED_FEATS} GUI-Qt5")
      SET(ENABLE_GUI OFF)
    ENDIF(Qt5Widgets_FOUND AND OPENGL_FOUND AND GLUT_FOUND AND GLIB2_FOUND AND QGLVIEWER_FOUND)
  ELSE(USE_QT5)   # Use Qt4
690
    MESSAGE(FATAL_ERROR "QT4 is no longer supported")
Anton Gladky's avatar
Anton Gladky committed
691
  ENDIF(USE_QT5)
692 693
ELSE(ENABLE_GUI)
  SET(DISABLED_FEATS "${DISABLED_FEATS} GUI")
694 695
ENDIF(ENABLE_GUI)
#===========================================================
696
# This one will cry on attempts to build CGAL-based packages without cgal
697
IF(NOT ENABLE_CGAL AND (ENABLE_PFVFLOW OR ENABLE_TWOPHASEFLOW OR ENABLE_THERMAL))
698
  MESSAGE(STATUS "PFVFLOW, TWOPHASEFLOW and THERMAL depends on CGAL, but CGAL is disabled (not found or turned OFF)")
699
ENDIF(NOT ENABLE_CGAL AND (ENABLE_PFVFLOW OR ENABLE_TWOPHASEFLOW OR ENABLE_THERMAL))
700
#===========================================================
701
IF(ENABLE_CGAL)
Anton Gladky's avatar
Anton Gladky committed
702
  INCLUDE(FindGMP)
703
  FIND_PACKAGE(CGAL)
Anton Gladky's avatar
Anton Gladky committed
704
  FIND_PACKAGE(GMP)
705
  IF(CGAL_FOUND AND GMP_FOUND AND (NOT("${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" MATCHES ".*clang"))) #Check for clang should be removed, when CGAL will be compilable by clang
706

707
    FILE(GLOB CGAL_SRC_LIB "lib/triangulation/*.cpp")
708
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CGAL_DEFINITIONS} -DYADE_CGAL")
709 710 711 712 713
    IF(NOT (${CGAL_LIBRARIES} STREQUAL "CGAL_LIBRARIES-NOTFOUND"))
      SET(LINKLIBS  "${LINKLIBS};${CGAL_LIBRARIES};${GMP_LIBRARIES};${GMPXX_LIBRARIES};")
    ELSE()
      SET(LINKLIBS  "${LINKLIBS};${GMP_LIBRARIES};${GMPXX_LIBRARIES};")
    ENDIF()
714 715
    MESSAGE(STATUS "Found CGAL")
    SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} CGAL")
716

717
    ADD_DEFINITIONS("-DCGAL_DISABLE_ROUNDING_MATH_CHECK -frounding-math")
718 719 720

    IF(ENABLE_PFVFLOW)
      SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFLOW_ENGINE")
Anton Gladky's avatar
Anton Gladky committed
721
      SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} PFVFLOW")
722
    ELSE(ENABLE_PFVFLOW)
Anton Gladky's avatar
Anton Gladky committed
723
      SET(DISABLED_FEATS "${DISABLED_FEATS} PFVFLOW")
724 725
    ENDIF(ENABLE_PFVFLOW)

726
  ELSE(CGAL_FOUND AND GMP_FOUND AND (NOT("${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" MATCHES ".*clang")))
727
    MESSAGE(STATUS "CGAL NOT found")
728
    SET(DISABLED_FEATS "${DISABLED_FEATS} CGAL")
Anton Gladky's avatar
Anton Gladky committed
729
    SET(ENABLE_CGAL OFF)
730
    IF(ENABLE_PFVFLOW)
bchareyre's avatar
bchareyre committed
731 732
      SET(DISABLED_FEATS "${DISABLED_FEATS} PFVFLOW TWOPHASEFLOW")
      MESSAGE(STATUS "CGAL NOT found: PFVFLOW and TWOPHASEFLOW disabled")
733 734
    ENDIF(ENABLE_PFVFLOW)

735
  ENDIF(CGAL_FOUND AND GMP_FOUND AND (NOT("${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" MATCHES ".*clang")))
736 737
ELSE(ENABLE_CGAL)
  SET(DISABLED_FEATS "${DISABLED_FEATS} CGAL")
738
ENDIF(ENABLE_CGAL)
739 740 741 742 743 744 745 746 747 748 749 750 751 752

#===========================================================
IF(ENABLE_PFVFLOW)
	IF(ENABLE_CGAL)
		SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFLOW_ENGINE")
		SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} PFVFLOW")
	ELSE(ENABLE_CGAL)
		SET(DISABLED_FEATS "${DISABLED_FEATS} PFVFLOW")
		SET(ENABLE_PFVFLOW OFF)
	ENDIF(ENABLE_CGAL)
ELSE(ENABLE_PFVFLOW)
	SET(DISABLED_FEATS "${DISABLED_FEATS} PFVFLOW")
ENDIF(ENABLE_PFVFLOW)

753
#===========================================================
754
IF(ENABLE_PFVFLOW AND ENABLE_LINSOLV)
755 756 757 758 759 760 761
  IF(DEFINED SUITESPARSEPATH) 
    set(SUITESPARSE_PREFIX_PATH ${SUITESPARSEPATH})
    MESSAGE(STATUS "Using custom suitsparse path " ${SUITESPARSE_PREFIX_PATH})
  ELSE(DEFINED SUITESPARSEPATH)
    set(SUITESPARSE_PREFIX_PATH /usr)
    MESSAGE(STATUS "Using typical suitesparse path " ${SUITESPARSE_PREFIX_PATH})
  ENDIF(DEFINED SUITESPARSEPATH)
Bruno Chareyre's avatar
Bruno Chareyre committed
762
  FIND_PACKAGE(Cholmod)
763 764
  FIND_PACKAGE(OpenBlas)
  FIND_PACKAGE(Metis)
Robert Caulk's avatar
Robert Caulk committed
765

766
  IF(CHOLMOD_FOUND AND OPENBLAS_FOUND AND METIS_FOUND AND CGAL_FOUND)
767
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CGAL_DEFINITIONS} -DLINSOLV")
Robert Caulk's avatar
Robert Caulk committed
768

769
    SET(LINKLIBS  "${LINKLIBS};${CHOLMOD_LIBRARIES};${AMD_LIBRARY};${CAMD_LIBRARY};${COLAMD_LIBRARY};${CCOLAMD_LIBRARY};${OPENBLAS_LIBRARY};${METIS_LIBRARY};${SUITESPARSE_LIBRARY};${SUITESPARSECONFIG_LIBRARY}")
770
    INCLUDE_DIRECTORIES(${METIS_INCLUDE_DIR} ${CHOLMOD_INCLUDE_DIR} ${BLAS_INCLUDE_DIR})
Robert Caulk's avatar
Robert Caulk committed
771 772 773
    MESSAGE(STATUS "Found Cholmod in " ${CHOLMOD_LIBRARIES})
    MESSAGE(STATUS "Found OpenBlas in " ${OPENBLAS_LIBRARY})
    MESSAGE(STATUS "Found Metis in " ${METIS_LIBRARY})
Anton Gladky's avatar
Anton Gladky committed
774
    SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} LINSOLV")
Robert Caulk's avatar
Robert Caulk committed
775

776 777 778 779 780 781 782 783 784 785 786 787 788 789 790
    IF(CHOLMOD_GPU)
      FIND_PACKAGE(CuBlas)
      FIND_PACKAGE(Lapack)
      IF(CUBLAS_FOUND AND LAPACK_FOUND)
        ADD_DEFINITIONS("-DPFV_GPU")
        SET(LINKLIBS "${LINKLIBS};${CUBLAS_LIBRARY};${CUDART_LIBRARY};${LAPACK_LIBRARY}")
        MESSAGE(STATUS "Found CuBlas in " ${CUBLAS_LIBRARY})
        MESSAGE(STATUS "Found Lapack in " ${LAPACK_LIBRARY})
        SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} CHOLMOD_GPU")
      ELSE(CUBLAS_FOUND AND LAPACK_FOUND)
        MESSAGE(STATUS "Missing dependency for CHOLMOD_GPU, disabled")
        SET(DISABLED_FEATS "${DISABLED_FEATS} CHOLMOD_GPU")
        SET(CHOLMOD_GPU OFF)
      ENDIF(CUBLAS_FOUND AND LAPACK_FOUND)
    ELSE(CHOLMOD_GPU)
Robert Caulk's avatar
Robert Caulk committed
791
      SET(DISABLED_FEATS "${DISABLED_FEATS} CHOLMOD_GPU")
792
    ENDIF(CHOLMOD_GPU)
Robert Caulk's avatar
Robert Caulk committed
793

794
  ELSE(CHOLMOD_FOUND AND OPENBLAS_FOUND AND METIS_FOUND AND CGAL_FOUND)
795
    MESSAGE(STATUS "Missing dependency for LINSOLV, disabled")
Anton Gladky's avatar
Anton Gladky committed
796
    SET(DISABLED_FEATS "${DISABLED_FEATS} LINSOLV")
Bruno Chareyre's avatar
Bruno Chareyre committed
797
    SET(ENABLE_LINSOLV OFF)
798
  ENDIF(CHOLMOD_FOUND AND OPENBLAS_FOUND AND METIS_FOUND AND CGAL_FOUND)
799
ELSE(ENABLE_PFVFLOW AND ENABLE_LINSOLV)
Anton Gladky's avatar
Anton Gladky committed
800
  SET(DISABLED_FEATS "${DISABLED_FEATS} LINSOLV")
801 802 803 804
      IF(ENABLE_TWOPHASEFLOW)
         MESSAGE(STATUS "TWOPHASEFLOW was disabled automatically because LINSOLV is disabled")
         SET(ENABLE_TWOPHASEFLOW OFF)
      ENDIF(ENABLE_TWOPHASEFLOW)
805
ENDIF(ENABLE_PFVFLOW AND ENABLE_LINSOLV)
806
#===============================================
Deepak kn's avatar
Deepak kn committed
807
IF(ENABLE_MPI)
808
  IF(${PYTHON_VERSION_STRING} VERSION_GREATER 3)
809 810 811 812
  FIND_PACKAGE(MPI REQUIRED)
  FIND_PACKAGE(MPI4PY REQUIRED)
  IF (MPI_FOUND AND MPI4PY_FOUND)
    INCLUDE_DIRECTORIES(${MPI_CXX_INCLUDE_PATH} ${MPI4PY_INCLUDE_DIR})
813
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MPI_CXX_COMPILE_FLAGS} -DYADE_MPI")
814 815 816
    string (STRIP "${MPI_CXX_LIBRARIES}" MPI_LIBRARIES)
    string (STRIP "${MPI_CXX_LINK_FLAGS}" MPI_LINK_FLAGS)
    SET (LINKLIBS "${LINKLIBS};${MPI_LIBRARIES};${MPI_LINK_FLAGS}")
817
    MESSAGE(STATUS "MPI found")
Deepak kn's avatar
Deepak kn committed
818
    SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} MPI")
819 820
    # sometimes mpi.h is not found. cmake should find it, but didn't. I'm not sure why. Here I put all directotries where it can be found.
    # it is an OR operation from ubuntu, debian and opensuse of this: https://packages.debian.org/search?suite=sid&arch=any&mode=path&searchon=contents&keywords=include%2Fmpi.h
821 822 823 824 825 826 827 828 829 830 831 832
#     find_path(MPI_H_INCLUDE_DIR mpi.h /usr/include/openmpi /usr/lib/openmpi /usr/lib/openmpi/include /usr/lib/x86_64-linux-gnu /usr/lib64/mpi/gcc/openmpi 
#     /usr/include/aarch64-linux-gnu /usr/include/arm-linux-gnueabihf /usr/include/i386-kfreebsd-gnu /usr/include/i386-linux-gnu
#     /usr/include/mips64el-linux-gnuabi64 /usr/include/openblas /usr/include/powerpc64-linux-gnu /usr/include/powerpc64le-linux-gnu
#     /usr/include/s390x-linux-gnu /usr/include/sparc64-linux-gnu /usr/include/x86_64-kfreebsd-gnu /usr/include/x86_64-linux-gnu
#     /usr/lib/aarch64-linux-gnu /usr/lib/alpha-linux-gnu /usr/lib/arm-linux-gnueabi /usr/lib/arm-linux-gnueabihf
#     /usr/lib/hppa-linux-gnu /usr/lib/i386-gnu /usr/lib/i386-kfreebsd-gnu /usr/lib/i386-linux-gnu
#     /usr/lib/m68k-linux-gnu /usr/lib/mips-linux-gnu /usr/lib/mips64el-linux-gnuabi64 /usr/lib/mipsel-linux-gnu
#     /usr/lib/powerpc-linux-gnu /usr/lib/powerpc-linux-gnuspe /usr/lib/powerpc64-linux-gnu /usr/lib/powerpc64le-linux-gnu
#     /usr/lib/riscv64-linux-gnu /usr/lib/s390x-linux-gnu /usr/lib/sh4-linux-gnu /usr/lib/sparc64-linux-gnu
#     /usr/lib/x86_64-kfreebsd-gnu /usr/lib/x86_64-linux-gnux32
#     )
#     INCLUDE_DIRECTORIES(${MPI_H_INCLUDE_DIR})
833
  ELSE(MPI_FOUND AND MPI4PY_FOUND)
834
    MESSAGE(STATUS "MPI NOT FOUND, YADE-OpenFOAM coupling disabled")
Deepak kn's avatar
Deepak kn committed
835
    SET (DISABLED_FEATS "${DISABLED_FEATS} MPI")
836
  ENDIF(MPI_FOUND AND MPI4PY_FOUND)
837 838 839 840
  ELSE(${PYTHON_VERSION_STRING} VERSION_GREATER 3)
    MESSAGE(STATUS "MPI was disabled automatically because it requires Python 3 and you'll use ${PYTHON_VERSION_STRING}")
    SET(DISABLED_FEATS "${DISABLED_FEATS} MPI")
 ENDIF(${PYTHON_VERSION_STRING} VERSION_GREATER 3)
Deepak kn's avatar
Deepak kn committed
841
ELSE(ENABLE_MPI)
Deepak kn's avatar
Deepak kn committed
842 843
    SET (DISABLED_FEATS "${DISABLED_FEATS} MPI")
ENDIF(ENABLE_MPI)
844
#===============================================
845
IF(ENABLE_TWOPHASEFLOW)
bchareyre's avatar
bchareyre committed
846 847 848 849 850 851 852
	IF(ENABLE_PFVFLOW)
		SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTWOPHASEFLOW")
		SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} TWOPHASEFLOW")
	ELSE(ENABLE_PFVFLOW)
		SET(DISABLED_FEATS "${DISABLED_FEATS} TWOPHASEFLOW")
		MESSAGE(STATUS "PFVFLOW disabled, TWOPHASEFLOW will not be compiled")
	ENDIF(ENABLE_PFVFLOW)
853 854 855
ELSE(ENABLE_TWOPHASEFLOW)
	SET(DISABLED_FEATS "${DISABLED_FEATS} TWOPHASEFLOW")
ENDIF(ENABLE_TWOPHASEFLOW)
856
#===============================================
857 858 859 860 861 862 863
IF(ENABLE_SPH)
  ADD_DEFINITIONS("-DYADE_SPH")
  SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} SPH")
ELSE(ENABLE_SPH)
  SET(DISABLED_FEATS "${DISABLED_FEATS} SPH")
ENDIF(ENABLE_SPH)
#===============================================
864 865 866 867 868 869 870
IF(ENABLE_DEFORM)
  ADD_DEFINITIONS("-DYADE_DEFORM")
  SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} DEFORM")
ELSE(ENABLE_DEFORM)
  SET(DISABLED_FEATS "${DISABLED_FEATS} DEFORM")
ENDIF(ENABLE_DEFORM)
#===============================================
871 872 873 874 875 876 877
IF(ENABLE_FEMLIKE)
  ADD_DEFINITIONS("-DYADE_FEM")
  SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} FEMLIKE")
ELSE(ENABLE_FEMLIKE)
  SET(DISABLED_FEATS "${DISABLED_FEATS} FEMLIKE")
ENDIF(ENABLE_FEMLIKE)
#===============================================
878 879
IF(ENABLE_LIQMIGRATION)
  ADD_DEFINITIONS("-DYADE_LIQMIGRATION")
880
  SET(CONFIGURED_FEATS "${CONFIGURED_FEATS} LIQMIGRATION")
881
ELSE(ENABLE_LIQMIGRATION)
882
  SET(DISABLED_FEATS "${DISABLED_FEATS} LIQMIGRATION")
883 884
ENDIF(ENABLE_LIQMIGRATION)
#===============================================