CMakeLists.txt 62 KB
Newer Older
1
2
3
4
5
6
############################################################################################################################
##
## waLBerla's main cmake file
##
## Contents:
##   - definition of build options
7
##   - compiler variables ( c++ standard, warnings etc. )
8
9
10
##   - Finding of service libraries. Required: boost, Optional: MPI, PE, METIS
##     the include paths are set, and the libraries are added to variable SERVICE_LIBS
##   - Subdirectory cmake lists are called
11
12
##       -> src/   this folder contains all modules, each module (that contains c or cpp files) is linked to a
##                 static library.  Dependencies between these shared libraries are tracked manually,
13
14
15
##                 for more information see waLBerlaModuleDependencySystem.cmake
##       -> tests/ Same subdirectories as src/ folder. Contains tests for each module
##   - Export of variables into internal cache variables, for usage in applications or projects that use walberla as
16
##     subdirectory. Variables containing the service-libs,
17
18
19
20
21
22
23
24
25
26
27
##
############################################################################################################################



############################################################################################################################
##
## Project name, version, Custom CMake functions
##
############################################################################################################################

28
CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
29
30


31
PROJECT ( walberla )
32
33
34
35
36

set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${walberla_SOURCE_DIR}/cmake )

include ( waLBerlaFunctions )

Martin Bauer's avatar
Martin Bauer committed
37
set_version( 5 0 )
38

Michael Kuron's avatar
Michael Kuron committed
39
include( CMakeParseArguments )
40

41
42
43
44
# Enable CTest
enable_testing()
include( CTest )

45

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
############################################################################################################################




############################################################################################################################
##
## Definition of build options
##
############################################################################################################################


# Build options
option ( WALBERLA_DOUBLE_ACCURACY           "Floating point accuracy, defaults to double"     ON )
option ( WALBERLA_ENABLE_GUI                "Compile with GUI"                                   )
61

62
63
64
65
option ( WALBERLA_BUILD_TESTS               "Build Testcases"                                    )
option ( WALBERLA_BUILD_BENCHMARKS          "Build Benchmarks"                                ON )
option ( WALBERLA_BUILD_TOOLS               "Build Tools"                                        )
option ( WALBERLA_BUILD_TUTORIALS           "Build Tutorials"                                 ON )
Christoph Rettinger's avatar
Christoph Rettinger committed
66
option ( WALBERLA_BUILD_SHOWCASES           "Build Showcases"                                OFF )
67
option ( WALBERLA_BUILD_DOC                 "Build Documentation"                             ON )
68

69
option ( WALBERLA_BUILD_WITH_MPI            "Build with MPI"                                  ON )
70
option ( WALBERLA_BUILD_WITH_METIS          "Build with metis graph partitioner"             OFF )
71
option ( WALBERLA_BUILD_WITH_PARMETIS       "Build with ParMetis graph partitioner"          OFF )
72

73
74
75
option ( WALBERLA_BUILD_WITH_GPROF          "Enables gprof"                                      )
option ( WALBERLA_BUILD_WITH_GCOV           "Enables gcov"                                       )
option ( WALBERLA_BUILD_WITH_LTO            "Enable link time optimizations"                     )
76
77
option ( WALBERLA_BUILD_WITH_OPENMP         "Enable OpenMP support"                              )
option ( WALBERLA_BUILD_WITH_PYTHON         "Support for embedding Python"                       )
78
option ( WALBERLA_BUILD_WITH_PYTHON_MODULE  "Build waLBerla python module"                       )
Martin Bauer's avatar
Martin Bauer committed
79
option ( WALBERLA_BUILD_WITH_PYTHON_LBM     "Include LBM module into python module"          OFF )
80
81
option ( WALBERLA_BUILD_WITH_CODEGEN        "Enable pystencils code generation"              OFF )

Martin Bauer's avatar
Martin Bauer committed
82

83
84
option ( WALBERLA_BUILD_WITH_LIKWID_MARKERS "Compile in markers for likwid-perfctr"              )

Martin Bauer's avatar
Martin Bauer committed
85
86
option ( WALBERLA_BUILD_WITH_CUDA	        "Enable CUDA support"                                )

87
88

option ( WALBERLA_BUILD_WITH_FASTMATH       "Fast math"                                          )
89

90
option ( WALBERLA_SIMD_FORCE_SCALAR         "Do not use SIMD operations even when available" OFF )
91

92
93
94
option ( WALBERLA_BUFFER_DEBUG              "Type checking for BufferSystem ( slow )"        OFF )

# Profile guided optimization
95
96
option ( WALBERLA_PROFILE_GENERATE          "Generates Profile for Optimization"                 )
option ( WALBERLA_PROFILE_USE               "Uses Profile to optimize"                           )
97
98

# Compiler Optimization
99
100
option ( WALBERLA_OPTIMIZE_FOR_LOCALHOST    "Enable compiler optimizations spcific to localhost" )

101
option ( WALBERLA_LOG_SKIPPED               "Log skipped cmake targets"                      ON  )
102
103
104
105
106
107
108
109
110
111
112

# Installation Directory
set ( CMAKE_INSTALL_PREFIX /usr/local/waLBerla CACHE STRING "The default installation directory."   )

# Default build type
if ( NOT CMAKE_BUILD_TYPE )
    set ( CMAKE_BUILD_TYPE Release CACHE STRING "Build Types: Debug Release DebugOptimized RelWithDebInfo MinSizeRel."  FORCE )
endif()
SET_PROPERTY( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release DebugOptimized RelWithDebInfo MinSizeRel )

# Debugging options                                      )
113
option ( WALBERLA_STL_BOUNDS_CHECKS  "Use debug capabilites of libstd++: iterator and bounds checks" )
114
115
116
117
118
119
120

# Warning options
option ( WARNING_DISABLE    "Disables additional compiler warnings"          OFF )
option ( WARNING_PEDANTIC   "Enables pedantic compiler warnings"             ON  )
option ( WARNING_ERROR      "Convert warnings to errors compiler warnings"   OFF )
option ( WARNING_DEPRECATED "Show warning when deprecated features are used" ON  )

121
122
123
# Sanitizer options
option ( WALBERLA_SANITIZE_ADDRESS    "Enables address sanitizer in gcc and clang"            )
option ( WALBERLA_SANITIZE_UNDEFINED  "Enables undefined behavior sanitizer in gcc and clang" )
124
125
126

# Every folder that is listed here can contain modules or tests
# this can be extended by applications to have own modules
127
# Here the src/ folder is added to this list, where all modules are located
128
129
130
131
list( APPEND WALBERLA_MODULE_DIRS "${walberla_SOURCE_DIR}/src" "${walberla_SOURCE_DIR}/tests" )
list( REMOVE_DUPLICATES  WALBERLA_MODULE_DIRS )
set ( WALBERLA_MODULE_DIRS  ${WALBERLA_MODULE_DIRS} CACHE INTERNAL "All folders that contain modules or tests" )

132
133
134
135
136
# target_link_libraries needs to called with keywords everywhere if it is called with keywords once
if( DEFINED CUDA_LINK_LIBRARIES_KEYWORD AND NOT CUDA_LINK_LIBRARIES_KEYWORD STREQUAL "" )
    set( WALBERLA_LINK_LIBRARIES_KEYWORD PUBLIC )
endif()

137
138
############################################################################################################################

139
140
141
set( CMAKE_CXX_STANDARD 14 )
set( CMAKE_CXX_STANDARD_REQUIRED ON )
set( CMAKE_CXX_EXTENSIONS OFF )
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

############################################################################################################################
##
## Compiler detection
##
############################################################################################################################

# Check for intel compiler
if( CMAKE_CXX_COMPILER MATCHES "icpc" OR CMAKE_CXX_COMPILER_ARG1 MATCHES "icpc" )
    option ( WALBERLA_CXX_COMPILER_IS_INTEL "Use Intel compiler" ON  )
    # Intel(R) Compiler has its own library archiver,
    # if you build libraries and do not use xiar,
    # the Intel compiler will complain about invalid
    # archives at the link phase.
    # The Intel(R) archiver is "xiar" usually
    # located in the same folder as the compiler,
    FIND_PROGRAM(XIAR xiar)
    IF(XIAR)
        SET(CMAKE_AR "${XIAR}")
    ENDIF(XIAR)
    MARK_AS_ADVANCED(XIAR)

    # Intel(R) Compiler also comes with its own linker
    # which provides a number of additional benefits when
    # linking code compiled with the Intel(R) compiler.
    # Again, usually in the same place as icc itself,
    FIND_PROGRAM(XILD xild)
    IF(XILD)
       SET(CMAKE_LINKER "${XILD}")
    ENDIF(XILD)
    MARK_AS_ADVANCED(XILD)
Michael Kuron's avatar
Michael Kuron committed
173
    if( CMAKE_VERSION VERSION_LESS 3.6.0 )
Michael Kuron's avatar
Michael Kuron committed
174
      set( CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++14" )
175
      add_flag ( CMAKE_CXX_FLAGS ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION} )
Michael Kuron's avatar
Michael Kuron committed
176
    endif()
177
178
179
180
181
182
183
184
185
186
187
188
else()
    option ( WALBERLA_CXX_COMPILER_IS_INTEL "Use Intel compiler" OFF  )
endif()
mark_as_advanced ( WALBERLA_CXX_COMPILER_IS_INTEL )

# Check for Gnu compiler
if ( CMAKE_COMPILER_IS_GNUCXX  AND NOT WALBERLA_CXX_COMPILER_IS_INTEL )
     option ( WALBERLA_CXX_COMPILER_IS_GNU "Use gnu compiler" ON  )
else()
     option ( WALBERLA_CXX_COMPILER_IS_GNU "Use gnu compiler" OFF  )
endif()
mark_as_advanced ( WALBERLA_CXX_COMPILER_IS_GNU )
189

190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Check for Visual Studio
if ( MSVC )
     option ( WALBERLA_CXX_COMPILER_IS_MSVC "Use Visual Studio compiler" ON  )
