@@ -19,6 +19,7 @@ option(Idefix_PYTHON "Enable python bindings (requires pybind11)" OFF)
1919option (Idefix_MPI_GPU_DIRECT "Enable usage of GPU direct to avoid CPU-GPU copies for MPI messages." ON )
2020option (Idefix_MPI_GPU_FORCE_COPY "When GPU_DIRECT is disabled, force using transfers for validation purpose." OFF )
2121mark_as_advanced (Idefix_MPI_GPU_FORCE_TRANSFERS )
22+ option (Idefix_SUPPRESS_FMA "Disable FMA (fused multiply-add) contraction/codegen. Useful for code validation across architectures." OFF )
2223set (Idefix_PROBLEM_DIR "${CMAKE_BINARY_DIR } " CACHE STRING "Problem directory to build for." )
2324set (Idefix_CXX_FLAGS "" CACHE STRING "Additional compiler/linker flag" )
2425set (Idefix_DEFS "definitions.hpp" CACHE FILEPATH "Problem definition header file" )
@@ -49,6 +50,8 @@ include(ReplaceIdefixSource)
4950include (AddIdefixSource )
5051include (SetIdefixProperty )
5152include (SetRequiredBuildSettingsForGCC8 )
53+ include (CheckHdf5ParallelSupport )
54+ include (SuppressFMA )
5255
5356#Idefix requires Cuda Lambdas (experimental)
5457if (Kokkos_ENABLE_CUDA)
@@ -64,6 +67,8 @@ include_directories(${Kokkos_INCLUDE_DIRS_RET})
6467# Add Idefix CXX Flags
6568add_compile_options (${Idefix_CXX_FLAGS} )
6669
70+
71+
6772# Add filesystem libraries for GCC8
6873set_required_build_settings_for_GCC8 ()
6974
@@ -124,12 +129,25 @@ if(Idefix_HDF5)
124129 PUBLIC src/output/xdmf.cpp
125130 PUBLIC src/output/xdmf.hpp
126131 )
127- find_package (HDF5 REQUIRED )
128- target_link_libraries (idefix "${HDF5_LIBRARIES} " )
132+ # Prefer imported targets (matches older working behavior), then fall back.
133+ find_package (HDF5 QUIET COMPONENTS C )
134+ if (NOT HDF5_FOUND)
135+ find_package (HDF5 REQUIRED MODULE COMPONENTS C )
136+ endif ()
137+
138+ set (_idefix_hdf5_link_items "${HDF5_LIBRARIES} " )
139+ if (TARGET hdf5::hdf5)
140+ set (_idefix_hdf5_link_items hdf5::hdf5)
141+ elseif (TARGET HDF5::HDF5)
142+ set (_idefix_hdf5_link_items HDF5::HDF5)
143+ endif ()
144+
145+ target_link_libraries (idefix ${_idefix_hdf5_link_items} )
129146 message (STATUS "Found HDF5 include directories: ${HDF5_INCLUDE_DIRS} " )
130147 target_include_directories (idefix PUBLIC "${HDF5_INCLUDE_DIRS} " )
131148 if (Idefix_MPI)
132- if (NOT HDF5_IS_PARALLEL)
149+ CheckHdf5ParallelSupport ("${_idefix_hdf5_link_items} " )
150+ if (NOT IDEFIX_HDF5_IS_PARALLEL)
133151 message (FATAL_ERROR "Parallel HDF5 required for Idefix_MPI but the found HDF5 library does not support it" )
134152 endif ()
135153 endif ()
@@ -178,15 +196,15 @@ endif()
178196if (Idefix_EVOLVE_VECTOR_POTENTIAL)
179197 add_compile_definitions ("EVOLVE_VECTOR_POTENTIAL" )
180198endif ()
181- #update version.hpp if possible
199+
200+ # determine idefix version from git
182201git_describe (GIT_SHA1 )
183202set (Idefix_VERSION ${Idefix_VERSION_MAJOR} .${Idefix_VERSION_MINOR} .${Idefix_VERSION_PATCH} -${GIT_SHA1} )
184- file (WRITE ${CMAKE_SOURCE_DIR } /src/version.hpp "#define IDEFIX_GIT_COMMIT \" ${GIT_SHA1} \"\n " )
185- file (APPEND ${CMAKE_SOURCE_DIR } /src/version.hpp "#define IDEFIX_VERSION_MAJOR \" ${Idefix_VERSION_MAJOR} \"\n " )
186- file (APPEND ${CMAKE_SOURCE_DIR } /src/version.hpp "#define IDEFIX_VERSION_MINOR \" ${Idefix_VERSION_MINOR} \"\n " )
187- file (APPEND ${CMAKE_SOURCE_DIR } /src/version.hpp "#define IDEFIX_VERSION_PATCH \" ${Idefix_VERSION_PATCH} \"\n " )
188- file (APPEND ${CMAKE_SOURCE_DIR } /src/version.hpp "#define IDEFIX_VERSION \" ${Idefix_VERSION} \"\n " )
189-
203+ configure_file (
204+ ${CMAKE_SOURCE_DIR } /src/version.h.in
205+ ${CMAKE_BINARY_DIR } /build/generated/version.h
206+ @ONLY
207+ )
190208
191209if (NOT ${Idefix_DEFS} STREQUAL "definitions.hpp" )
192210 add_compile_definitions ("DEFINITIONS_FILE=\" ${Idefix_DEFS} \" " )
@@ -280,6 +298,21 @@ target_include_directories(idefix PUBLIC
280298
281299target_link_libraries (idefix Kokkos::kokkos )
282300
301+ # Generate header with compiler information (name, flags, path)
302+ configure_file (
303+ ${CMAKE_SOURCE_DIR } /src/compiler_info.h.in
304+ ${CMAKE_BINARY_DIR } /build/generated/compiler_info.h
305+ @ONLY
306+ )
307+ # Make sure the generated header is on the include path
308+ target_include_directories (idefix PRIVATE ${CMAKE_BINARY_DIR } /build/generated )
309+
310+ # disable FMA if needed
311+ if (Idefix_SUPPRESS_FMA)
312+ message (STATUS "FMA (fused multiply-add) contraction/codegen is disabled" )
313+ target_suppress_fma (idefix )
314+ endif ()
315+
283316message (STATUS "Idefix final configuration" )
284317if (Idefix_EVOLVE_VECTOR_POTENTIAL)
285318 message (STATUS " MHD: ${Idefix_MHD} (Vector potential)" )
0 commit comments