-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
CMakeLists.txt
679 lines (549 loc) · 21 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
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
215
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
282
283
284
285
286
287
288
289
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
INCLUDE(CMakeDependentOption)
INCLUDE(cmake/modules/macros.cmake)
INCLUDE(CheckCSourceCompiles)
PROJECT (parmmg)
LIST(APPEND CMAKE_MODULE_PATH
${PROJECT_SOURCE_DIR}/cmake/modules
${PROJECT_SOURCE_DIR}/cmake/testing )
# Must use GNUInstallDirs to install libraries into correct
# locations on all platforms.
include(GNUInstallDirs)
###############################################################################
#####
##### Release version and date
#####
###############################################################################
SET (CMAKE_RELEASE_VERSION_MAJOR "1")
SET (CMAKE_RELEASE_VERSION_MINOR "5")
SET (CMAKE_RELEASE_VERSION_PATCH "0")
SET (CMAKE_RELEASE_DATE "Nov. 01, 2024")
SET (CMAKE_RELEASE_VERSION
"${CMAKE_RELEASE_VERSION_MAJOR}.${CMAKE_RELEASE_VERSION_MINOR}.${CMAKE_RELEASE_VERSION_PATCH}")
###############################################################################
#####
##### Main CMake compilation variables
#####
###############################################################################
SET(PMMG_BINARY_DIR ${PROJECT_BINARY_DIR}/src/parmmg)
SET(PMMG_SHRT_INCLUDE parmmg )
SET(PMMG_INCLUDE ${PROJECT_BINARY_DIR}/include/${PMMG_SHRT_INCLUDE} )
FILE(MAKE_DIRECTORY ${PMMG_BINARY_DIR})
# Create pmmgversion.h file with the release infos
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/src/pmmgversion.h.in
${PMMG_BINARY_DIR}/pmmgversion.h @ONLY)
# To see flags and options of compilation
#SET(CMAKE_VERBOSE_MAKEFILE TRUE)
# Executable path
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
SET(PMMG_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)
LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
# Find "exotic" compilers
IF (${CMAKE_C_COMPILER} MATCHES Clang OR ${CMAKE_C_COMPILER} MATCHES clang)
# using clang
SET(CMAKE_COMPILER_IS_CLANG TRUE)
ELSEIF(${CMAKE_C_COMPILER} MATCHES Icc OR ${CMAKE_C_COMPILER} MATCHES icc)
# using icc
SET(CMAKE_COMPILER_IS_INTEL TRUE)
ENDIF()
# Hide some options
MARK_AS_ADVANCED(CMAKE_OSX_ARCHITECTURES
CMAKE_OSX_DEPLOYMENT_TARGET
CMAKE_OSX_SYSROOT)
include(add_build_types)
IF(CMAKE_COMPILER_IS_GNUCC)
IF(APPLE)
# Add flags to the compiler to work on old mac
ADD_DEFINITIONS( -mmacosx-version-min=10.4 -arch x86_64)
# To avoid pbs with binary files...
SET(CMAKE_EXE_LINKER_FLAGS "-arch x86_64 ${CMAKE_EXE_LINKER_FLAGS} ")
# Determine if the processor supports 64bit execution
EXECUTE_PROCESS(
COMMAND sysctl hw.cpu64bit_capable
ERROR_QUIET
OUTPUT_VARIABLE 64_CMD
OUTPUT_STRIP_TRAILING_WHITESPACE
)
STRING(REGEX REPLACE "^hw.cpu64bit_capable: (.*)" "\\1" 64_BIT "${64_CMD}")
# ELSEIF(UNIX)# UNIX must be after APPLE becaus APPLE is UNIX too
ENDIF()
ENDIF()
IF(NOT CMAKE_COMPILER_IS_CLANG)
# Compiler options for profiling... but not possible with clang
OPTION ( PROFILING "Enable/Disable PROFILING" OFF )
IF(PROFILING)
ADD_DEFINITIONS(-pg)
SET(CMAKE_EXE_LINKER_FLAGS "-pg ${CMAKE_EXE_LINKER_FLAGS}")
ENDIF(PROFILING)
ENDIF(NOT CMAKE_COMPILER_IS_CLANG)
###############################################################################
#####
##### Choose executable target to compile
#####
###############################################################################
IF(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
MESSAGE(STATUS "Setting build type to 'Release' as none was specified.")
seT(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
SET(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} )
ENDIF()
# Explicitly set the DNDEBUG flag in case the user or a parent project overrides
# it.
if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-DNDEBUG)
endif()
#------------------------------- static or shared libs
FUNCTION (INVERT_BOOL OUTVAR INVAR)
IF(${INVAR})
SET(${OUTVAR} OFF PARENT_SCOPE)
ELSE()
SET(${OUTVAR} ON PARENT_SCOPE)
ENDIF()
ENDFUNCTION()
OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF)
INVERT_BOOL("BUILD_STATIC_LIBS" ${BUILD_SHARED_LIBS})
IF ( (${BUILD_STATIC_LIBS} EQUAL ON) AND NOT CMAKE_POSITION_INDEPENDENT_CODE)
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
ENDIF()
SET ( LIBPARMMG_SHARED ${BUILD_SHARED_LIBS})
IF( NOT DEFINED LIBPARMMG_STATIC)
SET ( LIBPARMMG_STATIC ${BUILD_STATIC_LIBS})
ENDIF()
############################################################################
#####
##### MPI
#####
############################################################################
# compile parallel version
ENABLE_LANGUAGE ( Fortran )
FIND_PACKAGE( MPI COMPONENTS C CXX OPTIONAL_COMPONENTS Fortran )
SET( CMAKE_C_COMPILE_FLAGS "${CMAKE_C_COMPILE_FLAGS} ${MPI_COMPILE_FLAGS}" )
SET( CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} ${MPI_LINK_FLAGS}" )
SET( CMAKE_CXX_COMPILE_FLAGS "${CMAKE_CXX_COMPILE_FLAGS} ${MPI_COMPILE_FLAGS}" )
SET( CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} ${MPI_LINK_FLAGS}" )
INCLUDE_DIRECTORIES( ${MPI_INCLUDE_PATH} )
# openmpi is bugged (deadlocks) : warn the user
EXECUTE_PROCESS ( COMMAND grep "OMPI_MAJOR_VERSION" "${MPI_C_INCLUDE_PATH}/mpi.h"
RESULT_VARIABLE CMD_ERROR
OUTPUT_VARIABLE CMD_OUTPUT )
IF ( ${CMD_ERROR} MATCHES 0 )
SET ( OMPI_LIST ${CMD_OUTPUT} )
separate_arguments(OMPI_LIST)
list(LENGTH OMPI_LIST ompi_list_len)
MATH(EXPR ompi_list_len "${ompi_list_len}-1")
list ( GET OMPI_LIST ${ompi_list_len} OMPI_MAJOR_VERSION )
IF ( OMPI_MAJOR_VERSION VERSION_LESS 4 )
MESSAGE(WARNING "Possible deadlocks with version <= 3 of open-mpi
(see https://github.com/open-mpi/ompi/issues/6568 )...")
ENDIF()
ENDIF()
SET( CMAKE_C_FLAGS "-DUSE_MPI ${CMAKE_C_FLAGS}" )
SET( CMAKE_CXX_FLAGS "-DUSE_MPI ${CMAKE_CXX_FLAGS}" )
MESSAGE( STATUS "Compilation with mpi" )
SET( LIBRARIES ${MPI_C_LIBRARIES} ${LIBRARIES} )
SET( LIBRARIES ${MPI_CXX_LIBRARIES} ${LIBRARIES} )
EXECUTE_PROCESS ( COMMAND ${MPIEXEC} --oversubscribe sleep 1
RESULT_VARIABLE CMD_ERROR
OUTPUT_VARIABLE CMD_OUTPUT )
IF ( "${CMD_ERROR}" MATCHES "0" )
SET ( MPI_ARGS "-oversubscribe" )
ENDIF()
# Check the minimum MPI version
SET ( CMAKE_REQUIRED_INCLUDES "${MPI_INCLUDE_PATH}" )
SET ( CMAKE_REQUIRED_LIBRARIES "${MPI_C_LIBRARIES}" )
CHECK_C_SOURCE_COMPILES( "
#include <stdio.h>
#include <stdint.h>
#include <mpi.h>
int main(int argc, char **argv) {
MPI_Comm comm_shm = 0;
MPI_Comm_split_type( MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL,
&comm_shm );
}
"
MPI3_TEST_COMPILES )
IF( NOT MPI3_TEST_COMPILES )
MESSAGE( FATAL_ERROR "ERROR: impossible to compile a simple MPI test program."
" Check your MPI library version:"
" ParMmg requires an MPI version >= 3.0.0.")
ENDIF ( )
############################################################################
#####
##### Search for optional libraries: scotch, vtk, linearelasticity
#####
############################################################################
INCLUDE(optional-dependencies)
############################################################################
#####
##### MMG (for mesh data structure)
#####
############################################################################
INCLUDE ( ExternalProject )
# forward scotch configuration
SET ( SCOTCH_CFG -DUSE_SCOTCH=${USE_SCOTCH} -DSCOTCH_DIR=${SCOTCH_DIR}
-DSCOTCH_scotch.h_DIRS=${SCOTCH_scotch.h_DIRS}
-DSCOTCH_scotch_LIBRARY=${SCOTCH_scotch_LIBRARY}
-DSCOTCH_scotcherrexit_LIBRARY=${SCOTCH_scotcherrexit_LIBRARY} )
IF ( VTK_FOUND )
# forward VTK config
SET ( VTK_CFG -DUSE_VTK=${USE_VTK} -DVTK_DIR=${VTK_DIR} )
ENDIF()
# forward compiler
SET ( COMPILER_CFG -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_Fortran_COMPILER=${CMAKE_Fortran_COMPILER} )
# forward flags
SET ( FLAGS_CFG -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_Fortran_FLAGS=${CMAKE_Fortran_FLAGS}
-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS} )
OPTION ( DOWNLOAD_MMG "Download and build automatically Mmg." ON )
IF ( DOWNLOAD_MMG )
UNSET(MMG_DIR CACHE)
# Use pointmap
OPTION ( USE_POINTMAP "Use map for point tracking" ON )
EXTERNALPROJECT_ADD ( Mmg
GIT_REPOSITORY https://github.com/MmgTools/mmg.git
GIT_TAG v5.8.0
INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install
CMAKE_ARGS ${MMG_ARGS} -DUSE_ELAS=OFF ${COMPILER_CFG} ${FLAGS_CFG}
${SCOTCH_CFG} ${VTK_CFG} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD=MMG3D -DBUILD_SHARED_LIBS=${LIBPARMMG_SHARED}
-DUSE_VTK=${USE_VTK} -DPMMG_CALL=1
-DMMG_INSTALL_PRIVATE_HEADERS=ON
-DUSE_POINTMAP=${USE_POINTMAP} -DCMAKE_INSTALL_PREFIX=../Mmg-install)
EXTERNALPROJECT_GET_PROPERTY ( Mmg BINARY_DIR )
SET ( MMG_BINARY_DIR ${BINARY_DIR} )
EXTERNALPROJECT_GET_PROPERTY ( Mmg SOURCE_DIR )
SET ( MMG_SOURCE_DIR ${SOURCE_DIR} )
SET (MMG_INSTALL_DIR ${SOURCE_DIR}/../Mmg-install)
SET (MMG_INCLUDE_DIRS ${MMG_INSTALL_DIR}/include )
EXTERNALPROJECT_ADD_STEP ( Mmg reconfigure
COMMAND ${CMAKE_COMMAND} -E remove ${MMG_BINARY_DIR}/CMakeCache.txt
DEPENDEES update
DEPENDERS configure )
IF( LIBPARMMG_SHARED )
SET(MMG3D_LIBRARY ${MMG_INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}/libmmg3d${CMAKE_SHARED_LIBRARY_SUFFIX})
ELSE()
# default behaviour is to link static libs
SET(MMG3D_LIBRARY ${MMG_INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}/libmmg3d${CMAKE_STATIC_LIBRARY_SUFFIX})
ENDIF()
MESSAGE(STATUS
"Compilation with Mmg: ${MMG3D_LIBRARY}")
SET( LIBRARIES ${MMG3D_LIBRARY} ${LIBRARIES})
ELSE ( )
UNSET ( USE_POINTMAP CACHE )
SET(MMG_DIR "" CACHE PATH "Installation or build directory for mmg")
MESSAGE ( STATUS "Manual installation of Mmg: please, build and install MMG"
" with MMG_INSTALL_PRIVATE_HEADERS option enabled and provide the path to"
" the install directory in the MMG_DIR variable of ParMmg." )
FIND_PACKAGE(MMG)
IF(NOT MMG_FOUND )
MESSAGE ( FATAL_ERROR "ERROR: The installation directory for mmg is required: "
"(see https://github.com/MmgTools/mmg and download the branch develop). "
"If you have already installed Mmg and want to use it, "
"please build Mmg with MMG_INSTALL_PRIVATE_HEADERS CMake "
"option enabled and set the MMG_DIR CMake variable or environment variable "
"to the mmg install directory.")
ELSE()
INCLUDE_DIRECTORIES(${MMG_INCLUDE_DIRS})
MESSAGE(STATUS
"Compilation with Mmg: ${MMG_LIBRARIES}")
SET( LIBRARIES ${MMG_LIBRARIES} ${LIBRARIES})
ENDIF ( )
ENDIF()
INCLUDE_DIRECTORIES(${MMG_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${MMG_INCLUDE_DIRS}/mmg/mmg3d)
INCLUDE_DIRECTORIES(${MMG_INCLUDE_DIRS}/mmg/common)
############################################################################
#####
##### Metis / ParMetis
#####
############################################################################
OPTION ( DOWNLOAD_METIS "Download and build automatically Metis/ParMetis." ON )
IF ( DOWNLOAD_METIS )
UNSET ( METIS_DIR CACHE )
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if (CMAKE_VERSION VERSION_GREATER "3.23.4")
cmake_policy(SET CMP0135 NEW)
endif()
# Metis
EXTERNALPROJECT_ADD ( Metis
URL ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/metis-5.1.0.tar.gz
URL_MD5 5465e67079419a69e0116de24fce58fe
UPDATE_COMMAND ""
CONFIGURE_COMMAND ${CMAKE_MAKE_PROGRAM} config prefix=../../../Metis-install
BUILD_IN_SOURCE 1
BUILD_COMMAND unset MFLAGS && unset MAKEFLAGS && unset MAKELEVEL && ${CMAKE_MAKE_PROGRAM}
INSTALL_COMMAND unset MFLAGS && unset MAKEFLAGS && unset MAKELEVEL && ${CMAKE_MAKE_PROGRAM} install
)
EXTERNALPROJECT_GET_PROPERTY(Metis SOURCE_DIR)
SET ( METIS_INSTALL_DIR ${SOURCE_DIR}/../Metis-install)
INCLUDE_DIRECTORIES(${METIS_INSTALL_DIR}/include)
SET ( METIS_LIBRARIES ${METIS_INSTALL_DIR}/lib/libmetis.a )
SET(CMAKE_C_FLAGS "-DUSE_METIS ${CMAKE_C_FLAGS}")
MESSAGE(STATUS
"Compilation with metis: ${METIS_LIBRARIES}")
SET( LIBRARIES ${METIS_LIBRARIES} ${LIBRARIES})
ELSE ( )
# add metis library?
SET(METIS_DIR "" CACHE PATH "Installation directory for metis")
FIND_PACKAGE(METIS)
IF( METIS_FOUND)
OPTION ( USE_METIS "Detected METIS Tool" ON)
IF( USE_METIS )
# Set flags for building test program
INCLUDE_DIRECTORIES(${METIS_INCLUDE_DIRS})
SET(CMAKE_C_FLAGS "-DUSE_METIS ${CMAKE_C_FLAGS}")
MESSAGE(STATUS
"Compilation with metis: ${METIS_LIBRARIES}")
SET( LIBRARIES ${METIS_LIBRARIES} ${LIBRARIES})
ENDIF()
ELSE ( )
MESSAGE(STATUS ${METIS_INCLUDE_DIR} ${METIS_LIBRARIES} )
MESSAGE ( ERROR " Metis library not found: "
"If you have already installed Metis and want to use it, "
"please set the CMake variable or environment variable METIS_DIR "
"to your metis directory.")
ENDIF ( )
IF ( NOT ${METIS_INTSIZE} EQUAL 4 )
MESSAGE ( WARNING "Metis integer uses ${METIS_INTSIZE} bytes."
" Only int32 are supported." )
ENDIF ( )
ENDIF ( )
############################################################################
#####
##### ParMetis
#####
############################################################################
# add parmetis library?
#SET(PARMETIS_DIR "" CACHE PATH "Installation directory for parmetis")
#FIND_PACKAGE(Parmetis)
#
#IF( PARMETIS_FOUND)
# OPTION ( USE_PARMETIS "Detected PARMETIS TOOL" ON)
# IF( USE_PARMETIS )
# # Set flags for building test program
# INCLUDE_DIRECTORIES(${PARMETIS_INCLUDE_DIRS})
#
# SET(CMAKE_C_FLAGS "-DUSE_PARMETIS ${CMAKE_C_FLAGS}")
#
# MESSAGE(STATUS
# "Compilation with parmetis: ${PARMETIS_LIBRARIES}")
# SET( LIBRARIES ${PARMETIS_LIBRARIES} ${LIBRARIES})
# ENDIF()
#ELSE ( )
# # MESSAGE(STATUS ${PARMETIS_INCLUDE_DIR} ${PARMETIS_LIBRARY} )
# #
# # MESSAGE ( ERROR " parmetis library not found: "
# # "If you have already installed ParMetis and want to use it, "
# # "please set the CMake variable or environment variable PARMETIS_DIR "
# # "to your parmetis directory.")
#ENDIF ( )
############################################################################
#####
##### Fortran header: libparmmgf.h
#####
############################################################################
ADD_EXECUTABLE(genheader_pmmg ${PROJECT_SOURCE_DIR}/scripts/genheader.c)
GENERATE_FORTRAN_HEADER ( pmmgtypes
${PMMG_SOURCE_DIR} libparmmgtypes.h
${PMMG_SHRT_INCLUDE}
${PMMG_BINARY_DIR} libparmmgtypesf.h
)
GENERATE_FORTRAN_HEADER ( pmmg
${PMMG_SOURCE_DIR} libparmmg.h
${PMMG_SHRT_INCLUDE}
${PMMG_BINARY_DIR} libparmmgf.h
)
###############################################################################
#####
##### Sources and libraries
#####
###############################################################################
# Header files
INCLUDE_DIRECTORIES(${PMMG_SOURCE_DIR})
# Source files
FILE(
GLOB
pmmg_library_files
${PMMG_SOURCE_DIR}/*.c
${PMMG_SOURCE_DIR}/*.cpp
)
LIST(REMOVE_ITEM pmmg_library_files
${PMMG_SOURCE_DIR}/parmmg.c
${REMOVE_FILE})
FILE(
GLOB
pmmg_main_file
${PMMG_SOURCE_DIR}/parmmg.c
)
IF (NOT WIN32)
FIND_LIBRARY(M_LIB m)
SET( LIBRARIES ${LIBRARIES} ${M_LIB})
ENDIF()
############################################################################
#####
##### RPATH for MacOSX
#####
############################################################################
SET(CMAKE_MACOSX_RPATH 1)
############################################################################
#####
##### Compile parmmg libraries
#####
############################################################################
SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
add_library( ParMmg INTERFACE )
IF ( LIBPARMMG_STATIC )
ADD_AND_INSTALL_LIBRARY ( lib${PROJECT_NAME}_a STATIC
"${pmmg_library_files}" ${PROJECT_NAME} )
target_link_libraries( ParMmg INTERFACE lib${PROJECT_NAME}_a )
IF ( DOWNLOAD_MMG )
Add_Dependencies(lib${PROJECT_NAME}_a Mmg)
ENDIF ( )
IF ( DOWNLOAD_METIS )
Add_Dependencies(lib${PROJECT_NAME}_a Metis)
ENDIF ( )
ENDIF()
# Compile shared library
IF ( LIBPARMMG_SHARED )
ADD_AND_INSTALL_LIBRARY ( lib${PROJECT_NAME}_so SHARED
"${pmmg_library_files}" ${PROJECT_NAME} )
target_link_libraries( ParMmg INTERFACE lib${PROJECT_NAME}_so )
IF ( DOWNLOAD_MMG )
Add_Dependencies(lib${PROJECT_NAME}_so Mmg)
ENDIF ( )
IF ( DOWNLOAD_METIS )
Add_Dependencies(lib${PROJECT_NAME}_so Metis)
ENDIF ( )
ENDIF()
add_library(ParMmg::ParMmg ALIAS ParMmg)
install(TARGETS ParMmg EXPORT ParMmgTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/parmmg
)
# parmmg header files needed for library
SET( pmmg_headers
${PMMG_SOURCE_DIR}/libparmmg.h
${PMMG_BINARY_DIR}/libparmmgf.h
${PMMG_SOURCE_DIR}/libparmmgtypes.h
${PMMG_BINARY_DIR}/libparmmgtypesf.h
${PMMG_BINARY_DIR}/pmmgversion.h
)
IF (NOT WIN32 OR MINGW)
LIST(APPEND pmmg_headers ${PMMG_BINARY_DIR}/git_log_pmmg.h )
ENDIF()
# Install header files in /usr/local or equivalent
INSTALL(FILES ${pmmg_headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/parmmg COMPONENT headers )
# Copy header files in project directory at every build step
COPY_HEADERS_AND_CREATE_TARGET ( ${PMMG_SOURCE_DIR} ${PMMG_BINARY_DIR} ${PMMG_INCLUDE} )
IF (LIBPARMMG_STATIC OR LIBPARMMG_SHARED)
SET(LIBPARMMG_INTERNAL ON )
ELSE()
SET(LIBPARMMG_INTERNAL OFF )
ENDIF()
if ( BUILD_SHARED_LIBS )
set(LIBPARMMG lib${PROJECT_NAME}_so)
else()
set(LIBPARMMG lib${PROJECT_NAME}_a)
endif()
install(EXPORT ParMmgTargets
FILE ParMmgTargets.cmake
NAMESPACE ParMmg::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/parmmg
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/ParMmgConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/ParMmgConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/parmmg"
)
# Install ParMmgConfig.cmake and ParMmgConfigVersion.cmake
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/ParMmgConfig.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/parmmg"
)
# Install ParMmgConfigVersion.cmake for version tracking
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/ParMmgConfigVersion.cmake"
VERSION ${CMAKE_RELEASE_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/ParMmgConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/parmmg"
)
###############################################################################
#####
##### Compile PMMG executable
#####
###############################################################################
ADD_AND_INSTALL_EXECUTABLE ( ${PROJECT_NAME}
"${pmmg_library_files}" ${pmmg_main_file} )
IF ( DOWNLOAD_MMG )
Add_Dependencies(${PROJECT_NAME} Mmg)
ENDIF ( )
IF ( DOWNLOAD_METIS )
Add_Dependencies(${PROJECT_NAME} Metis)
ENDIF ( )
############################################################################
#####
##### Print git hash to source file
#####
############################################################################
IF (NOT WIN32 OR MINGW)
ADD_CUSTOM_TARGET(GenerateGitHashParMmg
COMMAND ./git_log_pmmg.sh ${PROJECT_SOURCE_DIR} ${PMMG_BINARY_DIR}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/scripts/
COMMENT "Getting git commit hash"
)
ADD_DEPENDENCIES(${PROJECT_NAME} GenerateGitHashParMmg)
IF( LIBPARMMG_STATIC )
ADD_DEPENDENCIES(lib${PROJECT_NAME}_a GenerateGitHashParMmg)
ENDIF ()
IF( LIBPARMMG_SHARED )
ADD_DEPENDENCIES(lib${PROJECT_NAME}_so GenerateGitHashParMmg)
ENDIF ()
INCLUDE_DIRECTORIES(${PMMG_BINARY_DIR})
ENDIF ()
###############################################################################
#####
##### Create API Documentation
#####
###############################################################################
FIND_PACKAGE(Doxygen)
IF(DOXYGEN_FOUND)
# PARMMG Documentation
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/doc/doxygen/Doxyfile.in
${CMAKE_CURRENT_SOURCE_DIR}/doc/doxygen/Doxyfile @ONLY)
ADD_CUSTOM_TARGET(parmmg_doc
COMMAND ${DOXYGEN_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/doc/doxygen/Doxyfile
# COMMAND ${CMAKE_COMMAND} -E chdir
# ${CMAKE_CURRENT_SOURCE_DIR}/doc/doxygen/latex make
# COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/doc/doxygen/latex/refman.pdf
# ${CMAKE_CURRENT_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc/doxygen/
COMMENT "Generating PARMMG API documentation with Doxygen.
Open the doc/doxygen/html/index.html file to see it." VERBATIM
)
if ( NOT TARGET doc )
ADD_CUSTOM_TARGET(doc
DEPENDS parmmg_doc
COMMENT "Generating PARMMG API documentation with Doxygen.
Open the doc/doxygen/html/index.html file to see it" VERBATIM
)
else()
add_dependencies(doc parmmg_doc)
endif()
ENDIF ( DOXYGEN_FOUND )
OPTION ( BUILD_TESTING "Enable / Disable tests" OFF )
CMAKE_DEPENDENT_OPTION (
ONLY_LIBRARY_TESTS "Enable / Disable tests hosted outside the ParMmg repos
(non library tests)" OFF "BUILD_TESTING;LIBPARMMG_INTERNAL" OFF )
INCLUDE( ${PROJECT_SOURCE_DIR}/cmake/testing/pmmg_tests.cmake )