else()
     option ( WALBERLA_CXX_COMPILER_IS_MSVC "Use Visual Studio compiler" OFF  )
endif()
mark_as_advanced ( WALBERLA_CXX_COMPILER_IS_MSVC )

# Check for IBM compiler
if( CMAKE_CXX_COMPILER MATCHES "xlc" OR CMAKE_CXX_COMPILER_ARG1 MATCHES "xlc" )
    option ( WALBERLA_CXX_COMPILER_IS_IBM "Use IBM compiler" ON  )
else()
    option ( WALBERLA_CXX_COMPILER_IS_IBM "Use IBM compiler" OFF  )
endif()
mark_as_advanced ( WALBERLA_CXX_COMPILER_IS_IBM )

# Check for NEC SX compiler
if( CMAKE_CXX_COMPILER MATCHES "sxc" OR CMAKE_CXX_COMPILER_ARG1 MATCHES "sxc" OR CMAKE_CXX_COMPILER MATCHES "sxmpic" OR CMAKE_CXX_COMPILER_ARG1 MATCHES "sxmpic" )
    option ( WALBERLA_CXX_COMPILER_IS_NEC "Use NEC compiler" ON  )
else()
    option ( WALBERLA_CXX_COMPILER_IS_NEC "Use NEC compiler" OFF  )
endif()
mark_as_advanced ( WALBERLA_CXX_COMPILER_IS_NEC )

# Check for Clang compiler
Michael Kuron's avatar
Michael Kuron committed
215
if( CMAKE_CXX_COMPILER MATCHES "clang" OR CMAKE_CXX_COMPILER_ARG1 MATCHES "clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" )
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
    option ( WALBERLA_CXX_COMPILER_IS_CLANG "Use clang compiler" ON  )
else()
    option ( WALBERLA_CXX_COMPILER_IS_CLANG "Use clang compiler" OFF  )
endif()
mark_as_advanced ( WALBERLA_CXX_COMPILER_IS_CLANG )

if( CMAKE_CXX_COMPILER_ID MATCHES Cray )
    option ( WALBERLA_CXX_COMPILER_IS_CRAY "Use Cray compiler" ON   )
    if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.4)
        message( FATAL_ERROR "Insufficient Cray Compiler Environment version" )
    endif()
else()
    option ( WALBERLA_CXX_COMPILER_IS_CRAY "Use Cray compiler" OFF  )
endif()
mark_as_advanced ( WALBERLA_CXX_COMPILER_IS_CRAY )

# Check for MPI wrapper
get_filename_component( CXX_COMPILER_WITHOUT_PATH ${CMAKE_CXX_COMPILER} NAME )
if( CXX_COMPILER_WITHOUT_PATH MATCHES "mpi" OR CMAKE_CXX_COMPILER_ARG1 MATCHES "mpi" )
    option ( WALBERLA_CXX_COMPILER_IS_MPI_WRAPPER "Compiler is MPI wrapper" ON  )
else()
    option ( WALBERLA_CXX_COMPILER_IS_MPI_WRAPPER "Compiler is MPI wrapper" OFF  )
endif()
mark_as_advanced ( WALBERLA_CXX_COMPILER_IS_MPI_WRAPPER )

############################################################################################################################



############################################################################################################################
##
## Compiler Setup
##
############################################################################################################################

