CMakeLists.txt 9.51 KB
Newer Older
1
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
lambrechts's avatar
lambrechts committed
2
3
4
5
6
7
8
## Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
  set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
  # Set the possible values of build type for cmake-gui
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
9
10
enable_language(C)
enable_language(CXX)
11
enable_language(Fortran)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
12
enable_testing()
13
14
option(ENABLE_MPI "Enable MPI" ON)
option(ENABLE_METIS "Enable METIS" ON)
15
option(ENABLE_MUMPS "Enable MUMPS" OFF)
Jonathan Lambrechts's avatar
petsc    
Jonathan Lambrechts committed
16
option(ENABLE_PETSC "Enable PETSc" ON)
17
option(ENABLE_PETSC4PY "Enable PETSc4Py" ON)
18
option(ENABLE_FUNCTIONC "ENABLE C CALLBACK" ON)
geuzaine's avatar
oops    
geuzaine committed
19
20

project(dg CXX)
21
22
23
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
24
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
geuzaine's avatar
oops    
geuzaine committed
25

26
27
include(ExternalProject)

Jonathan Lambrechts's avatar
petsc    
Jonathan Lambrechts committed
28
29
30
31
32
33
34
macro(set_dg_config_option VARNAME STRING)
  set(${VARNAME} TRUE)
  list(APPEND DG_CONFIG_OPTIONS " ${STRING}")
  message(STATUS "Found " ${STRING})
endmacro(set_dg_config_option)


35
36
37
38
39
40
41
42
43
44
45
46
47
if(ENABLE_MPI)
  find_package(MPI)
  if(MPI_FOUND)
   set_dg_config_option(HAVE_MPI "MPI")
    # this hack is only required for openmpi compiled with dynamic modules
    # unfortunately I do not know how to detect this situation => I always enable it
    set(DG_PYTHON_OPENMPI_HACK "import ctypes\n")
    FOREACH (lib ${MPI_C_LIBRARIES})
      IF (${lib} MATCHES ".*libmpi.*")
        set(DG_PYTHON_OPENMPI_HACK 
          "${DG_PYTHON_OPENMPI_HACK}ctypes.CDLL(\"${lib}\", mode = ctypes.RTLD_GLOBAL)\n")
      ENDIF (${lib} MATCHES ".*libmpi.*")
    ENDFOREACH (lib)
48
    list(APPEND EXTERNAL_LIBRARIES ${MPI_C_LIBRARIES})
49
    include_directories(${MPI_C_INCLUDE_PATH})
50
51
52
53
54
55
56
57
58
59
60
  endif(MPI_FOUND)
endif(ENABLE_MPI)

if(ENABLE_METIS)
  find_package(METIS)
  if (METIS_FOUND)
    set_dg_config_option(HAVE_METIS "METIS")
    include_directories(${METIS_INCLUDE_DIRS})
    list(APPEND EXTERNAL_LIBRARIES ${METIS_LIBRARIES})
  endif(METIS_FOUND)
endif(ENABLE_METIS)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
61

bertrand's avatar
bertrand committed
62
63
64
65
66
67
68
69
if(ENABLE_OPENMP)
   find_package(OpenMP)
   if (OPENMP_FOUND)
     set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
     set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
   endif(OPENMP_FOUND)
endif(ENABLE_OPENMP)

Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
70
71
72
73
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)
list(APPEND EXTERNAL_LIBRARIES ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})

Jonathan Lambrechts's avatar
petsc    
Jonathan Lambrechts committed
74
if(ENABLE_PETSC)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
75
76
  find_package(PETSc)
  if(PETSC_FOUND)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
77
    find_package(PythonInterp)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
78
    set_dg_config_option(HAVE_PETSC "PETSc")
Jonathan Lambrechts's avatar
petsc    
Jonathan Lambrechts committed
79
    list(APPEND EXTERNAL_LIBRARIES ${PETSC_LIBS})
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
80
    list(APPEND EXTERNAL_INCLUDES ${PETSC_INC})
81
82
83
84
85
86
87
88
89
90
91
92
93
    if(ENABLE_PETSC4PY)
      EXECUTE_PROCESS(
        COMMAND ${PYTHON_EXECUTABLE} -c "import petsc4py; print(petsc4py.get_include())"
        OUTPUT_VARIABLE PETSC4PY_INC
        RESULT_VARIABLE PETSC4PY_NOT_FOUND
        ERROR_QUIET
        OUTPUT_STRIP_TRAILING_WHITESPACE
      )
      if(PETSC4PY_INC)
        list(APPEND EXTERNAL_INCLUDES ${PETSC4PY_INC})
        set_dg_config_option(HAVE_PETSC4PY "PETSc4py")
      endif(PETSC4PY_INC)
    endif(ENABLE_PETSC4PY)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
94
  endif(PETSC_FOUND)
Jonathan Lambrechts's avatar
petsc    
Jonathan Lambrechts committed
95
endif(ENABLE_PETSC)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
96

