Skip to content

Commit 5e9529b

Browse files
committed
ENH: Address part of @angus-g review
1 parent cff3100 commit 5e9529b

File tree

7 files changed

+54
-81
lines changed

7 files changed

+54
-81
lines changed

CMakeLists.txt

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ project(fluidity
55
LANGUAGES C CXX Fortran
66
)
77

8+
function(build_unittest_executable unittest_sources)
9+
foreach(unittest_source ${unittest_sources})
10+
get_filename_component(unittest ${unittest_source} NAME_WE)
11+
12+
add_executable(${unittest} ${unittest_source} test_main.cpp)
13+
set_target_properties(${unittest}
14+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/tests
15+
)
16+
target_compile_definitions(${unittest} PUBLIC TESTNAME=${unittest}_)
17+
target_link_libraries(${unittest} fluidity)
18+
endforeach()
19+
endfunction()
20+
821
if(NOT CMAKE_BUILD_TYPE)
922
set(CMAKE_BUILD_TYPE Release CACHE STRING "Set build type; \
1023
typical values include Debug, Release, RelWithDebInfo and MinSizeRel." FORCE
@@ -13,8 +26,6 @@ elseif(CMAKE_BUILD_TYPE STREQUAL Debug)
1326
set(DDEBUG DDEBUG)
1427
endif()
1528

16-
set(CMAKE_PREFIX_PATH $ENV{PETSC_DIR}/$ENV{PETSC_ARCH})
17-
1829
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
1930
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
2031
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
@@ -39,7 +50,19 @@ find_package(MPI REQUIRED C CXX Fortran)
3950
find_package(HDF5 REQUIRED Fortran)
4051

4152
# Check for VTK
42-
find_package(VTK REQUIRED)
53+
find_package(VTK REQUIRED
54+
CommonCore
55+
CommonDataModel
56+
FiltersCore
57+
FiltersGeneral
58+
FiltersVerdict
59+
IOLegacy
60+
IOCore
61+
IOImage
62+
IOParallelXML
63+
IOXML
64+
ParallelMPI
65+
)
4366

4467
# Check for Python 3
4568
find_package(Python3 REQUIRED Interpreter Development NumPy)
@@ -50,11 +73,15 @@ find_package(Python3 REQUIRED Interpreter Development NumPy)
5073
# Check for CGAL
5174
find_package(CGAL QUIET)
5275
if(CGAL_FOUND)
53-
set(HAVE_LIBCGAL HAVE_LIBCGAL)
54-
set(CGAL_IMPORTED_TARGET CGAL::CGAL)
76+
message(STATUS "Found CGAL ${CGAL_VERSION}")
5577
endif()
5678

5779
# Check for PETSc
80+
if(DEFINED ENV{PETSC_ARCH})
81+
set(CMAKE_PREFIX_PATH $ENV{PETSC_DIR}/$ENV{PETSC_ARCH})
82+
else()
83+
set(CMAKE_PREFIX_PATH $ENV{PETSC_DIR})
84+
endif()
5885
pkg_search_module(PETSC REQUIRED IMPORTED_TARGET PETSc)
5986
message(STATUS "Found PETSc ${PETSC_VERSION}")
6087

@@ -67,8 +94,10 @@ pkg_search_module(NETCDF REQUIRED netcdf)
6794
message(STATUS "Found NetCDF ${NETCDF_VERSION}")
6895

6996
# Check for TCMalloc
70-
pkg_search_module(TCMALLOC REQUIRED libtcmalloc)
71-
message(STATUS "Found TCMalloc ${TCMALLOC_VERSION}")
97+
pkg_search_module(TCMALLOC QUIET libtcmalloc)
98+
if(TCMALLOC_FOUND)
99+
message(STATUS "Found TCMalloc ${TCMALLOC_VERSION}")
100+
endif()
72101

73102
# Check for UDUNITS
74103
pkg_search_module(UDUNITS REQUIRED udunits)
@@ -78,16 +107,13 @@ message(STATUS "Found UDUNITS ${UDUNITS_VERSION}")
78107
pkg_search_module(LIBSUPERMESH QUIET libsupermesh)
79108
if(LIBSUPERMESH_FOUND)
80109
message(STATUS "Found libsupermesh ${LIBSUPERMESH_VERSION}")
81-
set(HAVE_LIBSUPERMESH HAVE_LIBSUPERMESH)
82110
endif()
83111

84112
# Check for ExodusII
85113
find_library(EXODUSII_LIBRARY exoIIv2c)
114+
find_path(EXODUSII_INCLUDE_DIR exodusII.h)
86115
if(EXODUSII_LIBRARY)
87-
set(HAVE_LIBEXOIIV2C HAVE_LIBEXOIIV2C)
88-
find_path(EXODUSII_INCLUDE_DIR exodusII.h REQUIRED)
89-
else()
90-
unset(EXODUSII_LIBRARY CACHE)
116+
message(STATUS "Found ExodusII")
91117
endif()
92118

93119
# Add libspatialindex
@@ -214,6 +240,7 @@ file(WRITE "${CMAKE_BINARY_DIR}/include/vtk.h"
214240
#include <vtkIdList.h>
215241
#include <vtkImageData.h>
216242
#include <vtkIntArray.h>
243+
#include <vtkMPICommunicator.h>
217244
#include <vtkMPIController.h>
218245
#include <vtkPointData.h>
219246
#include <vtkPointLocator.h>
@@ -298,11 +325,11 @@ target_compile_definitions(fluidity PUBLIC
298325
# HAVE_HYPERLIGHT
299326
HAVE_HYPRE
300327
# HAVE_LIBARPACK
301-
${HAVE_LIBCGAL}
302-
${HAVE_LIBEXOIIV2C}
328+
$<$<BOOL:${CGAL_FOUND}>:HAVE_LIBCGAL>
329+
$<$<BOOL:${EXODUSII_LIBRARY}>:HAVE_LIBEXOIIV2C>
303330
HAVE_LIBNETCDF
304-
${HAVE_LIBSUPERMESH}
305-
HAVE_LIBTCMALLOC
331+
$<$<BOOL:${LIBSUPERMESH_FOUND}>:HAVE_LIBSUPERMESH>
332+
$<$<BOOL:${LIBTCMALLOC_FOUND}>:HAVE_LIBTCMALLOC>
306333
HAVE_LIBUDUNITS
307334
HAVE_MEMORY_STATS
308335
HAVE_MBA_2D
@@ -332,7 +359,7 @@ target_include_directories(fluidity PUBLIC
332359
${PETSC_INCLUDE_DIRS}
333360
${NETCDF_INCLUDE_DIRS}
334361

335-
${EXODUSII_INCLUDE_DIR}
362+
$<$<BOOL:${EXODUSII_INCLUDE_DIR}>:${EXODUSII_INCLUDE_DIR}>
336363

337364
${libspatialindex_SOURCE_DIR}/include
338365
${libjudy_SOURCE_DIR}/src
@@ -351,17 +378,17 @@ target_link_libraries(fluidity
351378
${VTK_LIBRARIES}
352379
${Python3_LIBRARIES}
353380
# ${OpenMP_Fortran_LIBRARIES}
354-
${CGAL_IMPORTED_TARGET}
381+
$<TARGET_NAME_IF_EXISTS:CGAL::CGAL>
355382

356383
PkgConfig::PETSC
357384
${PETSC_STATIC_LDFLAGS}
358385
# ${ARPACK_STATIC_LDFLAGS}
359386
${NETCDF_STATIC_LDFLAGS}
360-
${TCMALLOC_STATIC_LDFLAGS}
387+
$<$<BOOL:${TCMALLOC_STATIC_LDFLAGS}>:${TCMALLOC_STATIC_LDFLAGS}>
361388
${UDUNITS_STATIC_LDFLAGS}
362-
${LIBSUPERMESH_STATIC_LDFLAGS}
389+
$<$<BOOL:${LIBSUPERMESH_STATIC_LDFLAGS}>:${LIBSUPERMESH_STATIC_LDFLAGS}>
363390

364-
${EXODUSII_LIBRARY}
391+
$<$<BOOL:${EXODUSII_LIBRARY}>:${EXODUSII_LIBRARY}>
365392
)
366393
vtk_module_autoinit(TARGETS fluidity MODULES ${VTK_LIBRARIES})
367394

assemble/tests/CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,4 @@ set(unittest_sources
2828
test_vertical_prolongation_operator.F90
2929
)
3030

31-
foreach(unittest_source ${unittest_sources})
32-
get_filename_component(unittest ${unittest_source} NAME_WE)
33-
34-
add_executable(${unittest} ${unittest_source} test_main.cpp)
35-
set_target_properties(${unittest}
36-
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/tests
37-
)
38-
target_compile_definitions(${unittest} PUBLIC TESTNAME=${unittest}_)
39-
target_link_libraries(${unittest} fluidity)
40-
endforeach()
31+
cmake_language(CALL build_unittest_executable "${unittest_sources}")

error_measures/tests/CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,4 @@ set(unittest_sources
6666
test_warp_directions.F90
6767
)
6868

69-
foreach(unittest_source ${unittest_sources})
70-
get_filename_component(unittest ${unittest_source} NAME_WE)
71-
72-
add_executable(${unittest} ${unittest_source} test_main.cpp)
73-
set_target_properties(${unittest}
74-
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/tests
75-
)
76-
target_compile_definitions(${unittest} PUBLIC TESTNAME=${unittest}_)
77-
target_link_libraries(${unittest} fluidity)
78-
endforeach()
69+
cmake_language(CALL build_unittest_executable "${unittest_sources}")

femtools/tests/CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,4 @@ set(unittest_sources
149149
test_wandzura_quadrature.F90
150150
)
151151

152-
foreach(unittest_source ${unittest_sources})
153-
get_filename_component(unittest ${unittest_source} NAME_WE)
154-
155-
add_executable(${unittest} ${unittest_source} test_main.cpp)
156-
set_target_properties(${unittest}
157-
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/tests
158-
)
159-
target_compile_definitions(${unittest} PUBLIC TESTNAME=${unittest}_)
160-
target_link_libraries(${unittest} fluidity)
161-
endforeach()
152+
cmake_language(CALL build_unittest_executable "${unittest_sources}")

horizontal_adaptivity/tests/CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,4 @@ set(unittest_sources
55
test_metric_based_extrusion.F90
66
)
77

8-
foreach(unittest_source ${unittest_sources})
9-
get_filename_component(unittest ${unittest_source} NAME_WE)
10-
11-
add_executable(${unittest} ${unittest_source} test_main.cpp)
12-
set_target_properties(${unittest}
13-
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/tests
14-
)
15-
target_compile_definitions(${unittest} PUBLIC TESTNAME=${unittest}_)
16-
target_link_libraries(${unittest} fluidity)
17-
endforeach()
8+
cmake_language(CALL build_unittest_executable "${unittest_sources}")

ocean_forcing/tests/CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,4 @@ set(unittest_sources
66
test_ncar_ocean_fluxes.cpp
77
)
88

9-
foreach(unittest_source ${unittest_sources})
10-
get_filename_component(unittest ${unittest_source} NAME_WE)
11-
12-
add_executable(${unittest} ${unittest_source} test_main.cpp)
13-
set_target_properties(${unittest}
14-
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/tests
15-
)
16-
target_compile_definitions(${unittest} PUBLIC TESTNAME=${unittest}_)
17-
target_link_libraries(${unittest} fluidity)
18-
endforeach()
9+
cmake_language(CALL build_unittest_executable "${unittest_sources}")

parameterisation/tests/CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,4 @@ set(unittest_sources
33
test_tensor_inner_product.F90
44
)
55

6-
foreach(unittest_source ${unittest_sources})
7-
get_filename_component(unittest ${unittest_source} NAME_WE)
8-
9-
add_executable(${unittest} ${unittest_source} test_main.cpp)
10-
set_target_properties(${unittest}
11-
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/tests
12-
)
13-
target_compile_definitions(${unittest} PUBLIC TESTNAME=${unittest}_)
14-
target_link_libraries(${unittest} fluidity)
15-
endforeach()
6+
cmake_language(CALL build_unittest_executable "${unittest_sources}")

0 commit comments

Comments
 (0)