# Profile guided optimization
if ( WALBERLA_PROFILE_GENERATE )
    if( WALBERLA_CXX_COMPILER_IS_INTEL )
        add_flag( CMAKE_CXX_FLAGS "-prof-gen" )
        file( MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/profile" )
        add_flag( CMAKE_CXX_FLAGS "-prof-dir${CMAKE_BINARY_DIR}/profile" )
    elseif( WALBERLA_CXX_COMPILER_IS_GNU )
        add_flag( CMAKE_CXX_FLAGS "-fprofile-generate" )
    elseif( WALBERLA_CXX_COMPILER_IS_MSVC )
      add_flag ( CMAKE_CXX_FLAGS           "/GL"                )
      add_flag ( CMAKE_MODULE_LINKER_FLAGS "/LTCG:PGINSTRUMENT" )
      add_flag ( CMAKE_SHARED_LINKER_FLAGS "/LTCG:PGINSTRUMENT" )
      add_flag ( CMAKE_EXE_LINKER_FLAGS    "/LTCG:PGINSTRUMENT" )
    endif()
endif()

if ( WALBERLA_PROFILE_USE )
    if( WALBERLA_CXX_COMPILER_IS_INTEL )
       add_flag( CMAKE_CXX_FLAGS "-prof-use" )
       add_flag( CMAKE_CXX_FLAGS "-prof-dir${CMAKE_BINARY_DIR}/profile" )
    elseif( WALBERLA_CXX_COMPILER_IS_GNU )
       add_flag( CMAKE_CXX_FLAGS "-fprofile-use" )
    elseif( WALBERLA_CXX_COMPILER_IS_MSVC )
      add_flag ( CMAKE_CXX_FLAGS           "/GL"              )
      add_flag ( CMAKE_MODULE_LINKER_FLAGS "/LTCG:PGOPTIMIZE" )
      add_flag ( CMAKE_SHARED_LINKER_FLAGS "/LTCG:PGOPTIMIZE" )
      add_flag ( CMAKE_EXE_LINKER_FLAGS    "/LTCG:PGOPTIMIZE" )
    endif()
endif()

# common flags for intel and g++
282
if ( NOT WARNING_DISABLE AND ( WALBERLA_CXX_COMPILER_IS_GNU OR WALBERLA_CXX_COMPILER_IS_INTEL ) )
283
284
285
   add_flag ( CMAKE_CXX_FLAGS "-Wall -Wconversion -Wshadow" )
endif()

Michael Kuron's avatar
Michael Kuron committed
286
# C++ language features for NEC compiler
287
if( WALBERLA_CXX_COMPILER_IS_NEC )
Michael Kuron's avatar
Michael Kuron committed
288
   set( CMAKE_CXX14_STANDARD_COMPILE_OPTION "-Kcpp14" )
289
   add_flag ( CMAKE_CXX_FLAGS "${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION} -Krtti -Kexceptions -size_t64 -Kgcc" )
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
   add_flag ( CMAKE_CXX_FLAGS "-D__BIG_ENDIAN -D__BYTE_ORDER=__BIG_ENDIAN" )
   add_flag ( CMAKE_CXX_FLAGS "-Tnoauto,used" )
   add_flag ( CMAKE_EXE_LINKER_FLAGS "-Wl,-h,muldefs" )
   add_flag ( CMAKE_C_FLAGS "-size_t64 -Kgcc" )
   add_flag ( CMAKE_C_FLAGS "-D__BIG_ENDIAN -D__BYTE_ORDER=__BIG_ENDIAN" )
   add_flag ( CMAKE_C_FLAGS "-DSQLITE_OMIT_WAL -DHAVE_UTIME -DTHREADSAFE=0" )
   set( CMAKE_RANLIB /bin/true )
   set( CMAKE_SKIP_BUILD_RPATH TRUE )
   set( CMAKE_C_FLAGS_DEBUGOPTIMIZED    "-Chopt -g"                               )
   set( CMAKE_C_FLAGS_DEBUG             "-Cdebug -g"                              )
   set( CMAKE_CXX_FLAGS_DEBUGOPTIMIZED  "-Chopt -g"                               )
   set( CMAKE_CXX_FLAGS_DEBUG           "-Cdebug -g"                              )
endif()

# Fixes linker errors with IBM compiler
if( WALBERLA_CXX_COMPILER_IS_IBM )
   add_flag ( CMAKE_CXX_FLAGS "-qpic=large" )
endif()
# Fixes linker errors with Cray compiler
if( WALBERLA_CXX_COMPILER_IS_CRAY )
   add_flag ( CMAKE_EXE_LINKER_FLAGS  "-dynamic -L/opt/gcc/4.9.3/snos/lib64" )
endif()

# Silences compiler and linker warnings and information with the IBM compiler
if( WALBERLA_CXX_COMPILER_IS_IBM )
   add_flag ( CMAKE_CXX_FLAGS "-qsuppress=1586-267" )  # 1586-267 (I) Inlining of specified subprogram failed due to the presence of a C++ exception handler
   add_flag ( CMAKE_CXX_FLAGS "-qsuppress=1586-266" )  # 1586-266 (I) Inlining of specified subprogram failed due to the presence of a global label
   add_flag ( CMAKE_CXX_FLAGS "-qsuppress=1540-0724" ) # 1540-0724 (W) The non-type template argument "2147483648" of type "T" has wrapped [coming from boost/integer_traits.hpp]
   add_flag ( CMAKE_CXX_FLAGS "-qsuppress=1540-0095" ) # 1540-0095 (W) The friend function declaration ... [coming from boost/mpl/map/aux_/map0.hpp]
   add_flag ( CMAKE_CXX_FLAGS "-qsuppress=1500-030" )  # 1500-030: (I) INFORMATION: [...] Additional optimization may be attained by recompiling and specifying MAXMEM option with a value greater than 8192.
   add_flag ( CMAKE_C_FLAGS "-qsuppress=1500-030" )    # 1500-030: (I) INFORMATION: [...] Additional optimization may be attained by recompiling and specifying MAXMEM option with a value greater than 8192.
endif()

# Silences compiler and linker warnings and information with the Cray compiler
if( WALBERLA_CXX_COMPILER_IS_CRAY )
   set( CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem " )
   add_flag ( CMAKE_CXX_FLAGS "-h nomessage=1" )      # CC-1    The source file does not end with a new-line character.
   add_flag ( CMAKE_C_FLAGS   "-DSQLITE_HAVE_ISNAN" ) # SQLite will not work correctly with the -ffast-math option of GCC.
   add_flag ( CMAKE_CXX_FLAGS "-DSQLITE_HAVE_ISNAN" ) # SQLite will not work correctly with the -ffast-math option of GCC.
endif()

# architecture optimization
if( WALBERLA_OPTIMIZE_FOR_LOCALHOST )
   if( WALBERLA_CXX_COMPILER_IS_GNU OR WALBERLA_CXX_COMPILER_IS_INTEL OR WALBERLA_CXX_COMPILER_IS_CLANG )
      add_flag ( CMAKE_CXX_FLAGS "-march=native" )
      add_flag ( CMAKE_C_FLAGS   "-march=native" )
      if( WALBERLA_CXX_COMPILER_IS_INTEL )
        add_flag ( CMAKE_CXX_FLAGS "-xhost" )
        add_flag ( CMAKE_C_FLAGS   "-xhost" )
      endif()
   endif()
341
endif()
342

343
# warning flags
344
345
346
347
348
if( WALBERLA_CXX_COMPILER_IS_INTEL )
   # system headers are also supported by intel, but cmake does not recognize that
   set( CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem " )
   add_flag ( CMAKE_CXX_FLAGS "-wd2928,2504,2259,1682,597" )
elseif( WALBERLA_CXX_COMPILER_IS_GNU )
349
   add_flag ( CMAKE_CXX_FLAGS "-Wfloat-equal -Wextra" )
350
351
352
353
354
elseif( WALBERLA_CXX_COMPILER_IS_NEC )
   add_flag ( CMAKE_CXX_FLAGS "-wall" )
endif()

if ( WARNING_PEDANTIC AND WALBERLA_CXX_COMPILER_IS_GNU )
355
   add_flag ( CMAKE_CXX_FLAGS "-pedantic" )
356
endif ( )
357

358
 # omit deprecated warnings
359
if( NOT WARNING_DEPRECATED)
360
361
362
363
364
365
   if( WALBERLA_CXX_COMPILER_IS_INTEL )
       add_flag( CMAKE_CXX_FLAGS "-wd1478" )  # Disable compiler warning # 1478: "declared as deprecated"
   elseif( WALBERLA_CXX_COMPILER_IS_GNU OR WALBERLA_CXX_COMPILER_IS_CLANG )
       add_flag ( CMAKE_CXX_FLAGS "-Wno-deprecated-declarations")
   endif()
endif()
366

367
368

if ( WALBERLA_CXX_COMPILER_IS_CLANG )
Michael Kuron's avatar
Michael Kuron committed
369
    add_flag ( CMAKE_CXX_FLAGS "-Wall -Wconversion -Wshadow -Wno-c++11-extensions -Qunused-arguments" )
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
    add_flag ( CMAKE_CXX_FLAGS "-D'_LIBCPP_EXTERN_TEMPLATE(...)='")
endif ( )

if( WALBERLA_CXX_COMPILER_IS_GNU OR WALBERLA_CXX_COMPILER_IS_INTEL OR WALBERLA_CXX_COMPILER_IS_CLANG )
    if ( WALBERLA_STL_BOUNDS_CHECKS )
        add_definitions ( "-D_GLIBCXX_DEBUG" )
    endif()
endif()


#fastmath
if ( WALBERLA_BUILD_WITH_FASTMATH )
    if ( WALBERLA_CXX_COMPILER_IS_INTEL )
        add_flag( CMAKE_CXX_FLAGS "-fp-model fast=2 -no-prec-sqrt -no-prec-div" )
    endif()
385

386
387
388
    if ( WALBERLA_CXX_COMPILER_IS_GNU OR WALBERLA_CXX_COMPILER_IS_CLANG )
        add_flag( CMAKE_CXX_FLAGS "-ffast-math")
    endif()
389

390
391
392
    if( WALBERLA_CXX_COMPILER_IS_MSVC )
        add_flag( CMAKE_CXX_FLAGS "/fp:fast" )
    endif()
393
endif()
394
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
432
433

# Xcode generator disables -isystem flag, even though current versions of Xcode support it
if(CMAKE_GENERATOR STREQUAL "Xcode")
    set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ")
    set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ")
endif()


#GCC 5+ ABI selection
if( WALBERLA_CXX_COMPILER_IS_GNU )
   if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0.0 )
      option ( WALBERLA_USE_CPP11_ABI "On GCC 5+ use the C++11 ABI" ON )
      if( WALBERLA_USE_CPP11_ABI )
         add_flag( CMAKE_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=1" )
      else()
         add_flag( CMAKE_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0" )
      endif()
   endif()
endif()


# disable Xcode 7.3+ linker deduplication pass to speed up linking in debug mode
if ( APPLE )
   execute_process( COMMAND ${CMAKE_LINKER} -v OUTPUT_VARIABLE LINKER_VERSION ERROR_VARIABLE LINKER_VERSION )
   string( REGEX MATCH "ld64-[0-9\\.\\-]+" LINKER_VERSION ${LINKER_VERSION} )
   string( REGEX MATCHALL "[^\\-]+" LINKER_VERSION ${LINKER_VERSION} )
   list( GET LINKER_VERSION 0 LINKER_TYPE )
   list( GET LINKER_VERSION 1 LINKER_VERSION )
   if( LINKER_TYPE STREQUAL "ld64" AND LINKER_VERSION VERSION_GREATER 264.3.101 )
       add_flag( CMAKE_EXE_LINKER_FLAGS_DEBUG    "-Wl,-no_deduplicate")
       add_flag( CMAKE_MODULE_LINKER_FLAGS_DEBUG "-Wl,-no_deduplicate")
       add_flag( CMAKE_SHARED_LINKER_FLAGS_DEBUG "-Wl,-no_deduplicate")
   endif()
endif()


############################################################################################################################



Michael Kuron's avatar
Michael Kuron committed
434
435
436
437
438
439
############################################################################################################################
##
##  Find optional C++ libraries
##
############################################################################################################################

440
try_compile( WALBERLA_USE_STD_FILESYSTEM "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/TestStdFilesystem.cpp"
441
             COMPILE_DEFINITIONS -DWALBERLA_USE_STD_FILESYSTEM ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION} )
Michael Kuron's avatar
Michael Kuron committed
442
443
444
if( WALBERLA_USE_STD_FILESYSTEM )
   message( STATUS "Found std::filesystem")
else()
445
   try_compile( WALBERLA_USE_STD_EXPERIMENTAL_FILESYSTEM "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/TestStdFilesystem.cpp"
446
                COMPILE_DEFINITIONS -DWALBERLA_USE_STD_EXPERIMENTAL_FILESYSTEM ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION} )
Michael Kuron's avatar
Michael Kuron committed
447
448
449
450
451
   if( WALBERLA_USE_STD_EXPERIMENTAL_FILESYSTEM )
      message( STATUS "Found std::experimental::filesystem")
   endif()
   if( NOT WALBERLA_CXX_COMPILER_IS_MSVC AND NOT WALBERLA_USE_STD_EXPERIMENTAL_FILESYSTEM )
      unset( WALBERLA_USE_STD_EXPERIMENTAL_FILESYSTEM CACHE )
452
      try_compile( WALBERLA_USE_STD_EXPERIMENTAL_FILESYSTEM "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/TestStdFilesystem.cpp"
453
                   COMPILE_DEFINITIONS -DWALBERLA_USE_STD_EXPERIMENTAL_FILESYSTEM ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION}
Michael Kuron's avatar
Michael Kuron committed
454
455
456
457
458
459
460
461
                   LINK_LIBRARIES stdc++fs )
      if( WALBERLA_USE_STD_EXPERIMENTAL_FILESYSTEM )
         message( STATUS "Found std::experimental::filesystem in libstdc++fs")
      list ( APPEND SERVICE_LIBS -lstdc++fs )
      endif()
   endif()
   if( NOT WALBERLA_CXX_COMPILER_IS_MSVC AND NOT WALBERLA_USE_STD_EXPERIMENTAL_FILESYSTEM )
      unset( WALBERLA_USE_STD_EXPERIMENTAL_FILESYSTEM CACHE )
462
      try_compile( WALBERLA_USE_STD_EXPERIMENTAL_FILESYSTEM "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/TestStdFilesystem.cpp"
463
                   COMPILE_DEFINITIONS -DWALBERLA_USE_STD_EXPERIMENTAL_FILESYSTEM ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION}
Michael Kuron's avatar
Michael Kuron committed
464
465
466
467
468
469
470
471
                   LINK_LIBRARIES c++experimental )
      if( WALBERLA_USE_STD_EXPERIMENTAL_FILESYSTEM )
         message( STATUS "Found std::experimental::filesystem in libc++experimental")
         list ( APPEND SERVICE_LIBS -lc++experimental )
      endif()
   endif()
endif()

472
try_compile( WALBERLA_USE_STD_ANY "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/TestStdAny.cpp"
473
             COMPILE_DEFINITIONS -DWALBERLA_USE_STD_ANY ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION} )
474
475
476
if( WALBERLA_USE_STD_ANY )
   message( STATUS "Found std::any")
else()
477
   try_compile( WALBERLA_USE_STD_EXPERIMENTAL_ANY "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/TestStdAny.cpp"
478
                COMPILE_DEFINITIONS -DWALBERLA_USE_STD_EXPERIMENTAL_ANY ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION} )
479
480
481
482
483
   if( WALBERLA_USE_STD_EXPERIMENTAL_ANY )
      message( STATUS "Found std::experimental::any")
   endif()
endif()

484
try_compile( WALBERLA_USE_STD_OPTIONAL "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/TestStdOptional.cpp"
485
             COMPILE_DEFINITIONS -DWALBERLA_USE_STD_OPTIONAL ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION} )
486
487
488
if( WALBERLA_USE_STD_OPTIONAL )
   message( STATUS "Found std::optional")
else()
489
   try_compile( WALBERLA_USE_STD_EXPERIMENTAL_OPTIONAL "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/TestStdOptional.cpp"
490
                COMPILE_DEFINITIONS -DWALBERLA_USE_STD_EXPERIMENTAL_OPTIONAL ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION} )
491
492
493
494
495
   if( WALBERLA_USE_STD_EXPERIMENTAL_OPTIONAL )
      message( STATUS "Found std::experimental::optional")
   endif()
endif()