97
if(ENABLE_MUMPS)
98
  include(ExternalProject)
99
100
101
102
  list(APPEND EXTERNAL_LIBRARIES
    ${CMAKE_CURRENT_BINARY_DIR}/mumps/build/libdmumps.a
    ${CMAKE_CURRENT_BINARY_DIR}/mumps/build/libmumps_common.a
    ${CMAKE_CURRENT_BINARY_DIR}/mumps/build/libpord.a
103
    -lgfortran
104
    ${BLAS_LIBRARIES}
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
    )
   list(APPEND EXTERNAL_INCLUDES
     ${CMAKE_CURRENT_BINARY_DIR}/mumps/src/MUMPS/src
     ${CMAKE_CURRENT_BINARY_DIR}/mumps/src/MUMPS/include
     ${CMAKE_CURRENT_BINARY_DIR}/mumps/src/MUMPS/PORD/include
     )
   if(HAVE_MPI)
     ExternalProject_Add(
        scalapack
        URL http://www.netlib.org/scalapack/scalapack-2.0.2.tgz
        URL_MD5 2f75e600a2ba155ed9ce974a1c4b536f
        CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_Fortran_FLAGS=-fPIC -DCMAKE_C_FLAGS=-fPIC -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
        INSTALL_COMMAND ""
        PREFIX scalapack
        BINARY_DIR scalapack/build
     )
     ExternalProject_Add(
       MUMPS
       URL http://mumps.enseeiht.fr/MUMPS_5.0.1.tar.gz
       URL_MD5 b477573fdcc87babe861f62316833db0
       PATCH_COMMAND ${CMAKE_COMMAND} -E copy
           "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists-mumps.txt" <SOURCE_DIR>/CMakeLists.txt
           CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DENABLE_MPI=TRUE
       INSTALL_COMMAND ""
       PREFIX mumps
       BINARY_DIR mumps/build
     )
     list(APPEND EXTERNAL_LIBRARIES ${MPI_Fortran_LIBRARIES})
     list(APPEND EXTERNAL_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/scalapack/build/lib/libscalapack.a)
   else(HAVE_MPI)
     ExternalProject_Add(
       MUMPS
       URL http://mumps.enseeiht.fr/MUMPS_5.0.1.tar.gz
       URL_MD5 b477573fdcc87babe861f62316833db0
       PATCH_COMMAND ${CMAKE_COMMAND} -E copy
           "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists-mumps.txt" <SOURCE_DIR>/CMakeLists.txt
           CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
       INSTALL_COMMAND ""
       PREFIX mumps
       BINARY_DIR mumps/build
     )
     list(APPEND EXTERNAL_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/mumps/build/libmpiseq.a)
     list(APPEND EXTERNAL_INCLUDES ${CMAKE_CURRENT_BINARY_DIR}/mumps/src/MUMPS/mpiseq)
   endif(HAVE_MPI)
   set_dg_config_option(HAVE_MUMPS "MUMPS")
endif(ENABLE_MUMPS)

152
153
154
155
156
157
find_library(REALTIME_LIB rt)
if (REALTIME_LIB)
  list(APPEND EXTERNAL_LIBRARIES ${REALTIME_LIB})
  set_dg_config_option(HAVE_REALTIME "RealTime")
endif (REALTIME_LIB)