Michael Kuron's avatar
Michael Kuron committed
496
try_compile( WALBERLA_USE_STD_VARIANT "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/TestStdVariant.cpp"
497
             COMPILE_DEFINITIONS -DWALBERLA_USE_STD_VARIANT ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION} )
Michael Kuron's avatar
Michael Kuron committed
498
499
500
501
if( WALBERLA_USE_STD_VARIANT )
   message( STATUS "Found std::variant")
endif()

Michael Kuron's avatar
Michael Kuron committed
502
503


504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
############################################################################################################################
##
##  Visual Studio Setup
##
############################################################################################################################
if ( WALBERLA_CXX_COMPILER_IS_MSVC )
   string( REGEX REPLACE "[/-]W[0-4]" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ) # remove default warning flags

   option ( WALBERLA_GROUP_PROJECTS   "Flag if the projects are grouped or in a flat hierarchy"    ON )
   option ( WALBERLA_GROUP_FILES      "Flag if the files are grouped or in a flat hierarchy"       ON )
   set_property ( GLOBAL PROPERTY USE_FOLDERS ${WALBERLA_GROUP_PROJECTS} )

   option ( WALBERLA_VS_MULTI_PROCESS_BUILD "Use the /mp option for VS builds" ON )
   if( WALBERLA_VS_MULTI_PROCESS_BUILD )
      add_flag ( CMAKE_CXX_FLAGS "-MP" ) # enable multi-threaded compiling
   endif()
520

521
522
523
524
525
   add_definitions ( "-DNOMINMAX" )                # Disable Min/Max-Macros
   add_definitions ( "-D_WIN32_WINNT=0x501" )      # Minimum Windows versions is Windows XP
   add_definitions ( "-DWINVER=0x501" )            # Minimum Windows versions is Windows XP
   add_definitions ( "-D_CRT_SECURE_NO_WARNINGS" ) # disable warnings promoting Microsoft's security enhanced CRT
   add_definitions ( "-D_SCL_SECURE_NO_WARNINGS" ) # disable warnings triggered by Microsoft's checked iterators
526
   add_flag ( CMAKE_CXX_FLAGS "-W4" )              # set warning level to maximum
527
528
529
   add_flag ( CMAKE_CXX_FLAGS "-bigobj" )          # enable big object files
   add_flag ( CMAKE_CXX_FLAGS "-wd4127" )          # disable compiler warning C4127: "conditional expression is constant"
   add_flag ( CMAKE_CXX_FLAGS "-wd4512" )          # disable compiler warning C4512: "assignment operator could not be generated"
530
   add_flag ( CMAKE_CXX_FLAGS "-wd4913" )          # disable compiler warning C4512: "user defined binary operator ',' exists but
531
532
533
534
535
                                                   # no overload could convert all operands, default built-in binary operator ','
                                                   # used"
   add_flag ( CMAKE_CXX_FLAGS "-wd4702" )          # disable compiler warning C4702: "unreachable code"
   add_flag ( CMAKE_CXX_FLAGS "-wd4505" )          # disable compiler warning C4505: "unreferenced local function has been removed"
   add_flag ( CMAKE_CXX_FLAGS "-wd4503" )          # disable compiler warning C4503: "'identifier' : decorated name length exceeded, name was truncated"
536

537
538
539
   if ( WARNING_ERROR )
      add_flag ( CMAKE_CXX_FLAGS "-WX" )           # Treat warnings as errors
   endif ( )
540

541
542
543
544
545
   if( NOT WARNING_DEPRECATED)
      add_definitions( "-D_CRT_SECURE_NO_DEPRECATE" )
      add_definitions( "-D_SCL_SECURE_NO_DEPRECATE" )
      add_flag       ( CMAKE_CXX_FLAGS "-wd4996"    ) # Disable compiler warning C4996: "declared as deprecated"
   endif()
546

547
548
549
550
551
552
endif ( )
############################################################################################################################




553
554
555
556
557
558
559
############################################################################################################################
##
## Code Generation (pystencils)
##
#############################################################################################################################
if ( WALBERLA_BUILD_WITH_CODEGEN )
    find_package( PythonInterp 3 QUIET REQUIRED)
560
    execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from pystencils.include import get_pystencils_include_path; print(get_pystencils_include_path())"
561
562
                    RESULT_VARIABLE PYTHON_RET_CODE
                    OUTPUT_VARIABLE PYSTENCILS_INCLUDE_PATH)
563
564
565
    if(NOT PYTHON_RET_CODE EQUAL 0)
        message(FATAL_ERROR "WALBERLA_BUILD_WITH_CODEGEN activated and pystencils_walberla package not found")
    endif()
566
    include_directories( ${PYSTENCILS_INCLUDE_PATH} )
567
568
569
570
571
572
endif()
############################################################################################################################




573
574
575
576
577
578
############################################################################################################################
##
## Python Libraries
##
#############################################################################################################################
if ( WALBERLA_BUILD_WITH_PYTHON )
579

580
    set ( waLBerla_REQUIRED_MIN_PYTHON_VERSION "2.7")
581

Martin Bauer's avatar
Martin Bauer committed
582
583
584
585
    find_package( PythonInterp 3 QUIET) # search for Python3 first
    find_package( PythonInterp QUIET) # fallback to any Python version

    find_package( PythonLibs QUIET REQUIRED)
586

587
588
589
    if( PYTHONLIBS_VERSION_STRING VERSION_LESS ${waLBerla_REQUIRED_MIN_PYTHON_VERSION} )
        message( FATAL_ERROR "Found old python library: ${PYTHONLIBS_VERSION_STRING} need at least ${waLBerla_REQUIRED_MIN_PYTHON_VERSION}" )
    endif()
590

591
    option( WALBERLA_USE_PYTHON_DEBUG_LIBRARY "Make use of the python debug library" OFF )
592

593
594
595
596
    if( WALBERLA_USE_PYTHON_DEBUG_LIBRARY )
      # you have to make sure this matches the settings you compiled boost with!
      add_definitions( "-DBOOST_DEBUG_PYTHON" )
    endif()
597

598
599
600
    if( NOT (PYTHON_LIBRARY AND PYTHON_INCLUDE_DIR ) )
        message( FATAL_ERROR "Couldn't find any python library" )
    endif()
601

602
603
604
    SET( WALBERLA_BUILD_WITH_PYTHON 1 )
    include_directories( ${PYTHON_INCLUDE_DIR} )
    list ( APPEND SERVICE_LIBS ${PYTHON_LIBRARY} )
605

606
607
608
    if( NOT WALBERLA_CXX_COMPILER_IS_MSVC )
        list ( APPEND SERVICE_LIBS -lutil )
    endif()
609

610
611
    if ( WALBERLA_BUILD_WITH_PYTHON_MODULE )
        # a python module is a shared library - so everything has to be compiled to position independent code
612
        # otherwise linking the static libs into the shared lib will result in errors
613
614
615
616
617
        if( NOT WALBERLA_CXX_COMPILER_IS_MSVC )
            add_flag ( CMAKE_CXX_FLAGS "-fPIC" )
            add_flag ( CMAKE_C_FLAGS "-fPIC" )
        endif()
    endif()
618

619
620
621
622
623
624
625
    if( MSVC10 )
        include(CMakeDependentOption)
        CMAKE_DEPENDENT_OPTION( PYTHON_FIXED_HYPOT_REDEFINITION "fixed _hypot redefinition by python" OFF "WALBERLA_BUILD_WITH_PYTHON" OFF )
        if( NOT PYTHON_FIXED_HYPOT_REDEFINITION )
            message( WARNING "Make sure you modified your pyconfig.h that _hypot is not redefined -> see: http://connect.microsoft.com/VisualStudio/feedback/details/633988/warning-in-math-h-line-162-re-nonstandard-extensions-used" )
        endif()
    endif()
626

627

628
629
630
631
632
633
634
    if(WALBERLA_BUILD_DOC)
      # Sphinx documentation
      # to build documentation make sure to have sphinx and read-the-docs theme installed
      # Install with: "pip install sphinx sphinx_rtd_theme"
      add_custom_target( docPython sphinx-build -b html "${walberla_SOURCE_DIR}/python/waLBerla_docs" "${walberla_BINARY_DIR}/doc/python"
                         COMMENT "Building HTML documentation for Python extension with Sphinx")
  endif()
635
636
637
638
639
640
641
642
643
endif()


############################################################################################################################
##
## BOOST Libraries
##
#############################################################################################################################
set ( waLBerla_REQUIRED_MIN_BOOST_VERSION "1.48")
644
set ( Boost_NO_BOOST_CMAKE ON)
645

Michael Kuron's avatar
Michael Kuron committed
646
647
if ( NOT WALBERLA_USE_STD_FILESYSTEM AND NOT WALBERLA_USE_STD_EXPERIMENTAL_FILESYSTEM )
  list ( APPEND waLBerla_REQUIRED_BOOST_COMPONENTS filesystem system )
648
649
else()
  list ( APPEND waLBerla_OPTIONAL_BOOST_COMPONENTS system )
Michael Kuron's avatar
Michael Kuron committed
650
endif()
651

652
653
if ( WALBERLA_BUILD_WITH_PYTHON )
  if( WALBERLA_CXX_COMPILER_IS_MSVC )
654
655
    get_filename_component(PYTHON_REQUIRED_LIB ${PYTHON_LIBRARY} NAME_WE)
    list( APPEND waLBerla_REQUIRED_BOOST_COMPONENTS ${PYTHON_REQUIRED_LIB} )
656
657
658
659
  elseif( WALBERLA_USE_STD_FILESYSTEM OR WALBERLA_USE_STD_EXPERIMENTAL_FILESYSTEM )
    list( APPEND waLBerla_REQUIRED_BOOST_COMPONENTS system )
    list( REMOVE_ITEM waLBerla_OPTIONAL_BOOST_COMPONENTS system )
  endif()
660
661
662
663
endif()

# This variable is necessary, if the CMAKE version used is not aware of a more recent boost version (keep this up to date!)
set ( Boost_ADDITIONAL_VERSIONS
664
665
      "1.45" "1.45.0" "1.46" "1.46.0" "1.46.1" "1.47" "1.47.0" "1.48" "1.48.0" "1.49" "1.49.0"
      "1.50" "1.50.0" "1.51" "1.51.0" "1.52" "1.52.0" "1.53" "1.53.0" "1.54" "1.54.0" "1.55" "1.55.0"
666
      "1.56" "1.56.0" "1.57" "1.57.0" "1.58" "1.58.0" "1.59" "1.59.0" "1.60" "1.60.0" "1.61" "1.61.0" "1.62" "1.62.0" "1.63" "1.63.0"
Markus Holzer's avatar
Markus Holzer committed
667
      "1.64.0" "1.65.0" "1.65.1" "1.66.0" "1.67.0" "1.68.0" "1.69.0" "1.70.0" "1.71.0" "1.72.0" "1.73.0")
668
669
670
671
672
673
674
675
676
677
678
679
680
681

set ( Boost_USE_STATIC_LIBS    OFF CACHE BOOL "Use boost static libraries" )
set ( Boost_USE_MULTITHREADED  OFF CACHE BOOL "Use boost multithreaded libraries" )
set ( Boost_USE_STATIC_RUNTIME OFF CACHE BOOL "Use boost libraries statically linked to runtime libs" )

# if you defined BOOST_ROOT or BOOST_BASE in your environment use it here to find boost too
if ( NOT BOOST_ROOT )
   foreach ( var  BOOST_ROOT  BOOST_BASE )
      if ( NOT "$ENV{${var}}" STREQUAL "" )
         message ( STATUS "Use environment boost directory: $ENV{${var}}" )
         set ( BOOST_ROOT $ENV{${var}} CACHE INTERNAL "")
         break ( )
      endif ( )
   endforeach ( )
682
endif ( )
683

684
find_package ( Boost ${waLBerla_REQUIRED_MIN_BOOST_VERSION} COMPONENTS ${waLBerla_REQUIRED_BOOST_COMPONENTS} OPTIONAL_COMPONENTS ${waLBerla_OPTIONAL_BOOST_COMPONENTS} QUIET )
685
686

if( NOT Boost_FOUND )
687
   message ( WARNING
688
689
690
      "The specified configuration of the BOOST libraries was not found on your system! Now trying some other configuration..." )
   foreach ( Boost_USE_STATIC_LIBS ON OFF )
      foreach ( Boost_USE_MULTITHREADED ON OFF )
691
         find_package ( Boost ${waLBerla_REQUIRED_MIN_BOOST_VERSION} COMPONENTS ${waLBerla_REQUIRED_BOOST_COMPONENTS} OPTIONAL_COMPONENTS ${waLBerla_OPTIONAL_BOOST_COMPONENTS} QUIET )
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
         if ( Boost_FOUND )
            set ( Boost_USE_STATIC_LIBS   ${Boost_USE_STATIC_LIBS}   CACHE BOOL "Use boost static libraries"        FORCE )
            set ( Boost_USE_MULTITHREADED ${Boost_USE_MULTITHREADED} CACHE BOOL "Use boost multithreaded libraries" FORCE )
            set ( Boost_USE_MULTITHREADED_LIBRARY ${Boost_USE_MULTITHREADED} )
            message ( STATUS "Working configuration of the BOOST libraries was found :o)!" )
            message ( STATUS "Boost_USE_STATIC_LIBS and Boost_USE_MULTITHREADED was adapted accordingly." )
            BREAK ( )
         endif ( Boost_FOUND )
      endforeach ( Boost_USE_MULTITHREADED )
      if ( Boost_FOUND )
         BREAK ( )
      endif ( Boost_FOUND )
   endforeach ( Boost_USE_STATIC_LIBS )
endif ( NOT Boost_FOUND )

if ( Boost_FOUND )
   if(CMAKE_GENERATOR STREQUAL "Xcode")
      # this is needed because the SYSTEM flag to include_directories does not work
      add_flag ( CMAKE_CXX_FLAGS "-isystem ${Boost_INCLUDE_DIRS}" )
   else()
      include_directories ( SYSTEM ${Boost_INCLUDE_DIRS} )
   endif()
714
715
716
717
   if( waLBerla_REQUIRED_BOOST_COMPONENTS )
      link_directories ( ${Boost_LIBRARY_DIRS} )
      list ( APPEND SERVICE_LIBS ${Boost_LIBRARIES} )
   endif()
718
   add_definitions ( -DBOOST_ALL_NO_LIB ) # Disable Boost auto-linking (CMAKE does that for us...)
719

720
721
722
723
   #fix for static lib usage: http://stackoverflow.com/questions/11812463/boost-python-link-errors-under-windows-msvc10
   if( PYTHONLIBS_FOUND AND Boost_USE_STATIC_LIBS)
      add_definitions( -DBOOST_PYTHON_STATIC_LIB )
   endif()
724

725
726
727
728
729
730
731
   #fix for strange link behaviour of boost to python: boost only links to 'pyhton*.lib' and not to the absolute path
   if( WIN32 AND PYTHONLIBS_FOUND )
      get_filename_component( PYTHON_LIBRARY_DIR ${PYTHON_INCLUDE_DIR} PATH )
      link_directories( ${PYTHON_LIBRARY_DIR}/libs )
      list( APPEND LINK_DIRS ${PYTHON_LIBRARY_DIR}/libs )
   endif()

Michael Kuron's avatar
Michael Kuron committed
732
   set( WALBERLA_BUILD_WITH_BOOST TRUE CACHE INTERNAL "Build with Boost" )
733
else( Boost_FOUND )
Michael Kuron's avatar
Michael Kuron committed
734
735
736
737
738
739
740
741
742
743
   if( (WALBERLA_USE_STD_EXPERIMENTAL_FILESYSTEM OR WALBERLA_USE_STD_FILESYSTEM) AND (WALBERLA_USE_STD_EXPERIMENTAL_ANY OR WALBERLA_USE_STD_ANY) AND (WALBERLA_USE_STD_EXPERIMENTAL_OPTIONAL OR WALBERLA_USE_STD_OPTIONAL) AND NOT WALBERLA_BUILD_WITH_PYTHON)
      # we don't really need Boost
      set( WALBERLA_BUILD_WITH_BOOST FALSE CACHE INTERNAL "Build with Boost" )
   else()
      # Search again, this time with the REQUIRED option. This will give a CMAKE error and a detailed error message for the user
      find_package ( Boost ${waLBerla_REQUIRED_MIN_BOOST_VERSION} REQUIRED ${waLBerla_REQUIRED_BOOST_COMPONENTS} OPTIONAL_COMPONENTS ${waLBerla_OPTIONAL_BOOST_COMPONENTS} )
      if( (WALBERLA_USE_STD_EXPERIMENTAL_FILESYSTEM OR WALBERLA_USE_STD_FILESYSTEM) AND (WALBERLA_USE_STD_EXPERIMENTAL_ANY OR WALBERLA_USE_STD_ANY) AND (WALBERLA_USE_STD_EXPERIMENTAL_OPTIONAL OR WALBERLA_USE_STD_OPTIONAL) )
         message(WARNING "If you set WALBERLA_BUILD_WITH_PYTHON=OFF, you can build without the Boost library.")
      endif()
   endif()
744
745
746
747
748
749
750
751
752
753
endif( Boost_FOUND )


# Check if Python3 found and look for according boost python library
if ( WALBERLA_BUILD_WITH_PYTHON AND NOT WALBERLA_CXX_COMPILER_IS_MSVC)
    SET(_boost_MULTITHREADED "")
    if (Boost_USE_MULTITHREADED OR Boost_USE_MULTITHREADED_LIBRARY)
        SET(_boost_MULTITHREADED "-mt")
    endif()
    if( PYTHON_LIBRARY MATCHES "python3" )