lambrechts's avatar
lambrechts committed
158
159
160
161
162
163
164
macro(dg_add_source FILES)
  foreach(FILE ${FILES})
    list(APPEND LIST ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
  endforeach(FILE)
  set(DG_SRC ${DG_SRC};${LIST} PARENT_SCOPE)
endmacro(dg_add_source)

Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
165
include(dgpy/dgpy.cmake)
lambrechts's avatar
lambrechts committed
166

lambrechts's avatar
lambrechts committed
167
168
169
macro(dg_add_test_directory directory email)
  get_filename_component(ABSPATH ${directory} ABSOLUTE)
  string(REPLACE "${CMAKE_SOURCE_DIR}/" "" RELPATH "${ABSPATH}")
lambrechts's avatar
lambrechts committed
170
171
172
  file(COPY ${directory} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
  file(GLOB sub-dir RELATIVE ${ABSPATH} ${directory}/*)
  foreach(testn ${sub-dir})
lambrechts's avatar
lambrechts committed
173
174
    if (EXISTS ${CMAKE_BINARY_DIR}/${RELPATH}/${testn}/test.py)
      add_test(NAME ${RELPATH}/${testn} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${RELPATH}/${testn} COMMAND ${CMAKE_BINARY_DIR}/rundgpy test.py)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
175
      set_tests_properties(${RELPATH}/${testn} PROPERTIES TIMEOUT 600)
lambrechts's avatar
lambrechts committed
176
    endif()
lambrechts's avatar
lambrechts committed
177
  endforeach()
lambrechts's avatar
lambrechts committed
178
179
endmacro(dg_add_test_directory)

180
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dgConfig.h.in
lambrechts's avatar
lambrechts committed
181
182
               ${CMAKE_CURRENT_BINARY_DIR}/dgConfig.h)

Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
183
184
185
186

include_directories(${EXTERNAL_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR}
  mesh numeric tools dofContainer function linearSystem conservationLaw timeIntegrator limiter)

Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
187
add_subdirectory(mesh)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
188
189
190
191
192
193
194
195
196
197
198
199
add_subdirectory(conservationLaw)
add_subdirectory(dofContainer)
add_subdirectory(numeric)
add_subdirectory(function)
add_subdirectory(limiter)
add_subdirectory(linearSystem)
add_subdirectory(timeIntegrator)
add_subdirectory(tools)


macro(dg_add_module_ module FILES)
  add_library(${module} SHARED ${FILES})
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
200
  set_target_properties(${module} PROPERTIES COMPILE_FLAGS "-Wall -pedantic -DFORTIFY_SOURCE=1 -Wno-unknown-pragmas -Wno-long-long -Wno-literal-suffix -Wno-unused-result" LINK_FLAGS "-Wall")
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
201
202
203
204
205
206
207
208
209
210
211
  if(LAPACK_LINKER_FLAGS)
    set_target_properties(${module} PROPERTIES LINK_FLAGS ${LAPACK_LINKER_FLAGS})
  endif(LAPACK_LINKER_FLAGS)
  if(BLAS_LINKER_FLAGS)
    set_target_properties(${module} PROPERTIES LINK_FLAGS ${BLAS_LINKER_FLAGS})
  endif(BLAS_LINKER_FLAGS)
endmacro(dg_add_module_)

dg_add_module_(dg "${DG_SRC}")
target_link_libraries(dg ${EXTERNAL_LIBRARIES})

212
213
214
215
216
217
218
if(ENABLE_MUMPS)
  add_dependencies(dg MUMPS)
  if(HAVE_MPI)
    add_dependencies(MUMPS scalapack)
  endif(HAVE_MPI)
endif(ENABLE_MUMPS)

Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
219
macro(dg_add_module module FILES LIBS)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
220
  dg_add_module_(${module} "${FILES}")
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
221
  target_link_libraries(${module} dg ${EXTERNAL_LIBRARIES} ${LIBS})
222
223
  list(APPEND DG_MODULES ${module})
  set(DG_MODULES ${DG_MODULES} PARENT_SCOPE)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
224
225
endmacro(dg_add_module)

Sébastien Blaise's avatar
Sébastien Blaise committed
226
add_subdirectory(modules/atmosphere)
Jonathan Lambrechts's avatar
HOmesh    
Jonathan Lambrechts committed
227
228
229
230
231
232
add_subdirectory(modules/sweNonHydro)
add_subdirectory(modules/elastodynamics)
add_subdirectory(modules/generic)
add_subdirectory(modules/lee)
add_subdirectory(modules/maxwell)
add_subdirectory(modules/navierStokesIncomp)
233
#add_subdirectory(modules/particle)
Jonathan Lambrechts's avatar
HOmesh    
Jonathan Lambrechts committed
234
add_subdirectory(modules/perfectGas)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
235
add_subdirectory(modules/shallowWater)
Sébastien Blaise's avatar
Sébastien Blaise committed
236
add_subdirectory(modules/slim3d)
Jonathan Lambrechts's avatar
HOmesh    
Jonathan Lambrechts committed
237
238
239
240
241
add_subdirectory(modules/slimFunction)
add_subdirectory(modules/slimIce)
add_subdirectory(modules/subsurface)
add_subdirectory(modules/supra)
add_subdirectory(modules/wave)
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
242

243
add_subdirectory(dgpy)
lambrechts's avatar
lambrechts committed
244
configure_file(rundgpy ${CMAKE_CURRENT_BINARY_DIR}/rundgpy @ONLY)
245
configure_file(dgftpupload ${CMAKE_CURRENT_BINARY_DIR}/dgftpupload @ONLY)
246
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dgConfig.h.in
247
248
               ${CMAKE_CURRENT_BINARY_DIR}/dgConfig.h)

Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
249
250
251
252
253
254
255
256
257
258
259
set (EXTERNAL_LIBRARIES_COMMAND_LINE "")
FOREACH(lib ${EXTERNAL_LIBRARIES})
  IF ("${lib}" MATCHES "^[-/].*")
    set (EXTERNAL_LIBRARIES_COMMAND_LINE "${EXTERNAL_LIBRARIES_COMMAND_LINE} ${lib}")
  ELSE()
    set (EXTERNAL_LIBRARIES_COMMAND_LINE "${EXTERNAL_LIBRARIES_COMMAND_LINE} -l${lib}")
  ENDIF()
ENDFOREACH(lib)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/external_libraries.make.in 
               ${CMAKE_CURRENT_BINARY_DIR}/external_libraries.make)

260

Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
261
message("Dg has been configured with the following options: " ${DG_CONFIG_OPTIONS})
262
include(cmake/windows_package.cmake)