754
755
756
        string(REPLACE "." ";" VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
        list(GET VERSION_LIST 0 PY_VER_MAJOR)
        list(GET VERSION_LIST 1 PY_VER_MINOR)
757
        find_library( BOOST_PYTHON_LIBRARY NAMES
758
759
760
                boost_python${PY_VER_MAJOR}${PY_VER_MINOR}${_boost_MULTITHREADED}
                boost_python-py${PY_VER_MAJOR}${PY_VER_MINOR}${_boost_MULTITHREADED}
                boost_python${PY_VER_MAJOR}${_boost_MULTITHREADED}
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
                boost_python${_boost_MULTITHREADED}
                PATHS ${Boost_LIBRARY_DIRS} NO_DEFAULT_PATH )
    else()
        find_library( BOOST_PYTHON_LIBRARY NAMES boost_python${_boost_MULTITHREADED}
                      PATHS ${Boost_LIBRARY_DIRS} NO_DEFAULT_PATH )
    endif()
    message(STATUS "Using Boost Python Library ${BOOST_PYTHON_LIBRARY}" )
    list ( APPEND SERVICE_LIBS ${BOOST_PYTHON_LIBRARY} )
endif()


############################################################################################################################





############################################################################################################################
##
780
## PThread is required in Linux environments by std::thread
781
782
783
##
############################################################################################################################

784
if ( NOT WIN32 )
785
786
787
788
789
   add_flag( CMAKE_CXX_FLAGS "-pthread" )
endif()



790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
############################################################################################################################
##
## backtrace may be in a separate library
##
############################################################################################################################

if ( NOT WIN32 AND (WALBERLA_CXX_COMPILER_IS_GNU OR WALBERLA_CXX_COMPILER_IS_INTEL OR WALBERLA_CXX_COMPILER_IS_CLANG))
   find_package ( Backtrace QUIET )
   if ( Backtrace_FOUND )
      list ( APPEND SERVICE_LIBS ${Backtrace_LIBRARIES} )
      set ( WALBERLA_BUILD_WITH_BACKTRACE ON )
      set ( WALBERLA_BACKTRACE_HEADER ${Backtrace_HEADER} )
   endif ( Backtrace_FOUND )
endif()



807
808
809
810
811
812
############################################################################################################################
##
## MPI
##
############################################################################################################################

813
if ( WALBERLA_BUILD_WITH_MPI AND NOT WALBERLA_CXX_COMPILER_IS_MPI_WRAPPER )
814
   find_package ( MPI )
815

816
817
818
819
820
821
822
823
824
825
   # FindMPI does not really work under windows, because it expects linux formatted strings from the mpi compiler.
   # Nevertheless for Microsoft MPI and MPICH there are workarounds included, but not for OpenMPI.
   # Here is a workaround for windows with OpenMPI (use configure twice to see correct output).
   # The workaround bases on the elseif(try_libs) case in the interrogate_* function of FindMPI.
   # For this workaround we assume, that the compiler was found in any PATH or ENV variable
   # but FindMPI was not able to interpret the command line outputs.
   if ( MPI_CXX_COMPILER AND NOT MPI_CXX_LIBRARIES )
      if ( WIN32 )
         message ( STATUS "Enter Workaround Routine for Windows and OpenMPI: PRESS CONFIGURE ONE MORE TIME!" )
         string ( REGEX REPLACE "(.*)/bin/.*" "\\1" MPI_PATH ${MPI_CXX_COMPILER} )
826
         find_path ( MPI_C_INCLUDE_PATH mpi.h
827
828
            HINTS ${MPI_PATH}
            PATH_SUFFIXES include Inc)
829
         set ( MPI_CXX_INCLUDE_PATH ${MPI_C_INCLUDE_PATH} CACHE FILEPATH "" FORCE )
830
831
832
833
834
835
836
837
838
839

         set ( MPI_CXX_LIBRARIES "MPI_CXX_LIBRARIES-NOTFOUND" CACHE FILEPATH "Cleared" FORCE )
         find_library ( MPI_CXX_LIBRARIES
            NAMES         mpi++ mpicxx cxx mpi_cxx libmpi++ libmpicxx libcxx libmpi_cxx
            HINTS         ${MPI_PATH}
            PATH_SUFFIXES lib )

         if ( NOT MPI_CXX_LIBRARIES STREQUAL "MPI_CXX_LIBRARIES-NOTFOUND" )
            set ( MPI_CXX_FOUND ON FORCE )
         endif ( )
840

841
842
843
844
845
         set ( MPI_C_LIBRARIES "MPI_C_LIBRARIES-NOTFOUND" CACHE FILEPATH "Cleared" FORCE )
         find_library ( MPI_C_LIBRARIES
           NAMES         mpi mpich mpich2 msmpi libmpi libmpich libmpich2 libmsmpi
           HINTS         ${MPI_PATH}
           PATH_SUFFIXES lib )
846

847
848
849
         if ( NOT MPI_C_LIBRARIES STREQUAL "MPI_C_LIBRARIES-NOTFOUND" )
            set ( MPI_C_FOUND ON FORCE )
         endif ( )
850

851
852
853
854
855
856
857
858
         if ( MPI_PATH MATCHES ".*OpenMPI.*" )
            set ( MPI_CXX_COMPILE_FLAGS "/DOMPI_IMPORTS" CACHE STRING "" FORCE )
            set ( MPI_C_COMPILE_FLAGS   "/DOMPI_IMPORTS" CACHE STRING "" FORCE )
         endif ( )
      elseif ( WALBERLA_CXX_COMPILER_IS_CRAY )
      else ( )
         message ( WARNING "Found MPI Compiler but no Libraries -> invent a new workaround" )
      endif ( )
859
860
861
   endif ( )

   if ( MPI_FOUND )
862
863
864
865
     include_directories ( SYSTEM ${MPI_CXX_INCLUDE_PATH} ${MPI_C_INCLUDE_PATH} )
     foreach( LIB ${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES} )
         if ( LIB )
            list ( APPEND SERVICE_LIBS ${LIB} )
866
         endif ( )
867
868
869
     endforeach ( )
     add_flag ( CMAKE_CXX_FLAGS "${MPI_CXX_COMPILE_FLAGS}" )
     add_flag ( CMAKE_C_FLAGS   "${MPI_C_COMPILE_FLAGS}" )
870

871
872
873
874
875
     add_flag ( CMAKE_MODULE_LINKER_FLAGS "${MPI_CXX_LINK_FLAGS}" )
     add_flag ( CMAKE_EXE_LINKER_FLAGS    "${MPI_CXX_LINK_FLAGS}" )
     add_flag ( CMAKE_SHARED_LINKER_FLAGS "${MPI_CXX_LINK_FLAGS}" )
   endif ( )
endif ( )
876
877
878
879

# OpenMPI 3.0 and higher checks the number of processes against the number of CPUs
execute_process(COMMAND ${MPIEXEC} --version RESULT_VARIABLE mpi_version_result OUTPUT_VARIABLE mpi_version_output)
if (mpi_version_result EQUAL 0 AND mpi_version_output MATCHES "\\(Open(RTE| MPI)\\) ([3-9]\\.|1[0-9])")
880
    set ( MPIEXEC_PREFLAGS "${MPIEXEC_PREFLAGS}" "-oversubscribe" CACHE STRING "" FORCE)
881
endif()
882
883
884
885
886
887
888
889
890
891
892
893
894
895
############################################################################################################################



############################################################################################################################
##
## Qt
##
############################################################################################################################
option (WALBERLA_ENABLE_GUI "This flag builds the graphical user interface, depends on Qt Libraries")

if ( WALBERLA_ENABLE_GUI )

    find_package( Qt4 COMPONENTS QtCore QtGui QtOpenGL QtXml REQUIRED )
896
    set( OpenGL_GL_PREFERENCE LEGACY )
897
    find_package( OpenGL REQUIRED )
898

899
900
    INCLUDE( ${QT_USE_FILE} )
    list ( APPEND SERVICE_LIBS ${OPENGL_LIBRARIES} ${QT_LIBRARIES} )
901

902
903
    # Workaround for Qt4 moc and newer boost versions - moc cannot parse BOOST_JOIN
    # so additional defines are passed to the moc compiler that prevent the problematic header to be parsed
904
905
    set( QT_MOC_EXECUTABLE ${QT_MOC_EXECUTABLE} -DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED )

906
907
908
909
910
911
912
913
914
915
916
917
918
919
endif(WALBERLA_ENABLE_GUI)

############################################################################################################################



############################################################################################################################
##
## METIS
##
############################################################################################################################

if ( WALBERLA_BUILD_WITH_METIS )
    find_package ( Metis QUIET )
920

921
    if ( METIS_FOUND )
922
        include_directories( ${METIS_INCLUDE_DIRS} )
923
924
925
926
927
928
929
        link_directories   ( ${METIS_LIBRARY_DIR}  )
        list ( APPEND SERVICE_LIBS ${METIS_LIBRARIES} )
        set  ( WALBERLA_BUILD_WITH_METIS TRUE )
    else()
        set  ( WALBERLA_BUILD_WITH_METIS OFF CACHE BOOL "Build with metis graph partitioner" FORCE )
    endif()
else()
930
    set ( METIS_FOUND OFF CACHE BOOL "Metis found" FORCE )
931
932
endif()

933
934
935
936
937
938
939
940

if ( WALBERLA_BUILD_WITH_PARMETIS )
   find_path(PARMETIS_INCLUDE_DIR parmetis.h
      /usr/local/include
      /usr/include
      ${PARMETIS_ROOT}/include
      $ENV{PARMETIS_ROOT}/include
   )
941

942
943
944
945
946
947
  find_library(PARMETIS_LIBRARY parmetis
    /usr/local/lib
    /usr/lib
    ${PARMETIS_ROOT}/lib
    $ENV{PARMETIS_ROOT}/lib
  )
948

949
950
951
952
953
954
  if( PARMETIS_INCLUDE_DIR AND PARMETIS_LIBRARY AND METIS_LIBRARY )
    include_directories( ${PARMETIS_INCLUDE_DIR} )
    list ( APPEND SERVICE_LIBS ${PARMETIS_LIBRARY} ${METIS_LIBRARY} )
  endif()
endif()

955
956
957
958
959
960
961
962
963
964
965
966
967
968
############################################################################################################################



############################################################################################################################
##
## FFTW3
##
############################################################################################################################

if( WALBERLA_BUILD_WITH_MPI )
   find_package( PFFT )
   find_package( FFTW3 )
   set( FFT_REQUIRED_LIBRARIES pfft fftw3_mpi fftw3 )
969
   if( PFFT_FOUND AND FFTW3_MPI_FOUND )
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
      set( WALBERLA_BUILD_WITH_FFT TRUE CACHE INTERNAL "Build with FFT" )
      include_directories( SYSTEM ${PFFT_INCLUDE_DIR} ${FFTW3_MPI_INCLUDE_DIR} )
      list( APPEND SERVICE_LIBS ${PFFT_LIBRARIES} ${FFTW3_LIBRARIES} ${FFTW3_MPI_LIBRARIES} )
   endif()
else()
   find_package( FFTW3 )
   set( FFT_REQUIRED_LIBRARIES fftw3 )
   if ( FFTW3_FOUND )
      set( WALBERLA_BUILD_WITH_FFT TRUE CACHE INTERNAL "Build with FFT" )
      include_directories( SYSTEM ${FFTW3_INCLUDE_DIR} )
      list( APPEND SERVICE_LIBS ${FFTW3_LIBRARIES} )
   endif()
endif()



986
987
988
989
990
991
992
993
994
995
996
############################################################################################################################
##
## OpenMesh
##
############################################################################################################################
if( (NOT DEFINED WALBERLA_BUILD_WITH_OPENMESH) OR WALBERLA_BUILD_WITH_OPENMESH )
   find_package( OpenMesh )
   if( OPENMESH_FOUND )
      set( WALBERLA_BUILD_WITH_OPENMESH ON CACHE BOOL "Build with OpenMesh support" )
      include_directories( SYSTEM ${OPENMESH_INCLUDE_DIRS} )
      list( APPEND SERVICE_LIBS ${OPENMESH_LIBRARIES} )
Christian Godenschwager's avatar
Christian Godenschwager committed
997
998
999
      if( WALBERLA_CXX_COMPILER_IS_MSVC )
         add_definitions(-D_USE_MATH_DEFINES )
      endif()
1000
1001
1002
1003
1004
   else()
      set( WALBERLA_BUILD_WITH_OPENMESH OFF CACHE BOOL "Build with OpenMesh support" FORCE )
   endif()
endif()

1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
############################################################################################################################
##
## DebugOptimized Build Configuration for fast execution of tests with enabled asserts
##
############################################################################################################################

set( CMAKE_C_FLAGS_DEBUGOPTIMIZED             ${CMAKE_C_FLAGS_DEBUG}             )
set( CMAKE_CXX_FLAGS_DEBUGOPTIMIZED           ${CMAKE_CXX_FLAGS_DEBUG}           )
set( CMAKE_EXE_LINKER_FLAGS_DEBUGOPTIMIZED    ${CMAKE_EXE_LINKER_FLAGS_DEBUG}    )
set( CMAKE_SHARED_LINKER_FLAGS_DEBUGOPTIMIZED ${CMAKE_SHARED_LINKER_FLAGS_DEBUG} )
set( CMAKE_MODULE_LINKER_FLAGS_DEBUGOPTIMIZED ${CMAKE_MODULE_LINKER_FLAGS_DEBUG} )

set_property(GLOBAL PROPERTY DEBUG_CONFIGURATIONS Debug DebugOptimized)

if ( WALBERLA_CXX_COMPILER_IS_MSVC )
    string(REPLACE "/Od" "/O2"   CMAKE_C_FLAGS_DEBUGOPTIMIZED   ${CMAKE_C_FLAGS_DEBUGOPTIMIZED})
    string(REPLACE "/Ob0" "/Ob2" CMAKE_C_FLAGS_DEBUGOPTIMIZED   ${CMAKE_C_FLAGS_DEBUGOPTIMIZED})
    string(REPLACE "/RTC1" ""    CMAKE_C_FLAGS_DEBUGOPTIMIZED   ${CMAKE_C_FLAGS_DEBUGOPTIMIZED})
    string(REPLACE "/Od" "/O2"   CMAKE_CXX_FLAGS_DEBUGOPTIMIZED ${CMAKE_CXX_FLAGS_DEBUGOPTIMIZED})
    string(REPLACE "/Ob0" "/Ob2" CMAKE_CXX_FLAGS_DEBUGOPTIMIZED ${CMAKE_CXX_FLAGS_DEBUGOPTIMIZED})
    string(REPLACE "/RTC1" ""    CMAKE_CXX_FLAGS_DEBUGOPTIMIZED ${CMAKE_CXX_FLAGS_DEBUGOPTIMIZED})
elseif( WALBERLA_CXX_COMPILER_IS_GNU OR WALBERLA_CXX_COMPILER_IS_INTEL OR WALBERLA_CXX_COMPILER_IS_CLANG )
1027
1028
   set( CMAKE_C_FLAGS_DEBUGOPTIMIZED   "${CMAKE_C_FLAGS_DEBUGOPTIMIZED} -O3" )
   set( CMAKE_CXX_FLAGS_DEBUGOPTIMIZED "${CMAKE_CXX_FLAGS_DEBUGOPTIMIZED} -O3" )
1029
1030
endif()

1031
set(CMAKE_C_FLAGS_DEBUGOPTIMIZED ${CMAKE_C_FLAGS_DEBUGOPTIMIZED} CACHE STRING
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
    "Flags used by the compiler during DebugOptimized builds")
set(CMAKE_CXX_FLAGS_DEBUGOPTIMIZED ${CMAKE_CXX_FLAGS_DEBUGOPTIMIZED}  CACHE STRING
    "Flags used by the compiler during DebugOptimized builds")
set(CMAKE_EXE_LINKER_FLAGS_DEBUGOPTIMIZED ${CMAKE_EXE_LINKER_FLAGS_DEBUGOPTIMIZED} CACHE STRING
    "Flags used by the linker for executables during DebugOptimized builds")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUGOPTIMIZED ${CMAKE_SHARED_LINKER_FLAGS_DEBUGOPTIMIZED} CACHE STRING
    "Flags used by the linker for shared libraries during DebugOptimized builds")
set(CMAKE_MODULE_LINKER_FLAGS_DEBUGOPTIMIZED ${CMAKE_MODULE_LINKER_FLAGS_DEBUGOPTIMIZED} CACHE STRING
    "Flags used by the linker for loadable modules during DebugOptimized builds")

mark_as_advanced(
    CMAKE_C_FLAGS_DEBUGOPTIMIZED
    CMAKE_CXX_FLAGS_DEBUGOPTIMIZED
    CMAKE_EXE_LINKER_FLAGS_DEBUGOPTIMIZED
    CMAKE_SHARED_LINKER_FLAGS_DEBUGOPTIMIZED
    CMAKE_MODULE_LINKER_FLAGS_DEBUGOPTIMIZED
)

# This variable is only set for multi-config IDE generators like VC
if( CMAKE_CONFIGURATION_TYPES )
    list( APPEND CMAKE_CONFIGURATION_TYPES DebugOptimized )
    list( REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES )
    set ( CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}"
          CACHE STRING "Semicolon separated list of supported types
                      [Debug|Release|MinSizeRel|RelWithDebInfo|ReleaseNoOutfiles|DebugOptimized]" FORCE )
endif()
############################################################################################################################




1063

1064
1065
1066
1067
1068
1069
1070
1071
1072
############################################################################################################################
##
## OpenMP
##
############################################################################################################################

option ( WALBERLA_THREAD_SAFE_LOGGING "Enables/Disables thread-safe logging" ON )

if ( WALBERLA_BUILD_WITH_OPENMP )
1073
1074
1075
1076
1077
1078
    if ( WALBERLA_CXX_COMPILER_IS_INTEL AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "16.0.3" )
       add_flag ( CMAKE_C_FLAGS   "-openmp" )
       add_flag ( CMAKE_CXX_FLAGS "-openmp" )
    elseif ( WALBERLA_CXX_COMPILER_IS_NEC )
       add_flag ( CMAKE_C_FLAGS   "-Popenmp" )
       add_flag ( CMAKE_CXX_FLAGS "-Popenmp" )
1079
    else()
1080
1081
1082
1083
       find_package( OpenMP )
       add_flag ( CMAKE_C_FLAGS   "${OpenMP_C_FLAGS}" )
       add_flag ( CMAKE_CXX_FLAGS "${OpenMP_CXX_FLAGS}" )
       list ( APPEND SERVICE_LIBS ${OpenMP_CXX_LIBRARIES} )
1084
1085
1086
    endif()
else()
    if ( WALBERLA_CXX_COMPILER_IS_CRAY )
1087
1088
       add_flag ( CMAKE_C_FLAGS   "-h noomp" )
       add_flag ( CMAKE_CXX_FLAGS "-h noomp" )
1089
1090
1091
1092
1093
1094
    endif()
endif()
############################################################################################################################



Martin Bauer's avatar
Martin Bauer committed
1095
1096
1097
1098
1099
1100
############################################################################################################################
##
## CUDA
##
############################################################################################################################
if ( WALBERLA_BUILD_WITH_CUDA )
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
    include(CheckLanguage)
    check_language(CUDA)
    if( CMAKE_CUDA_COMPILER )
      enable_language(CUDA)

      #include directories and cudart lib is needed for cpp files that use cuda headers/libs
      include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
      find_library(CUDART_LIBRARY cudart ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
      list ( APPEND SERVICE_LIBS ${CUDART_LIBRARY} )

      #TODO: check if this is really needed? is it possible that nvtx is missing?
      find_library( NVTX_LIBRARY nvToolsExt ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES} )
      if( NVTX_LIBRARY )
          set( WALBERLA_CUDA_NVTX_AVAILABLE 1)
          list ( APPEND SERVICE_LIBS ${NVTX_LIBRARY} )
      endif()
Martin Bauer's avatar
Martin Bauer committed
1117

1118
1119
      #CUDA_FOUND is need for our cmake mechanism
      set ( CUDA_FOUND TRUE )
Martin Bauer's avatar
Martin Bauer committed
1120
    else()
1121
      set ( WALBERLA_BUILD_WITH_CUDA FALSE )
Martin Bauer's avatar
Martin Bauer committed
1122
1123
1124
1125
1126
1127
    endif ( )
endif ( )
############################################################################################################################



1128
1129
############################################################################################################################
##
1130
##  Testing Coverage
1131
1132
1133
##
############################################################################################################################
if (WALBERLA_BUILD_WITH_GCOV AND CMAKE_COMPILER_IS_GNUCXX  )
1134
    add_flag ( CMAKE_CXX_FLAGS "--coverage" )
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
endif()
############################################################################################################################



############################################################################################################################
##
##  Profiling with gprof
##
############################################################################################################################

if ( WALBERLA_BUILD_WITH_GPROF )
    if ( WALBERLA_CXX_COMPILER_IS_INTEL )
1148
        add_flag ( CMAKE_CXX_FLAGS        "-pg" )
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
        add_flag ( CMAKE_EXE_LINKER_FLAGS "-pg" )
    elseif ( WALBERLA_CXX_COMPILER_IS_GNU OR WALBERLA_CXX_COMPILER_IS_CLANG )
        add_flag ( CMAKE_CXX_FLAGS        "-pg" )
    endif()
endif()
############################################################################################################################


############################################################################################################################
##
##  Likwid Marker API
##
############################################################################################################################


if ( WALBERLA_BUILD_WITH_LIKWID_MARKERS )
1165
1166
    find_library( LIKWID_LIB likwid HINTS $ENV{LIKWID_LIBDIR} $ENV{LIKWID_ROOT}/lib )
    find_path( LIKWID_INCLUDE_DIR likwid.h HINTS $ENV{LIKWID_INCDIR} $ENV{LIKWID_ROOT}/include )
1167

1168
    if ( LIKWID_LIB AND LIKWID_INCLUDE_DIR)
1169
        set( LIKWID_FOUND 1)
1170
        include_directories( ${LIKWID_INCLUDE_DIR})
1171
        add_definitions ( "-DLIKWID_PERFMON" )
1172
        list ( APPEND SERVICE_LIBS ${LIKWID_LIB} )
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
    else()
        message(WARNING "likwid marker library not found. Set environment variable LIKWID_ROOT")
        set ( WALBERLA_BUILD_WITH_LIKWID_MARKERS OFF CACHE BOOL "Compile in markers for likwid-perfctr" FORCE )
    endif()
endif()



############################################################################################################################
##
##  Link time optimizations
##
############################################################################################################################
if ( WALBERLA_BUILD_WITH_LTO  )
1187

1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
   if( WALBERLA_CXX_COMPILER_IS_INTEL )
      add_flag( CMAKE_CXX_FLAGS_RELEASE "-ip -ipo3" )
      add_flag( CMAKE_C_FLAGS_RELEASE   "-ip -ipo3" )
   endif()

   if ( CMAKE_COMPILER_IS_GNUCXX )
      add_flag ( CMAKE_C_FLAGS_RELEASE     "-flto=3" )
      add_flag ( CMAKE_CXX_FLAGS_RELEASE   "-flto=3" )
      add_flag ( CMAKE_EXE_LINKER_FLAGS    "-fuse-linker-plugin" )
   endif ( )
1198

1199
1200
1201
1202
1203
1204
   if( WALBERLA_CXX_COMPILER_IS_MSVC )
      add_flag ( CMAKE_CXX_FLAGS_RELEASE           "/GL"   )
      add_flag ( CMAKE_EXE_LINKER_FLAGS_RELEASE    "/LTCG" )
      add_flag ( CMAKE_SHARED_LINKER_FLAGS_RELEASE "/LTCG" )
      add_flag ( CMAKE_MODULE_LINKER_FLAGS_RELEASE "/LTCG" )
   endif ( )
1205

1206
1207
1208
1209
   if( WALBERLA_CXX_COMPILER_IS_IBM )
      add_flag ( CMAKE_C_FLAGS_RELEASE     "-qipa" )
      add_flag ( CMAKE_CXX_FLAGS_RELEASE   "-qipa" )
      add_flag ( CMAKE_EXE_LINKER_FLAGS    "-qipa" )
1210
1211
   endif( )

1212
endif ( )
Michael Kuron's avatar
Michael Kuron committed
1213
1214
1215
1216
1217

############################################################################################################################
##
##  Some more compiler flags that need to happen after any try_compile (e.g. inside FindMPI)
##
1218
1219
############################################################################################################################

Michael Kuron's avatar
Michael Kuron committed
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
# Treat warnings as errors
if ( WARNING_ERROR )
   if( WALBERLA_CXX_COMPILER_IS_GNU OR WALBERLA_CXX_COMPILER_IS_INTEL OR WALBERLA_CXX_COMPILER_IS_CLANG )
      add_flag ( CMAKE_CXX_FLAGS "-pedantic-errors -Werror" )
   elseif( WALBERLA_CXX_COMPILER_IS_MSVC )
      add_flag ( CMAKE_CXX_FLAGS "/WX" )
   elseif ( WALBERLA_CXX_COMPILER_IS_CRAY )
      add_flag ( CMAKE_CXX_FLAGS "-h error_on_warning" )
   endif()
endif ( )

1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
############################################################################################################################
##
##  Sanitizer
##
############################################################################################################################
if ( WALBERLA_SANITIZE_ADDRESS )
    if ( WALBERLA_CXX_COMPILER_IS_GNU OR WALBERLA_CXX_COMPILER_IS_CLANG )
        add_flag( CMAKE_CXX_FLAGS "-fsanitize=address")
    endif()
endif()
1241

1242
1243
1244
1245
1246
if ( WALBERLA_SANITIZE_UNDEFINED )
    if ( WALBERLA_CXX_COMPILER_IS_GNU OR WALBERLA_CXX_COMPILER_IS_CLANG )
        add_flag( CMAKE_CXX_FLAGS "-fsanitize=undefined")
    endif()
endif()
1247
1248
1249
1250

############################################################################################################################
# Documentation Generation
#
1251
1252
1253
1254
1255
if (WALBERLA_BUILD_DOC)
  # Build documentation using Doxygen (www.doxygen.org)
  ############################################################################################################################
  find_package ( Doxygen  )
  find_package ( HTMLHelp )
1256

1257
1258
1259
1260
1261
  if ( HTML_HELP_COMPILER EQUAL "" )
     set ( HTML_HELP_FOUND "NO" )
  else ( )
     set ( HTML_HELP_FOUND "YES" )
  endif ( )
1262

1263
1264
1265
1266
  if ( DOXYGEN_FOUND )
     set ( DOXYGEN_HTML_HEADER ${walberla_SOURCE_DIR}/doc/header.html )
     set ( DOXYGEN_HTML_FOOTER ${walberla_SOURCE_DIR}/doc/footer.html )
     set ( DOXYGEN_HTML_OUTPUT "html" )
1267

1268
1269
1270
1271
1272
1273
1274
     configure_file ( ${walberla_SOURCE_DIR}/doc/doxygen.in ${walberla_BINARY_DIR}/doc/doxygen.cfg @ONLY )

     add_custom_target ( doc   ${DOXYGEN_EXECUTABLE} ${walberla_BINARY_DIR}/doc/doxygen.cfg
                            COMMENT "Generating API documentation with Doxygen" VERBATIM )

  endif ( )
endif()
1275

1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
############################################################################################################################





############################################################################################################################
#
# Fix compiler bugs
#
############################################################################################################################

# The NEC SX has a few issues in its standard library headers
if( WALBERLA_CXX_COMPILER_IS_NEC )
   file( WRITE ${walberla_BINARY_DIR}/CMakeFiles/src/math.h         "#include_next <math.h>\n#undef fpclassify\n#undef signbit\n#undef isfinite\n#undef isinf\n#undef isnan\n#undef isnormal\n#undef isgreater\n#undef isgreaterequal\n#undef isless\n#undef islessequal\n#undef islessgreater\n#undef isunordered\n")
   file( WRITE ${walberla_BINARY_DIR}/CMakeFiles/src/sys/types.h    "#define uint_t SX_UINT_T\n#include \"/SX/usr/include/sys/types.h\"   \n#undef uint_t\n")
   file( WRITE ${walberla_BINARY_DIR}/CMakeFiles/src/sys/acl.h      "#define uint_t SX_UINT_T\n#include \"/SX/usr/include/sys/acl.h\"     \n#undef uint_t\n")
   file( WRITE ${walberla_BINARY_DIR}/CMakeFiles/src/sys/if_ehcpl.h "#define uint_t SX_UINT_T\n#include \"/SX/usr/include/sys/if_ehcpl.h\"\n#undef uint_t\n")
   file( WRITE ${walberla_BINARY_DIR}/CMakeFiles/src/sys/ptms.h     "#define uint_t SX_UINT_T\n#include \"/SX/usr/include/sys/ptms.h\"    \n#undef uint_t\n")
   file( WRITE ${walberla_BINARY_DIR}/CMakeFiles/src/sys/stream.h   "#define uint_t SX_UINT_T\n#include \"/SX/usr/include/sys/stream.h\"  \n#undef uint_t\n")
   file( WRITE ${walberla_BINARY_DIR}/CMakeFiles/src/sys/strsubr.h  "#define uint_t SX_UINT_T\n#include \"/SX/usr/include/sys/strsubr.h\" \n#undef uint_t\n")
   configure_file ( ${walberla_BINARY_DIR}/CMakeFiles/src/math.h         ${walberla_BINARY_DIR}/src/math.h COPYONLY )
   configure_file ( ${walberla_BINARY_DIR}/CMakeFiles/src/sys/types.h    ${walberla_BINARY_DIR}/src/sys/types.h    COPYONLY )
   configure_file ( ${walberla_BINARY_DIR}/CMakeFiles/src/sys/acl.h      ${walberla_BINARY_DIR}/src/sys/acl.h      COPYONLY )
   configure_file ( ${walberla_BINARY_DIR}/CMakeFiles/src/sys/if_ehcpl.h ${walberla_BINARY_DIR}/src/sys/if_ehcpl.h COPYONLY )
   configure_file ( ${walberla_BINARY_DIR}/CMakeFiles/src/sys/ptms.h     ${walberla_BINARY_DIR}/src/sys/ptms.h     COPYONLY )
   configure_file ( ${walberla_BINARY_DIR}/CMakeFiles/src/sys/stream.h   ${walberla_BINARY_DIR}/src/sys/stream.h   COPYONLY )
   configure_file ( ${walberla_BINARY_DIR}/CMakeFiles/src/sys/strsubr.h  ${walberla_BINARY_DIR}/src/sys/strsubr.h  COPYONLY )
endif()



############################################################################################################################
#
# Subdirectories
#
############################################################################################################################

# Add binary dir for generated headers
include_directories ( ${CMAKE_CURRENT_BINARY_DIR}/src )
1316
# All include paths are specified relative to src/ directory
1317
1318
1319
1320
include_directories ( ${CMAKE_CURRENT_SOURCE_DIR}/src )


# Generate file with compile options, and add install rule for it
1321
configure_file ( src/waLBerlaDefinitions.in.h
1322
                 src/waLBerlaDefinitions.h    )
1323

1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
install( FILES ${walberla_BINARY_DIR}/src/waLBerlaDefinitions.h DESTINATION walberla/ )

# sources
add_subdirectory ( src )

# test
if ( WALBERLA_BUILD_TESTS )
    add_subdirectory ( tests )
else()
    add_subdirectory( tests EXCLUDE_FROM_ALL )
endif()


add_subdirectory ( apps )

waLBerla_export()

############################################################################################################################
1342
1343
1344
1345
1346
1347
1348
1349

############################################################################################################################
##
## clang-tidy
##
############################################################################################################################

waLBerla_link_files_to_builddir( .clang-tidy )
1350
add_subdirectory( utilities )